diff --git a/LICENSE b/LICENSE deleted file mode 100644 index e771730..0000000 --- a/LICENSE +++ /dev/null @@ -1,14 +0,0 @@ -Copyright (c) 2015, Chad Engler - -Permission to use, copy, modify, and/or distribute this software for any purpose with -or without fee is hereby granted, provided that the above copyright notice and this -permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD -TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN -NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL -DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER -IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN -CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -Source: http://opensource.org/licenses/ISC diff --git a/Pixi_examples.jpg b/Pixi_examples.jpg deleted file mode 100644 index b648d23..0000000 Binary files a/Pixi_examples.jpg and /dev/null differ diff --git a/README.md b/README.md index 21bf1ad..9294b50 100644 --- a/README.md +++ b/README.md @@ -1,32 +1,29 @@ -# pixi-examples +# Pixi examples guidelines: # -Repository for the pixi.js v3 examples, available online [here](ghio). +<<<<<<< HEAD +This is the new repository for the pixi examples. +In the previous one, each example was a JavaScript file, we moved away from this and it is now an HTML file that can be opened on its own. +======= +Repository for the pixi.js v3 examples, available online [here](https://pixijs.github.io/examples/). +>>>>>>> origin/master -## Running +The iframe that displays the examples is **800 * 600**, consequently please avoid creating a renderer that is larger than these dimensions. -You can view the examples online [here][ghio]. If you want to run it locally you can clone the repository -or download the zip file. Then just run a server pointing to the root of this repo. -For example using the node [http-server][httpserver] module: +## How to run the project ## -```js -git clone git@github.com:pixijs/examples.git -cd examples/ +This micro-site is built using HTML and jQuery and can be run on your local server without additional requirements. -npm i && npm start -``` +## Project structure ## -## Contributing +All the examples are stored in the ``` required/examples ``` folder and loaded via the ``` manifest.json ``` file. -Ideally you will need to have [node][node] setup on your machine. +All the assets are stored in ``` required/examples/assets ```. -Then you can add a new example, modify the section's `_details.json`, and rebuild the manifest file: +Every sub-folder in the examples folder corresponds to a sub-menu in the website's sidebar. -```js -node generateManifest.js -``` -Your local copy of the website should then be updated automatically. +## How to create an example ## -[node]: http://nodejs.org/ -[ghio]: http://pixijs.github.io/examples -[httpserver]: https://www.npmjs.com/package/http-server +You can use the basic example as a template, it is located in ``` required/examples/basics/basic.html ```. +All you need to do is copy and paste this file to where you think your example belongs. +You can then come back to the browser and navigate to your file and start changing it. diff --git a/_assets2/bunnies/square_blue.png b/_assets2/bunnies/square_blue.png new file mode 100644 index 0000000..3188b50 Binary files /dev/null and b/_assets2/bunnies/square_blue.png differ diff --git a/_assets/bunny_square.png b/_assets2/bunnies/square_green.png similarity index 100% rename from _assets/bunny_square.png rename to _assets2/bunnies/square_green.png diff --git a/_site/css/app.css b/_site/css/app.css deleted file mode 100644 index 4e73171..0000000 --- a/_site/css/app.css +++ /dev/null @@ -1,341 +0,0 @@ -@import url(//fonts.googleapis.com/css?family=Open+Sans); - -body,html{ - margin: 0; - padding: 0; - border: 0; - font-size: 100%; - font: inherit; - vertical-align: baseline; - line-height: 1; - color : #393939; - font-family: 'Open Sans'; - background-color : #e2e2e2; -} - -a{ - color : #7669e9; - font-family: 'Open Sans'; - text-decoration: none; -} - -a:hover{ - text-decoration: underline; -} - -a:visited{ - text-decoration: underline; -} - -h1,h2{ - text-align: center; - color : #d0c8df; - font-family: 'Open Sans'; -} - -h1{ - font-size: 1.8rem; -} - -.marginTop{ - margin : 2rem 0; -} - - -.containerTop{ - background: url('../img/pixi_examples_bg.jpg') no-repeat; - background-size : 100% 870px; - width : 100%; - min-height : 770px; - margin : 0; -} - -.centred{ - max-width: 56.125428571rem; - margin : 0 auto; -} - -.liveView{ - padding: 5px; - box-sizing : border-box; - min-height: 600px; -} - -.themeSelect{ - display: none; -} -/* Important, makes the editor scale to fit !*/ -.CodeMirror { - border: 1px solid #eee; - height: auto; -} - -.codeRefresh button{ - background-color: transparent; - border : 0; - outline: none; - margin : 0 auto; - display: block; - z-index : 4; -} - -.codeRefresh button:active,.codeRefresh button:focus{ - background-color: transparent; - border : 0; - outline: none; -} - -.codeRefresh button:active .btn{ - margin-top : -3px; -} - -.codeRefresh .btn{ - margin : -1px auto 0 auto; - width : 78px; - height : 78px; - display: block; - background: url('../img/code_refresh_no_shadow.png') no-repeat; - background-size: cover; - cursor: pointer; - position: relative; - left : 17px; - top : 55px; - z-index: 7; -} - -.codeRefresh .shadow{ - width : 136px; - height : 139px; - margin : 0 auto; - background: url('../img/code_refresh_tab_new.png') no-repeat; - position : relative; - left : 17px; - z-index:2; - float : left; -} - -#example{ - width : 100%; - margin : 0 auto; -} - -#example iframe{ - display: block; - margin : 0 auto; - width: 820px; - height : 620px; - z-index : 1; -} - -.containerBottom{ - margin-top : -155px; - box-sizing : border-box; -} - -.downloadSection a{ - font-weight: bold; -} - -#version{ - margin-right : 1rem; -} - -.downloadSection a:hover{ - text-decoration: underline; -} - -footer{ - position: relative; - width: calc(100vw - 9px); - left: calc(-50vw + 50%); - height : 60px; - background: #393939; - color : white; - padding: 5px 0 5px 0px; - box-sizing : border-box; - line-height: 50px; /* the footer is 60px - 5px top and bottom -> 50px */ -} - -@media (max-width: 897px){ - footer{ - height : 120px; - } -} - -@media (max-width: 570px){ - footer{ - height : 180px; - } -} - -footer p{ - margin : 0; -} - -.copyright, .goodboy, .icons{ - display: inline-block; - vertical-align: middle; - line-height: 16px; -} - -.goodboy{ - margin-left: 15px; -} - -.copyright a{ - color : white; -} - -.icons{ - color: #fff; - font-size: 12px; - font-weight: bold; - margin-left: 3.8%; -} -/* These two are aligned */ -.icons, .copyright{ - margin-top: 0px; -} - -.icons a{ - color : white; - margin-left: 5px; -} - -.icons img{ - vertical-align: middle; - padding : 0px 2px; - box-sizing : border-box; -} - -footer .copyright{ - color: #fff; - font-size: 12px; - line-height: 16px; - margin-left : 20px; -} - -/* Nav section */ -nav{ - position: absolute; - top: 0; - left : 0; - width : 16rem; - overflow: hidden; - background : url('../img/nav_bg.png') repeat-y; - color : white; - z-index : 15; -} - -nav li a { - color : white; - text-decoration: none; -} - -nav li a:hover{ - color : #7669e9; -} - -nav ul{ - padding: 0; - margin: 0; -} - -#navList{ - margin-left : 13px; -} - -/*nav li:first{ - margin-left : 13px; -}*/ - -nav li{ - line-height : 21px; - list-style: none; -} - -nav li span{ - text-transform: uppercase; - font-family: 'Open Sans'; - margin: 8px 0 0 0; - color : #a590d2; - display : block; -} - -nav ul:last-child li:last-child{ - margin-bottom: 5px; -} - -nav img{ - margin-left : 2px; - margin-top : 5px; - display: inline-block; -} - - -#hamburger{ - cursor: pointer; - display: inline-block; - margin-left : 8px; - margin-top : 5px; -} - -nav.hidden{ - - -webkit-animation: scaleDown 0.8s forwards; /* Safari 4+ */ - -moz-animation: scaleDown 0.8s forwards; /* Fx 5+ */ - animation: scaleDown 0.8s forwards; /* IE 10+, Fx 29+ */ -} - -nav.show{ - - -webkit-animation: scaleUp 0.8s forwards; /* Safari 4+ */ - -moz-animation: scaleUp 0.8s forwards; /* Fx 5+ */ - animation: scaleUp 0.8s forwards; /* IE 10+, Fx 29+ */ - -} - -@-webkit-keyframes scaleUp { - 0%{ width : 2.6rem; - height : 2.8rem; - } - 40% {width : 17rem ; height : 2.8rem;} - 100% {width : 17rem; height : auto;} -} -@-moz-keyframes scaleUp { - 0%{ width : 2.6rem; - height : 2.8rem; - } - 40% {width : 17rem ; height : 2.8rem;} - 100% {width : 17rem; height : auto;} -} -@keyframes scaleUp { - 0%{ width : 17rem; - height : 2.8rem; - } - 40% {width : 17rem; height : 2.8rem;} - 100% {width : 17rem; height : auto;} -} - -@-webkit-keyframes scaleDown { - 0%{ width : 17rem; - height : 2.8rem; - } - 40% {width : 2.6rem;} - 100% {width : 2.6rem; height : 2.8rem;} -} -@-moz-keyframes scaleDown { - 0%{ width : 17rem; - height : 2.8rem; - } - 40% {width : 2.6rem;} - 100% {width : 2.6rem; height : 2.8rem;} -} -@keyframes scaleDown { - 0%{ width : 17rem; - height : 2.8rem; - } - 40% {width : 2.6rem;} - 100% {width : 2.6rem; height : 2.8rem;} -} - diff --git a/_site/css/codemirror/theme/ambiance.css b/_site/css/codemirror/theme/ambiance.css deleted file mode 100644 index afcf15a..0000000 --- a/_site/css/codemirror/theme/ambiance.css +++ /dev/null @@ -1,75 +0,0 @@ -/* ambiance theme for codemirror */ - -/* Color scheme */ - -.cm-s-ambiance .cm-keyword { color: #cda869; } -.cm-s-ambiance .cm-atom { color: #CF7EA9; } -.cm-s-ambiance .cm-number { color: #78CF8A; } -.cm-s-ambiance .cm-def { color: #aac6e3; } -.cm-s-ambiance .cm-variable { color: #ffb795; } -.cm-s-ambiance .cm-variable-2 { color: #eed1b3; } -.cm-s-ambiance .cm-variable-3 { color: #faded3; } -.cm-s-ambiance .cm-property { color: #eed1b3; } -.cm-s-ambiance .cm-operator {color: #fa8d6a;} -.cm-s-ambiance .cm-comment { color: #555; font-style:italic; } -.cm-s-ambiance .cm-string { color: #8f9d6a; } -.cm-s-ambiance .cm-string-2 { color: #9d937c; } -.cm-s-ambiance .cm-meta { color: #D2A8A1; } -.cm-s-ambiance .cm-qualifier { color: yellow; } -.cm-s-ambiance .cm-builtin { color: #9999cc; } -.cm-s-ambiance .cm-bracket { color: #24C2C7; } -.cm-s-ambiance .cm-tag { color: #fee4ff } -.cm-s-ambiance .cm-attribute { color: #9B859D; } -.cm-s-ambiance .cm-header {color: blue;} -.cm-s-ambiance .cm-quote { color: #24C2C7; } -.cm-s-ambiance .cm-hr { color: pink; } -.cm-s-ambiance .cm-link { color: #F4C20B; } -.cm-s-ambiance .cm-special { color: #FF9D00; } -.cm-s-ambiance .cm-error { color: #AF2018; } - -.cm-s-ambiance .CodeMirror-matchingbracket { color: #0f0; } -.cm-s-ambiance .CodeMirror-nonmatchingbracket { color: #f22; } - -.cm-s-ambiance .CodeMirror-selected { background: rgba(255, 255, 255, 0.15); } -.cm-s-ambiance.CodeMirror-focused .CodeMirror-selected { background: rgba(255, 255, 255, 0.10); } -.cm-s-ambiance.CodeMirror ::selection { background: rgba(255, 255, 255, 0.10); } -.cm-s-ambiance.CodeMirror ::-moz-selection { background: rgba(255, 255, 255, 0.10); } - -/* Editor styling */ - -.cm-s-ambiance.CodeMirror { - line-height: 1.40em; - color: #E6E1DC; - background-color: #202020; - -webkit-box-shadow: inset 0 0 10px black; - -moz-box-shadow: inset 0 0 10px black; - box-shadow: inset 0 0 10px black; -} - -.cm-s-ambiance .CodeMirror-gutters { - background: #3D3D3D; - border-right: 1px solid #4D4D4D; - box-shadow: 0 10px 20px black; -} - -.cm-s-ambiance .CodeMirror-linenumber { - text-shadow: 0px 1px 1px #4d4d4d; - color: #111; - padding: 0 5px; -} - -.cm-s-ambiance .CodeMirror-guttermarker { color: #aaa; } -.cm-s-ambiance .CodeMirror-guttermarker-subtle { color: #111; } - -.cm-s-ambiance .CodeMirror-lines .CodeMirror-cursor { - border-left: 1px solid #7991E8; -} - -.cm-s-ambiance .CodeMirror-activeline-background { - background: none repeat scroll 0% 0% rgba(255, 255, 255, 0.031); -} - -.cm-s-ambiance.CodeMirror, -.cm-s-ambiance .CodeMirror-gutters { - background-image: url("data:image/png;base64,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"); -} diff --git a/_site/css/codemirror/theme/monokai.css b/_site/css/codemirror/theme/monokai.css deleted file mode 100644 index 6dfcc73..0000000 --- a/_site/css/codemirror/theme/monokai.css +++ /dev/null @@ -1,33 +0,0 @@ -/* Based on Sublime Text's Monokai theme */ - -.cm-s-monokai.CodeMirror {background: #272822; color: #f8f8f2;} -.cm-s-monokai div.CodeMirror-selected {background: #49483E !important;} -.cm-s-monokai.CodeMirror ::selection { background: rgba(73, 72, 62, .99); } -.cm-s-monokai.CodeMirror ::-moz-selection { background: rgba(73, 72, 62, .99); } -.cm-s-monokai .CodeMirror-gutters {background: #272822; border-right: 0px;} -.cm-s-monokai .CodeMirror-guttermarker { color: white; } -.cm-s-monokai .CodeMirror-guttermarker-subtle { color: #d0d0d0; } -.cm-s-monokai .CodeMirror-linenumber {color: #d0d0d0;} -.cm-s-monokai .CodeMirror-cursor {border-left: 1px solid #f8f8f0 !important;} - -.cm-s-monokai span.cm-comment {color: #75715e;} -.cm-s-monokai span.cm-atom {color: #ae81ff;} -.cm-s-monokai span.cm-number {color: #ae81ff;} - -.cm-s-monokai span.cm-property, .cm-s-monokai span.cm-attribute {color: #a6e22e;} -.cm-s-monokai span.cm-keyword {color: #f92672;} -.cm-s-monokai span.cm-string {color: #e6db74;} - -.cm-s-monokai span.cm-variable {color: #a6e22e;} -.cm-s-monokai span.cm-variable-2 {color: #9effff;} -.cm-s-monokai span.cm-def {color: #fd971f;} -.cm-s-monokai span.cm-bracket {color: #f8f8f2;} -.cm-s-monokai span.cm-tag {color: #f92672;} -.cm-s-monokai span.cm-link {color: #ae81ff;} -.cm-s-monokai span.cm-error {background: #f92672; color: #f8f8f0;} - -.cm-s-monokai .CodeMirror-activeline-background {background: #373831 !important;} -.cm-s-monokai .CodeMirror-matchingbracket { - text-decoration: underline; - color: white !important; -} diff --git a/_site/css/codemirror/theme/neat.css b/_site/css/codemirror/theme/neat.css deleted file mode 100644 index 115083b..0000000 --- a/_site/css/codemirror/theme/neat.css +++ /dev/null @@ -1,12 +0,0 @@ -.cm-s-neat span.cm-comment { color: #a86; } -.cm-s-neat span.cm-keyword { line-height: 1em; font-weight: bold; color: blue; } -.cm-s-neat span.cm-string { color: #a22; } -.cm-s-neat span.cm-builtin { line-height: 1em; font-weight: bold; color: #077; } -.cm-s-neat span.cm-special { line-height: 1em; font-weight: bold; color: #0aa; } -.cm-s-neat span.cm-variable { color: black; } -.cm-s-neat span.cm-number, .cm-s-neat span.cm-atom { color: #3a3; } -.cm-s-neat span.cm-meta {color: #555;} -.cm-s-neat span.cm-link { color: #3a3; } - -.cm-s-neat .CodeMirror-activeline-background {background: #e8f2ff !important;} -.cm-s-neat .CodeMirror-matchingbracket {outline:1px solid grey; color:black !important;} diff --git a/_site/css/codemirror/theme/neo.css b/_site/css/codemirror/theme/neo.css deleted file mode 100644 index cecaaf2..0000000 --- a/_site/css/codemirror/theme/neo.css +++ /dev/null @@ -1,43 +0,0 @@ -/* neo theme for codemirror */ - -/* Color scheme */ - -.cm-s-neo.CodeMirror { - background-color:#ffffff; - color:#2e383c; - line-height:1.4375; -} -.cm-s-neo .cm-comment {color:#75787b} -.cm-s-neo .cm-keyword, .cm-s-neo .cm-property {color:#1d75b3} -.cm-s-neo .cm-atom,.cm-s-neo .cm-number {color:#75438a} -.cm-s-neo .cm-node,.cm-s-neo .cm-tag {color:#9c3328} -.cm-s-neo .cm-string {color:#b35e14} -.cm-s-neo .cm-variable,.cm-s-neo .cm-qualifier {color:#047d65} - - -/* Editor styling */ - -.cm-s-neo pre { - padding:0; -} - -.cm-s-neo .CodeMirror-gutters { - border:none; - border-right:10px solid transparent; - background-color:transparent; -} - -.cm-s-neo .CodeMirror-linenumber { - padding:0; - color:#e0e2e5; -} - -.cm-s-neo .CodeMirror-guttermarker { color: #1d75b3; } -.cm-s-neo .CodeMirror-guttermarker-subtle { color: #e0e2e5; } - -.cm-s-neo div.CodeMirror-cursor { - width: auto; - border: 0; - background: rgba(155,157,162,0.37); - z-index: 1; -} diff --git a/_site/css/codemirror/theme/night.css b/_site/css/codemirror/theme/night.css deleted file mode 100644 index 6b2ac6c..0000000 --- a/_site/css/codemirror/theme/night.css +++ /dev/null @@ -1,28 +0,0 @@ -/* Loosely based on the Midnight Textmate theme */ - -.cm-s-night.CodeMirror { background: #0a001f; color: #f8f8f8; } -.cm-s-night div.CodeMirror-selected { background: #447 !important; } -.cm-s-night.CodeMirror ::selection { background: rgba(68, 68, 119, .99); } -.cm-s-night.CodeMirror ::-moz-selection { background: rgba(68, 68, 119, .99); } -.cm-s-night .CodeMirror-gutters { background: #0a001f; border-right: 1px solid #aaa; } -.cm-s-night .CodeMirror-guttermarker { color: white; } -.cm-s-night .CodeMirror-guttermarker-subtle { color: #bbb; } -.cm-s-night .CodeMirror-linenumber { color: #f8f8f8; } -.cm-s-night .CodeMirror-cursor { border-left: 1px solid white !important; } - -.cm-s-night span.cm-comment { color: #6900a1; } -.cm-s-night span.cm-atom { color: #845dc4; } -.cm-s-night span.cm-number, .cm-s-night span.cm-attribute { color: #ffd500; } -.cm-s-night span.cm-keyword { color: #599eff; } -.cm-s-night span.cm-string { color: #37f14a; } -.cm-s-night span.cm-meta { color: #7678e2; } -.cm-s-night span.cm-variable-2, .cm-s-night span.cm-tag { color: #99b2ff; } -.cm-s-night span.cm-variable-3, .cm-s-night span.cm-def { color: white; } -.cm-s-night span.cm-bracket { color: #8da6ce; } -.cm-s-night span.cm-comment { color: #6900a1; } -.cm-s-night span.cm-builtin, .cm-s-night span.cm-special { color: #ff9e59; } -.cm-s-night span.cm-link { color: #845dc4; } -.cm-s-night span.cm-error { color: #9d1e15; } - -.cm-s-night .CodeMirror-activeline-background {background: #1C005A !important;} -.cm-s-night .CodeMirror-matchingbracket {outline:1px solid grey; color:white !important;} diff --git a/_site/img/burger_button.png b/_site/img/burger_button.png deleted file mode 100644 index c950812..0000000 Binary files a/_site/img/burger_button.png and /dev/null differ diff --git a/_site/img/code_refresh.png b/_site/img/code_refresh.png deleted file mode 100644 index 2def0da..0000000 Binary files a/_site/img/code_refresh.png and /dev/null differ diff --git a/_site/img/code_refresh_no_shadow.png b/_site/img/code_refresh_no_shadow.png deleted file mode 100644 index e278788..0000000 Binary files a/_site/img/code_refresh_no_shadow.png and /dev/null differ diff --git a/_site/img/code_refresh_shadow.png b/_site/img/code_refresh_shadow.png deleted file mode 100644 index 54047dd..0000000 Binary files a/_site/img/code_refresh_shadow.png and /dev/null differ diff --git a/_site/img/code_refresh_tab.png b/_site/img/code_refresh_tab.png deleted file mode 100644 index 3d98a59..0000000 Binary files a/_site/img/code_refresh_tab.png and /dev/null differ diff --git a/_site/img/code_refresh_tab_new.png b/_site/img/code_refresh_tab_new.png deleted file mode 100644 index bda0822..0000000 Binary files a/_site/img/code_refresh_tab_new.png and /dev/null differ diff --git a/_site/img/footer_forums.png b/_site/img/footer_forums.png deleted file mode 100644 index fb43fff..0000000 Binary files a/_site/img/footer_forums.png and /dev/null differ diff --git a/_site/img/footer_github.png b/_site/img/footer_github.png deleted file mode 100644 index 3867330..0000000 Binary files a/_site/img/footer_github.png and /dev/null differ diff --git a/_site/img/footer_twitter.png b/_site/img/footer_twitter.png deleted file mode 100644 index 1618ef2..0000000 Binary files a/_site/img/footer_twitter.png and /dev/null differ diff --git a/_site/img/goodboyLogo.png b/_site/img/goodboyLogo.png deleted file mode 100644 index 251d33d..0000000 Binary files a/_site/img/goodboyLogo.png and /dev/null differ diff --git a/_site/img/nav_bg.png b/_site/img/nav_bg.png deleted file mode 100644 index acc7ae1..0000000 Binary files a/_site/img/nav_bg.png and /dev/null differ diff --git a/_site/img/pixi_examples_bg.jpg b/_site/img/pixi_examples_bg.jpg deleted file mode 100644 index 62e68d4..0000000 Binary files a/_site/img/pixi_examples_bg.jpg and /dev/null differ diff --git a/_site/img/pixi_nav_title.png b/_site/img/pixi_nav_title.png deleted file mode 100644 index adfb809..0000000 Binary files a/_site/img/pixi_nav_title.png and /dev/null differ diff --git a/_site/js/Editor.js b/_site/js/Editor.js deleted file mode 100644 index 5d5476a..0000000 --- a/_site/js/Editor.js +++ /dev/null @@ -1,178 +0,0 @@ -function Editor (domElement,textarea, pixiUrl) { - - /* this is the delay before refreshing the iframe - * after the user presses a key - */ - this.delay = 1500; - this.timeout; - - this.domElement = domElement || document.createElement('div'); - this.textarea = textarea || document.createElement('textarea'); - this.iframe; - this.autoUpdate = false; - - this.request = new XMLHttpRequest(); - this.editor; - this.plugins; - - this.pixiUrl = pixiUrl; - - return this; -} - -Editor.prototype.constructor = Editor; - -Editor.prototype = { - - init : function (jsFile, plugins) { - - this.plugins = plugins; - - this.iframe = document.getElementById('preview'); - - // hook the loaded funtion to the onload event - this.request.onload = this.loaded.bind(this); - - // console.log(jsFile); - this.request.open('get',jsFile,true); - - this.request.send(); - }, - - iframeResize : function () { - - var frameDoc = this.iframe.contentDocument || this.iframe.contentWindow.document; - - var canvas = frameDoc.querySelector('canvas'); - - // for slow connections - if(canvas) - { - var ratio = canvas.width/canvas.height; - - ratio = window.innerWidth/(canvas.width) < window.innerHeight/(canvas.height) ? window.innerWidth/(canvas.width) : window.innerHeight/(canvas.height); - - var w2 = Math.min(canvas.width * ratio, window.innerWidth); - var h2 = Math.min(canvas.height * ratio, window.innerHeight); - - w2 = Math.min(800,w2); - h2 = Math.min(600,h2); - - canvas.style.width = w2 + "px"; - canvas.style.height = h2 + "px"; - - this.iframe.style.width = w2 + 20 + "px"; - } - }, - - loaded : function () { - - this.textarea.innerHTML = this.request.responseText; - - var editorOptions = { - mode: 'javascript', - lineNumbers: true, - styleActiveLine: true, - matchBrackets: true, - viewportMargin: Infinity - }; - - this.editor = CodeMirror.fromTextArea(this.textarea,editorOptions); - - window.addEventListener('resize',this.iframeResize.bind(this),false); - - this.updatePreview(); - - setTimeout(this.iframeResize.bind(this),600); - }, - - handleTimeOuts : function () { - - clearTimeout(this.timeout); - - if(this.autoUpdate) - { - this.timeout = setTimeout(this.updatePreview.bind(this), this.delay); - } - - - }, - - getContent : function () { - return this.editor.getValue(); - }, - - toggleAutoUpdate : function () { - - this.autoUpdate = !this.autoUpdate; - this.handleTimeOuts(); - }, - - insertBetween : function (js) { - var begin = 'pixi.js example 1";' + - '";'; - if (this.plugins) { - this.plugins.forEach(function(pluginName) { - begin+=''; - }); - } - begin += '"; - - var html = begin + js + end; - - return html; - }, - - flattenString : function (string) { - var noSpace = string.trim(); - - var noLine = noSpace.replace(/(\r\n|\n|\r)/gm,""); - - return noSpace; - }, - - /* - * open a stream and replace the current content of the iframe - * with the new content from codemirror (editor.getValue()) - * - */ - updatePreview : function (callback) { - - // these give us access to the document and the window element of the frame - var frameDoc = this.iframe.contentDocument || this.iframe.contentWindow.document; - - var frameWin = this.iframe.contentWindow || this.iframe; - - var js = this.getContent(); - - var html = this.insertBetween(js); - - /* - * The js codes adds the pixi canvas to the iframe's DOM - * therefore the html of the iframe is different from the original html - */ - /* - * I know there is some unused code here but it might be useful in the future if we get time to expand the editor - */ - // var pixiCanvas = frameDoc.querySelector('canvas'); - - // var currentHtml = frameDoc.documentElement.outerHTML; - - // var html = this.flattenString(html); - - // var currentHtml = this.flattenString(currentHtml); - - frameDoc.open(); - frameDoc.write(html); - frameDoc.close(); - - if(callback) - { - callback(); - } - - - } -} diff --git a/_site/js/app.js b/_site/js/app.js index 1138bf2..903642a 100644 --- a/_site/js/app.js +++ b/_site/js/app.js @@ -65,13 +65,14 @@ var App = { var select = document.getElementById(selectId); console.log('Loading tags from github ...'); - $.getJSON('https://api.github.com/repos/GoodBoyDigital/pixi.js/git/refs/tags') + $.getJSON('https://api.github.com/repos/pixijs/pixi.js/git/refs/tags') .done(function (data) { // filters the tags to only include v3 and above data = data .filter(function (tag) { - return tag.ref.indexOf('refs/tags/v3') === 0; + return tag.ref.indexOf('refs/tags/v3.0.11') === 0 || + tag.ref.indexOf('refs/tags/v4') === 0; }) .map(function (tag) { return tag.ref.replace('refs/tags/', ''); @@ -82,7 +83,7 @@ var App = { for (var i = 0; i < data.length; i++) { var option = document.createElement('option'); - option.value = 'https://cdn.rawgit.com/GoodBoyDigital/pixi.js/' + data[i] + '/bin/pixi.js'; + option.value = 'https://cdn.rawgit.com/pixijs/pixi.js/' + data[i] + '/bin/pixi.js'; option.textContent = data[i]; option.dataset.version = data[i]; select.appendChild(option); diff --git a/_site/js/index.js b/_site/js/index.js deleted file mode 100644 index 3557890..0000000 --- a/_site/js/index.js +++ /dev/null @@ -1,7 +0,0 @@ -$(document).ready(function () { - - // generates the links from the json manifest - - var ul = document.getElementById('exampleList') - App.loadManifest(ul); -}); diff --git a/_site/js/pixi.js b/_site/js/pixi.js index 7355be4..9721598 100644 --- a/_site/js/pixi.js +++ b/_site/js/pixi.js @@ -1,5 +1,13 @@ -(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.PIXI = 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= 0 && + arr.length % 1 === 0 + ); + } + + function _arrayEach(arr, iterator) { + var index = -1, + length = arr.length; + + while (++index < length) { + iterator(arr[index], index, arr); } - var results = []; - _each(arr, function (x, i, a) { - results.push(iterator(x, i, a)); - }); - return results; - }; + } + + function _map(arr, iterator) { + var index = -1, + length = arr.length, + result = Array(length); - var _reduce = function (arr, iterator, memo) { - if (arr.reduce) { - return arr.reduce(iterator, memo); + while (++index < length) { + result[index] = iterator(arr[index], index, arr); } - _each(arr, function (x, i, a) { + return result; + } + + function _range(count) { + return _map(Array(count), function (v, i) { return i; }); + } + + function _reduce(arr, iterator, memo) { + _arrayEach(arr, function (x, i, a) { memo = iterator(memo, x, i, a); }); return memo; - }; + } + + function _forEachOf(object, iterator) { + _arrayEach(_keys(object), function (key) { + iterator(object[key], key); + }); + } - var _keys = function (obj) { - if (Object.keys) { - return Object.keys(obj); + function _indexOf(arr, item) { + for (var i = 0; i < arr.length; i++) { + if (arr[i] === item) return i; } + return -1; + } + + var _keys = Object.keys || function (obj) { var keys = []; for (var k in obj) { if (obj.hasOwnProperty(k)) { @@ -83,191 +141,247 @@ return keys; }; - //// exported async module functions //// - - //// nextTick implementation with browser-compatible fallback //// - if (typeof process === 'undefined' || !(process.nextTick)) { - if (typeof setImmediate === 'function') { - async.nextTick = function (fn) { - // not a direct alias for IE10 compatibility - setImmediate(fn); + function _keyIterator(coll) { + var i = -1; + var len; + var keys; + if (_isArrayLike(coll)) { + len = coll.length; + return function next() { + i++; + return i < len ? i : null; }; - async.setImmediate = async.nextTick; - } - else { - async.nextTick = function (fn) { - setTimeout(fn, 0); + } else { + keys = _keys(coll); + len = keys.length; + return function next() { + i++; + return i < len ? keys[i] : null; }; - async.setImmediate = async.nextTick; } } - else { + + // Similar to ES6's rest param (http://ariya.ofilabs.com/2013/03/es6-and-rest-parameter.html) + // This accumulates the arguments passed into an array, after a given index. + // From underscore.js (https://github.com/jashkenas/underscore/pull/2140). + function _restParam(func, startIndex) { + startIndex = startIndex == null ? func.length - 1 : +startIndex; + return function() { + var length = Math.max(arguments.length - startIndex, 0); + var rest = Array(length); + for (var index = 0; index < length; index++) { + rest[index] = arguments[index + startIndex]; + } + switch (startIndex) { + case 0: return func.call(this, rest); + case 1: return func.call(this, arguments[0], rest); + } + // Currently unused but handle cases outside of the switch statement: + // var args = Array(startIndex + 1); + // for (index = 0; index < startIndex; index++) { + // args[index] = arguments[index]; + // } + // args[startIndex] = rest; + // return func.apply(this, args); + }; + } + + function _withoutIndex(iterator) { + return function (value, index, callback) { + return iterator(value, callback); + }; + } + + //// exported async module functions //// + + //// nextTick implementation with browser-compatible fallback //// + + // capture the global reference to guard against fakeTimer mocks + var _setImmediate = typeof setImmediate === 'function' && setImmediate; + + var _delay = _setImmediate ? function(fn) { + // not a direct alias for IE10 compatibility + _setImmediate(fn); + } : function(fn) { + setTimeout(fn, 0); + }; + + if (typeof process === 'object' && typeof process.nextTick === 'function') { async.nextTick = process.nextTick; - if (typeof setImmediate !== 'undefined') { - async.setImmediate = function (fn) { - // not a direct alias for IE10 compatibility - setImmediate(fn); - }; - } - else { - async.setImmediate = async.nextTick; - } + } else { + async.nextTick = _delay; } + async.setImmediate = _setImmediate ? _delay : async.nextTick; + + async.forEach = async.each = function (arr, iterator, callback) { - callback = callback || function () {}; - if (!arr.length) { - return callback(); + return async.eachOf(arr, _withoutIndex(iterator), callback); + }; + + async.forEachSeries = + async.eachSeries = function (arr, iterator, callback) { + return async.eachOfSeries(arr, _withoutIndex(iterator), callback); + }; + + + async.forEachLimit = + async.eachLimit = function (arr, limit, iterator, callback) { + return _eachOfLimit(limit)(arr, _withoutIndex(iterator), callback); + }; + + async.forEachOf = + async.eachOf = function (object, iterator, callback) { + callback = _once(callback || noop); + object = object || []; + + var iter = _keyIterator(object); + var key, completed = 0; + + while ((key = iter()) != null) { + completed += 1; + iterator(object[key], key, only_once(done)); } - var completed = 0; - _each(arr, function (x) { - iterator(x, only_once(done) ); - }); + + if (completed === 0) callback(null); + function done(err) { - if (err) { - callback(err); - callback = function () {}; - } - else { - completed += 1; - if (completed >= arr.length) { - callback(); - } - } + completed--; + if (err) { + callback(err); + } + // Check key is null in case iterator isn't exhausted + // and done resolved synchronously. + else if (key === null && completed <= 0) { + callback(null); + } } }; - async.forEach = async.each; - async.eachSeries = function (arr, iterator, callback) { - callback = callback || function () {}; - if (!arr.length) { - return callback(); - } - var completed = 0; - var iterate = function () { - iterator(arr[completed], function (err) { + async.forEachOfSeries = + async.eachOfSeries = function (obj, iterator, callback) { + callback = _once(callback || noop); + obj = obj || []; + var nextKey = _keyIterator(obj); + var key = nextKey(); + function iterate() { + var sync = true; + if (key === null) { + return callback(null); + } + iterator(obj[key], key, only_once(function (err) { if (err) { callback(err); - callback = function () {}; } else { - completed += 1; - if (completed >= arr.length) { - callback(); - } - else { - iterate(); + key = nextKey(); + if (key === null) { + return callback(null); + } else { + if (sync) { + async.setImmediate(iterate); + } else { + iterate(); + } } } - }); - }; + })); + sync = false; + } iterate(); }; - async.forEachSeries = async.eachSeries; - async.eachLimit = function (arr, limit, iterator, callback) { - var fn = _eachLimit(limit); - fn.apply(null, [arr, iterator, callback]); + + + async.forEachOfLimit = + async.eachOfLimit = function (obj, limit, iterator, callback) { + _eachOfLimit(limit)(obj, iterator, callback); }; - async.forEachLimit = async.eachLimit; - var _eachLimit = function (limit) { + function _eachOfLimit(limit) { - return function (arr, iterator, callback) { - callback = callback || function () {}; - if (!arr.length || limit <= 0) { - return callback(); + return function (obj, iterator, callback) { + callback = _once(callback || noop); + obj = obj || []; + var nextKey = _keyIterator(obj); + if (limit <= 0) { + return callback(null); } - var completed = 0; - var started = 0; + var done = false; var running = 0; + var errored = false; (function replenish () { - if (completed >= arr.length) { - return callback(); + if (done && running <= 0) { + return callback(null); } - while (running < limit && started < arr.length) { - started += 1; + while (running < limit && !errored) { + var key = nextKey(); + if (key === null) { + done = true; + if (running <= 0) { + callback(null); + } + return; + } running += 1; - iterator(arr[started - 1], function (err) { + iterator(obj[key], key, only_once(function (err) { + running -= 1; if (err) { callback(err); - callback = function () {}; + errored = true; } else { - completed += 1; - running -= 1; - if (completed >= arr.length) { - callback(); - } - else { - replenish(); - } + replenish(); } - }); + })); } })(); }; - }; + } - var doParallel = function (fn) { - return function () { - var args = Array.prototype.slice.call(arguments); - return fn.apply(null, [async.each].concat(args)); + function doParallel(fn) { + return function (obj, iterator, callback) { + return fn(async.eachOf, obj, iterator, callback); }; - }; - var doParallelLimit = function(limit, fn) { - return function () { - var args = Array.prototype.slice.call(arguments); - return fn.apply(null, [_eachLimit(limit)].concat(args)); + } + function doParallelLimit(fn) { + return function (obj, limit, iterator, callback) { + return fn(_eachOfLimit(limit), obj, iterator, callback); }; - }; - var doSeries = function (fn) { - return function () { - var args = Array.prototype.slice.call(arguments); - return fn.apply(null, [async.eachSeries].concat(args)); + } + function doSeries(fn) { + return function (obj, iterator, callback) { + return fn(async.eachOfSeries, obj, iterator, callback); }; - }; - + } - var _asyncMap = function (eachfn, arr, iterator, callback) { - arr = _map(arr, function (x, i) { - return {index: i, value: x}; - }); - if (!callback) { - eachfn(arr, function (x, callback) { - iterator(x.value, function (err) { - callback(err); - }); - }); - } else { - var results = []; - eachfn(arr, function (x, callback) { - iterator(x.value, function (err, v) { - results[x.index] = v; - callback(err); - }); - }, function (err) { - callback(err, results); + function _asyncMap(eachfn, arr, iterator, callback) { + callback = _once(callback || noop); + arr = arr || []; + var results = _isArrayLike(arr) ? [] : {}; + eachfn(arr, function (value, index, callback) { + iterator(value, function (err, v) { + results[index] = v; + callback(err); }); - } - }; + }, function (err) { + callback(err, results); + }); + } + async.map = doParallel(_asyncMap); async.mapSeries = doSeries(_asyncMap); - async.mapLimit = function (arr, limit, iterator, callback) { - return _mapLimit(limit)(arr, iterator, callback); - }; - - var _mapLimit = function(limit) { - return doParallelLimit(limit, _asyncMap); - }; + async.mapLimit = doParallelLimit(_asyncMap); // reduce only has a series version, as doing reduce in parallel won't // work in many situations. + async.inject = + async.foldl = async.reduce = function (arr, memo, iterator, callback) { - async.eachSeries(arr, function (x, callback) { + async.eachOfSeries(arr, function (x, i, callback) { iterator(memo, x, function (err, v) { memo = v; callback(err); @@ -276,118 +390,106 @@ callback(err, memo); }); }; - // inject alias - async.inject = async.reduce; - // foldl alias - async.foldl = async.reduce; + async.foldr = async.reduceRight = function (arr, memo, iterator, callback) { - var reversed = _map(arr, function (x) { - return x; - }).reverse(); + var reversed = _map(arr, identity).reverse(); async.reduce(reversed, memo, iterator, callback); }; - // foldr alias - async.foldr = async.reduceRight; - var _filter = function (eachfn, arr, iterator, callback) { - var results = []; - arr = _map(arr, function (x, i) { - return {index: i, value: x}; + async.transform = function (arr, memo, iterator, callback) { + if (arguments.length === 3) { + callback = iterator; + iterator = memo; + memo = _isArray(arr) ? [] : {}; + } + + async.eachOf(arr, function(v, k, cb) { + iterator(memo, v, k, cb); + }, function(err) { + callback(err, memo); }); - eachfn(arr, function (x, callback) { - iterator(x.value, function (v) { + }; + + function _filter(eachfn, arr, iterator, callback) { + var results = []; + eachfn(arr, function (x, index, callback) { + iterator(x, function (v) { if (v) { - results.push(x); + results.push({index: index, value: x}); } callback(); }); - }, function (err) { + }, function () { callback(_map(results.sort(function (a, b) { return a.index - b.index; }), function (x) { return x.value; })); }); - }; + } + + async.select = async.filter = doParallel(_filter); + + async.selectLimit = + async.filterLimit = doParallelLimit(_filter); + + async.selectSeries = async.filterSeries = doSeries(_filter); - // select alias - async.select = async.filter; - async.selectSeries = async.filterSeries; - var _reject = function (eachfn, arr, iterator, callback) { - var results = []; - arr = _map(arr, function (x, i) { - return {index: i, value: x}; - }); - eachfn(arr, function (x, callback) { - iterator(x.value, function (v) { - if (!v) { - results.push(x); - } - callback(); + function _reject(eachfn, arr, iterator, callback) { + _filter(eachfn, arr, function(value, cb) { + iterator(value, function(v) { + cb(!v); }); - }, function (err) { - callback(_map(results.sort(function (a, b) { - return a.index - b.index; - }), function (x) { - return x.value; - })); - }); - }; + }, callback); + } async.reject = doParallel(_reject); + async.rejectLimit = doParallelLimit(_reject); async.rejectSeries = doSeries(_reject); - var _detect = function (eachfn, arr, iterator, main_callback) { - eachfn(arr, function (x, callback) { - iterator(x, function (result) { - if (result) { - main_callback(x); - main_callback = function () {}; - } - else { + function _createTester(eachfn, check, getResult) { + return function(arr, limit, iterator, cb) { + function done() { + if (cb) cb(getResult(false, void 0)); + } + function iteratee(x, _, callback) { + if (!cb) return callback(); + iterator(x, function (v) { + if (cb && check(v)) { + cb(getResult(true, x)); + cb = iterator = false; + } callback(); - } - }); - }, function (err) { - main_callback(); - }); - }; - async.detect = doParallel(_detect); - async.detectSeries = doSeries(_detect); + }); + } + if (arguments.length > 3) { + eachfn(arr, limit, iteratee, done); + } else { + cb = iterator; + iterator = limit; + eachfn(arr, iteratee, done); + } + }; + } - async.some = function (arr, iterator, main_callback) { - async.each(arr, function (x, callback) { - iterator(x, function (v) { - if (v) { - main_callback(true); - main_callback = function () {}; - } - callback(); - }); - }, function (err) { - main_callback(false); - }); - }; - // any alias - async.any = async.some; + async.any = + async.some = _createTester(async.eachOf, toBool, identity); - async.every = function (arr, iterator, main_callback) { - async.each(arr, function (x, callback) { - iterator(x, function (v) { - if (!v) { - main_callback(false); - main_callback = function () {}; - } - callback(); - }); - }, function (err) { - main_callback(true); - }); - }; - // all alias - async.all = async.every; + async.someLimit = _createTester(async.eachOfLimit, toBool, identity); + + async.all = + async.every = _createTester(async.eachOf, notId, notId); + + async.everyLimit = _createTester(async.eachOfLimit, notId, notId); + + function _findGetResult(v, x) { + return x; + } + async.detect = _createTester(async.eachOf, identity, _findGetResult); + async.detectSeries = _createTester(async.eachOfSeries, identity, _findGetResult); + async.detectLimit = _createTester(async.eachOfLimit, identity, _findGetResult); async.sortBy = function (arr, iterator, callback) { async.map(arr, function (x, callback) { @@ -404,147 +506,206 @@ return callback(err); } else { - var fn = function (left, right) { - var a = left.criteria, b = right.criteria; - return a < b ? -1 : a > b ? 1 : 0; - }; - callback(null, _map(results.sort(fn), function (x) { + callback(null, _map(results.sort(comparator), function (x) { return x.value; })); } + }); + + function comparator(left, right) { + var a = left.criteria, b = right.criteria; + return a < b ? -1 : a > b ? 1 : 0; + } }; - async.auto = function (tasks, callback) { - callback = callback || function () {}; + async.auto = function (tasks, concurrency, callback) { + if (typeof arguments[1] === 'function') { + // concurrency is optional, shift the args. + callback = concurrency; + concurrency = null; + } + callback = _once(callback || noop); var keys = _keys(tasks); - var remainingTasks = keys.length + var remainingTasks = keys.length; if (!remainingTasks) { - return callback(); + return callback(null); + } + if (!concurrency) { + concurrency = remainingTasks; } var results = {}; + var runningTasks = 0; + + var hasError = false; var listeners = []; - var addListener = function (fn) { + function addListener(fn) { listeners.unshift(fn); - }; - var removeListener = function (fn) { - for (var i = 0; i < listeners.length; i += 1) { - if (listeners[i] === fn) { - listeners.splice(i, 1); - return; - } - } - }; - var taskComplete = function () { - remainingTasks-- - _each(listeners.slice(0), function (fn) { + } + function removeListener(fn) { + var idx = _indexOf(listeners, fn); + if (idx >= 0) listeners.splice(idx, 1); + } + function taskComplete() { + remainingTasks--; + _arrayEach(listeners.slice(0), function (fn) { fn(); }); - }; + } addListener(function () { if (!remainingTasks) { - var theCallback = callback; - // prevent final callback from calling itself if it errors - callback = function () {}; - - theCallback(null, results); + callback(null, results); } }); - _each(keys, function (k) { + _arrayEach(keys, function (k) { + if (hasError) return; var task = _isArray(tasks[k]) ? tasks[k]: [tasks[k]]; - var taskCallback = function (err) { - var args = Array.prototype.slice.call(arguments, 1); + var taskCallback = _restParam(function(err, args) { + runningTasks--; if (args.length <= 1) { args = args[0]; } if (err) { var safeResults = {}; - _each(_keys(results), function(rkey) { - safeResults[rkey] = results[rkey]; + _forEachOf(results, function(val, rkey) { + safeResults[rkey] = val; }); safeResults[k] = args; + hasError = true; + callback(err, safeResults); - // stop subsequent errors hitting callback multiple times - callback = function () {}; } else { results[k] = args; async.setImmediate(taskComplete); } - }; - var requires = task.slice(0, Math.abs(task.length - 1)) || []; - var ready = function () { - return _reduce(requires, function (a, x) { + }); + var requires = task.slice(0, task.length - 1); + // prevent dead-locks + var len = requires.length; + var dep; + while (len--) { + if (!(dep = tasks[requires[len]])) { + throw new Error('Has nonexistent dependency in ' + requires.join(', ')); + } + if (_isArray(dep) && _indexOf(dep, k) >= 0) { + throw new Error('Has cyclic dependencies'); + } + } + function ready() { + return runningTasks < concurrency && _reduce(requires, function (a, x) { return (a && results.hasOwnProperty(x)); }, true) && !results.hasOwnProperty(k); - }; + } if (ready()) { + runningTasks++; task[task.length - 1](taskCallback, results); } else { - var listener = function () { - if (ready()) { - removeListener(listener); - task[task.length - 1](taskCallback, results); - } - }; addListener(listener); } + function listener() { + if (ready()) { + runningTasks++; + removeListener(listener); + task[task.length - 1](taskCallback, results); + } + } }); }; + + async.retry = function(times, task, callback) { var DEFAULT_TIMES = 5; + var DEFAULT_INTERVAL = 0; + var attempts = []; - // Use defaults if times not passed - if (typeof times === 'function') { + + var opts = { + times: DEFAULT_TIMES, + interval: DEFAULT_INTERVAL + }; + + function parseTimes(acc, t){ + if(typeof t === 'number'){ + acc.times = parseInt(t, 10) || DEFAULT_TIMES; + } else if(typeof t === 'object'){ + acc.times = parseInt(t.times, 10) || DEFAULT_TIMES; + acc.interval = parseInt(t.interval, 10) || DEFAULT_INTERVAL; + } else { + throw new Error('Unsupported argument type for \'times\': ' + typeof t); + } + } + + var length = arguments.length; + if (length < 1 || length > 3) { + throw new Error('Invalid arguments - must be either (task), (task, callback), (times, task) or (times, task, callback)'); + } else if (length <= 2 && typeof times === 'function') { callback = task; task = times; - times = DEFAULT_TIMES; } - // Make sure times is a number - times = parseInt(times, 10) || DEFAULT_TIMES; - var wrappedTask = function(wrappedCallback, wrappedResults) { - var retryAttempt = function(task, finalAttempt) { + if (typeof times !== 'function') { + parseTimes(opts, times); + } + opts.callback = callback; + opts.task = task; + + function wrappedTask(wrappedCallback, wrappedResults) { + function retryAttempt(task, finalAttempt) { return function(seriesCallback) { task(function(err, result){ seriesCallback(!err || finalAttempt, {err: err, result: result}); }, wrappedResults); }; - }; - while (times) { - attempts.push(retryAttempt(task, !(times-=1))); } + + function retryInterval(interval){ + return function(seriesCallback){ + setTimeout(function(){ + seriesCallback(null); + }, interval); + }; + } + + while (opts.times) { + + var finalAttempt = !(opts.times-=1); + attempts.push(retryAttempt(opts.task, finalAttempt)); + if(!finalAttempt && opts.interval > 0){ + attempts.push(retryInterval(opts.interval)); + } + } + async.series(attempts, function(done, data){ data = data[data.length - 1]; - (wrappedCallback || callback)(data.err, data.result); + (wrappedCallback || opts.callback)(data.err, data.result); }); } + // If a callback is passed, run this as a controll flow - return callback ? wrappedTask() : wrappedTask + return opts.callback ? wrappedTask() : wrappedTask; }; async.waterfall = function (tasks, callback) { - callback = callback || function () {}; + callback = _once(callback || noop); if (!_isArray(tasks)) { - var err = new Error('First argument to waterfall must be an array of functions'); - return callback(err); + var err = new Error('First argument to waterfall must be an array of functions'); + return callback(err); } if (!tasks.length) { return callback(); } - var wrapIterator = function (iterator) { - return function (err) { + function wrapIterator(iterator) { + return _restParam(function (err, args) { if (err) { - callback.apply(null, arguments); - callback = function () {}; + callback.apply(null, [err].concat(args)); } else { - var args = Array.prototype.slice.call(arguments, 1); var next = iterator.next(); if (next) { args.push(wrapIterator(next)); @@ -552,260 +713,254 @@ else { args.push(callback); } - async.setImmediate(function () { - iterator.apply(null, args); - }); + ensureAsync(iterator).apply(null, args); } - }; - }; + }); + } wrapIterator(async.iterator(tasks))(); }; - var _parallel = function(eachfn, tasks, callback) { - callback = callback || function () {}; - if (_isArray(tasks)) { - eachfn.map(tasks, function (fn, callback) { - if (fn) { - fn(function (err) { - var args = Array.prototype.slice.call(arguments, 1); - if (args.length <= 1) { - args = args[0]; - } - callback.call(null, err, args); - }); - } - }, callback); - } - else { - var results = {}; - eachfn.each(_keys(tasks), function (k, callback) { - tasks[k](function (err) { - var args = Array.prototype.slice.call(arguments, 1); - if (args.length <= 1) { - args = args[0]; - } - results[k] = args; - callback(err); - }); - }, function (err) { - callback(err, results); - }); - } - }; + function _parallel(eachfn, tasks, callback) { + callback = callback || noop; + var results = _isArrayLike(tasks) ? [] : {}; + + eachfn(tasks, function (task, key, callback) { + task(_restParam(function (err, args) { + if (args.length <= 1) { + args = args[0]; + } + results[key] = args; + callback(err); + })); + }, function (err) { + callback(err, results); + }); + } async.parallel = function (tasks, callback) { - _parallel({ map: async.map, each: async.each }, tasks, callback); + _parallel(async.eachOf, tasks, callback); }; async.parallelLimit = function(tasks, limit, callback) { - _parallel({ map: _mapLimit(limit), each: _eachLimit(limit) }, tasks, callback); + _parallel(_eachOfLimit(limit), tasks, callback); }; - async.series = function (tasks, callback) { - callback = callback || function () {}; - if (_isArray(tasks)) { - async.mapSeries(tasks, function (fn, callback) { - if (fn) { - fn(function (err) { - var args = Array.prototype.slice.call(arguments, 1); - if (args.length <= 1) { - args = args[0]; - } - callback.call(null, err, args); - }); - } - }, callback); - } - else { - var results = {}; - async.eachSeries(_keys(tasks), function (k, callback) { - tasks[k](function (err) { - var args = Array.prototype.slice.call(arguments, 1); - if (args.length <= 1) { - args = args[0]; - } - results[k] = args; - callback(err); - }); - }, function (err) { - callback(err, results); - }); - } + async.series = function(tasks, callback) { + _parallel(async.eachOfSeries, tasks, callback); }; async.iterator = function (tasks) { - var makeCallback = function (index) { - var fn = function () { + function makeCallback(index) { + function fn() { if (tasks.length) { tasks[index].apply(null, arguments); } return fn.next(); - }; + } fn.next = function () { return (index < tasks.length - 1) ? makeCallback(index + 1): null; }; return fn; - }; + } return makeCallback(0); }; - async.apply = function (fn) { - var args = Array.prototype.slice.call(arguments, 1); - return function () { + async.apply = _restParam(function (fn, args) { + return _restParam(function (callArgs) { return fn.apply( - null, args.concat(Array.prototype.slice.call(arguments)) + null, args.concat(callArgs) ); - }; - }; + }); + }); - var _concat = function (eachfn, arr, fn, callback) { - var r = []; - eachfn(arr, function (x, cb) { + function _concat(eachfn, arr, fn, callback) { + var result = []; + eachfn(arr, function (x, index, cb) { fn(x, function (err, y) { - r = r.concat(y || []); + result = result.concat(y || []); cb(err); }); }, function (err) { - callback(err, r); + callback(err, result); }); - }; + } async.concat = doParallel(_concat); async.concatSeries = doSeries(_concat); async.whilst = function (test, iterator, callback) { + callback = callback || noop; if (test()) { - iterator(function (err) { + var next = _restParam(function(err, args) { if (err) { - return callback(err); + callback(err); + } else if (test.apply(this, args)) { + iterator(next); + } else { + callback.apply(null, [null].concat(args)); } - async.whilst(test, iterator, callback); }); - } - else { - callback(); + iterator(next); + } else { + callback(null); } }; async.doWhilst = function (iterator, test, callback) { - iterator(function (err) { - if (err) { - return callback(err); - } - var args = Array.prototype.slice.call(arguments, 1); - if (test.apply(null, args)) { - async.doWhilst(iterator, test, callback); - } - else { - callback(); - } - }); + var calls = 0; + return async.whilst(function() { + return ++calls <= 1 || test.apply(this, arguments); + }, iterator, callback); }; async.until = function (test, iterator, callback) { - if (!test()) { - iterator(function (err) { - if (err) { - return callback(err); - } - async.until(test, iterator, callback); - }); - } - else { - callback(); - } + return async.whilst(function() { + return !test.apply(this, arguments); + }, iterator, callback); }; async.doUntil = function (iterator, test, callback) { - iterator(function (err) { + return async.doWhilst(iterator, function() { + return !test.apply(this, arguments); + }, callback); + }; + + async.during = function (test, iterator, callback) { + callback = callback || noop; + + var next = _restParam(function(err, args) { if (err) { - return callback(err); + callback(err); + } else { + args.push(check); + test.apply(this, args); } - var args = Array.prototype.slice.call(arguments, 1); - if (!test.apply(null, args)) { - async.doUntil(iterator, test, callback); + }); + + var check = function(err, truth) { + if (err) { + callback(err); + } else if (truth) { + iterator(next); + } else { + callback(null); } - else { - callback(); + }; + + test(check); + }; + + async.doDuring = function (iterator, test, callback) { + var calls = 0; + async.during(function(next) { + if (calls++ < 1) { + next(null, true); + } else { + test.apply(this, arguments); } - }); + }, iterator, callback); }; - async.queue = function (worker, concurrency) { - if (concurrency === undefined) { + function _queue(worker, concurrency, payload) { + if (concurrency == null) { concurrency = 1; } + else if(concurrency === 0) { + throw new Error('Concurrency must not be zero'); + } function _insert(q, data, pos, callback) { - if (!q.started){ + if (callback != null && typeof callback !== "function") { + throw new Error("task callback must be a function"); + } q.started = true; - } - if (!_isArray(data)) { - data = [data]; - } - if(data.length == 0) { - // call drain immediately if there are no tasks - return async.setImmediate(function() { - if (q.drain) { - q.drain(); - } - }); - } - _each(data, function(task) { - var item = { - data: task, - callback: typeof callback === 'function' ? callback : null - }; - - if (pos) { - q.tasks.unshift(item); - } else { - q.tasks.push(item); - } - - if (q.saturated && q.tasks.length === q.concurrency) { - q.saturated(); - } - async.setImmediate(q.process); - }); + if (!_isArray(data)) { + data = [data]; + } + if(data.length === 0 && q.idle()) { + // call drain immediately if there are no tasks + return async.setImmediate(function() { + q.drain(); + }); + } + _arrayEach(data, function(task) { + var item = { + data: task, + callback: callback || noop + }; + + if (pos) { + q.tasks.unshift(item); + } else { + q.tasks.push(item); + } + + if (q.tasks.length === q.concurrency) { + q.saturated(); + } + }); + async.setImmediate(q.process); + } + function _next(q, tasks) { + return function(){ + workers -= 1; + + var removed = false; + var args = arguments; + _arrayEach(tasks, function (task) { + _arrayEach(workersList, function (worker, index) { + if (worker === task && !removed) { + workersList.splice(index, 1); + removed = true; + } + }); + + task.callback.apply(task, args); + }); + if (q.tasks.length + workers === 0) { + q.drain(); + } + q.process(); + }; } var workers = 0; + var workersList = []; var q = { tasks: [], concurrency: concurrency, - saturated: null, - empty: null, - drain: null, + payload: payload, + saturated: noop, + empty: noop, + drain: noop, started: false, paused: false, push: function (data, callback) { - _insert(q, data, false, callback); + _insert(q, data, false, callback); }, kill: function () { - q.drain = null; - q.tasks = []; + q.drain = noop; + q.tasks = []; }, unshift: function (data, callback) { - _insert(q, data, true, callback); + _insert(q, data, true, callback); }, process: function () { - if (!q.paused && workers < q.concurrency && q.tasks.length) { - var task = q.tasks.shift(); - if (q.empty && q.tasks.length === 0) { + while(!q.paused && workers < q.concurrency && q.tasks.length){ + + var tasks = q.payload ? + q.tasks.splice(0, q.payload) : + q.tasks.splice(0, q.tasks.length); + + var data = _map(tasks, function (task) { + return task.data; + }); + + if (q.tasks.length === 0) { q.empty(); } workers += 1; - var next = function () { - workers -= 1; - if (task.callback) { - task.callback.apply(task, arguments); - } - if (q.drain && q.tasks.length + workers === 0) { - q.drain(); - } - q.process(); - }; - var cb = only_once(next); - worker(task.data, cb); + workersList.push(tasks[0]); + var cb = only_once(_next(q, tasks)); + worker(data, cb); } }, length: function () { @@ -814,75 +969,85 @@ running: function () { return workers; }, + workersList: function () { + return workersList; + }, idle: function() { return q.tasks.length + workers === 0; }, pause: function () { - if (q.paused === true) { return; } q.paused = true; }, resume: function () { if (q.paused === false) { return; } q.paused = false; + var resumeCount = Math.min(q.concurrency, q.tasks.length); // Need to call q.process once per concurrent // worker to preserve full concurrency after pause - for (var w = 1; w <= q.concurrency; w++) { + for (var w = 1; w <= resumeCount; w++) { async.setImmediate(q.process); } } }; + return q; + } + + async.queue = function (worker, concurrency) { + var q = _queue(function (items, cb) { + worker(items[0], cb); + }, concurrency, 1); + return q; }; async.priorityQueue = function (worker, concurrency) { function _compareTasks(a, b){ - return a.priority - b.priority; - }; + return a.priority - b.priority; + } function _binarySearch(sequence, item, compare) { - var beg = -1, - end = sequence.length - 1; - while (beg < end) { - var mid = beg + ((end - beg + 1) >>> 1); - if (compare(item, sequence[mid]) >= 0) { - beg = mid; - } else { - end = mid - 1; + var beg = -1, + end = sequence.length - 1; + while (beg < end) { + var mid = beg + ((end - beg + 1) >>> 1); + if (compare(item, sequence[mid]) >= 0) { + beg = mid; + } else { + end = mid - 1; + } } - } - return beg; + return beg; } function _insert(q, data, priority, callback) { - if (!q.started){ + if (callback != null && typeof callback !== "function") { + throw new Error("task callback must be a function"); + } q.started = true; - } - if (!_isArray(data)) { - data = [data]; - } - if(data.length == 0) { - // call drain immediately if there are no tasks - return async.setImmediate(function() { - if (q.drain) { - q.drain(); - } - }); - } - _each(data, function(task) { - var item = { - data: task, - priority: priority, - callback: typeof callback === 'function' ? callback : null - }; - - q.tasks.splice(_binarySearch(q.tasks, item, _compareTasks) + 1, 0, item); - - if (q.saturated && q.tasks.length === q.concurrency) { - q.saturated(); - } - async.setImmediate(q.process); - }); + if (!_isArray(data)) { + data = [data]; + } + if(data.length === 0) { + // call drain immediately if there are no tasks + return async.setImmediate(function() { + q.drain(); + }); + } + _arrayEach(data, function(task) { + var item = { + data: task, + priority: priority, + callback: typeof callback === 'function' ? callback : noop + }; + + q.tasks.splice(_binarySearch(q.tasks, item, _compareTasks) + 1, 0, item); + + if (q.tasks.length === q.concurrency) { + q.saturated(); + } + async.setImmediate(q.process); + }); } // Start with a normal queue @@ -890,7 +1055,7 @@ // Override push to accept second parameter representing priority q.push = function (data, priority, callback) { - _insert(q, data, priority, callback); + _insert(q, data, priority, callback); }; // Remove unshift function @@ -900,93 +1065,27 @@ }; async.cargo = function (worker, payload) { - var working = false, - tasks = []; - - var cargo = { - tasks: tasks, - payload: payload, - saturated: null, - empty: null, - drain: null, - drained: true, - push: function (data, callback) { - if (!_isArray(data)) { - data = [data]; - } - _each(data, function(task) { - tasks.push({ - data: task, - callback: typeof callback === 'function' ? callback : null - }); - cargo.drained = false; - if (cargo.saturated && tasks.length === payload) { - cargo.saturated(); - } - }); - async.setImmediate(cargo.process); - }, - process: function process() { - if (working) return; - if (tasks.length === 0) { - if(cargo.drain && !cargo.drained) cargo.drain(); - cargo.drained = true; - return; - } - - var ts = typeof payload === 'number' - ? tasks.splice(0, payload) - : tasks.splice(0, tasks.length); - - var ds = _map(ts, function (task) { - return task.data; - }); - - if(cargo.empty) cargo.empty(); - working = true; - worker(ds, function () { - working = false; - - var args = arguments; - _each(ts, function (data) { - if (data.callback) { - data.callback.apply(null, args); - } - }); - - process(); - }); - }, - length: function () { - return tasks.length; - }, - running: function () { - return working; - } - }; - return cargo; + return _queue(worker, 1, payload); }; - var _console_fn = function (name) { - return function (fn) { - var args = Array.prototype.slice.call(arguments, 1); - fn.apply(null, args.concat([function (err) { - var args = Array.prototype.slice.call(arguments, 1); - if (typeof console !== 'undefined') { + function _console_fn(name) { + return _restParam(function (fn, args) { + fn.apply(null, args.concat([_restParam(function (err, args) { + if (typeof console === 'object') { if (err) { if (console.error) { console.error(err); } } else if (console[name]) { - _each(args, function (x) { + _arrayEach(args, function (x) { console[name](x); }); } } - }])); - }; - }; + })])); + }); + } async.log = _console_fn('log'); async.dir = _console_fn('dir'); /*async.info = _console_fn('info'); @@ -996,123 +1095,174 @@ async.memoize = function (fn, hasher) { var memo = {}; var queues = {}; - hasher = hasher || function (x) { - return x; - }; - var memoized = function () { - var args = Array.prototype.slice.call(arguments); + var has = Object.prototype.hasOwnProperty; + hasher = hasher || identity; + var memoized = _restParam(function memoized(args) { var callback = args.pop(); var key = hasher.apply(null, args); - if (key in memo) { - async.nextTick(function () { + if (has.call(memo, key)) { + async.setImmediate(function () { callback.apply(null, memo[key]); }); } - else if (key in queues) { + else if (has.call(queues, key)) { queues[key].push(callback); } else { queues[key] = [callback]; - fn.apply(null, args.concat([function () { - memo[key] = arguments; + fn.apply(null, args.concat([_restParam(function (args) { + memo[key] = args; var q = queues[key]; delete queues[key]; for (var i = 0, l = q.length; i < l; i++) { - q[i].apply(null, arguments); + q[i].apply(null, args); } - }])); + })])); } - }; + }); memoized.memo = memo; memoized.unmemoized = fn; return memoized; }; async.unmemoize = function (fn) { - return function () { - return (fn.unmemoized || fn).apply(null, arguments); - }; + return function () { + return (fn.unmemoized || fn).apply(null, arguments); + }; }; - async.times = function (count, iterator, callback) { - var counter = []; - for (var i = 0; i < count; i++) { - counter.push(i); - } - return async.map(counter, iterator, callback); - }; + function _times(mapper) { + return function (count, iterator, callback) { + mapper(_range(count), iterator, callback); + }; + } - async.timesSeries = function (count, iterator, callback) { - var counter = []; - for (var i = 0; i < count; i++) { - counter.push(i); - } - return async.mapSeries(counter, iterator, callback); + async.times = _times(async.map); + async.timesSeries = _times(async.mapSeries); + async.timesLimit = function (count, limit, iterator, callback) { + return async.mapLimit(_range(count), limit, iterator, callback); }; async.seq = function (/* functions... */) { var fns = arguments; - return function () { + return _restParam(function (args) { var that = this; - var args = Array.prototype.slice.call(arguments); - var callback = args.pop(); + + var callback = args[args.length - 1]; + if (typeof callback == 'function') { + args.pop(); + } else { + callback = noop; + } + async.reduce(fns, args, function (newargs, fn, cb) { - fn.apply(that, newargs.concat([function () { - var err = arguments[0]; - var nextargs = Array.prototype.slice.call(arguments, 1); + fn.apply(that, newargs.concat([_restParam(function (err, nextargs) { cb(err, nextargs); - }])) + })])); }, function (err, results) { callback.apply(that, [err].concat(results)); }); - }; + }); }; async.compose = function (/* functions... */) { - return async.seq.apply(null, Array.prototype.reverse.call(arguments)); + return async.seq.apply(null, Array.prototype.reverse.call(arguments)); }; - var _applyEach = function (eachfn, fns /*args...*/) { - var go = function () { - var that = this; - var args = Array.prototype.slice.call(arguments); - var callback = args.pop(); - return eachfn(fns, function (fn, cb) { - fn.apply(that, args.concat([cb])); - }, - callback); - }; - if (arguments.length > 2) { - var args = Array.prototype.slice.call(arguments, 2); - return go.apply(this, args); - } - else { - return go; - } - }; - async.applyEach = doParallel(_applyEach); - async.applyEachSeries = doSeries(_applyEach); + + function _applyEach(eachfn) { + return _restParam(function(fns, args) { + var go = _restParam(function(args) { + var that = this; + var callback = args.pop(); + return eachfn(fns, function (fn, _, cb) { + fn.apply(that, args.concat([cb])); + }, + callback); + }); + if (args.length) { + return go.apply(this, args); + } + else { + return go; + } + }); + } + + async.applyEach = _applyEach(async.eachOf); + async.applyEachSeries = _applyEach(async.eachOfSeries); + async.forever = function (fn, callback) { + var done = only_once(callback || noop); + var task = ensureAsync(fn); function next(err) { if (err) { - if (callback) { - return callback(err); - } - throw err; + return done(err); } - fn(next); + task(next); } next(); }; + function ensureAsync(fn) { + return _restParam(function (args) { + var callback = args.pop(); + args.push(function () { + var innerArgs = arguments; + if (sync) { + async.setImmediate(function () { + callback.apply(null, innerArgs); + }); + } else { + callback.apply(null, innerArgs); + } + }); + var sync = true; + fn.apply(this, args); + sync = false; + }); + } + + async.ensureAsync = ensureAsync; + + async.constant = _restParam(function(values) { + var args = [null].concat(values); + return function (callback) { + return callback.apply(this, args); + }; + }); + + async.wrapSync = + async.asyncify = function asyncify(func) { + return _restParam(function (args) { + var callback = args.pop(); + var result; + try { + result = func.apply(this, args); + } catch (e) { + return callback(e); + } + // if result is Promise object + if (_isObject(result) && typeof result.then === "function") { + result.then(function(value) { + callback(null, value); + })["catch"](function(err) { + callback(err.message ? err : new Error(err)); + }); + } else { + callback(null, result); + } + }); + }; + // Node.js - if (typeof module !== 'undefined' && module.exports) { + if (typeof module === 'object' && module.exports) { module.exports = async; } // AMD / RequireJS - else if (typeof define !== 'undefined' && define.amd) { + else if (typeof define === 'function' && define.amd) { define([], function () { return async; }); @@ -1124,279 +1274,16 @@ }()); -}).call(this,require('_process')) -},{"_process":5}],2:[function(require,module,exports){ -'use strict'; - -// -// We store our EE objects in a plain object whose properties are event names. -// If `Object.create(null)` is not supported we prefix the event names with a -// `~` to make sure that the built-in object properties are not overridden or -// used as an attack vector. -// We also assume that `Object.create(null)` is available when the event name -// is an ES6 Symbol. -// -var prefix = typeof Object.create !== 'function' ? '~' : false; +}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"_process":24}],2:[function(require,module,exports){ /** - * Representation of a single EventEmitter function. + * Bit twiddling hacks for JavaScript. * - * @param {Function} fn Event handler to be called. - * @param {Mixed} context Context for function execution. - * @param {Boolean} once Only emit once - * @api private - */ -function EE(fn, context, once) { - this.fn = fn; - this.context = context; - this.once = once || false; -} - -/** - * Minimal EventEmitter interface that is molded against the Node.js - * EventEmitter interface. + * Author: Mikola Lysenko * - * @constructor - * @api public - */ -function EventEmitter() { /* Nothing to set */ } - -/** - * Holds the assigned EventEmitters by name. - * - * @type {Object} - * @private - */ -EventEmitter.prototype._events = undefined; - -/** - * Return a list of assigned event listeners. - * - * @param {String} event The events that should be listed. - * @param {Boolean} exists We only need to know if there are listeners. - * @returns {Array|Boolean} - * @api public - */ -EventEmitter.prototype.listeners = function listeners(event, exists) { - var evt = prefix ? prefix + event : event - , available = this._events && this._events[evt]; - - if (exists) return !!available; - if (!available) return []; - if (available.fn) return [available.fn]; - - for (var i = 0, l = available.length, ee = new Array(l); i < l; i++) { - ee[i] = available[i].fn; - } - - return ee; -}; - -/** - * Emit an event to all registered event listeners. - * - * @param {String} event The name of the event. - * @returns {Boolean} Indication if we've emitted an event. - * @api public - */ -EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) { - var evt = prefix ? prefix + event : event; - - if (!this._events || !this._events[evt]) return false; - - var listeners = this._events[evt] - , len = arguments.length - , args - , i; - - if ('function' === typeof listeners.fn) { - if (listeners.once) this.removeListener(event, listeners.fn, undefined, true); - - switch (len) { - case 1: return listeners.fn.call(listeners.context), true; - case 2: return listeners.fn.call(listeners.context, a1), true; - case 3: return listeners.fn.call(listeners.context, a1, a2), true; - case 4: return listeners.fn.call(listeners.context, a1, a2, a3), true; - case 5: return listeners.fn.call(listeners.context, a1, a2, a3, a4), true; - case 6: return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true; - } - - for (i = 1, args = new Array(len -1); i < len; i++) { - args[i - 1] = arguments[i]; - } - - listeners.fn.apply(listeners.context, args); - } else { - var length = listeners.length - , j; - - for (i = 0; i < length; i++) { - if (listeners[i].once) this.removeListener(event, listeners[i].fn, undefined, true); - - switch (len) { - case 1: listeners[i].fn.call(listeners[i].context); break; - case 2: listeners[i].fn.call(listeners[i].context, a1); break; - case 3: listeners[i].fn.call(listeners[i].context, a1, a2); break; - default: - if (!args) for (j = 1, args = new Array(len -1); j < len; j++) { - args[j - 1] = arguments[j]; - } - - listeners[i].fn.apply(listeners[i].context, args); - } - } - } - - return true; -}; - -/** - * Register a new EventListener for the given event. - * - * @param {String} event Name of the event. - * @param {Functon} fn Callback function. - * @param {Mixed} context The context of the function. - * @api public - */ -EventEmitter.prototype.on = function on(event, fn, context) { - var listener = new EE(fn, context || this) - , evt = prefix ? prefix + event : event; - - if (!this._events) this._events = prefix ? {} : Object.create(null); - if (!this._events[evt]) this._events[evt] = listener; - else { - if (!this._events[evt].fn) this._events[evt].push(listener); - else this._events[evt] = [ - this._events[evt], listener - ]; - } - - return this; -}; - -/** - * Add an EventListener that's only called once. - * - * @param {String} event Name of the event. - * @param {Function} fn Callback function. - * @param {Mixed} context The context of the function. - * @api public - */ -EventEmitter.prototype.once = function once(event, fn, context) { - var listener = new EE(fn, context || this, true) - , evt = prefix ? prefix + event : event; - - if (!this._events) this._events = prefix ? {} : Object.create(null); - if (!this._events[evt]) this._events[evt] = listener; - else { - if (!this._events[evt].fn) this._events[evt].push(listener); - else this._events[evt] = [ - this._events[evt], listener - ]; - } - - return this; -}; - -/** - * Remove event listeners. - * - * @param {String} event The event we want to remove. - * @param {Function} fn The listener that we need to find. - * @param {Mixed} context Only remove listeners matching this context. - * @param {Boolean} once Only remove once listeners. - * @api public - */ -EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) { - var evt = prefix ? prefix + event : event; - - if (!this._events || !this._events[evt]) return this; - - var listeners = this._events[evt] - , events = []; - - if (fn) { - if (listeners.fn) { - if ( - listeners.fn !== fn - || (once && !listeners.once) - || (context && listeners.context !== context) - ) { - events.push(listeners); - } - } else { - for (var i = 0, length = listeners.length; i < length; i++) { - if ( - listeners[i].fn !== fn - || (once && !listeners[i].once) - || (context && listeners[i].context !== context) - ) { - events.push(listeners[i]); - } - } - } - } - - // - // Reset the array, or remove it completely if we have no more listeners. - // - if (events.length) { - this._events[evt] = events.length === 1 ? events[0] : events; - } else { - delete this._events[evt]; - } - - return this; -}; - -/** - * Remove all listeners or only the listeners for the specified event. - * - * @param {String} event The event want to remove all listeners for. - * @api public - */ -EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) { - if (!this._events) return this; - - if (event) delete this._events[prefix ? prefix + event : event]; - else this._events = prefix ? {} : Object.create(null); - - return this; -}; - -// -// Alias methods names because people roll like that. -// -EventEmitter.prototype.off = EventEmitter.prototype.removeListener; -EventEmitter.prototype.addListener = EventEmitter.prototype.on; - -// -// This function doesn't apply anymore. -// -EventEmitter.prototype.setMaxListeners = function setMaxListeners() { - return this; -}; - -// -// Expose the prefix. -// -EventEmitter.prefixed = prefix; - -// -// Expose the module. -// -if ('undefined' !== typeof module) { - module.exports = EventEmitter; -} - -},{}],3:[function(require,module,exports){ -/** - * Bit twiddling hacks for JavaScript. - * - * Author: Mikola Lysenko - * - * Ported from Stanford bit twiddling hack library: - * http://graphics.stanford.edu/~seander/bithacks.html + * Ported from Stanford bit twiddling hack library: + * http://graphics.stanford.edu/~seander/bithacks.html */ "use strict"; "use restrict"; @@ -1595,26231 +1482,35198 @@ exports.nextCombination = function(v) { } -},{}],4:[function(require,module,exports){ -(function (process){ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -// resolves . and .. elements in a path array with directory names there -// must be no slashes, empty elements, or device names (c:\) in the array -// (so also no leading and trailing slashes - it does not distinguish -// relative and absolute paths) -function normalizeArray(parts, allowAboveRoot) { - // if the path tries to go above the root, `up` ends up > 0 - var up = 0; - for (var i = parts.length - 1; i >= 0; i--) { - var last = parts[i]; - if (last === '.') { - parts.splice(i, 1); - } else if (last === '..') { - parts.splice(i, 1); - up++; - } else if (up) { - parts.splice(i, 1); - up--; - } - } - - // if the path is allowed to go above the root, restore leading ..s - if (allowAboveRoot) { - for (; up--; up) { - parts.unshift('..'); - } - } - - return parts; -} +},{}],3:[function(require,module,exports){ +'use strict'; -// Split a filename into [root, dir, basename, ext], unix version -// 'root' is just a slash, or nothing. -var splitPathRe = - /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/; -var splitPath = function(filename) { - return splitPathRe.exec(filename).slice(1); -}; +module.exports = earcut; -// path.resolve([from ...], to) -// posix version -exports.resolve = function() { - var resolvedPath = '', - resolvedAbsolute = false; +function earcut(data, holeIndices, dim) { - for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) { - var path = (i >= 0) ? arguments[i] : process.cwd(); + dim = dim || 2; - // Skip empty and invalid entries - if (typeof path !== 'string') { - throw new TypeError('Arguments to path.resolve must be strings'); - } else if (!path) { - continue; - } + var hasHoles = holeIndices && holeIndices.length, + outerLen = hasHoles ? holeIndices[0] * dim : data.length, + outerNode = linkedList(data, 0, outerLen, dim, true), + triangles = []; - resolvedPath = path + '/' + resolvedPath; - resolvedAbsolute = path.charAt(0) === '/'; - } + if (!outerNode) return triangles; - // At this point the path should be resolved to a full absolute path, but - // handle relative paths to be safe (might happen when process.cwd() fails) + var minX, minY, maxX, maxY, x, y, size; - // Normalize the path - resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) { - return !!p; - }), !resolvedAbsolute).join('/'); + if (hasHoles) outerNode = eliminateHoles(data, holeIndices, outerNode, dim); - return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.'; -}; + // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox + if (data.length > 80 * dim) { + minX = maxX = data[0]; + minY = maxY = data[1]; -// path.normalize(path) -// posix version -exports.normalize = function(path) { - var isAbsolute = exports.isAbsolute(path), - trailingSlash = substr(path, -1) === '/'; + for (var i = dim; i < outerLen; i += dim) { + x = data[i]; + y = data[i + 1]; + if (x < minX) minX = x; + if (y < minY) minY = y; + if (x > maxX) maxX = x; + if (y > maxY) maxY = y; + } - // Normalize the path - path = normalizeArray(filter(path.split('/'), function(p) { - return !!p; - }), !isAbsolute).join('/'); + // minX, minY and size are later used to transform coords into integers for z-order calculation + size = Math.max(maxX - minX, maxY - minY); + } - if (!path && !isAbsolute) { - path = '.'; - } - if (path && trailingSlash) { - path += '/'; - } + earcutLinked(outerNode, triangles, dim, minX, minY, size); - return (isAbsolute ? '/' : '') + path; -}; + return triangles; +} -// posix version -exports.isAbsolute = function(path) { - return path.charAt(0) === '/'; -}; +// create a circular doubly linked list from polygon points in the specified winding order +function linkedList(data, start, end, dim, clockwise) { + var i, last; -// posix version -exports.join = function() { - var paths = Array.prototype.slice.call(arguments, 0); - return exports.normalize(filter(paths, function(p, index) { - if (typeof p !== 'string') { - throw new TypeError('Arguments to path.join must be strings'); + if (clockwise === (signedArea(data, start, end, dim) > 0)) { + for (i = start; i < end; i += dim) last = insertNode(i, data[i], data[i + 1], last); + } else { + for (i = end - dim; i >= start; i -= dim) last = insertNode(i, data[i], data[i + 1], last); } - return p; - }).join('/')); -}; + if (last && equals(last, last.next)) { + removeNode(last); + last = last.next; + } -// path.relative(from, to) -// posix version -exports.relative = function(from, to) { - from = exports.resolve(from).substr(1); - to = exports.resolve(to).substr(1); + return last; +} - function trim(arr) { - var start = 0; - for (; start < arr.length; start++) { - if (arr[start] !== '') break; - } +// eliminate colinear or duplicate points +function filterPoints(start, end) { + if (!start) return start; + if (!end) end = start; - var end = arr.length - 1; - for (; end >= 0; end--) { - if (arr[end] !== '') break; - } + var p = start, + again; + do { + again = false; - if (start > end) return []; - return arr.slice(start, end - start + 1); - } + if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) { + removeNode(p); + p = end = p.prev; + if (p === p.next) return null; + again = true; - var fromParts = trim(from.split('/')); - var toParts = trim(to.split('/')); + } else { + p = p.next; + } + } while (again || p !== end); - var length = Math.min(fromParts.length, toParts.length); - var samePartsLength = length; - for (var i = 0; i < length; i++) { - if (fromParts[i] !== toParts[i]) { - samePartsLength = i; - break; - } - } + return end; +} - var outputParts = []; - for (var i = samePartsLength; i < fromParts.length; i++) { - outputParts.push('..'); - } +// main ear slicing loop which triangulates a polygon (given as a linked list) +function earcutLinked(ear, triangles, dim, minX, minY, size, pass) { + if (!ear) return; - outputParts = outputParts.concat(toParts.slice(samePartsLength)); + // interlink polygon nodes in z-order + if (!pass && size) indexCurve(ear, minX, minY, size); - return outputParts.join('/'); -}; + var stop = ear, + prev, next; -exports.sep = '/'; -exports.delimiter = ':'; + // iterate through ears, slicing them one by one + while (ear.prev !== ear.next) { + prev = ear.prev; + next = ear.next; -exports.dirname = function(path) { - var result = splitPath(path), - root = result[0], - dir = result[1]; + if (size ? isEarHashed(ear, minX, minY, size) : isEar(ear)) { + // cut off the triangle + triangles.push(prev.i / dim); + triangles.push(ear.i / dim); + triangles.push(next.i / dim); - if (!root && !dir) { - // No dirname whatsoever - return '.'; - } + removeNode(ear); - if (dir) { - // It has a dirname, strip trailing slash - dir = dir.substr(0, dir.length - 1); - } + // skipping the next vertice leads to less sliver triangles + ear = next.next; + stop = next.next; - return root + dir; -}; + continue; + } + ear = next; -exports.basename = function(path, ext) { - var f = splitPath(path)[2]; - // TODO: make this comparison case-insensitive on windows? - if (ext && f.substr(-1 * ext.length) === ext) { - f = f.substr(0, f.length - ext.length); - } - return f; -}; + // if we looped through the whole remaining polygon and can't find any more ears + if (ear === stop) { + // try filtering points and slicing again + if (!pass) { + earcutLinked(filterPoints(ear), triangles, dim, minX, minY, size, 1); + // if this didn't work, try curing all small self-intersections locally + } else if (pass === 1) { + ear = cureLocalIntersections(ear, triangles, dim); + earcutLinked(ear, triangles, dim, minX, minY, size, 2); -exports.extname = function(path) { - return splitPath(path)[3]; -}; + // as a last resort, try splitting the remaining polygon into two + } else if (pass === 2) { + splitEarcut(ear, triangles, dim, minX, minY, size); + } -function filter (xs, f) { - if (xs.filter) return xs.filter(f); - var res = []; - for (var i = 0; i < xs.length; i++) { - if (f(xs[i], i, xs)) res.push(xs[i]); + break; + } } - return res; } -// String.prototype.substr - negative index don't work in IE8 -var substr = 'ab'.substr(-1) === 'b' - ? function (str, start, len) { return str.substr(start, len) } - : function (str, start, len) { - if (start < 0) start = str.length + start; - return str.substr(start, len); - } -; +// check whether a polygon node forms a valid ear with adjacent nodes +function isEar(ear) { + var a = ear.prev, + b = ear, + c = ear.next; -}).call(this,require('_process')) -},{"_process":5}],5:[function(require,module,exports){ -// shim for using process in browser + if (area(a, b, c) >= 0) return false; // reflex, can't be an ear -var process = module.exports = {}; -var queue = []; -var draining = false; -var currentQueue; -var queueIndex = -1; + // now make sure we don't have other points inside the potential ear + var p = ear.next.next; -function cleanUpNextTick() { - draining = false; - if (currentQueue.length) { - queue = currentQueue.concat(queue); - } else { - queueIndex = -1; - } - if (queue.length) { - drainQueue(); + while (p !== ear.prev) { + if (pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && + area(p.prev, p, p.next) >= 0) return false; + p = p.next; } + + return true; } -function drainQueue() { - if (draining) { - return; - } - var timeout = setTimeout(cleanUpNextTick); - draining = true; +function isEarHashed(ear, minX, minY, size) { + var a = ear.prev, + b = ear, + c = ear.next; - var len = queue.length; - while(len) { - currentQueue = queue; - queue = []; - while (++queueIndex < len) { - if (currentQueue) { - currentQueue[queueIndex].run(); - } - } - queueIndex = -1; - len = queue.length; - } - currentQueue = null; - draining = false; - clearTimeout(timeout); -} + if (area(a, b, c) >= 0) return false; // reflex, can't be an ear -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]; - } + // triangle bbox; min & max are calculated like this for speed + var minTX = a.x < b.x ? (a.x < c.x ? a.x : c.x) : (b.x < c.x ? b.x : c.x), + minTY = a.y < b.y ? (a.y < c.y ? a.y : c.y) : (b.y < c.y ? b.y : c.y), + maxTX = a.x > b.x ? (a.x > c.x ? a.x : c.x) : (b.x > c.x ? b.x : c.x), + maxTY = a.y > b.y ? (a.y > c.y ? a.y : c.y) : (b.y > c.y ? b.y : c.y); + + // z-order range for the current triangle bbox; + var minZ = zOrder(minTX, minTY, minX, minY, size), + maxZ = zOrder(maxTX, maxTY, minX, minY, size); + + // first look for points inside the triangle in increasing z-order + var p = ear.nextZ; + + while (p && p.z <= maxZ) { + if (p !== ear.prev && p !== ear.next && + pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && + area(p.prev, p, p.next) >= 0) return false; + p = p.nextZ; } - queue.push(new Item(fun, args)); - if (queue.length === 1 && !draining) { - setTimeout(drainQueue, 0); + + // then look for points in decreasing z-order + p = ear.prevZ; + + while (p && p.z >= minZ) { + if (p !== ear.prev && p !== ear.next && + pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && + area(p.prev, p, p.next) >= 0) return false; + p = p.prevZ; } -}; -// v8 likes predictible objects -function Item(fun, array) { - this.fun = fun; - this.array = array; + return true; } -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() {} +// go through all polygon nodes and cure small local self-intersections +function cureLocalIntersections(start, triangles, dim) { + var p = start; + do { + var a = p.prev, + b = p.next.next; -process.on = noop; -process.addListener = noop; -process.once = noop; -process.off = noop; -process.removeListener = noop; -process.removeAllListeners = noop; -process.emit = noop; + if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) { -process.binding = function (name) { - throw new Error('process.binding is not supported'); -}; + triangles.push(a.i / dim); + triangles.push(p.i / dim); + triangles.push(b.i / dim); -process.cwd = function () { return '/' }; -process.chdir = function (dir) { - throw new Error('process.chdir is not supported'); -}; -process.umask = function() { return 0; }; + // remove two nodes involved + removeNode(p); + removeNode(p.next); -},{}],6:[function(require,module,exports){ -(function (global){ -/*! https://mths.be/punycode v1.3.2 by @mathias */ -;(function(root) { + p = start = b; + } + p = p.next; + } while (p !== start); - /** 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; - } + return p; +} - /** - * The `punycode` object. - * @name punycode - * @type Object - */ - var punycode, +// try splitting polygon into two and triangulate them independently +function splitEarcut(start, triangles, dim, minX, minY, size) { + // look for a valid diagonal that divides the polygon into two + var a = start; + do { + var b = a.next.next; + while (b !== a.prev) { + if (a.i !== b.i && isValidDiagonal(a, b)) { + // split the polygon in two by the diagonal + var c = splitPolygon(a, b); - /** Highest positive signed 32-bit float value */ - maxInt = 2147483647, // aka. 0x7FFFFFFF or 2^31-1 + // filter colinear points around the cuts + a = filterPoints(a, a.next); + c = filterPoints(c, c.next); - /** Bootstring parameters */ - base = 36, - tMin = 1, - tMax = 26, - skew = 38, - damp = 700, - initialBias = 72, - initialN = 128, // 0x80 - delimiter = '-', // '\x2D' + // run earcut on each half + earcutLinked(a, triangles, dim, minX, minY, size); + earcutLinked(c, triangles, dim, minX, minY, size); + return; + } + b = b.next; + } + a = a.next; + } while (a !== start); +} - /** Regular expressions */ - regexPunycode = /^xn--/, - regexNonASCII = /[^\x20-\x7E]/, // unprintable ASCII chars + non-ASCII chars - regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g, // RFC 3490 separators +// link every hole into the outer loop, producing a single-ring polygon without holes +function eliminateHoles(data, holeIndices, outerNode, dim) { + var queue = [], + i, len, start, end, list; - /** 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' - }, + for (i = 0, len = holeIndices.length; i < len; i++) { + start = holeIndices[i] * dim; + end = i < len - 1 ? holeIndices[i + 1] * dim : data.length; + list = linkedList(data, start, end, dim, false); + if (list === list.next) list.steiner = true; + queue.push(getLeftmost(list)); + } - /** Convenience shortcuts */ - baseMinusTMin = base - tMin, - floor = Math.floor, - stringFromCharCode = String.fromCharCode, + queue.sort(compareX); - /** Temporary variable */ - key; + // process holes from left to right + for (i = 0; i < queue.length; i++) { + eliminateHole(queue[i], outerNode); + outerNode = filterPoints(outerNode, outerNode.next); + } - /*--------------------------------------------------------------------------*/ + return outerNode; +} - /** - * 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 compareX(a, b) { + return a.x - b.x; +} - /** - * 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; - } +// find a bridge between vertices that connects hole with an outer ring and and link it +function eliminateHole(hole, outerNode) { + outerNode = findHoleBridge(hole, outerNode); + if (outerNode) { + var b = splitPolygon(outerNode, hole); + filterPoints(b, b.next); + } +} - /** - * 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; - } +// David Eberly's algorithm for finding a bridge between hole and outer polygon +function findHoleBridge(hole, outerNode) { + var p = outerNode, + hx = hole.x, + hy = hole.y, + qx = -Infinity, + m; - /** - * 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(''); - } + // find a segment intersected by a ray from the hole's leftmost point to the left; + // segment's endpoint with lesser x will be potential connection point + do { + if (hy <= p.y && hy >= p.next.y) { + var x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y); + if (x <= hx && x > qx) { + qx = x; + if (x === hx) { + if (hy === p.y) return p; + if (hy === p.next.y) return p.next; + } + m = p.x < p.next.x ? p : p.next; + } + } + p = p.next; + } while (p !== outerNode); - /** - * 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; - } + if (!m) return null; - /** - * 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); - } + if (hx === qx) return m.prev; // hole touches outer segment; pick lower endpoint - /** - * 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)); - } + // look for points inside the triangle of hole point, segment intersection and endpoint; + // if there are no points found, we have a valid connection; + // otherwise choose the point of the minimum angle with the ray as connection point - /** - * 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; + var stop = m, + mx = m.x, + my = m.y, + tanMin = Infinity, + tan; - // 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. + p = m.next; - basic = input.lastIndexOf(delimiter); - if (basic < 0) { - basic = 0; - } + while (p !== stop) { + if (hx >= p.x && p.x >= mx && + pointInTriangle(hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y)) { - 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)); - } + tan = Math.abs(hy - p.y) / (hx - p.x); // tangential - // Main decoding loop: start just after the last delimiter if any basic code - // points were copied; start at the beginning otherwise. + if ((tan < tanMin || (tan === tanMin && p.x > m.x)) && locallyInside(p, hole)) { + m = p; + tanMin = tan; + } + } - for (index = basic > 0 ? basic + 1 : 0; index < inputLength; /* no final expression */) { + p = p.next; + } - // `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) { + return m; +} - if (index >= inputLength) { - error('invalid-input'); - } +// interlink polygon nodes in z-order +function indexCurve(start, minX, minY, size) { + var p = start; + do { + if (p.z === null) p.z = zOrder(p.x, p.y, minX, minY, size); + p.prevZ = p.prev; + p.nextZ = p.next; + p = p.next; + } while (p !== start); - digit = basicToDigit(input.charCodeAt(index++)); + p.prevZ.nextZ = null; + p.prevZ = null; - if (digit >= base || digit > floor((maxInt - i) / w)) { - error('overflow'); - } + sortLinked(p); +} - i += digit * w; - t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias); +// Simon Tatham's linked list merge sort algorithm +// http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html +function sortLinked(list) { + var i, p, q, e, tail, numMerges, pSize, qSize, + inSize = 1; - if (digit < t) { - break; - } + do { + p = list; + list = null; + tail = null; + numMerges = 0; - baseMinusT = base - t; - if (w > floor(maxInt / baseMinusT)) { - error('overflow'); - } + while (p) { + numMerges++; + q = p; + pSize = 0; + for (i = 0; i < inSize; i++) { + pSize++; + q = q.nextZ; + if (!q) break; + } - w *= baseMinusT; + qSize = inSize; - } + while (pSize > 0 || (qSize > 0 && q)) { - out = output.length + 1; - bias = adapt(i - oldi, out, oldi == 0); + if (pSize === 0) { + e = q; + q = q.nextZ; + qSize--; + } else if (qSize === 0 || !q) { + e = p; + p = p.nextZ; + pSize--; + } else if (p.z <= q.z) { + e = p; + p = p.nextZ; + pSize--; + } else { + e = q; + q = q.nextZ; + qSize--; + } - // `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'); - } + if (tail) tail.nextZ = e; + else list = e; - n += floor(i / out); - i %= out; + e.prevZ = tail; + tail = e; + } - // Insert `n` at position `i` of the output - output.splice(i++, 0, n); + p = q; + } - } + tail.nextZ = null; + inSize *= 2; - return ucs2encode(output); - } + } while (numMerges > 1); - /** - * 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; + return list; +} - // Convert the input in UCS-2 to Unicode - input = ucs2decode(input); +// z-order of a point given coords and size of the data bounding box +function zOrder(x, y, minX, minY, size) { + // coords are transformed into non-negative 15-bit integer range + x = 32767 * (x - minX) / size; + y = 32767 * (y - minY) / size; - // Cache the length - inputLength = input.length; + x = (x | (x << 8)) & 0x00FF00FF; + x = (x | (x << 4)) & 0x0F0F0F0F; + x = (x | (x << 2)) & 0x33333333; + x = (x | (x << 1)) & 0x55555555; - // Initialize the state - n = initialN; - delta = 0; - bias = initialBias; + y = (y | (y << 8)) & 0x00FF00FF; + y = (y | (y << 4)) & 0x0F0F0F0F; + y = (y | (y << 2)) & 0x33333333; + y = (y | (y << 1)) & 0x55555555; - // Handle the basic code points - for (j = 0; j < inputLength; ++j) { - currentValue = input[j]; - if (currentValue < 0x80) { - output.push(stringFromCharCode(currentValue)); - } - } + return x | (y << 1); +} - handledCPCount = basicLength = output.length; +// find the leftmost node of a polygon ring +function getLeftmost(start) { + var p = start, + leftmost = start; + do { + if (p.x < leftmost.x) leftmost = p; + p = p.next; + } while (p !== start); - // `handledCPCount` is the number of code points that have been handled; - // `basicLength` is the number of basic code points. + return leftmost; +} - // Finish the basic string - if it is not empty - with a delimiter - if (basicLength) { - output.push(delimiter); - } +// check if a point lies within a convex triangle +function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) { + return (cx - px) * (ay - py) - (ax - px) * (cy - py) >= 0 && + (ax - px) * (by - py) - (bx - px) * (ay - py) >= 0 && + (bx - px) * (cy - py) - (cx - px) * (by - py) >= 0; +} - // Main encoding loop: - while (handledCPCount < inputLength) { +// check if a diagonal between two polygon nodes is valid (lies in polygon interior) +function isValidDiagonal(a, b) { + return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && + locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b); +} - // 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; - } - } +// signed area of a triangle +function area(p, q, r) { + return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y); +} - // 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'); - } +// check if two points are equal +function equals(p1, p2) { + return p1.x === p2.x && p1.y === p2.y; +} - delta += (m - n) * handledCPCountPlusOne; - n = m; +// check if two segments intersect +function intersects(p1, q1, p2, q2) { + if ((equals(p1, q1) && equals(p2, q2)) || + (equals(p1, q2) && equals(p2, q1))) return true; + return area(p1, q1, p2) > 0 !== area(p1, q1, q2) > 0 && + area(p2, q2, p1) > 0 !== area(p2, q2, q1) > 0; +} - for (j = 0; j < inputLength; ++j) { - currentValue = input[j]; +// check if a polygon diagonal intersects any polygon segments +function intersectsPolygon(a, b) { + var p = a; + do { + if (p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i && + intersects(p, p.next, a, b)) return true; + p = p.next; + } while (p !== a); - if (currentValue < n && ++delta > maxInt) { - error('overflow'); - } + return false; +} - 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); - } +// check if a polygon diagonal is locally inside the polygon +function locallyInside(a, b) { + return area(a.prev, a, a.next) < 0 ? + area(a, b, a.next) >= 0 && area(a, a.prev, b) >= 0 : + area(a, b, a.prev) < 0 || area(a, a.next, b) < 0; +} - output.push(stringFromCharCode(digitToBasic(q, 0))); - bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength); - delta = 0; - ++handledCPCount; - } - } +// check if the middle point of a polygon diagonal is inside the polygon +function middleInside(a, b) { + var p = a, + inside = false, + px = (a.x + b.x) / 2, + py = (a.y + b.y) / 2; + do { + if (((p.y > py) !== (p.next.y > py)) && (px < (p.next.x - p.x) * (py - p.y) / (p.next.y - p.y) + p.x)) + inside = !inside; + p = p.next; + } while (p !== a); - ++delta; - ++n; + return inside; +} - } - return output.join(''); - } +// link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two; +// if one belongs to the outer ring and another to a hole, it merges it into a single ring +function splitPolygon(a, b) { + var a2 = new Node(a.i, a.x, a.y), + b2 = new Node(b.i, b.x, b.y), + an = a.next, + bp = b.prev; - /** - * 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; - }); - } + a.next = b; + b.prev = a; - /** - * 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; - }); - } + a2.next = an; + an.prev = a2; - /*--------------------------------------------------------------------------*/ + b2.next = a2; + a2.prev = b2; - /** 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 - }; + bp.next = b2; + b2.prev = bp; - /** 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; - } + return b2; +} -}(this)); +// create a node and optionally link it with previous one (in a circular doubly linked list) +function insertNode(i, x, y, last) { + var p = new Node(i, x, y); -}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{}],7:[function(require,module,exports){ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. + if (!last) { + p.prev = p; + p.next = p; -'use strict'; + } else { + p.next = last.next; + p.prev = last; + last.next.prev = p; + last.next = p; + } + return p; +} -// If obj.hasOwnProperty has been overridden, then calling -// obj.hasOwnProperty(prop) will break. -// See: https://github.com/joyent/node/issues/1707 -function hasOwnProperty(obj, prop) { - return Object.prototype.hasOwnProperty.call(obj, prop); +function removeNode(p) { + p.next.prev = p.prev; + p.prev.next = p.next; + + if (p.prevZ) p.prevZ.nextZ = p.nextZ; + if (p.nextZ) p.nextZ.prevZ = p.prevZ; } -module.exports = function(qs, sep, eq, options) { - sep = sep || '&'; - eq = eq || '='; - var obj = {}; +function Node(i, x, y) { + // vertice index in coordinates array + this.i = i; - if (typeof qs !== 'string' || qs.length === 0) { - return obj; - } + // vertex coordinates + this.x = x; + this.y = y; - var regexp = /\+/g; - qs = qs.split(sep); + // previous and next vertice nodes in a polygon ring + this.prev = null; + this.next = null; - var maxKeys = 1000; - if (options && typeof options.maxKeys === 'number') { - maxKeys = options.maxKeys; - } + // z-order curve value + this.z = null; - var len = qs.length; - // maxKeys <= 0 means that we should not limit keys count - if (maxKeys > 0 && len > maxKeys) { - len = maxKeys; - } + // previous and next nodes in z-order + this.prevZ = null; + this.nextZ = null; - for (var i = 0; i < len; ++i) { - var x = qs[i].replace(regexp, '%20'), - idx = x.indexOf(eq), - kstr, vstr, k, v; + // indicates whether this is a steiner point + this.steiner = false; +} - if (idx >= 0) { - kstr = x.substr(0, idx); - vstr = x.substr(idx + 1); - } else { - kstr = x; - vstr = ''; +// return a percentage difference between the polygon area and its triangulation area; +// used to verify correctness of triangulation +earcut.deviation = function (data, holeIndices, dim, triangles) { + var hasHoles = holeIndices && holeIndices.length; + var outerLen = hasHoles ? holeIndices[0] * dim : data.length; + + var polygonArea = Math.abs(signedArea(data, 0, outerLen, dim)); + if (hasHoles) { + for (var i = 0, len = holeIndices.length; i < len; i++) { + var start = holeIndices[i] * dim; + var end = i < len - 1 ? holeIndices[i + 1] * dim : data.length; + polygonArea -= Math.abs(signedArea(data, start, end, dim)); + } } - k = decodeURIComponent(kstr); - v = decodeURIComponent(vstr); - - if (!hasOwnProperty(obj, k)) { - obj[k] = v; - } else if (isArray(obj[k])) { - obj[k].push(v); - } else { - obj[k] = [obj[k], v]; + var trianglesArea = 0; + for (i = 0; i < triangles.length; i += 3) { + var a = triangles[i] * dim; + var b = triangles[i + 1] * dim; + var c = triangles[i + 2] * dim; + trianglesArea += Math.abs( + (data[a] - data[c]) * (data[b + 1] - data[a + 1]) - + (data[a] - data[b]) * (data[c + 1] - data[a + 1])); } - } - return obj; + return polygonArea === 0 && trianglesArea === 0 ? 0 : + Math.abs((trianglesArea - polygonArea) / polygonArea); }; -var isArray = Array.isArray || function (xs) { - return Object.prototype.toString.call(xs) === '[object Array]'; -}; +function signedArea(data, start, end, dim) { + var sum = 0; + for (var i = start, j = end - dim; i < end; i += dim) { + sum += (data[j] - data[i]) * (data[i + 1] + data[j + 1]); + j = i; + } + return sum; +} -},{}],8:[function(require,module,exports){ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. +// turn a polygon in a multi-dimensional array form (e.g. as in GeoJSON) into a form Earcut accepts +earcut.flatten = function (data) { + var dim = data[0][0].length, + result = {vertices: [], holes: [], dimensions: dim}, + holeIndex = 0; + + for (var i = 0; i < data.length; i++) { + for (var j = 0; j < data[i].length; j++) { + for (var d = 0; d < dim; d++) result.vertices.push(data[i][j][d]); + } + if (i > 0) { + holeIndex += data[i - 1].length; + result.holes.push(holeIndex); + } + } + return result; +}; +},{}],4:[function(require,module,exports){ 'use strict'; -var stringifyPrimitive = function(v) { - switch (typeof v) { - case 'string': - return v; +var has = Object.prototype.hasOwnProperty; - case 'boolean': - return v ? 'true' : 'false'; +// +// We store our EE objects in a plain object whose properties are event names. +// If `Object.create(null)` is not supported we prefix the event names with a +// `~` to make sure that the built-in object properties are not overridden or +// used as an attack vector. +// We also assume that `Object.create(null)` is available when the event name +// is an ES6 Symbol. +// +var prefix = typeof Object.create !== 'function' ? '~' : false; - case 'number': - return isFinite(v) ? v : ''; +/** + * Representation of a single EventEmitter function. + * + * @param {Function} fn Event handler to be called. + * @param {Mixed} context Context for function execution. + * @param {Boolean} [once=false] Only emit once + * @api private + */ +function EE(fn, context, once) { + this.fn = fn; + this.context = context; + this.once = once || false; +} - default: - return ''; - } -}; - -module.exports = function(obj, sep, eq, name) { - sep = sep || '&'; - eq = eq || '='; - if (obj === null) { - obj = undefined; - } - - if (typeof obj === 'object') { - return map(objectKeys(obj), function(k) { - var ks = encodeURIComponent(stringifyPrimitive(k)) + eq; - if (isArray(obj[k])) { - return map(obj[k], function(v) { - return ks + encodeURIComponent(stringifyPrimitive(v)); - }).join(sep); - } else { - return ks + encodeURIComponent(stringifyPrimitive(obj[k])); - } - }).join(sep); +/** + * Minimal EventEmitter interface that is molded against the Node.js + * EventEmitter interface. + * + * @constructor + * @api public + */ +function EventEmitter() { /* Nothing to set */ } - } +/** + * Hold the assigned EventEmitters by name. + * + * @type {Object} + * @private + */ +EventEmitter.prototype._events = undefined; - if (!name) return ''; - return encodeURIComponent(stringifyPrimitive(name)) + eq + - encodeURIComponent(stringifyPrimitive(obj)); -}; +/** + * Return an array listing the events for which the emitter has registered + * listeners. + * + * @returns {Array} + * @api public + */ +EventEmitter.prototype.eventNames = function eventNames() { + var events = this._events + , names = [] + , name; -var isArray = Array.isArray || function (xs) { - return Object.prototype.toString.call(xs) === '[object Array]'; -}; + if (!events) return names; -function map (xs, f) { - if (xs.map) return xs.map(f); - var res = []; - for (var i = 0; i < xs.length; i++) { - res.push(f(xs[i], i)); + for (name in events) { + if (has.call(events, name)) names.push(prefix ? name.slice(1) : name); } - return res; -} -var objectKeys = Object.keys || function (obj) { - var res = []; - for (var key in obj) { - if (Object.prototype.hasOwnProperty.call(obj, key)) res.push(key); + if (Object.getOwnPropertySymbols) { + return names.concat(Object.getOwnPropertySymbols(events)); } - return res; -}; -},{}],9:[function(require,module,exports){ -'use strict'; + return names; +}; -exports.decode = exports.parse = require('./decode'); -exports.encode = exports.stringify = require('./encode'); +/** + * Return a list of assigned event listeners. + * + * @param {String} event The events that should be listed. + * @param {Boolean} exists We only need to know if there are listeners. + * @returns {Array|Boolean} + * @api public + */ +EventEmitter.prototype.listeners = function listeners(event, exists) { + var evt = prefix ? prefix + event : event + , available = this._events && this._events[evt]; -},{"./decode":7,"./encode":8}],10:[function(require,module,exports){ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. + if (exists) return !!available; + if (!available) return []; + if (available.fn) return [available.fn]; -var punycode = require('punycode'); + for (var i = 0, l = available.length, ee = new Array(l); i < l; i++) { + ee[i] = available[i].fn; + } -exports.parse = urlParse; -exports.resolve = urlResolve; -exports.resolveObject = urlResolveObject; -exports.format = urlFormat; + return ee; +}; -exports.Url = Url; +/** + * Emit an event to all registered event listeners. + * + * @param {String} event The name of the event. + * @returns {Boolean} Indication if we've emitted an event. + * @api public + */ +EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) { + var evt = prefix ? prefix + event : event; -function Url() { - this.protocol = null; - this.slashes = null; - this.auth = null; - this.host = null; - this.port = null; - this.hostname = null; - this.hash = null; - this.search = null; - this.query = null; - this.pathname = null; - this.path = null; - this.href = null; -} + if (!this._events || !this._events[evt]) return false; -// Reference: RFC 3986, RFC 1808, RFC 2396 + var listeners = this._events[evt] + , len = arguments.length + , args + , i; -// define these here so at least they only have to be -// compiled once on the first module load. -var protocolPattern = /^([a-z0-9.+-]+:)/i, - portPattern = /:[0-9]*$/, + if ('function' === typeof listeners.fn) { + if (listeners.once) this.removeListener(event, listeners.fn, undefined, true); - // RFC 2396: characters reserved for delimiting URLs. - // We actually just auto-escape these. - delims = ['<', '>', '"', '`', ' ', '\r', '\n', '\t'], + switch (len) { + case 1: return listeners.fn.call(listeners.context), true; + case 2: return listeners.fn.call(listeners.context, a1), true; + case 3: return listeners.fn.call(listeners.context, a1, a2), true; + case 4: return listeners.fn.call(listeners.context, a1, a2, a3), true; + case 5: return listeners.fn.call(listeners.context, a1, a2, a3, a4), true; + case 6: return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true; + } - // RFC 2396: characters not allowed for various reasons. - unwise = ['{', '}', '|', '\\', '^', '`'].concat(delims), + for (i = 1, args = new Array(len -1); i < len; i++) { + args[i - 1] = arguments[i]; + } - // Allowed by RFCs, but cause of XSS attacks. Always escape these. - autoEscape = ['\''].concat(unwise), - // Characters that are never ever allowed in a hostname. - // Note that any invalid chars are also handled, but these - // are the ones that are *expected* to be seen, so we fast-path - // them. - nonHostChars = ['%', '/', '?', ';', '#'].concat(autoEscape), - hostEndingChars = ['/', '?', '#'], - hostnameMaxLen = 255, - hostnamePartPattern = /^[a-z0-9A-Z_-]{0,63}$/, - hostnamePartStart = /^([a-z0-9A-Z_-]{0,63})(.*)$/, - // protocols that can allow "unsafe" and "unwise" chars. - unsafeProtocol = { - 'javascript': true, - 'javascript:': true - }, - // protocols that never have a hostname. - hostlessProtocol = { - 'javascript': true, - 'javascript:': true - }, - // protocols that always contain a // bit. - slashedProtocol = { - 'http': true, - 'https': true, - 'ftp': true, - 'gopher': true, - 'file': true, - 'http:': true, - 'https:': true, - 'ftp:': true, - 'gopher:': true, - 'file:': true - }, - querystring = require('querystring'); + listeners.fn.apply(listeners.context, args); + } else { + var length = listeners.length + , j; -function urlParse(url, parseQueryString, slashesDenoteHost) { - if (url && isObject(url) && url instanceof Url) return url; + for (i = 0; i < length; i++) { + if (listeners[i].once) this.removeListener(event, listeners[i].fn, undefined, true); - var u = new Url; - u.parse(url, parseQueryString, slashesDenoteHost); - return u; -} + switch (len) { + case 1: listeners[i].fn.call(listeners[i].context); break; + case 2: listeners[i].fn.call(listeners[i].context, a1); break; + case 3: listeners[i].fn.call(listeners[i].context, a1, a2); break; + default: + if (!args) for (j = 1, args = new Array(len -1); j < len; j++) { + args[j - 1] = arguments[j]; + } -Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) { - if (!isString(url)) { - throw new TypeError("Parameter 'url' must be a string, not " + typeof url); + listeners[i].fn.apply(listeners[i].context, args); + } + } } - var rest = url; + return true; +}; - // trim before proceeding. - // This is to support parse stuff like " http://foo.com \n" - rest = rest.trim(); +/** + * Register a new EventListener for the given event. + * + * @param {String} event Name of the event. + * @param {Function} fn Callback function. + * @param {Mixed} [context=this] The context of the function. + * @api public + */ +EventEmitter.prototype.on = function on(event, fn, context) { + var listener = new EE(fn, context || this) + , evt = prefix ? prefix + event : event; - var proto = protocolPattern.exec(rest); - if (proto) { - proto = proto[0]; - var lowerProto = proto.toLowerCase(); - this.protocol = lowerProto; - rest = rest.substr(proto.length); + if (!this._events) this._events = prefix ? {} : Object.create(null); + if (!this._events[evt]) this._events[evt] = listener; + else { + if (!this._events[evt].fn) this._events[evt].push(listener); + else this._events[evt] = [ + this._events[evt], listener + ]; } - // figure out if it's got a host - // user@server is *always* interpreted as a hostname, and url - // resolution will treat //foo/bar as host=foo,path=bar because that's - // how the browser resolves relative URLs. - if (slashesDenoteHost || proto || rest.match(/^\/\/[^@\/]+@[^@\/]+/)) { - var slashes = rest.substr(0, 2) === '//'; - if (slashes && !(proto && hostlessProtocol[proto])) { - rest = rest.substr(2); - this.slashes = true; - } + return this; +}; + +/** + * Add an EventListener that's only called once. + * + * @param {String} event Name of the event. + * @param {Function} fn Callback function. + * @param {Mixed} [context=this] The context of the function. + * @api public + */ +EventEmitter.prototype.once = function once(event, fn, context) { + var listener = new EE(fn, context || this, true) + , evt = prefix ? prefix + event : event; + + if (!this._events) this._events = prefix ? {} : Object.create(null); + if (!this._events[evt]) this._events[evt] = listener; + else { + if (!this._events[evt].fn) this._events[evt].push(listener); + else this._events[evt] = [ + this._events[evt], listener + ]; } - if (!hostlessProtocol[proto] && - (slashes || (proto && !slashedProtocol[proto]))) { + return this; +}; - // there's a hostname. - // the first instance of /, ?, ;, or # ends the host. - // - // If there is an @ in the hostname, then non-host chars *are* allowed - // to the left of the last @ sign, unless some host-ending character - // comes *before* the @-sign. - // URLs are obnoxious. - // - // ex: - // http://a@b@c/ => user:a@b host:c - // http://a@b?@c => user:a host:c path:/?@c +/** + * Remove event listeners. + * + * @param {String} event The event we want to remove. + * @param {Function} fn The listener that we need to find. + * @param {Mixed} context Only remove listeners matching this context. + * @param {Boolean} once Only remove once listeners. + * @api public + */ +EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) { + var evt = prefix ? prefix + event : event; - // v0.12 TODO(isaacs): This is not quite how Chrome does things. - // Review our test case against browsers more comprehensively. + if (!this._events || !this._events[evt]) return this; - // find the first instance of any hostEndingChars - var hostEnd = -1; - for (var i = 0; i < hostEndingChars.length; i++) { - var hec = rest.indexOf(hostEndingChars[i]); - if (hec !== -1 && (hostEnd === -1 || hec < hostEnd)) - hostEnd = hec; - } + var listeners = this._events[evt] + , events = []; - // at this point, either we have an explicit point where the - // auth portion cannot go past, or the last @ char is the decider. - var auth, atSign; - if (hostEnd === -1) { - // atSign can be anywhere. - atSign = rest.lastIndexOf('@'); + if (fn) { + if (listeners.fn) { + if ( + listeners.fn !== fn + || (once && !listeners.once) + || (context && listeners.context !== context) + ) { + events.push(listeners); + } } else { - // atSign must be in auth portion. - // http://a@b/c@d => host:b auth:a path:/c@d - atSign = rest.lastIndexOf('@', hostEnd); + for (var i = 0, length = listeners.length; i < length; i++) { + if ( + listeners[i].fn !== fn + || (once && !listeners[i].once) + || (context && listeners[i].context !== context) + ) { + events.push(listeners[i]); + } + } } + } - // Now we have a portion which is definitely the auth. - // Pull that off. - if (atSign !== -1) { - auth = rest.slice(0, atSign); - rest = rest.slice(atSign + 1); - this.auth = decodeURIComponent(auth); - } + // + // Reset the array, or remove it completely if we have no more listeners. + // + if (events.length) { + this._events[evt] = events.length === 1 ? events[0] : events; + } else { + delete this._events[evt]; + } - // the host is the remaining to the left of the first non-host char - hostEnd = -1; - for (var i = 0; i < nonHostChars.length; i++) { - var hec = rest.indexOf(nonHostChars[i]); - if (hec !== -1 && (hostEnd === -1 || hec < hostEnd)) - hostEnd = hec; - } - // if we still have not hit it, then the entire thing is a host. - if (hostEnd === -1) - hostEnd = rest.length; + return this; +}; - this.host = rest.slice(0, hostEnd); - rest = rest.slice(hostEnd); +/** + * Remove all listeners or only the listeners for the specified event. + * + * @param {String} event The event want to remove all listeners for. + * @api public + */ +EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) { + if (!this._events) return this; - // pull out port. - this.parseHost(); + if (event) delete this._events[prefix ? prefix + event : event]; + else this._events = prefix ? {} : Object.create(null); - // we've indicated that there is a hostname, - // so even if it's empty, it has to be present. - this.hostname = this.hostname || ''; + return this; +}; - // if hostname begins with [ and ends with ] - // assume that it's an IPv6 address. - var ipv6Hostname = this.hostname[0] === '[' && - this.hostname[this.hostname.length - 1] === ']'; +// +// Alias methods names because people roll like that. +// +EventEmitter.prototype.off = EventEmitter.prototype.removeListener; +EventEmitter.prototype.addListener = EventEmitter.prototype.on; - // validate a little. - if (!ipv6Hostname) { - var hostparts = this.hostname.split(/\./); - for (var i = 0, l = hostparts.length; i < l; i++) { - var part = hostparts[i]; - if (!part) continue; - if (!part.match(hostnamePartPattern)) { - var newpart = ''; - for (var j = 0, k = part.length; j < k; j++) { - if (part.charCodeAt(j) > 127) { - // we replace non-ASCII char with a temporary placeholder - // we need this to make sure size of hostname is not - // broken by replacing non-ASCII by nothing - newpart += 'x'; - } else { - newpart += part[j]; - } - } - // we test again with ASCII char only - if (!newpart.match(hostnamePartPattern)) { - var validParts = hostparts.slice(0, i); - var notHost = hostparts.slice(i + 1); - var bit = part.match(hostnamePartStart); - if (bit) { - validParts.push(bit[1]); - notHost.unshift(bit[2]); - } - if (notHost.length) { - rest = '/' + notHost.join('.') + rest; - } - this.hostname = validParts.join('.'); - break; - } - } - } - } +// +// This function doesn't apply anymore. +// +EventEmitter.prototype.setMaxListeners = function setMaxListeners() { + return this; +}; - if (this.hostname.length > hostnameMaxLen) { - this.hostname = ''; - } else { - // hostnames are always lower case. - this.hostname = this.hostname.toLowerCase(); - } +// +// Expose the prefix. +// +EventEmitter.prefixed = prefix; - if (!ipv6Hostname) { - // IDNA Support: Returns a puny coded representation of "domain". - // It only converts the part of the domain name that - // has non ASCII characters. I.e. it dosent matter if - // you call it with a domain that already is in ASCII. - var domainArray = this.hostname.split('.'); - var newOut = []; - for (var i = 0; i < domainArray.length; ++i) { - var s = domainArray[i]; - newOut.push(s.match(/[^A-Za-z0-9_-]/) ? - 'xn--' + punycode.encode(s) : s); - } - this.hostname = newOut.join('.'); - } +// +// Expose the module. +// +if ('undefined' !== typeof module) { + module.exports = EventEmitter; +} - var p = this.port ? ':' + this.port : ''; - var h = this.hostname || ''; - this.host = h + p; - this.href += this.host; +},{}],5:[function(require,module,exports){ +/** + * isMobile.js v0.4.0 + * + * A simple library to detect Apple phones and tablets, + * Android phones and tablets, other mobile devices (like blackberry, mini-opera and windows phone), + * and any kind of seven inch device, via user agent sniffing. + * + * @author: Kai Mallea (kmallea@gmail.com) + * + * @license: http://creativecommons.org/publicdomain/zero/1.0/ + */ +(function (global) { - // strip [ and ] from the hostname - // the host field still retains them, though - if (ipv6Hostname) { - this.hostname = this.hostname.substr(1, this.hostname.length - 2); - if (rest[0] !== '/') { - rest = '/' + rest; - } - } - } + var apple_phone = /iPhone/i, + apple_ipod = /iPod/i, + apple_tablet = /iPad/i, + android_phone = /(?=.*\bAndroid\b)(?=.*\bMobile\b)/i, // Match 'Android' AND 'Mobile' + android_tablet = /Android/i, + amazon_phone = /(?=.*\bAndroid\b)(?=.*\bSD4930UR\b)/i, + amazon_tablet = /(?=.*\bAndroid\b)(?=.*\b(?:KFOT|KFTT|KFJWI|KFJWA|KFSOWI|KFTHWI|KFTHWA|KFAPWI|KFAPWA|KFARWI|KFASWI|KFSAWI|KFSAWA)\b)/i, + windows_phone = /IEMobile/i, + windows_tablet = /(?=.*\bWindows\b)(?=.*\bARM\b)/i, // Match 'Windows' AND 'ARM' + other_blackberry = /BlackBerry/i, + other_blackberry_10 = /BB10/i, + other_opera = /Opera Mini/i, + other_chrome = /(CriOS|Chrome)(?=.*\bMobile\b)/i, + other_firefox = /(?=.*\bFirefox\b)(?=.*\bMobile\b)/i, // Match 'Firefox' AND 'Mobile' + seven_inch = new RegExp( + '(?:' + // Non-capturing group - // now rest is set to the post-host stuff. - // chop off any delim chars. - if (!unsafeProtocol[lowerProto]) { + 'Nexus 7' + // Nexus 7 - // First, make 100% sure that any "autoEscape" chars get - // escaped, even if encodeURIComponent doesn't think they - // need to be. - for (var i = 0, l = autoEscape.length; i < l; i++) { - var ae = autoEscape[i]; - var esc = encodeURIComponent(ae); - if (esc === ae) { - esc = escape(ae); - } - rest = rest.split(ae).join(esc); - } - } + '|' + // OR + 'BNTV250' + // B&N Nook Tablet 7 inch - // chop off from the tail first. - var hash = rest.indexOf('#'); - if (hash !== -1) { - // got a fragment string. - this.hash = rest.substr(hash); - rest = rest.slice(0, hash); - } - var qm = rest.indexOf('?'); - if (qm !== -1) { - this.search = rest.substr(qm); - this.query = rest.substr(qm + 1); - if (parseQueryString) { - this.query = querystring.parse(this.query); - } - rest = rest.slice(0, qm); - } else if (parseQueryString) { - // no query string, but parseQueryString still requested - this.search = ''; - this.query = {}; - } - if (rest) this.pathname = rest; - if (slashedProtocol[lowerProto] && - this.hostname && !this.pathname) { - this.pathname = '/'; - } + '|' + // OR - //to support http.request - if (this.pathname || this.search) { - var p = this.pathname || ''; - var s = this.search || ''; - this.path = p + s; - } + 'Kindle Fire' + // Kindle Fire - // finally, reconstruct the href based on what has been validated. - this.href = this.format(); - return this; -}; + '|' + // OR -// format a parsed object into a url string -function urlFormat(obj) { - // ensure it's an object, and not a string url. - // If it's an obj, this is a no-op. - // this way, you can call url_format() on strings - // to clean up potentially wonky urls. - if (isString(obj)) obj = urlParse(obj); - if (!(obj instanceof Url)) return Url.prototype.format.call(obj); - return obj.format(); -} + 'Silk' + // Kindle Fire, Silk Accelerated -Url.prototype.format = function() { - var auth = this.auth || ''; - if (auth) { - auth = encodeURIComponent(auth); - auth = auth.replace(/%3A/i, ':'); - auth += '@'; - } + '|' + // OR - var protocol = this.protocol || '', - pathname = this.pathname || '', - hash = this.hash || '', - host = false, - query = ''; + 'GT-P1000' + // Galaxy Tab 7 inch - if (this.host) { - host = auth + this.host; - } else if (this.hostname) { - host = auth + (this.hostname.indexOf(':') === -1 ? - this.hostname : - '[' + this.hostname + ']'); - if (this.port) { - host += ':' + this.port; - } - } + ')', // End non-capturing group - if (this.query && - isObject(this.query) && - Object.keys(this.query).length) { - query = querystring.stringify(this.query); - } + 'i'); // Case-insensitive matching - var search = this.search || (query && ('?' + query)) || ''; + var match = function(regex, userAgent) { + return regex.test(userAgent); + }; - if (protocol && protocol.substr(-1) !== ':') protocol += ':'; + var IsMobileClass = function(userAgent) { + var ua = userAgent || navigator.userAgent; - // only the slashedProtocols get the //. Not mailto:, xmpp:, etc. - // unless they had them to begin with. - if (this.slashes || - (!protocol || slashedProtocol[protocol]) && host !== false) { - host = '//' + (host || ''); - if (pathname && pathname.charAt(0) !== '/') pathname = '/' + pathname; - } else if (!host) { - host = ''; - } + // Facebook mobile app's integrated browser adds a bunch of strings that + // match everything. Strip it out if it exists. + var tmp = ua.split('[FBAN'); + if (typeof tmp[1] !== 'undefined') { + ua = tmp[0]; + } - if (hash && hash.charAt(0) !== '#') hash = '#' + hash; - if (search && search.charAt(0) !== '?') search = '?' + search; + // Twitter mobile app's integrated browser on iPad adds a "Twitter for + // iPhone" string. Same probable happens on other tablet platforms. + // This will confuse detection so strip it out if it exists. + tmp = ua.split('Twitter'); + if (typeof tmp[1] !== 'undefined') { + ua = tmp[0]; + } - pathname = pathname.replace(/[?#]/g, function(match) { - return encodeURIComponent(match); - }); - search = search.replace('#', '%23'); + this.apple = { + phone: match(apple_phone, ua), + ipod: match(apple_ipod, ua), + tablet: !match(apple_phone, ua) && match(apple_tablet, ua), + device: match(apple_phone, ua) || match(apple_ipod, ua) || match(apple_tablet, ua) + }; + this.amazon = { + phone: match(amazon_phone, ua), + tablet: !match(amazon_phone, ua) && match(amazon_tablet, ua), + device: match(amazon_phone, ua) || match(amazon_tablet, ua) + }; + this.android = { + phone: match(amazon_phone, ua) || match(android_phone, ua), + tablet: !match(amazon_phone, ua) && !match(android_phone, ua) && (match(amazon_tablet, ua) || match(android_tablet, ua)), + device: match(amazon_phone, ua) || match(amazon_tablet, ua) || match(android_phone, ua) || match(android_tablet, ua) + }; + this.windows = { + phone: match(windows_phone, ua), + tablet: match(windows_tablet, ua), + device: match(windows_phone, ua) || match(windows_tablet, ua) + }; + this.other = { + blackberry: match(other_blackberry, ua), + blackberry10: match(other_blackberry_10, ua), + opera: match(other_opera, ua), + firefox: match(other_firefox, ua), + chrome: match(other_chrome, ua), + device: match(other_blackberry, ua) || match(other_blackberry_10, ua) || match(other_opera, ua) || match(other_firefox, ua) || match(other_chrome, ua) + }; + this.seven_inch = match(seven_inch, ua); + this.any = this.apple.device || this.android.device || this.windows.device || this.other.device || this.seven_inch; - return protocol + host + pathname + search + hash; -}; + // excludes 'other' devices and ipods, targeting touchscreen phones + this.phone = this.apple.phone || this.android.phone || this.windows.phone; -function urlResolve(source, relative) { - return urlParse(source, false, true).resolve(relative); -} + // excludes 7 inch devices, classifying as phone or tablet is left to the user + this.tablet = this.apple.tablet || this.android.tablet || this.windows.tablet; -Url.prototype.resolve = function(relative) { - return this.resolveObject(urlParse(relative, false, true)).format(); -}; + if (typeof window === 'undefined') { + return this; + } + }; -function urlResolveObject(source, relative) { - if (!source) return relative; - return urlParse(source, false, true).resolveObject(relative); + var instantiate = function() { + var IM = new IsMobileClass(); + IM.Class = IsMobileClass; + return IM; + }; + + if (typeof module !== 'undefined' && module.exports && typeof window === 'undefined') { + //node + module.exports = IsMobileClass; + } else if (typeof module !== 'undefined' && module.exports && typeof window !== 'undefined') { + //browserify + module.exports = instantiate(); + } else if (typeof define === 'function' && define.amd) { + //AMD + define('isMobile', [], global.isMobile = instantiate()); + } else { + global.isMobile = instantiate(); + } + +})(this); + +},{}],6:[function(require,module,exports){ +'use strict'; +/* eslint-disable no-unused-vars */ +var hasOwnProperty = Object.prototype.hasOwnProperty; +var propIsEnumerable = Object.prototype.propertyIsEnumerable; + +function toObject(val) { + if (val === null || val === undefined) { + throw new TypeError('Object.assign cannot be called with null or undefined'); + } + + return Object(val); } -Url.prototype.resolveObject = function(relative) { - if (isString(relative)) { - var rel = new Url(); - rel.parse(relative, false, true); - relative = rel; - } +function shouldUseNative() { + try { + if (!Object.assign) { + return false; + } - var result = new Url(); - Object.keys(this).forEach(function(k) { - result[k] = this[k]; - }, this); + // Detect buggy property enumeration order in older V8 versions. - // hash is always overridden, no matter what. - // even href="" will remove it. - result.hash = relative.hash; + // https://bugs.chromium.org/p/v8/issues/detail?id=4118 + var test1 = new String('abc'); // eslint-disable-line + test1[5] = 'de'; + if (Object.getOwnPropertyNames(test1)[0] === '5') { + return false; + } - // if the relative url is empty, then there's nothing left to do here. - if (relative.href === '') { - result.href = result.format(); - return result; - } + // https://bugs.chromium.org/p/v8/issues/detail?id=3056 + var test2 = {}; + for (var i = 0; i < 10; i++) { + test2['_' + String.fromCharCode(i)] = i; + } + var order2 = Object.getOwnPropertyNames(test2).map(function (n) { + return test2[n]; + }); + if (order2.join('') !== '0123456789') { + return false; + } - // hrefs like //foo/bar always cut to the protocol. - if (relative.slashes && !relative.protocol) { - // take everything except the protocol from relative - Object.keys(relative).forEach(function(k) { - if (k !== 'protocol') - result[k] = relative[k]; - }); + // https://bugs.chromium.org/p/v8/issues/detail?id=3056 + var test3 = {}; + 'abcdefghijklmnopqrst'.split('').forEach(function (letter) { + test3[letter] = letter; + }); + if (Object.keys(Object.assign({}, test3)).join('') !== + 'abcdefghijklmnopqrst') { + return false; + } - //urlParse appends trailing / to urls like http://www.example.com - if (slashedProtocol[result.protocol] && - result.hostname && !result.pathname) { - result.path = result.pathname = '/'; - } + return true; + } catch (e) { + // We don't expect any of the above to throw, but better to be safe. + return false; + } +} - result.href = result.format(); - return result; - } +module.exports = shouldUseNative() ? Object.assign : function (target, source) { + var from; + var to = toObject(target); + var symbols; - if (relative.protocol && relative.protocol !== result.protocol) { - // if it's a known url protocol, then changing - // the protocol does weird things - // first, if it's not file:, then we MUST have a host, - // and if there was a path - // to begin with, then we MUST have a path. - // if it is file:, then the host is dropped, - // because that's known to be hostless. - // anything else is assumed to be absolute. - if (!slashedProtocol[relative.protocol]) { - Object.keys(relative).forEach(function(k) { - result[k] = relative[k]; - }); - result.href = result.format(); - return result; - } + for (var s = 1; s < arguments.length; s++) { + from = Object(arguments[s]); - result.protocol = relative.protocol; - if (!relative.host && !hostlessProtocol[relative.protocol]) { - var relPath = (relative.pathname || '').split('/'); - while (relPath.length && !(relative.host = relPath.shift())); - if (!relative.host) relative.host = ''; - if (!relative.hostname) relative.hostname = ''; - if (relPath[0] !== '') relPath.unshift(''); - if (relPath.length < 2) relPath.unshift(''); - result.pathname = relPath.join('/'); - } else { - result.pathname = relative.pathname; + for (var key in from) { + if (hasOwnProperty.call(from, key)) { + to[key] = from[key]; + } + } + + if (Object.getOwnPropertySymbols) { + symbols = Object.getOwnPropertySymbols(from); + for (var i = 0; i < symbols.length; i++) { + if (propIsEnumerable.call(from, symbols[i])) { + to[symbols[i]] = from[symbols[i]]; + } + } + } + } + + return to; +}; + +},{}],7:[function(require,module,exports){ +(function (process){ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +// resolves . and .. elements in a path array with directory names there +// must be no slashes, empty elements, or device names (c:\) in the array +// (so also no leading and trailing slashes - it does not distinguish +// relative and absolute paths) +function normalizeArray(parts, allowAboveRoot) { + // if the path tries to go above the root, `up` ends up > 0 + var up = 0; + for (var i = parts.length - 1; i >= 0; i--) { + var last = parts[i]; + if (last === '.') { + parts.splice(i, 1); + } else if (last === '..') { + parts.splice(i, 1); + up++; + } else if (up) { + parts.splice(i, 1); + up--; } - result.search = relative.search; - result.query = relative.query; - result.host = relative.host || ''; - result.auth = relative.auth; - result.hostname = relative.hostname || relative.host; - result.port = relative.port; - // to support http.request - if (result.pathname || result.search) { - var p = result.pathname || ''; - var s = result.search || ''; - result.path = p + s; + } + + // if the path is allowed to go above the root, restore leading ..s + if (allowAboveRoot) { + for (; up--; up) { + parts.unshift('..'); } - result.slashes = result.slashes || relative.slashes; - result.href = result.format(); - return result; } - var isSourceAbs = (result.pathname && result.pathname.charAt(0) === '/'), - isRelAbs = ( - relative.host || - relative.pathname && relative.pathname.charAt(0) === '/' - ), - mustEndAbs = (isRelAbs || isSourceAbs || - (result.host && relative.pathname)), - removeAllDots = mustEndAbs, - srcPath = result.pathname && result.pathname.split('/') || [], - relPath = relative.pathname && relative.pathname.split('/') || [], - psychotic = result.protocol && !slashedProtocol[result.protocol]; - - // if the url is a non-slashed url, then relative - // links like ../.. should be able - // to crawl up to the hostname, as well. This is strange. - // result.protocol has already been set by now. - // Later on, put the first path part into the host field. - if (psychotic) { - result.hostname = ''; - result.port = null; - if (result.host) { - if (srcPath[0] === '') srcPath[0] = result.host; - else srcPath.unshift(result.host); - } - result.host = ''; - if (relative.protocol) { - relative.hostname = null; - relative.port = null; - if (relative.host) { - if (relPath[0] === '') relPath[0] = relative.host; - else relPath.unshift(relative.host); - } - relative.host = null; - } - mustEndAbs = mustEndAbs && (relPath[0] === '' || srcPath[0] === ''); - } + return parts; +} - if (isRelAbs) { - // it's absolute. - result.host = (relative.host || relative.host === '') ? - relative.host : result.host; - result.hostname = (relative.hostname || relative.hostname === '') ? - relative.hostname : result.hostname; - result.search = relative.search; - result.query = relative.query; - srcPath = relPath; - // fall through to the dot-handling below. - } else if (relPath.length) { - // it's relative - // throw away the existing file, and take the new path instead. - if (!srcPath) srcPath = []; - srcPath.pop(); - srcPath = srcPath.concat(relPath); - result.search = relative.search; - result.query = relative.query; - } else if (!isNullOrUndefined(relative.search)) { - // just pull out the search. - // like href='?foo'. - // Put this after the other two cases because it simplifies the booleans - if (psychotic) { - result.hostname = result.host = srcPath.shift(); - //occationaly the auth can get stuck only in host - //this especialy happens in cases like - //url.resolveObject('mailto:local1@domain1', 'local2@domain2') - var authInHost = result.host && result.host.indexOf('@') > 0 ? - result.host.split('@') : false; - if (authInHost) { - result.auth = authInHost.shift(); - result.host = result.hostname = authInHost.shift(); - } - } - result.search = relative.search; - result.query = relative.query; - //to support http.request - if (!isNull(result.pathname) || !isNull(result.search)) { - result.path = (result.pathname ? result.pathname : '') + - (result.search ? result.search : ''); - } - result.href = result.format(); - return result; - } +// Split a filename into [root, dir, basename, ext], unix version +// 'root' is just a slash, or nothing. +var splitPathRe = + /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/; +var splitPath = function(filename) { + return splitPathRe.exec(filename).slice(1); +}; - if (!srcPath.length) { - // no path at all. easy. - // we've already handled the other stuff above. - result.pathname = null; - //to support http.request - if (result.search) { - result.path = '/' + result.search; - } else { - result.path = null; - } - result.href = result.format(); - return result; - } +// path.resolve([from ...], to) +// posix version +exports.resolve = function() { + var resolvedPath = '', + resolvedAbsolute = false; - // if a url ENDs in . or .., then it must get a trailing slash. - // however, if it ends in anything else non-slashy, - // then it must NOT get a trailing slash. - var last = srcPath.slice(-1)[0]; - var hasTrailingSlash = ( - (result.host || relative.host) && (last === '.' || last === '..') || - last === ''); + for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) { + var path = (i >= 0) ? arguments[i] : process.cwd(); - // strip single dots, resolve double dots to parent dir - // if the path tries to go above the root, `up` ends up > 0 - var up = 0; - for (var i = srcPath.length; i >= 0; i--) { - last = srcPath[i]; - if (last == '.') { - srcPath.splice(i, 1); - } else if (last === '..') { - srcPath.splice(i, 1); - up++; - } else if (up) { - srcPath.splice(i, 1); - up--; + // Skip empty and invalid entries + if (typeof path !== 'string') { + throw new TypeError('Arguments to path.resolve must be strings'); + } else if (!path) { + continue; } - } - // if the path is allowed to go above the root, restore leading ..s - if (!mustEndAbs && !removeAllDots) { - for (; up--; up) { - srcPath.unshift('..'); - } + resolvedPath = path + '/' + resolvedPath; + resolvedAbsolute = path.charAt(0) === '/'; } - if (mustEndAbs && srcPath[0] !== '' && - (!srcPath[0] || srcPath[0].charAt(0) !== '/')) { - srcPath.unshift(''); - } + // At this point the path should be resolved to a full absolute path, but + // handle relative paths to be safe (might happen when process.cwd() fails) - if (hasTrailingSlash && (srcPath.join('/').substr(-1) !== '/')) { - srcPath.push(''); - } + // Normalize the path + resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) { + return !!p; + }), !resolvedAbsolute).join('/'); - var isAbsolute = srcPath[0] === '' || - (srcPath[0] && srcPath[0].charAt(0) === '/'); + return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.'; +}; - // put the host back - if (psychotic) { - result.hostname = result.host = isAbsolute ? '' : - srcPath.length ? srcPath.shift() : ''; - //occationaly the auth can get stuck only in host - //this especialy happens in cases like - //url.resolveObject('mailto:local1@domain1', 'local2@domain2') - var authInHost = result.host && result.host.indexOf('@') > 0 ? - result.host.split('@') : false; - if (authInHost) { - result.auth = authInHost.shift(); - result.host = result.hostname = authInHost.shift(); - } - } +// path.normalize(path) +// posix version +exports.normalize = function(path) { + var isAbsolute = exports.isAbsolute(path), + trailingSlash = substr(path, -1) === '/'; - mustEndAbs = mustEndAbs || (result.host && srcPath.length); + // Normalize the path + path = normalizeArray(filter(path.split('/'), function(p) { + return !!p; + }), !isAbsolute).join('/'); - if (mustEndAbs && !isAbsolute) { - srcPath.unshift(''); + if (!path && !isAbsolute) { + path = '.'; } - - if (!srcPath.length) { - result.pathname = null; - result.path = null; - } else { - result.pathname = srcPath.join('/'); + if (path && trailingSlash) { + path += '/'; } - //to support request.http - if (!isNull(result.pathname) || !isNull(result.search)) { - result.path = (result.pathname ? result.pathname : '') + - (result.search ? result.search : ''); - } - result.auth = relative.auth || result.auth; - result.slashes = result.slashes || relative.slashes; - result.href = result.format(); - return result; + return (isAbsolute ? '/' : '') + path; }; -Url.prototype.parseHost = function() { - var host = this.host; - var port = portPattern.exec(host); - if (port) { - port = port[0]; - if (port !== ':') { - this.port = port.substr(1); +// posix version +exports.isAbsolute = function(path) { + return path.charAt(0) === '/'; +}; + +// posix version +exports.join = function() { + var paths = Array.prototype.slice.call(arguments, 0); + return exports.normalize(filter(paths, function(p, index) { + if (typeof p !== 'string') { + throw new TypeError('Arguments to path.join must be strings'); } - host = host.substr(0, host.length - port.length); - } - if (host) this.hostname = host; + return p; + }).join('/')); }; -function isString(arg) { - return typeof arg === "string"; -} -function isObject(arg) { - return typeof arg === 'object' && arg !== null; -} +// path.relative(from, to) +// posix version +exports.relative = function(from, to) { + from = exports.resolve(from).substr(1); + to = exports.resolve(to).substr(1); -function isNull(arg) { - return arg === null; -} -function isNullOrUndefined(arg) { - return arg == null; -} + function trim(arr) { + var start = 0; + for (; start < arr.length; start++) { + if (arr[start] !== '') break; + } -},{"punycode":6,"querystring":9}],11:[function(require,module,exports){ -'use strict'; + var end = arr.length - 1; + for (; end >= 0; end--) { + if (arr[end] !== '') break; + } -module.exports = earcut; + if (start > end) return []; + return arr.slice(start, end - start + 1); + } -function earcut(data, holeIndices, dim) { + var fromParts = trim(from.split('/')); + var toParts = trim(to.split('/')); - dim = dim || 2; + var length = Math.min(fromParts.length, toParts.length); + var samePartsLength = length; + for (var i = 0; i < length; i++) { + if (fromParts[i] !== toParts[i]) { + samePartsLength = i; + break; + } + } - var hasHoles = holeIndices && holeIndices.length, - outerLen = hasHoles ? holeIndices[0] * dim : data.length, - outerNode = linkedList(data, 0, outerLen, dim, true), - triangles = []; + var outputParts = []; + for (var i = samePartsLength; i < fromParts.length; i++) { + outputParts.push('..'); + } - if (!outerNode) return triangles; + outputParts = outputParts.concat(toParts.slice(samePartsLength)); - var minX, minY, maxX, maxY, x, y, size; + return outputParts.join('/'); +}; - if (hasHoles) outerNode = eliminateHoles(data, holeIndices, outerNode, dim); +exports.sep = '/'; +exports.delimiter = ':'; - // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox - if (data.length > 80 * dim) { - minX = maxX = data[0]; - minY = maxY = data[1]; +exports.dirname = function(path) { + var result = splitPath(path), + root = result[0], + dir = result[1]; - for (var i = dim; i < outerLen; i += dim) { - x = data[i]; - y = data[i + 1]; - if (x < minX) minX = x; - if (y < minY) minY = y; - if (x > maxX) maxX = x; - if (y > maxY) maxY = y; - } + if (!root && !dir) { + // No dirname whatsoever + return '.'; + } - // minX, minY and size are later used to transform coords into integers for z-order calculation - size = Math.max(maxX - minX, maxY - minY); - } + if (dir) { + // It has a dirname, strip trailing slash + dir = dir.substr(0, dir.length - 1); + } - earcutLinked(outerNode, triangles, dim, minX, minY, size); + return root + dir; +}; - return triangles; -} -// create a circular doubly linked list from polygon points in the specified winding order -function linkedList(data, start, end, dim, clockwise) { - var sum = 0, - i, j, last; +exports.basename = function(path, ext) { + var f = splitPath(path)[2]; + // TODO: make this comparison case-insensitive on windows? + if (ext && f.substr(-1 * ext.length) === ext) { + f = f.substr(0, f.length - ext.length); + } + return f; +}; - // calculate original winding order of a polygon ring - for (i = start, j = end - dim; i < end; i += dim) { - sum += (data[j] - data[i]) * (data[i + 1] + data[j + 1]); - j = i; + +exports.extname = function(path) { + return splitPath(path)[3]; +}; + +function filter (xs, f) { + if (xs.filter) return xs.filter(f); + var res = []; + for (var i = 0; i < xs.length; i++) { + if (f(xs[i], i, xs)) res.push(xs[i]); } + return res; +} - // link points into circular doubly-linked list in the specified winding order - if (clockwise === (sum > 0)) { - for (i = start; i < end; i += dim) last = insertNode(i, data[i], data[i + 1], last); - } else { - for (i = end - dim; i >= start; i -= dim) last = insertNode(i, data[i], data[i + 1], last); +// String.prototype.substr - negative index don't work in IE8 +var substr = 'ab'.substr(-1) === 'b' + ? function (str, start, len) { return str.substr(start, len) } + : function (str, start, len) { + if (start < 0) start = str.length + start; + return str.substr(start, len); } +; - return last; -} +}).call(this,require('_process')) -// eliminate colinear or duplicate points -function filterPoints(start, end) { - if (!start) return start; - if (!end) end = start; +},{"_process":24}],8:[function(require,module,exports){ +var EMPTY_ARRAY_BUFFER = new ArrayBuffer(0); - var p = start, - again; - do { - again = false; +/** + * Helper class to create a webGL buffer + * + * @class + * @memberof pixi.gl + * @param gl {WebGLRenderingContext} The current WebGL rendering context + * @param type {gl.ARRAY_BUFFER | gl.ELEMENT_ARRAY_BUFFER} @mat + * @param data {ArrayBuffer| SharedArrayBuffer|ArrayBufferView} an array of data + * @param drawType {gl.STATIC_DRAW|gl.DYNAMIC_DRAW|gl.STREAM_DRAW} + */ +var Buffer = function(gl, type, data, drawType) +{ - if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) { - removeNode(p); - p = end = p.prev; - if (p === p.next) return null; - again = true; + /** + * The current WebGL rendering context + * + * @member {WebGLRenderingContext} + */ + this.gl = gl; - } else { - p = p.next; - } - } while (again || p !== end); + /** + * The WebGL buffer, created upon instantiation + * + * @member {WebGLBuffer} + */ + this.buffer = gl.createBuffer(); - return end; -} + /** + * The type of the buffer + * + * @member {gl.ARRAY_BUFFER|gl.ELEMENT_ARRAY_BUFFER} + */ + this.type = type || gl.ARRAY_BUFFER; -// main ear slicing loop which triangulates a polygon (given as a linked list) -function earcutLinked(ear, triangles, dim, minX, minY, size, pass) { - if (!ear) return; + /** + * The draw type of the buffer + * + * @member {gl.STATIC_DRAW|gl.DYNAMIC_DRAW|gl.STREAM_DRAW} + */ + this.drawType = drawType || gl.STATIC_DRAW; - // interlink polygon nodes in z-order - if (!pass && size) indexCurve(ear, minX, minY, size); + /** + * The data in the buffer, as a typed array + * + * @member {ArrayBuffer| SharedArrayBuffer|ArrayBufferView} + */ + this.data = EMPTY_ARRAY_BUFFER; - var stop = ear, - prev, next; + if(data) + { + this.upload(data); + } +}; - // iterate through ears, slicing them one by one - while (ear.prev !== ear.next) { - prev = ear.prev; - next = ear.next; +/** + * Uploads the buffer to the GPU + * @param data {ArrayBuffer| SharedArrayBuffer|ArrayBufferView} an array of data to upload + * @param offset {Number} if only a subset of the data should be uploaded, this is the amount of data to subtract + * @param dontBind {Boolean} whether to bind the buffer before uploading it + */ +Buffer.prototype.upload = function(data, offset, dontBind) +{ + // todo - needed? + if(!dontBind) this.bind(); - if (size ? isEarHashed(ear, minX, minY, size) : isEar(ear)) { - // cut off the triangle - triangles.push(prev.i / dim); - triangles.push(ear.i / dim); - triangles.push(next.i / dim); + var gl = this.gl; - removeNode(ear); + data = data || this.data; + offset = offset || 0; - // skipping the next vertice leads to less sliver triangles - ear = next.next; - stop = next.next; + if(this.data.byteLength >= data.byteLength) + { + gl.bufferSubData(this.type, offset, data); + } + else + { + gl.bufferData(this.type, data, this.drawType); + } - continue; - } + this.data = data; +}; +/** + * Binds the buffer + * + */ +Buffer.prototype.bind = function() +{ + var gl = this.gl; + gl.bindBuffer(this.type, this.buffer); +}; - ear = next; +Buffer.createVertexBuffer = function(gl, data, drawType) +{ + return new Buffer(gl, gl.ARRAY_BUFFER, data, drawType); +}; - // if we looped through the whole remaining polygon and can't find any more ears - if (ear === stop) { - // try filtering points and slicing again - if (!pass) { - earcutLinked(filterPoints(ear), triangles, dim, minX, minY, size, 1); +Buffer.createIndexBuffer = function(gl, data, drawType) +{ + return new Buffer(gl, gl.ELEMENT_ARRAY_BUFFER, data, drawType); +}; - // if this didn't work, try curing all small self-intersections locally - } else if (pass === 1) { - ear = cureLocalIntersections(ear, triangles, dim); - earcutLinked(ear, triangles, dim, minX, minY, size, 2); +Buffer.create = function(gl, type, data, drawType) +{ + return new Buffer(gl, type, drawType); +}; - // as a last resort, try splitting the remaining polygon into two - } else if (pass === 2) { - splitEarcut(ear, triangles, dim, minX, minY, size); - } +/** + * Destroys the buffer + * + */ +Buffer.prototype.destroy = function(){ + this.gl.deleteBuffer(this.buffer); +}; - break; - } - } -} +module.exports = Buffer; -// check whether a polygon node forms a valid ear with adjacent nodes -function isEar(ear) { - var a = ear.prev, - b = ear, - c = ear.next; +},{}],9:[function(require,module,exports){ - if (area(a, b, c) >= 0) return false; // reflex, can't be an ear +var Texture = require('./GLTexture'); - // now make sure we don't have other points inside the potential ear - var p = ear.next.next; +/** + * Helper class to create a webGL Framebuffer + * + * @class + * @memberof pixi.gl + * @param gl {WebGLRenderingContext} The current WebGL rendering context + * @param width {Number} the width of the drawing area of the frame buffer + * @param height {Number} the height of the drawing area of the frame buffer + */ +var Framebuffer = function(gl, width, height) +{ + /** + * The current WebGL rendering context + * + * @member {WebGLRenderingContext} + */ + this.gl = gl; - while (p !== ear.prev) { - if (pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && - area(p.prev, p, p.next) >= 0) return false; - p = p.next; - } + /** + * The frame buffer + * + * @member {WebGLFramebuffer} + */ + this.framebuffer = gl.createFramebuffer(); - return true; -} + /** + * The stencil buffer + * + * @member {WebGLRenderbuffer} + */ + this.stencil = null; -function isEarHashed(ear, minX, minY, size) { - var a = ear.prev, - b = ear, - c = ear.next; + /** + * The stencil buffer + * + * @member {GLTexture} + */ + this.texture = null; - if (area(a, b, c) >= 0) return false; // reflex, can't be an ear + /** + * The width of the drawing area of the buffer + * + * @member {Number} + */ + this.width = width || 100; + /** + * The height of the drawing area of the buffer + * + * @member {Number} + */ + this.height = height || 100; +}; - // triangle bbox; min & max are calculated like this for speed - var minTX = a.x < b.x ? (a.x < c.x ? a.x : c.x) : (b.x < c.x ? b.x : c.x), - minTY = a.y < b.y ? (a.y < c.y ? a.y : c.y) : (b.y < c.y ? b.y : c.y), - maxTX = a.x > b.x ? (a.x > c.x ? a.x : c.x) : (b.x > c.x ? b.x : c.x), - maxTY = a.y > b.y ? (a.y > c.y ? a.y : c.y) : (b.y > c.y ? b.y : c.y); +/** + * Adds a texture to the frame buffer + * @param texture {GLTexture} + */ +Framebuffer.prototype.enableTexture = function(texture) +{ + var gl = this.gl; - // z-order range for the current triangle bbox; - var minZ = zOrder(minTX, minTY, minX, minY, size), - maxZ = zOrder(maxTX, maxTY, minX, minY, size); + this.texture = texture || new Texture(gl); - // first look for points inside the triangle in increasing z-order - var p = ear.nextZ; + this.texture.bind(); - while (p && p.z <= maxZ) { - if (p !== ear.prev && p !== ear.next && - pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && - area(p.prev, p, p.next) >= 0) return false; - p = p.nextZ; - } + //gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, this.width, this.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); - // then look for points in decreasing z-order - p = ear.prevZ; + this.bind(); - while (p && p.z >= minZ) { - if (p !== ear.prev && p !== ear.next && - pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && - area(p.prev, p, p.next) >= 0) return false; - p = p.prevZ; - } + gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this.texture.texture, 0); +}; - return true; -} +/** + * Initialises the stencil buffer + */ +Framebuffer.prototype.enableStencil = function() +{ + if(this.stencil)return; -// go through all polygon nodes and cure small local self-intersections -function cureLocalIntersections(start, triangles, dim) { - var p = start; - do { - var a = p.prev, - b = p.next.next; + var gl = this.gl; - // a self-intersection where edge (v[i-1],v[i]) intersects (v[i+1],v[i+2]) - if (intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) { + this.stencil = gl.createRenderbuffer(); - triangles.push(a.i / dim); - triangles.push(p.i / dim); - triangles.push(b.i / dim); + gl.bindRenderbuffer(gl.RENDERBUFFER, this.stencil); - // remove two nodes involved - removeNode(p); - removeNode(p.next); + // TODO.. this is depth AND stencil? + gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.RENDERBUFFER, this.stencil); + gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_STENCIL, this.width , this.height ); +}; - p = start = b; - } - p = p.next; - } while (p !== start); +/** + * Erases the drawing area and fills it with a colour + * @param r {Number} the red value of the clearing colour + * @param g {Number} the green value of the clearing colour + * @param b {Number} the blue value of the clearing colour + * @param a {Number} the alpha value of the clearing colour + */ +Framebuffer.prototype.clear = function( r, g, b, a ) +{ + this.bind(); - return p; -} + var gl = this.gl; -// try splitting polygon into two and triangulate them independently -function splitEarcut(start, triangles, dim, minX, minY, size) { - // look for a valid diagonal that divides the polygon into two - var a = start; - do { - var b = a.next.next; - while (b !== a.prev) { - if (a.i !== b.i && isValidDiagonal(a, b)) { - // split the polygon in two by the diagonal - var c = splitPolygon(a, b); + gl.clearColor(r, g, b, a); + gl.clear(gl.COLOR_BUFFER_BIT); +}; - // filter colinear points around the cuts - a = filterPoints(a, a.next); - c = filterPoints(c, c.next); +/** + * Binds the frame buffer to the WebGL context + */ +Framebuffer.prototype.bind = function() +{ + var gl = this.gl; - // run earcut on each half - earcutLinked(a, triangles, dim, minX, minY, size); - earcutLinked(c, triangles, dim, minX, minY, size); - return; - } - b = b.next; - } - a = a.next; - } while (a !== start); -} + if(this.texture) + { + this.texture.unbind(); + } -// link every hole into the outer loop, producing a single-ring polygon without holes -function eliminateHoles(data, holeIndices, outerNode, dim) { - var queue = [], - i, len, start, end, list; + gl.bindFramebuffer(gl.FRAMEBUFFER, this.framebuffer ); +}; - for (i = 0, len = holeIndices.length; i < len; i++) { - start = holeIndices[i] * dim; - end = i < len - 1 ? holeIndices[i + 1] * dim : data.length; - list = linkedList(data, start, end, dim, false); - if (list === list.next) list.steiner = true; - queue.push(getLeftmost(list)); - } +/** + * Unbinds the frame buffer to the WebGL context + */ +Framebuffer.prototype.unbind = function() +{ + var gl = this.gl; + gl.bindFramebuffer(gl.FRAMEBUFFER, null ); +}; +/** + * Resizes the drawing area of the buffer to the given width and height + * @param width {Number} the new width + * @param height {Number} the new height + */ +Framebuffer.prototype.resize = function(width, height) +{ + var gl = this.gl; - queue.sort(compareX); + this.width = width; + this.height = height; - // process holes from left to right - for (i = 0; i < queue.length; i++) { - eliminateHole(queue[i], outerNode); - outerNode = filterPoints(outerNode, outerNode.next); + if ( this.texture ) + { + this.texture.uploadData(null, width, height); } - return outerNode; -} + if ( this.stencil ) + { + // update the stencil buffer width and height + gl.bindRenderbuffer(gl.RENDERBUFFER, this.stencil); + gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_STENCIL, width, height); + } +}; -function compareX(a, b) { - return a.x - b.x; -} +/** + * Destroys this buffer + */ +Framebuffer.prototype.destroy = function() +{ + var gl = this.gl; -// find a bridge between vertices that connects hole with an outer ring and and link it -function eliminateHole(hole, outerNode) { - outerNode = findHoleBridge(hole, outerNode); - if (outerNode) { - var b = splitPolygon(outerNode, hole); - filterPoints(b, b.next); + //TODO + if(this.texture) + { + this.texture.destroy(); } -} -// David Eberly's algorithm for finding a bridge between hole and outer polygon -function findHoleBridge(hole, outerNode) { - var p = outerNode, - hx = hole.x, - hy = hole.y, - qx = -Infinity, - m; + gl.deleteFramebuffer(this.framebuffer); - // find a segment intersected by a ray from the hole's leftmost point to the left; - // segment's endpoint with lesser x will be potential connection point - do { - if (hy <= p.y && hy >= p.next.y) { - var x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y); - if (x <= hx && x > qx) { - qx = x; - m = p.x < p.next.x ? p : p.next; - } - } - p = p.next; - } while (p !== outerNode); + this.gl = null; - if (!m) return null; + this.stencil = null; + this.texture = null; +}; - // look for points inside the triangle of hole point, segment intersection and endpoint; - // if there are no points found, we have a valid connection; - // otherwise choose the point of the minimum angle with the ray as connection point +/** + * Creates a frame buffer with a texture containing the given data + * @static + * @param gl {WebGLRenderingContext} The current WebGL rendering context + * @param width {Number} the width of the drawing area of the frame buffer + * @param height {Number} the height of the drawing area of the frame buffer + * @param data {ArrayBuffer| SharedArrayBuffer|ArrayBufferView} an array of data + */ +Framebuffer.createRGBA = function(gl, width, height/*, data*/) +{ + var texture = Texture.fromData(gl, null, width, height); + texture.enableNearestScaling(); + texture.enableWrapClamp(); - var stop = m, - tanMin = Infinity, - tan; + //now create the framebuffer object and attach the texture to it. + var fbo = new Framebuffer(gl, width, height); + fbo.enableTexture(texture); - p = m.next; + fbo.unbind(); - while (p !== stop) { - if (hx >= p.x && p.x >= m.x && - pointInTriangle(hy < m.y ? hx : qx, hy, m.x, m.y, hy < m.y ? qx : hx, hy, p.x, p.y)) { + return fbo; +}; - tan = Math.abs(hy - p.y) / (hx - p.x); // tangential +/** + * Creates a frame buffer with a texture containing the given data + * @static + * @param gl {WebGLRenderingContext} The current WebGL rendering context + * @param width {Number} the width of the drawing area of the frame buffer + * @param height {Number} the height of the drawing area of the frame buffer + * @param data {ArrayBuffer| SharedArrayBuffer|ArrayBufferView} an array of data + */ +Framebuffer.createFloat32 = function(gl, width, height, data) +{ + // create a new texture.. + var texture = new Texture.fromData(gl, data, width, height); + texture.enableNearestScaling(); + texture.enableWrapClamp(); - if ((tan < tanMin || (tan === tanMin && p.x > m.x)) && locallyInside(p, hole)) { - m = p; - tanMin = tan; - } - } + //now create the framebuffer object and attach the texture to it. + var fbo = new Framebuffer(gl, width, height); + fbo.enableTexture(texture); - p = p.next; - } + fbo.unbind(); - return m; -} + return fbo; +}; -// interlink polygon nodes in z-order -function indexCurve(start, minX, minY, size) { - var p = start; - do { - if (p.z === null) p.z = zOrder(p.x, p.y, minX, minY, size); - p.prevZ = p.prev; - p.nextZ = p.next; - p = p.next; - } while (p !== start); +module.exports = Framebuffer; - p.prevZ.nextZ = null; - p.prevZ = null; +},{"./GLTexture":11}],10:[function(require,module,exports){ - sortLinked(p); -} +var compileProgram = require('./shader/compileProgram'), + extractAttributes = require('./shader/extractAttributes'), + extractUniforms = require('./shader/extractUniforms'), + generateUniformAccessObject = require('./shader/generateUniformAccessObject'); -// Simon Tatham's linked list merge sort algorithm -// http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html -function sortLinked(list) { - var i, p, q, e, tail, numMerges, pSize, qSize, - inSize = 1; +/** + * Helper class to create a webGL Shader + * + * @class + * @memberof pixi.gl + * @param gl {WebGLRenderingContext} + * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. + * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. + */ +var Shader = function(gl, vertexSrc, fragmentSrc) +{ + /** + * The current WebGL rendering context + * + * @member {WebGLRenderingContext} + */ + this.gl = gl; - do { - p = list; - list = null; - tail = null; - numMerges = 0; + /** + * The shader program + * + * @member {WebGLProgram} + */ + // First compile the program.. + this.program = compileProgram(gl, vertexSrc, fragmentSrc); - while (p) { - numMerges++; - q = p; - pSize = 0; - for (i = 0; i < inSize; i++) { - pSize++; - q = q.nextZ; - if (!q) break; - } - qSize = inSize; + /** + * The attributes of the shader as an object containing the following properties + * { + * type, + * size, + * location, + * pointer + * } + * @member {Object} + */ + // next extract the attributes + this.attributes = extractAttributes(gl, this.program); - while (pSize > 0 || (qSize > 0 && q)) { + var uniformData = extractUniforms(gl, this.program); - if (pSize === 0) { - e = q; - q = q.nextZ; - qSize--; - } else if (qSize === 0 || !q) { - e = p; - p = p.nextZ; - pSize--; - } else if (p.z <= q.z) { - e = p; - p = p.nextZ; - pSize--; - } else { - e = q; - q = q.nextZ; - qSize--; - } + /** + * The uniforms of the shader as an object containing the following properties + * { + * gl, + * data + * } + * @member {Object} + */ + this.uniforms = generateUniformAccessObject( gl, uniformData ); +}; +/** + * Uses this shader + */ +Shader.prototype.bind = function() +{ + this.gl.useProgram(this.program); +}; - if (tail) tail.nextZ = e; - else list = e; +/** + * Destroys this shader + * TODO + */ +Shader.prototype.destroy = function() +{ + // var gl = this.gl; +}; - e.prevZ = tail; - tail = e; - } +module.exports = Shader; - p = q; - } +},{"./shader/compileProgram":16,"./shader/extractAttributes":18,"./shader/extractUniforms":19,"./shader/generateUniformAccessObject":20}],11:[function(require,module,exports){ - tail.nextZ = null; - inSize *= 2; +/** + * Helper class to create a WebGL Texture + * + * @class + * @memberof pixi.gl + * @param gl {WebGLRenderingContext} The current WebGL context + * @param width {number} the width of the texture + * @param height {number} the height of the texture + * @param format {number} the pixel format of the texture. defaults to gl.RGBA + * @param type {number} the gl type of the texture. defaults to gl.UNSIGNED_BYTE + */ +var Texture = function(gl, width, height, format, type) +{ + /** + * The current WebGL rendering context + * + * @member {WebGLRenderingContext} + */ + this.gl = gl; - } while (numMerges > 1); - return list; -} + /** + * The WebGL texture + * + * @member {WebGLTexture} + */ + this.texture = gl.createTexture(); -// z-order of a point given coords and size of the data bounding box -function zOrder(x, y, minX, minY, size) { - // coords are transformed into non-negative 15-bit integer range - x = 32767 * (x - minX) / size; - y = 32767 * (y - minY) / size; + /** + * If mipmapping was used for this texture, enable and disable with enableMipmap() + * + * @member {Boolean} + */ + // some settings.. + this.mipmap = false; - x = (x | (x << 8)) & 0x00FF00FF; - x = (x | (x << 4)) & 0x0F0F0F0F; - x = (x | (x << 2)) & 0x33333333; - x = (x | (x << 1)) & 0x55555555; - y = (y | (y << 8)) & 0x00FF00FF; - y = (y | (y << 4)) & 0x0F0F0F0F; - y = (y | (y << 2)) & 0x33333333; - y = (y | (y << 1)) & 0x55555555; - - return x | (y << 1); -} + /** + * Set to true to enable pre-multiplied alpha + * + * @member {Boolean} + */ + this.premultiplyAlpha = false; -// find the leftmost node of a polygon ring -function getLeftmost(start) { - var p = start, - leftmost = start; - do { - if (p.x < leftmost.x) leftmost = p; - p = p.next; - } while (p !== start); + /** + * The width of texture + * + * @member {Number} + */ + this.width = width || 0; + /** + * The height of texture + * + * @member {Number} + */ + this.height = height || 0; - return leftmost; -} + /** + * The pixel format of the texture. defaults to gl.RGBA + * + * @member {Number} + */ + this.format = format || gl.RGBA; -// check if a point lies within a convex triangle -function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) { - return (cx - px) * (ay - py) - (ax - px) * (cy - py) >= 0 && - (ax - px) * (by - py) - (bx - px) * (ay - py) >= 0 && - (bx - px) * (cy - py) - (cx - px) * (by - py) >= 0; -} + /** + * The gl type of the texture. defaults to gl.UNSIGNED_BYTE + * + * @member {Number} + */ + this.type = type || gl.UNSIGNED_BYTE; -// check if a diagonal between two polygon nodes is valid (lies in polygon interior) -function isValidDiagonal(a, b) { - return equals(a, b) || a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && - locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b); -} -// signed area of a triangle -function area(p, q, r) { - return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y); -} +}; -// check if two points are equal -function equals(p1, p2) { - return p1.x === p2.x && p1.y === p2.y; -} +/** + * Uploads this texture to the GPU + * @param source {HTMLImageElement|ImageData|HTMLVideoElement} the source image of the texture + */ +Texture.prototype.upload = function(source) +{ + this.bind(); -// check if two segments intersect -function intersects(p1, q1, p2, q2) { - return area(p1, q1, p2) > 0 !== area(p1, q1, q2) > 0 && - area(p2, q2, p1) > 0 !== area(p2, q2, q1) > 0; -} + var gl = this.gl; -// check if a polygon diagonal intersects any polygon segments -function intersectsPolygon(a, b) { - var p = a; - do { - if (p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i && - intersects(p, p.next, a, b)) return true; - p = p.next; - } while (p !== a); + // if the source is a video, we need to use the videoWidth / videoHeight properties as width / height will be incorrect. + this.width = source.videoWidth || source.width; + this.height = source.videoHeight || source.height; - return false; -} + gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, this.premultiplyAlpha); + gl.texImage2D(gl.TEXTURE_2D, 0, this.format, this.format, this.type, source); +}; -// check if a polygon diagonal is locally inside the polygon -function locallyInside(a, b) { - return area(a.prev, a, a.next) < 0 ? - area(a, b, a.next) >= 0 && area(a, a.prev, b) >= 0 : - area(a, b, a.prev) < 0 || area(a, a.next, b) < 0; -} +var FLOATING_POINT_AVAILABLE = false; -// check if the middle point of a polygon diagonal is inside the polygon -function middleInside(a, b) { - var p = a, - inside = false, - px = (a.x + b.x) / 2, - py = (a.y + b.y) / 2; - do { - if (((p.y > py) !== (p.next.y > py)) && (px < (p.next.x - p.x) * (py - p.y) / (p.next.y - p.y) + p.x)) - inside = !inside; - p = p.next; - } while (p !== a); +/** + * Use a data source and uploads this texture to the GPU + * @param data {TypedArray} the data to upload to the texture + * @param width {number} the new width of the texture + * @param height {number} the new height of the texture + */ +Texture.prototype.uploadData = function(data, width, height) +{ + this.bind(); - return inside; -} + var gl = this.gl; -// link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two; -// if one belongs to the outer ring and another to a hole, it merges it into a single ring -function splitPolygon(a, b) { - var a2 = new Node(a.i, a.x, a.y), - b2 = new Node(b.i, b.x, b.y), - an = a.next, - bp = b.prev; + this.width = width || this.width; + this.height = height || this.height; - a.next = b; - b.prev = a; + if(data instanceof Float32Array) + { + if(!FLOATING_POINT_AVAILABLE) + { + var ext = gl.getExtension("OES_texture_float"); - a2.next = an; - an.prev = a2; + if(ext) + { + FLOATING_POINT_AVAILABLE = true; + } + else + { + throw new Error('floating point textures not available'); + } + } - b2.next = a2; - a2.prev = b2; + this.type = gl.FLOAT; + } + else + { + // TODO support for other types + this.type = gl.UNSIGNED_BYTE; + } - bp.next = b2; - b2.prev = bp; + - return b2; -} + // what type of data? + gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, this.premultiplyAlpha); + gl.texImage2D(gl.TEXTURE_2D, 0, this.format, this.width, this.height, 0, this.format, this.type, data || null); -// create a node and optionally link it with previous one (in a circular doubly linked list) -function insertNode(i, x, y, last) { - var p = new Node(i, x, y); +}; - if (!last) { - p.prev = p; - p.next = p; +/** + * Binds the texture + * @param location + */ +Texture.prototype.bind = function(location) +{ + var gl = this.gl; - } else { - p.next = last.next; - p.prev = last; - last.next.prev = p; - last.next = p; - } - return p; -} + if(location !== undefined) + { + gl.activeTexture(gl.TEXTURE0 + location); + } -function removeNode(p) { - p.next.prev = p.prev; - p.prev.next = p.next; + gl.bindTexture(gl.TEXTURE_2D, this.texture); +}; - if (p.prevZ) p.prevZ.nextZ = p.nextZ; - if (p.nextZ) p.nextZ.prevZ = p.prevZ; -} +/** + * Unbinds the texture + */ +Texture.prototype.unbind = function() +{ + var gl = this.gl; + gl.bindTexture(gl.TEXTURE_2D, null); +}; -function Node(i, x, y) { - // vertice index in coordinates array - this.i = i; +/** + * @param linear {Boolean} if we want to use linear filtering or nearest neighbour interpolation + */ +Texture.prototype.minFilter = function( linear ) +{ + var gl = this.gl; - // vertex coordinates - this.x = x; - this.y = y; + this.bind(); - // previous and next vertice nodes in a polygon ring - this.prev = null; - this.next = null; + if(this.mipmap) + { + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, linear ? gl.LINEAR_MIPMAP_LINEAR : gl.NEAREST_MIPMAP_NEAREST); + } + else + { + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, linear ? gl.LINEAR : gl.NEAREST); + } +}; - // z-order curve value - this.z = null; +/** + * @param linear {Boolean} if we want to use linear filtering or nearest neighbour interpolation + */ +Texture.prototype.magFilter = function( linear ) +{ + var gl = this.gl; - // previous and next nodes in z-order - this.prevZ = null; - this.nextZ = null; + this.bind(); - // indicates whether this is a steiner point - this.steiner = false; -} + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, linear ? gl.LINEAR : gl.NEAREST); +}; -},{}],12:[function(require,module,exports){ -arguments[4][2][0].apply(exports,arguments) -},{"dup":2}],13:[function(require,module,exports){ -/** - * isMobile.js v0.4.0 - * - * A simple library to detect Apple phones and tablets, - * Android phones and tablets, other mobile devices (like blackberry, mini-opera and windows phone), - * and any kind of seven inch device, via user agent sniffing. - * - * @author: Kai Mallea (kmallea@gmail.com) - * - * @license: http://creativecommons.org/publicdomain/zero/1.0/ - */ -(function (global) { - - var apple_phone = /iPhone/i, - apple_ipod = /iPod/i, - apple_tablet = /iPad/i, - android_phone = /(?=.*\bAndroid\b)(?=.*\bMobile\b)/i, // Match 'Android' AND 'Mobile' - android_tablet = /Android/i, - amazon_phone = /(?=.*\bAndroid\b)(?=.*\bSD4930UR\b)/i, - amazon_tablet = /(?=.*\bAndroid\b)(?=.*\b(?:KFOT|KFTT|KFJWI|KFJWA|KFSOWI|KFTHWI|KFTHWA|KFAPWI|KFAPWA|KFARWI|KFASWI|KFSAWI|KFSAWA)\b)/i, - windows_phone = /IEMobile/i, - windows_tablet = /(?=.*\bWindows\b)(?=.*\bARM\b)/i, // Match 'Windows' AND 'ARM' - other_blackberry = /BlackBerry/i, - other_blackberry_10 = /BB10/i, - other_opera = /Opera Mini/i, - other_chrome = /(CriOS|Chrome)(?=.*\bMobile\b)/i, - other_firefox = /(?=.*\bFirefox\b)(?=.*\bMobile\b)/i, // Match 'Firefox' AND 'Mobile' - seven_inch = new RegExp( - '(?:' + // Non-capturing group - - 'Nexus 7' + // Nexus 7 - - '|' + // OR - - 'BNTV250' + // B&N Nook Tablet 7 inch - - '|' + // OR - - 'Kindle Fire' + // Kindle Fire - - '|' + // OR - - 'Silk' + // Kindle Fire, Silk Accelerated - - '|' + // OR - - 'GT-P1000' + // Galaxy Tab 7 inch - - ')', // End non-capturing group - - 'i'); // Case-insensitive matching - - var match = function(regex, userAgent) { - return regex.test(userAgent); - }; - - var IsMobileClass = function(userAgent) { - var ua = userAgent || navigator.userAgent; - - // Facebook mobile app's integrated browser adds a bunch of strings that - // match everything. Strip it out if it exists. - var tmp = ua.split('[FBAN'); - if (typeof tmp[1] !== 'undefined') { - ua = tmp[0]; - } - - // Twitter mobile app's integrated browser on iPad adds a "Twitter for - // iPhone" string. Same probable happens on other tablet platforms. - // This will confuse detection so strip it out if it exists. - tmp = ua.split('Twitter'); - if (typeof tmp[1] !== 'undefined') { - ua = tmp[0]; - } - - this.apple = { - phone: match(apple_phone, ua), - ipod: match(apple_ipod, ua), - tablet: !match(apple_phone, ua) && match(apple_tablet, ua), - device: match(apple_phone, ua) || match(apple_ipod, ua) || match(apple_tablet, ua) - }; - this.amazon = { - phone: match(amazon_phone, ua), - tablet: !match(amazon_phone, ua) && match(amazon_tablet, ua), - device: match(amazon_phone, ua) || match(amazon_tablet, ua) - }; - this.android = { - phone: match(amazon_phone, ua) || match(android_phone, ua), - tablet: !match(amazon_phone, ua) && !match(android_phone, ua) && (match(amazon_tablet, ua) || match(android_tablet, ua)), - device: match(amazon_phone, ua) || match(amazon_tablet, ua) || match(android_phone, ua) || match(android_tablet, ua) - }; - this.windows = { - phone: match(windows_phone, ua), - tablet: match(windows_tablet, ua), - device: match(windows_phone, ua) || match(windows_tablet, ua) - }; - this.other = { - blackberry: match(other_blackberry, ua), - blackberry10: match(other_blackberry_10, ua), - opera: match(other_opera, ua), - firefox: match(other_firefox, ua), - chrome: match(other_chrome, ua), - device: match(other_blackberry, ua) || match(other_blackberry_10, ua) || match(other_opera, ua) || match(other_firefox, ua) || match(other_chrome, ua) - }; - this.seven_inch = match(seven_inch, ua); - this.any = this.apple.device || this.android.device || this.windows.device || this.other.device || this.seven_inch; - - // excludes 'other' devices and ipods, targeting touchscreen phones - this.phone = this.apple.phone || this.android.phone || this.windows.phone; - - // excludes 7 inch devices, classifying as phone or tablet is left to the user - this.tablet = this.apple.tablet || this.android.tablet || this.windows.tablet; - - if (typeof window === 'undefined') { - return this; - } - }; - - var instantiate = function() { - var IM = new IsMobileClass(); - IM.Class = IsMobileClass; - return IM; - }; - - if (typeof module !== 'undefined' && module.exports && typeof window === 'undefined') { - //node - module.exports = IsMobileClass; - } else if (typeof module !== 'undefined' && module.exports && typeof window !== 'undefined') { - //browserify - module.exports = instantiate(); - } else if (typeof define === 'function' && define.amd) { - //AMD - define('isMobile', [], global.isMobile = instantiate()); - } else { - global.isMobile = instantiate(); - } - -})(this); +/** + * Enables mipmapping + */ +Texture.prototype.enableMipmap = function() +{ + var gl = this.gl; -},{}],14:[function(require,module,exports){ -/* eslint-disable no-unused-vars */ -'use strict'; -var hasOwnProperty = Object.prototype.hasOwnProperty; -var propIsEnumerable = Object.prototype.propertyIsEnumerable; + this.bind(); -function toObject(val) { - if (val === null || val === undefined) { - throw new TypeError('Object.assign cannot be called with null or undefined'); - } + this.mipmap = true; - return Object(val); -} + gl.generateMipmap(gl.TEXTURE_2D); +}; -module.exports = Object.assign || function (target, source) { - var from; - var to = toObject(target); - var symbols; +/** + * Enables linear filtering + */ +Texture.prototype.enableLinearScaling = function() +{ + this.minFilter(true); + this.magFilter(true); +}; - for (var s = 1; s < arguments.length; s++) { - from = Object(arguments[s]); +/** + * Enables nearest neighbour interpolation + */ +Texture.prototype.enableNearestScaling = function() +{ + this.minFilter(false); + this.magFilter(false); +}; - for (var key in from) { - if (hasOwnProperty.call(from, key)) { - to[key] = from[key]; - } - } +/** + * Enables clamping on the texture so WebGL will not repeat it + */ +Texture.prototype.enableWrapClamp = function() +{ + var gl = this.gl; - if (Object.getOwnPropertySymbols) { - symbols = Object.getOwnPropertySymbols(from); - for (var i = 0; i < symbols.length; i++) { - if (propIsEnumerable.call(from, symbols[i])) { - to[symbols[i]] = from[symbols[i]]; - } - } - } - } + this.bind(); - return to; + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); }; -},{}],15:[function(require,module,exports){ - - -module.exports = { - - createContext: require('./lib/createContext'), - setVertexAttribArrays: require('./lib/setVertexAttribArrays'), - - GLBuffer: require('./lib/GLBuffer'), - GLFramebuffer: require('./lib/GLFramebuffer'), - GLShader: require('./lib/GLShader'), - GLTexture: require('./lib/GLTexture'), - - VertexArrayObject: require('./lib/VertexArrayObject') - +/** + * Enable tiling on the texture + */ +Texture.prototype.enableWrapRepeat = function() +{ + var gl = this.gl; + + this.bind(); + + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT); }; -},{"./lib/GLBuffer":16,"./lib/GLFramebuffer":17,"./lib/GLShader":18,"./lib/GLTexture":19,"./lib/VertexArrayObject":20,"./lib/createContext":21,"./lib/setVertexAttribArrays":22}],16:[function(require,module,exports){ -var EMPTY_ARRAY_BUFFER = new ArrayBuffer(0); - -/** - * Helper class to create a webGL buffer - * - * @class - * @memberof pixi.gl - * @param gl {WebGLRenderingContext} The current WebGL rendering context - * @param type {gl.ARRAY_BUFFER | gl.ELEMENT_ARRAY_BUFFER} @mat - * @param data {ArrayBuffer| SharedArrayBuffer|ArrayBufferView} an array of data - * @param drawType {gl.STATIC_DRAW|gl.DYNAMIC_DRAW|gl.STREAM_DRAW} - */ -var Buffer = function(gl, type, data, drawType) -{ - - /** - * The current WebGL rendering context - * - * @member {WebGLRenderingContext} - */ - this.gl = gl; - - /** - * The WebGL buffer, created upon instantiation - * - * @member {WebGLBuffer} - */ - this.buffer = gl.createBuffer(); - - /** - * The type of the buffer - * - * @member {gl.ARRAY_BUFFER || gl.ELEMENT_ARRAY_BUFFER} - */ - this.type = type || gl.ARRAY_BUFFER; - - /** - * The draw type of the buffer - * - * @member {gl.STATIC_DRAW|gl.DYNAMIC_DRAW|gl.STREAM_DRAW} - */ - this.drawType = drawType || gl.STATIC_DRAW; - - /** - * The data in the buffer, as a typed array - * - * @member {ArrayBuffer| SharedArrayBuffer|ArrayBufferView} - */ - this.data = EMPTY_ARRAY_BUFFER; - - if(data) - { - this.upload(data); - } -} - -/** - * Uploads the buffer to the GPU - * @param data {ArrayBuffer| SharedArrayBuffer|ArrayBufferView} an array of data to upload - * @param offset {Number} if only a subset of the data should be uploaded, this is the amount of data to subtract - * @param dontBind {Boolean} whether to bind the buffer before uploading it - */ -Buffer.prototype.upload = function(data, offset, dontBind) -{ - // todo - needed? - if(!dontBind) this.bind(); - - var gl = this.gl; - - data = data || this.data; - offset = offset || 0; - - if(this.data.byteLength >= data.byteLength) - { - gl.bufferSubData(this.type, offset, data); - } - else - { - gl.bufferData(this.type, data, this.drawType); - } - - this.data = data; -} -/** - * Binds the buffer - * - */ -Buffer.prototype.bind = function() -{ - var gl = this.gl; - gl.bindBuffer(this.type, this.buffer); -} - -Buffer.createVertexBuffer = function(gl, data, drawType) -{ - return new Buffer(gl, gl.ARRAY_BUFFER, data, drawType); -} - -Buffer.createIndexBuffer = function(gl, data, drawType) -{ - return new Buffer(gl, gl.ELEMENT_ARRAY_BUFFER, data, drawType); -} - -Buffer.create = function(gl, type, data, drawType) -{ - return new Buffer(gl, type, drawType); -} - -/** - * Destroys the buffer - * - */ -Buffer.prototype.destroy = function(){ - this.gl.deleteBuffer(this.buffer); -} - -module.exports = Buffer; -},{}],17:[function(require,module,exports){ - -var Texture = require('./GLTexture'); - -/** - * Helper class to create a webGL Framebuffer - * - * @class - * @memberof pixi.gl - * @param gl {WebGLRenderingContext} The current WebGL rendering context - * @param width {Number} the width of the drawing area of the frame buffer - * @param height {Number} the height of the drawing area of the frame buffer - */ -var Framebuffer = function(gl, width, height) -{ - /** - * The current WebGL rendering context - * - * @member {WebGLRenderingContext} - */ - this.gl = gl; - - /** - * The frame buffer - * - * @member {WebGLFramebuffer} - */ - this.framebuffer = gl.createFramebuffer(); - - /** - * The stencil buffer - * - * @member {WebGLRenderbuffer} - */ - this.stencil = null; - - /** - * The stencil buffer - * - * @member {GLTexture} - */ - this.texture = null; - - /** - * The width of the drawing area of the buffer - * - * @member {Number} - */ - this.width = width || 100; - /** - * The height of the drawing area of the buffer - * - * @member {Number} - */ - this.height = height || 100; -} - -/** - * Adds a texture to the frame buffer - * @param texture {GLTexture} - */ -Framebuffer.prototype.enableTexture = function(texture) -{ - var gl = this.gl; - - this.texture = texture || new Texture(gl); - - this.texture.bind(); - - //gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, this.width, this.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); - - this.bind(); - - gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this.texture.texture, 0); -} - -/** - * Initialises the stencil buffer - * @mat maybe you can come up with a better explaination - */ -Framebuffer.prototype.enableStencil = function() -{ - if(this.stencil)return; - - var gl = this.gl; - - this.stencil = gl.createRenderbuffer(); - - gl.bindRenderbuffer(gl.RENDERBUFFER, this.stencil); - - // TODO.. this is depth AND stencil? - gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.RENDERBUFFER, this.stencil); - gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_STENCIL, this.width , this.height ); -} - -/** - * Erases the drawing area and fills it with a colour - * @param r {Number} the red value of the clearing colour - * @param g {Number} the green value of the clearing colour - * @param b {Number} the blue value of the clearing colour - * @param a {Number} the alpha value of the clearing colour - */ -Framebuffer.prototype.clear = function( r, g, b, a ) -{ - this.bind(); - - var gl = this.gl; - - gl.clearColor(r, g, b, a); - gl.clear(gl.COLOR_BUFFER_BIT); -} - -/** - * Binds the frame buffer to the WebGL context - */ -Framebuffer.prototype.bind = function() -{ - var gl = this.gl; - - if(this.texture) - { - this.texture.unbind(); - } - - gl.bindFramebuffer(gl.FRAMEBUFFER, this.framebuffer ); -} - -/** - * Unbinds the frame buffer to the WebGL context - */ -Framebuffer.prototype.unbind = function() -{ - var gl = this.gl; - gl.bindFramebuffer(gl.FRAMEBUFFER, null ); -} -/** - * Resizes the drawing area of the buffer to the given width and height - * @param width {Number} the new width - * @param height {Number} the new height - */ -Framebuffer.prototype.resize = function(width, height) -{ - var gl = this.gl; - - this.width = width; - this.height = height; - - if ( this.texture ) - { - this.texture.uploadData(null, width, height); - } - - if ( this.stencil ) - { - // update the stencil buffer width and height - gl.bindRenderbuffer(gl.RENDERBUFFER, this.stencil); - gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_STENCIL, width, height); - } -} - -/** - * Destroys this buffer - */ -Framebuffer.prototype.destroy = function() -{ - var gl = this.gl; - - //TODO - if(this.texture) - { - this.texture.destroy(); - } - - gl.deleteFramebuffer(this.framebuffer); - - this.gl = null; - - this.stencil = null; - this.texture = null; -} - -/** - * Creates a frame buffer with a texture containing the given data - * @mat can you confirm ? :) - * @static - * @param gl {WebGLRenderingContext} The current WebGL rendering context - * @param width {Number} the width of the drawing area of the frame buffer - * @param height {Number} the height of the drawing area of the frame buffer - * @param data {ArrayBuffer| SharedArrayBuffer|ArrayBufferView} an array of data - */ -Framebuffer.createRGBA = function(gl, width, height, data) -{ - var texture = Texture.fromData(gl, null, width, height); - texture.enableNearestScaling(); - texture.enableWrapClamp(); - - //now create the framebuffer object and attach the texture to it. - var fbo = new Framebuffer(gl, width, height); - fbo.enableTexture(texture); - - fbo.unbind(); - - return fbo; -} - -/** - * Creates a frame buffer with a texture containing the given data - * @mat not sure what the difference is with the method above ? - * @static - * @param gl {WebGLRenderingContext} The current WebGL rendering context - * @param width {Number} the width of the drawing area of the frame buffer - * @param height {Number} the height of the drawing area of the frame buffer - * @param data {ArrayBuffer| SharedArrayBuffer|ArrayBufferView} an array of data - */ -Framebuffer.createFloat32 = function(gl, width, height, data) -{ - // create a new texture.. - var texture = new Texture.fromData(gl, data, width, height); - texture.enableNearestScaling(); - texture.enableWrapClamp(); - - //now create the framebuffer object and attach the texture to it. - var fbo = new Framebuffer(gl, width, height); - fbo.enableTexture(texture) - - fbo.unbind(); - - return fbo; -} - -module.exports = Framebuffer; +Texture.prototype.enableWrapMirrorRepeat = function() +{ + var gl = this.gl; -},{"./GLTexture":19}],18:[function(require,module,exports){ - -var compileProgram = require('./shader/compileProgram'), - extractAttributes = require('./shader/extractAttributes'), - extractUniforms = require('./shader/extractUniforms'), - generateUniformAccessObject = require('./shader/generateUniformAccessObject'); - -/** - * Helper class to create a webGL Shader - * - * @class - * @memberof pixi.gl - * @param gl {WebGLRenderingContext} - * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. - * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. - */ -var Shader = function(gl, vertexSrc, fragmentSrc) -{ - /** - * The current WebGL rendering context - * - * @member {WebGLRenderingContext} - */ - this.gl = gl; - - /** - * The shader program - * - * @member {WebGLProgram} - */ - // First compile the program.. - this.program = compileProgram(gl, vertexSrc, fragmentSrc); - - - /** - * The attributes of the shader as an object containing the following properties - * { - * type, - * size, - * location, - * pointer - * } - * @member {Object} - */ - // next extract the attributes - this.attributes = extractAttributes(gl, this.program); - - var uniformData = extractUniforms(gl, this.program); - - /** - * The uniforms of the shader as an object containing the following properties - * { - * gl, - * data - * } - * @member {Object} - */ - this.uniforms = generateUniformAccessObject( gl, uniformData ); -} -/** - * Uses this shader - */ -Shader.prototype.bind = function() -{ - this.gl.useProgram(this.program); -} - -/** - * Destroys this shader - * TODO - */ -Shader.prototype.destroy = function() -{ - var gl = this.gl; -} - -module.exports = Shader; + this.bind(); -},{"./shader/compileProgram":23,"./shader/extractAttributes":25,"./shader/extractUniforms":26,"./shader/generateUniformAccessObject":27}],19:[function(require,module,exports){ - -/** - * Helper class to create a WebGL Texture - * - * @class - * @memberof pixi.gl - * @param gl {WebGLRenderingContext} The current WebGL context - * @param width {number} the width of the texture - * @param height {number} the height of the texture - * @param format {number} the pixel format of the texture. defaults to gl.RGBA - * @param type {number} the gl type of the texture. defaults to gl.UNSIGNED_BYTE - */ -var Texture = function(gl, width, height, format, type) -{ - /** - * The current WebGL rendering context - * - * @member {WebGLRenderingContext} - */ - this.gl = gl; - - - /** - * The WebGL texture - * - * @member {WebGLTexture} - */ - this.texture = gl.createTexture(); - - /** - * If mipmapping was used for this texture, enable and disable with enableMipmap() - * - * @member {Boolean} - */ - // some settings.. - this.mipmap = false; - - - /** - * Set to true to enable pre-multiplied alpha - * - * @member {Boolean} - */ - this.premultiplyAlpha = false; - - /** - * The width of texture - * - * @member {Number} - */ - this.width = width || 0; - /** - * The height of texture - * - * @member {Number} - */ - this.height = height || 0; - - /** - * The pixel format of the texture. defaults to gl.RGBA - * - * @member {Number} - */ - this.format = format || gl.RGBA; - - /** - * The gl type of the texture. defaults to gl.UNSIGNED_BYTE - * - * @member {Number} - */ - this.type = type || gl.UNSIGNED_BYTE; - - -} - -/** - * Uploads this texture to the GPU - * @param source {HTMLImageElement|ImageData} the source image of the texture - */ -Texture.prototype.upload = function(source) -{ - this.bind(); - - var gl = this.gl; - - this.width = source.width; - this.height = source.height; - - gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, this.premultiplyAlpha); - gl.texImage2D(gl.TEXTURE_2D, 0, this.format, this.format, this.type, source); -} - -var FLOATING_POINT_AVAILABLE = false; - -/** - * Use a data source and uploads this texture to the GPU - * @param data {TypedArray} the data to upload to the texture - * @param width {number} the new width of the texture - * @param height {number} the new height of the texture - */ -Texture.prototype.uploadData = function(data, width, height) -{ - this.bind(); - - var gl = this.gl; - - this.width = width || this.width; - this.height = height || this.height; - - if(data instanceof Float32Array) - { - if(!FLOATING_POINT_AVAILABLE) - { - var ext = gl.getExtension("OES_texture_float"); - - if(ext) - { - FLOATING_POINT_AVAILABLE = true; - } - else - { - throw new Error('floating point textures not available'); - } - } - - this.type = gl.FLOAT; - } - else - { - // TODO support for other types - this.type = gl.UNSIGNED_BYTE; - } - - - - // what type of data? - gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, this.premultiplyAlpha); - gl.texImage2D(gl.TEXTURE_2D, 0, this.format, this.width, this.height, 0, this.format, this.type, data || null); - -} - -/** - * Binds the texture - * @param location {@mat} - */ -Texture.prototype.bind = function(location) -{ - var gl = this.gl; - - if(location !== undefined) - { - gl.activeTexture(gl.TEXTURE0 + location); - } - - gl.bindTexture(gl.TEXTURE_2D, this.texture); -} - -/** - * Unbinds the texture - */ -Texture.prototype.unbind = function() -{ - var gl = this.gl; - gl.bindTexture(gl.TEXTURE_2D, null); -} - -/** - * @mat - * @param linear {Boolean} if we want to use linear filtering or nearest neighbour interpolation - */ -Texture.prototype.minFilter = function( linear ) -{ - var gl = this.gl; - - this.bind(); - - if(this.mipmap) - { - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, linear ? gl.LINEAR_MIPMAP_LINEAR : gl.NEAREST_MIPMAP_NEAREST); - } - else - { - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, linear ? gl.LINEAR : gl.NEAREST); - } -} - -/** - * @mat - * @param linear {Boolean} if we want to use linear filtering or nearest neighbour interpolation - */ -Texture.prototype.magFilter = function( linear ) -{ - var gl = this.gl; - - this.bind(); - - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, linear ? gl.LINEAR : gl.NEAREST); -} - -/** - * Enables mipmapping - */ -Texture.prototype.enableMipmap = function() -{ - var gl = this.gl; - - this.bind(); - - this.mipmap = true; - - gl.generateMipmap(gl.TEXTURE_2D); -} - -/** - * Enables linear filtering - */ -Texture.prototype.enableLinearScaling = function() -{ - this.minFilter(true); - this.magFilter(true); -} - -/** - * Enables nearest neighbour interpolation - */ -Texture.prototype.enableNearestScaling = function() -{ - this.minFilter(false); - this.magFilter(false); -} - -/** - * Enables clamping on the texture so WebGL will not repeat it - */ -Texture.prototype.enableWrapClamp = function() -{ - var gl = this.gl; - - this.bind(); - - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); -} - -/** - * Enable tiling on the texture - */ -Texture.prototype.enableWrapRepeat = function() -{ - var gl = this.gl; - - this.bind(); - - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT); -} - -/** - * @mat - */ -Texture.prototype.enableWrapMirrorRepeat = function() -{ - var gl = this.gl; - - this.bind(); - - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.MIRRORED_REPEAT); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.MIRRORED_REPEAT); -} - - -/** - * Destroys this texture - */ -Texture.prototype.destroy = function() -{ - var gl = this.gl; - //TODO - gl.deleteTexture(this.texture); -} - -/** - * @static - * @param gl {WebGLRenderingContext} The current WebGL context - * @param source {HTMLImageElement|ImageData} the source image of the texture - * @param premultiplyAlpha {Boolean} If we want to use pre-multiplied alpha - */ -Texture.fromSource = function(gl, source, premultiplyAlpha) -{ - var texture = new Texture(gl); - texture.premultiplyAlpha = premultiplyAlpha || false; - texture.upload(source); - - return texture; -} - -/** - * @static - * @param gl {WebGLRenderingContext} The current WebGL context - * @param data {TypedArray} the data to upload to the texture - * @param width {number} the new width of the texture - * @param height {number} the new height of the texture - */ -Texture.fromData = function(gl, data, width, height) -{ - //console.log(data, width, height); - var texture = new Texture(gl); - texture.uploadData(data, width, height); - - return texture; -} - - -module.exports = Texture; - -},{}],20:[function(require,module,exports){ - -// state object// -var setVertexAttribArrays = require( './setVertexAttribArrays' ); - -/** - * Helper class to work with WebGL VertexArrayObjects (vaos) - * Only works if WebGL extensions are enabled (they usually are) - * - * @class - * @memberof pixi.gl - * @param gl {WebGLRenderingContext} The current WebGL rendering context - */ -function VertexArrayObject(gl, state) -{ - - this.nativeVaoExtension = ( - gl.getExtension('OES_vertex_array_object') || - gl.getExtension('MOZ_OES_vertex_array_object') || - gl.getExtension('WEBKIT_OES_vertex_array_object') - ); - - this.nativeState = state; - - if(this.nativeVaoExtension) - { - this.nativeVao = this.nativeVaoExtension.createVertexArrayOES(); - - var maxAttribs = gl.getParameter(gl.MAX_VERTEX_ATTRIBS); - - // VAO - overwrite the state.. - this.nativeState = {tempAttribState:new Array(maxAttribs) - ,attribState:new Array(maxAttribs)}; - } - - /** - * The current WebGL rendering context - * - * @member {WebGLRenderingContext} - */ - this.gl = gl; - - /** - * An array of attributes ? @mat - * - * @member {Array} - */ - this.attributes = []; - - /** - * @mat - * - * @member {Array} - */ - this.indexBuffer = null; - - /** - * A boolean flag - * - * @member {Boolean} - */ - this.dirty = false; -} - -VertexArrayObject.prototype.constructor = VertexArrayObject; -module.exports = VertexArrayObject; - - -/** - * Binds the buffer - */ -VertexArrayObject.prototype.bind = function() -{ - if(this.nativeVao) - { - this.nativeVaoExtension.bindVertexArrayOES(this.nativeVao); - - if(this.dirty) - { - this.dirty = false; - this.activate(); - } - } - else - { - - this.activate(); - } - - return this; -} - -/** - * Unbinds the buffer - */ -VertexArrayObject.prototype.unbind = function() -{ - if(this.nativeVao) - { - this.nativeVaoExtension.bindVertexArrayOES(null); - } - - return this; -} - -/** - * Uses this vao - */ -VertexArrayObject.prototype.activate = function() -{ - - var gl = this.gl; - var lastBuffer = null; - - for (var i = 0; i < this.attributes.length; i++) - { - var attrib = this.attributes[i]; - - if(lastBuffer !== attrib.buffer) - { - attrib.buffer.bind(); - lastBuffer = attrib.buffer; - } - - //attrib.attribute.pointer(attrib.type, attrib.normalized, attrib.stride, attrib.start); - gl.vertexAttribPointer(attrib.attribute.location, - attrib.attribute.size, attrib.type || gl.FLOAT, - attrib.normalized || false, - attrib.stride || 0, - attrib.start || 0); - - - }; - - setVertexAttribArrays(gl, this.attributes, this.nativeState); - - this.indexBuffer.bind(); - - return this; -} - -/** - * - * @param buffer {WebGLBuffer} - * @param attribute {[type]} - * @param type {[type]} - * @param normalized {[type]} - * @param stride {Number} - * @param start {Number} - */ -VertexArrayObject.prototype.addAttribute = function(buffer, attribute, type, normalized, stride, start) -{ - this.attributes.push({ - buffer: buffer, - attribute: attribute, - - location: attribute.location, - type: type || this.gl.FLOAT, - normalized: normalized || false, - stride: stride || 0, - start: start || 0 - }) - - this.dirty = true; - - return this; -} - -/** - * - * @param buffer {WebGLBuffer} - * @param options {Object} - */ -VertexArrayObject.prototype.addIndex = function(buffer, options) -{ - this.indexBuffer = buffer; - - this.dirty = true; - - return this; -} - -/** - * Unbinds this vao and disables it - */ -VertexArrayObject.prototype.clear = function() -{ - var gl = this.gl; - - // TODO - should this function unbind after clear? - // for now, no but lets see what happens in the real world! - if(this.nativeVao) - { - this.nativeVaoExtension.bindVertexArrayOES(this.nativeVao); - } - - this.attributes.length = 0; - this.indexBuffer = null; - - return this; -} - -/** - * @mat - * @param type {Number} - * @param size {Number} - * @param start {Number} - */ -VertexArrayObject.prototype.draw = function(type, size, start) -{ - var gl = this.gl; - gl.drawElements(type, size, gl.UNSIGNED_SHORT, start || 0); - - return this; -} + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.MIRRORED_REPEAT); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.MIRRORED_REPEAT); +}; -},{"./setVertexAttribArrays":22}],21:[function(require,module,exports){ - -/** - * Helper class to create a webGL Context - * - * @class - * @memberof pixi.gl - * @param canvas {HTMLCanvasElement} the canvas element that we will get the context from - * @param options {Object} An options object that gets passed in to the canvas element containing the context attributes, - * see https://developer.mozilla.org/en/docs/Web/API/HTMLCanvasElement/getContext for the options available - * @return {WebGLRenderingContext} the WebGL context - */ -var createContext = function(canvas, options) -{ - var gl = canvas.getContext('webgl', options) || - canvas.getContext('experimental-webgl', options); - - if (!gl) - { - // fail, not able to get a context - throw new Error('This browser does not support webGL. Try using the canvas renderer'); - } - - return gl; -} - -module.exports = createContext; -},{}],22:[function(require,module,exports){ -var GL_MAP = {}; - -/** - * @mat - * @param gl {WebGLRenderingContext} The current WebGL context - * @param attribs {[type]} - */ -var setVertexAttribArrays = function (gl, attribs, state) -{ - - if(state) - { - - var i, - tempAttribState = state.tempAttribState, - attribState = state.attribState; - - for (i = 0; i < tempAttribState.length; i++) - { - tempAttribState[i] = false; - } - - // set the new attribs - for (i in attribs) - { - tempAttribState[attribs[i].attribute.location] = true; - } - - for (i = 0; i < attribState.length; i++) - { - if (attribState[i] !== tempAttribState[i]) - { - attribState[i] = tempAttribState[i]; - - if (state.attribState[i]) - { - gl.enableVertexAttribArray(i); - } - else - { - gl.disableVertexAttribArray(i); - } - } - } - - } - else - { - for (var i = 0; i < attribs.length; i++) - { - var attrib = attribs[i]; - gl.enableVertexAttribArray(attrib.attribute.location); - } - } -}; - -module.exports = setVertexAttribArrays; +/** + * Destroys this texture + */ +Texture.prototype.destroy = function() +{ + var gl = this.gl; + //TODO + gl.deleteTexture(this.texture); +}; -},{}],23:[function(require,module,exports){ - -/** - * - * @param gl {WebGLRenderingContext} The current WebGL context {WebGLProgram} - * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. - * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. - * @return {WebGLProgram} the shader program - */ -compileProgram = function(gl, vertexSrc, fragmentSrc) -{ - var glVertShader = compileShader(gl, gl.VERTEX_SHADER, vertexSrc); - var glFragShader = compileShader(gl, gl.FRAGMENT_SHADER, fragmentSrc); - - var program = gl.createProgram(); - - gl.attachShader(program, glVertShader); - gl.attachShader(program, glFragShader); - gl.linkProgram(program); - - // if linking fails, then log and cleanup - if (!gl.getProgramParameter(program, gl.LINK_STATUS)) - { - console.error('Pixi.js Error: Could not initialize shader.'); - console.error('gl.VALIDATE_STATUS', gl.getProgramParameter(program, gl.VALIDATE_STATUS)); - console.error('gl.getError()', gl.getError()); - - // if there is a program info log, log it - if (gl.getProgramInfoLog(program) !== '') - { - console.warn('Pixi.js Warning: gl.getProgramInfoLog()', gl.getProgramInfoLog(program)); - } - - gl.deleteProgram(program); - program = null; - } - - // clean up some shaders - gl.deleteShader(glVertShader); - gl.deleteShader(glFragShader); - - return program; -} - -/** - * - * @param gl {WebGLRenderingContext} The current WebGL context {WebGLProgram} - * @param type {Number} the type, can be either VERTEX_SHADER or FRAGMENT_SHADER - * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. - * @return {WebGLShader} the shader - */ -var compileShader = function (gl, type, src) -{ - var shader = gl.createShader(type); - - gl.shaderSource(shader, src); - gl.compileShader(shader); - - if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) - { - console.log(gl.getShaderInfoLog(shader)); - return null; - } - - return shader; -}; - -module.exports = compileProgram; +/** + * @static + * @param gl {WebGLRenderingContext} The current WebGL context + * @param source {HTMLImageElement|ImageData} the source image of the texture + * @param premultiplyAlpha {Boolean} If we want to use pre-multiplied alpha + */ +Texture.fromSource = function(gl, source, premultiplyAlpha) +{ + var texture = new Texture(gl); + texture.premultiplyAlpha = premultiplyAlpha || false; + texture.upload(source); -},{}],24:[function(require,module,exports){ - - -var defaultValue = function(type, size) -{ - switch (type) - { - case 'float': - return 0; - - case 'vec2': - return new Float32Array(2 * size); - - case 'vec3': - return new Float32Array(3 * size); - - case 'vec4': - return new Float32Array(4 * size); - - case 'int': - case 'sampler2D': - return 0; - - case 'ivec2': - return new Int32Array(2 * size); - - case 'ivec3': - return new Int32Array(3 * size); - - case 'ivec4': - return new Int32Array(4 * size); - - case 'bool': - return false; - - case 'bvec2': - - return booleanArray( 2 * size); - - case 'bvec3': - return booleanArray(3 * size); - - case 'bvec4': - return booleanArray(4 * size); - - case 'mat2': - return new Float32Array([1, 0 - ,0, 1]); - - case 'mat3': - return new Float32Array([1, 0, 0 - ,0, 1, 0 - ,0, 0, 1]); - - case 'mat4': - return new Float32Array([1, 0, 0, 0 - ,0, 1, 0, 0 - ,0, 0, 1, 0 - ,0, 0, 0, 1]); - } -} - -var booleanArray = function(size) -{ - var array = new Array(size); - - for (var i = 0; i < array.length; i++) - { - array[i] = false; - }; - - return array; -} - -module.exports = defaultValue; + return texture; +}; -},{}],25:[function(require,module,exports){ - -var mapType = require('./mapType'); -var mapSize = require('./mapSize'); - -/** - * Extracts the attributes - * @param gl {WebGLRenderingContext} The current WebGL rendering context - * @param program {WebGLProgram} The shader program to get the attributes from - * @return attributes {Object} - */ -var extractAttributes = function(gl, program) -{ - var attributes = {}; - - var totalAttributes = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES) - - for (var i = 0; i < totalAttributes; i++) - { - var attribData = gl.getActiveAttrib(program, i); - var type = mapType(gl, attribData.type); - - attributes[attribData.name] = { - type:type, - size:mapSize(type), - location:gl.getAttribLocation(program, attribData.name), - //TODO - make an attribute object - pointer:function(type, normalized, stride, start){ - - // console.log(this.location) - gl.vertexAttribPointer(this.location,this.size, type || gl.FLOAT, normalized || false, stride || 0, start || 0); - - } - } - }; - - return attributes; -} - -module.exports = extractAttributes; +/** + * @static + * @param gl {WebGLRenderingContext} The current WebGL context + * @param data {TypedArray} the data to upload to the texture + * @param width {number} the new width of the texture + * @param height {number} the new height of the texture + */ +Texture.fromData = function(gl, data, width, height) +{ + //console.log(data, width, height); + var texture = new Texture(gl); + texture.uploadData(data, width, height); -},{"./mapSize":28,"./mapType":29}],26:[function(require,module,exports){ -var mapType = require('./mapType'); -var defaultValue = require('./defaultValue'); - -/** - * Extracts the uniforms - * @param gl {WebGLRenderingContext} The current WebGL rendering context - * @param program {WebGLProgram} The shader program to get the uniforms from - * @return uniforms {Object} - */ -var extractUniforms = function(gl, program) -{ - var uniforms = {}; - - var totalUniforms = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS) - - for (var i = 0; i < totalUniforms; i++) - { - var uniformData = gl.getActiveUniform(program, i); - var name = uniformData.name.replace(/\[.*?\]/, ""); - var type = mapType(gl, uniformData.type ); - - uniforms[name] = { - type:type, - size:uniformData.size, - location:gl.getUniformLocation(program, name), - value:defaultValue(type, uniformData.size) - } - }; - - return uniforms; -} - -module.exports = extractUniforms; + return texture; +}; -},{"./defaultValue":24,"./mapType":29}],27:[function(require,module,exports){ -/** - * Extracts the attributes - * @param gl {WebGLRenderingContext} The current WebGL rendering context - * @param uniforms {Array} @mat ? - * @return attributes {Object} - */ -var generateUniformAccessObject = function(gl, uniformData) -{ - // this is the object we will be sending back. - // an object hierachy will be created for structs - var uniforms = {data:{}}; - - uniforms.gl = gl; - - var uniformKeys= Object.keys(uniformData); - - for (var i = 0; i < uniformKeys.length; i++) - { - var fullName = uniformKeys[i] - - var nameTokens = fullName.split('.'); - var name = nameTokens[nameTokens.length - 1]; - - var uniformGroup = getUniformGroup(nameTokens, uniforms); - - var uniform = uniformData[fullName]; - uniformGroup.data[name] = uniform; - - uniformGroup.gl = gl; - - Object.defineProperty(uniformGroup, name, { - get: generateGetter(name), - set: generateSetter(name, uniform) - }) - }; - - return uniforms; -} - -var generateGetter = function(name) -{ - var template = getterTemplate.replace('%%', name); - return new Function(template); -} - -var generateSetter = function(name, uniform) -{ - var template = setterTemplate.replace(/%%/g, name); - var setTemplate - - if(uniform.size === 1) - { - setTemplate = GLSL_TO_SINGLE_SETTERS[uniform.type]; - } - else - { - setTemplate = GLSL_TO_ARRAY_SETTERS[uniform.type]; - } - - if(setTemplate) - { - template += "\nthis.gl." + setTemplate + ";"; - } - - return new Function('value', template); -} - -var getUniformGroup = function(nameTokens, uniform) -{ - var cur = uniform; - - for (var i = 0; i < nameTokens.length - 1; i++) - { - var o = cur[nameTokens[i]] || {data:{}}; - cur[nameTokens[i]] = o; - cur = o; - }; - - return cur -} - -var getterTemplate = [ - 'return this.data.%%.value;', -].join('\n'); - -var setterTemplate = [ - 'this.data.%%.value = value;', - 'var location = this.data.%%.location;' -].join('\n'); - - -var GLSL_TO_SINGLE_SETTERS = { - - 'float': 'uniform1f(location, value)', - - 'vec2': 'uniform2f(location, value[0], value[1])', - 'vec3': 'uniform3f(location, value[0], value[1], value[2])', - 'vec4': 'uniform4f(location, value[0], value[1], value[2], value[3])', - - 'int': 'uniform1i(location, value)', - 'ivec2': 'uniform2i(location, value[0], value[1])', - 'ivec3': 'uniform3i(location, value[0], value[1], value[2])', - 'ivec4': 'uniform4i(location, value[0], value[1], value[2], value[3])', - - 'bool': 'uniform1i(location, value)', - 'bvec2': 'uniform2i(location, value[0], value[1])', - 'bvec3': 'uniform3i(location, value[0], value[1], value[2])', - 'bvec4': 'uniform4i(location, value[0], value[1], value[2], value[3])', - - 'mat2': 'uniformMatrix2fv(location, false, value)', - 'mat3': 'uniformMatrix3fv(location, false, value)', - 'mat4': 'uniformMatrix4fv(location, false, value)', - - 'sampler2D':'uniform1i(location, value)' -} - -var GLSL_TO_ARRAY_SETTERS = { - - 'float': 'uniform1fv(location, value)', - - 'vec2': 'uniform2fv(location, value)', - 'vec3': 'uniform3fv(location, value)', - 'vec4': 'uniform4fv(location, value)', - - 'int': 'uniform1iv(location, value)', - 'ivec2': 'uniform2iv(location, value)', - 'ivec3': 'uniform3iv(location, value)', - 'ivec4': 'uniform4iv(location, value)', - - 'bool': 'uniform1iv(location, value)', - 'bvec2': 'uniform2iv(location, value)', - 'bvec3': 'uniform3iv(location, value)', - 'bvec4': 'uniform4iv(location, value)', - - 'sampler2D':'uniform1iv(location, value)' -} - -module.exports = generateUniformAccessObject; -},{}],28:[function(require,module,exports){ - - -var mapSize = function(type) -{ - return GLSL_TO_SIZE[type]; -} - - -var GLSL_TO_SIZE = { - 'float': 1, - 'vec2': 2, - 'vec3': 3, - 'vec4': 4, - - 'int': 1, - 'ivec2': 2, - 'ivec3': 3, - 'ivec4': 4, - - 'bool': 1, - 'bvec2': 2, - 'bvec3': 3, - 'bvec4': 4, - - 'mat2': 4, - 'mat3': 9, - 'mat4': 16, - - 'sampler2D': 1 -} - -module.exports = mapSize; +module.exports = Texture; -},{}],29:[function(require,module,exports){ - - -var mapSize = function(gl, type) -{ - if(!GL_TABLE) - { - var typeNames = Object.keys(GL_TO_GLSL_TYPES); - - GL_TABLE = {}; - - for(var i = 0; i < typeNames.length; ++i) - { - var tn = typeNames[i]; - GL_TABLE[ gl[tn] ] = GL_TO_GLSL_TYPES[tn]; - } - } - - return GL_TABLE[type]; -} - -var GL_TABLE = null; - -var GL_TO_GLSL_TYPES = { - 'FLOAT': 'float', - 'FLOAT_VEC2': 'vec2', - 'FLOAT_VEC3': 'vec3', - 'FLOAT_VEC4': 'vec4', - - 'INT': 'int', - 'INT_VEC2': 'ivec2', - 'INT_VEC3': 'ivec3', - 'INT_VEC4': 'ivec4', - - 'BOOL': 'bool', - 'BOOL_VEC2': 'bvec2', - 'BOOL_VEC3': 'bvec3', - 'BOOL_VEC4': 'bvec4', - - 'FLOAT_MAT2': 'mat2', - 'FLOAT_MAT3': 'mat3', - 'FLOAT_MAT4': 'mat4', - - 'SAMPLER_2D': 'sampler2D' -} - -module.exports = mapSize; +},{}],12:[function(require,module,exports){ -},{}],30:[function(require,module,exports){ -var core = require('../core'); - -// add some extra variables to the container.. -Object.assign( - core.DisplayObject.prototype, - require('./accessibleTarget') -); - - -/** - * The Accessibility manager reacreates the ability to tab and and have content read by screen readers. This is very important as it can possibly help people with disabilities access pixi content. - * Much like interaction any DisplayObject can be made accessible. This manager will map the events as if the mouse was being used, minimizing the efferot required to implement. - * - * @class - * @memberof PIXI - * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer - */ -function AccessibilityManager(renderer) -{ - // first we create a div that will sit over the pixi element. This is where the div overlays will go. - var div = document.createElement('div'); - - div.style.width = 100 + 'px'; - div.style.height = 100 + 'px'; - div.style.position = 'absolute'; - div.style.top = 0; - div.style.left = 0; - // - div.style.zIndex = 2; - - /** - * This is the dom element that will sit over the pixi element. This is where the div overlays will go. - * - * @type {HTMLElement} - * @private - */ - this.div = div; - - /** - * A simple pool for storing divs. - * - * @type {Array} - * @private - */ - this.pool = []; - - /** - * This is a tick used to check if an object is no longer being rendered. - * - * @type {Number} - * @private - */ - this.renderId = 0; - - /** - * Setting this to true will visually show the divs - * - * @type {Boolean} - */ - this.debug = false; - - /** - * The renderer this accessibility manager works for. - * - * @member {PIXI.SystemRenderer} - */ - this.renderer = renderer; - - /** - * The array of currently active accessible items. - * - * @member {Array} - * @private - */ - this.children = []; - - /** - * pre bind the functions.. - */ - this._onKeyDown = this._onKeyDown.bind(this); - this._onMouseMove = this._onMouseMove.bind(this); - - /** - * stores the state of the manager. If there are no accessible objects or the mouse is moving the will be false. - * - * @member {Array} - * @private - */ - this.isActive = false; - - - // let listen for tab.. once pressed we can fire up and show the accessibility layer - window.addEventListener('keydown', this._onKeyDown, false); -} - - -AccessibilityManager.prototype.constructor = AccessibilityManager; -module.exports = AccessibilityManager; - -/** - * Activating will cause the Accessibility layer to be shown. This is called when a user preses the tab key - * @private - */ -AccessibilityManager.prototype.activate = function() -{ - if(this.isActive) - { - return; - } - - this.isActive = true; - - window.document.addEventListener('mousemove', this._onMouseMove, true); - window.removeEventListener('keydown', this._onKeyDown, false); - - this.renderer.on('postrender', this.update, this); - - this.renderer.view.parentNode.appendChild(this.div); -}; - -/** - * Deactivating will cause the Accessibility layer to be hidden. This is called when a user moves the mouse - * @private - */ -AccessibilityManager.prototype.deactivate = function() -{ - if(!this.isActive) - { - return; - } - - this.isActive = false; - - window.document.removeEventListener('mousemove', this._onMouseMove); - window.addEventListener('keydown', this._onKeyDown, false); - - this.renderer.off('postrender', this.update); - - this.div.parentNode.removeChild(this.div); - -}; - -/** - * This recursive function will run throught he scene graph and add any new accessible objects to the DOM layer. - * @param element {PIXI.Container|PIXI.Sprite|PIXI.extras.TilingSprite} the DisplayObject to check. - * @private - */ -AccessibilityManager.prototype.updateAccessibleObjects = function(displayObject) -{ - if(!displayObject.visible) - { - return; - } - - if(displayObject.accessible && displayObject.interactive) - { - if(!displayObject._accessibleActive) - { - this.addChild(displayObject); - } - - displayObject.renderId = this.renderId; - } - - var children = displayObject.children; - - for (var i = children.length - 1; i >= 0; i--) { - - this.updateAccessibleObjects(children[i]); - } -}; - - -/** - * Before each render this function will ensure that all divs are mapped correctly to their DisplayObjects - * @private - */ -AccessibilityManager.prototype.update = function() -{ - if(!this.renderer.renderingToScreen) { - return; - } - - // update children... - this.updateAccessibleObjects(this.renderer._lastObjectRendered); - - var rect = this.renderer.view.getBoundingClientRect(); - var sx = rect.width / this.renderer.width; - var sy = rect.height / this.renderer.height; - - var div = this.div; - - div.style.left = rect.left + 'px'; - div.style.top = rect.top + 'px'; - div.style.width = this.renderer.width + 'px'; - div.style.height = this.renderer.height + 'px'; - - for (var i = 0; i < this.children.length; i++) - { - - var child = this.children[i]; - - if(child.renderId !== this.renderId) - { - child._accessibleActive = false; - - core.utils.removeItems(this.children, i, 1); - this.div.removeChild( child._accessibleDiv ); - this.pool.push(child._accessibleDiv); - child._accessibleDiv = null; - - i--; - - if(this.children.length === 0) - { - this.deactivate(); - } - } - else - { - // map div to display.. - div = child._accessibleDiv; - var hitArea = child.hitArea; - var wt = child.worldTransform; - - if(child.hitArea) - { - div.style.left = ((wt.tx + (hitArea.x * wt.a)) * sx) + 'px'; - div.style.top = ((wt.ty + (hitArea.y * wt.d)) * sy) + 'px'; - - div.style.width = (hitArea.width * wt.a * sx) + 'px'; - div.style.height = (hitArea.height * wt.d * sy) + 'px'; - - } - else - { - hitArea = child.getBounds(); - - this.capHitArea(hitArea); - - div.style.left = (hitArea.x * sx) + 'px'; - div.style.top = (hitArea.y * sy) + 'px'; - - div.style.width = (hitArea.width * sx) + 'px'; - div.style.height = (hitArea.height * sy) + 'px'; - } - } - } - - // increment the render id.. - this.renderId++; -}; - -AccessibilityManager.prototype.capHitArea = function (hitArea) -{ - if (hitArea.x < 0) - { - hitArea.width += hitArea.x; - hitArea.x = 0; - } - - if (hitArea.y < 0) - { - hitArea.height += hitArea.y; - hitArea.y = 0; - } - - if ( hitArea.x + hitArea.width > this.renderer.width ) - { - hitArea.width = this.renderer.width - hitArea.x; - } - - if ( hitArea.y + hitArea.height > this.renderer.height ) - { - hitArea.height = this.renderer.height - hitArea.y; - } -}; - - -/** - * Adds a DisplayObject to the accessibility manager - * @private - */ -AccessibilityManager.prototype.addChild = function(displayObject) -{ -// this.activate(); - - var div = this.pool.pop(); - - if(!div) - { - div = document.createElement('button'); - - div.style.width = 100 + 'px'; - div.style.height = 100 + 'px'; - div.style.backgroundColor = this.debug ? 'rgba(255,0,0,0.5)' : 'transparent'; - div.style.position = 'absolute'; - div.style.zIndex = 2; - div.style.borderStyle = 'none'; - - - div.addEventListener('click', this._onClick.bind(this)); - div.addEventListener('focus', this._onFocus.bind(this)); - div.addEventListener('focusout', this._onFocusOut.bind(this)); - } - - - - - div.title = displayObject.accessibleTitle || 'displayObject ' + this.tabIndex; - - // - - displayObject._accessibleActive = true; - displayObject._accessibleDiv = div; - div.displayObject = displayObject; - - - this.children.push(displayObject); - this.div.appendChild( displayObject._accessibleDiv ); - displayObject._accessibleDiv.tabIndex = displayObject.tabIndex; -}; - - -/** - * Maps the div button press to pixi's InteractionManager (click) - * @private - */ -AccessibilityManager.prototype._onClick = function(e) -{ - var interactionManager = this.renderer.plugins.interaction; - interactionManager.dispatchEvent(e.target.displayObject, 'click', interactionManager.eventData); -}; - -/** - * Maps the div focus events to pixis InteractionManager (mouseover) - * @private - */ -AccessibilityManager.prototype._onFocus = function(e) -{ - var interactionManager = this.renderer.plugins.interaction; - interactionManager.dispatchEvent(e.target.displayObject, 'mouseover', interactionManager.eventData); -}; - -/** - * Maps the div focus events to pixis InteractionManager (mouseout) - * @private - */ -AccessibilityManager.prototype._onFocusOut = function(e) -{ - var interactionManager = this.renderer.plugins.interaction; - interactionManager.dispatchEvent(e.target.displayObject, 'mouseout', interactionManager.eventData); -}; - -/** - * Is called when a key is pressed - * - * @private - */ -AccessibilityManager.prototype._onKeyDown = function(e) -{ - if(e.keyCode !== 9) - { - return; - } - - this.activate(); -}; - -/** - * Is called when the mouse moves across the renderer element - * - * @private - */ -AccessibilityManager.prototype._onMouseMove = function() -{ - this.deactivate(); -}; - - -/** - * Destroys the accessibility manager - * - */ -AccessibilityManager.prototype.destroy = function () -{ - this.div = null; - - for (var i = 0; i < this.children.length; i++) - { - this.children[i].div = null; - } - - - window.document.removeEventListener('mousemove', this._onMouseMove); - window.removeEventListener('keydown', this._onKeyDown); - - this.pool = null; - this.children = null; - this.renderer = null; - -}; - -core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); -core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); - -},{"../core":50,"./accessibleTarget":31}],31:[function(require,module,exports){ -/** - * Default property values of accessible objects - * used by {@link PIXI.accessibility.AccessibilityManager}. - * - * @mixin - * @memberof PIXI - * @example - * function MyObject() {} - * - * Object.assign( - * MyObject.prototype, - * PIXI.accessibility.accessibleTarget - * ); - */ -var accessibleTarget = { - - /** - * @todo Needs docs. - */ - accessible:false, - - /** - * @todo Needs docs. - */ - accessibleTitle:null, - - /** - * @todo Needs docs. - */ - tabIndex:0, - - /** - * @todo Needs docs. - */ - _accessibleActive:false, - - /** - * @todo Needs docs. - */ - _accessibleDiv:false - -}; - -module.exports = accessibleTarget; - -},{}],32:[function(require,module,exports){ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ - -/** - * @namespace PIXI.interaction - */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; - -},{"./AccessibilityManager":30,"./accessibleTarget":31}],33:[function(require,module,exports){ - -/** - * Constant values used in pixi - * - * @lends PIXI - */ -var CONST = { - /** - * String of the current PIXI version - * - * @static - * @constant - * @property {string} VERSION - */ - VERSION: '4.0.0', - - /** - * @property {number} PI_2 - Two Pi - * @constant - * @static - */ - PI_2: Math.PI * 2, - - /** - * @property {number} RAD_TO_DEG - Constant conversion factor for converting radians to degrees - * @constant - * @static - */ - RAD_TO_DEG: 180 / Math.PI, - - /** - * @property {Number} DEG_TO_RAD - Constant conversion factor for converting degrees to radians - * @constant - * @static - */ - DEG_TO_RAD: Math.PI / 180, - - /** - * Target frames per millisecond. - * - * @static - * @constant - * @property {number} TARGET_FPMS=0.06 - */ - TARGET_FPMS: 0.06, - - /** - * Constant to identify the Renderer Type. - * - * @static - * @constant - * @property {object} RENDERER_TYPE - * @property {number} RENDERER_TYPE.UNKNOWN - * @property {number} RENDERER_TYPE.WEBGL - * @property {number} RENDERER_TYPE.CANVAS - */ - RENDERER_TYPE: { - UNKNOWN: 0, - WEBGL: 1, - CANVAS: 2 - }, - - /** - * Various blend modes supported by PIXI. IMPORTANT - The WebGL renderer only supports - * the NORMAL, ADD, MULTIPLY and SCREEN blend modes. Anything else will silently act like - * NORMAL. - * - * @static - * @constant - * @property {object} BLEND_MODES - * @property {number} BLEND_MODES.NORMAL - * @property {number} BLEND_MODES.ADD - * @property {number} BLEND_MODES.MULTIPLY - * @property {number} BLEND_MODES.SCREEN - * @property {number} BLEND_MODES.OVERLAY - * @property {number} BLEND_MODES.DARKEN - * @property {number} BLEND_MODES.LIGHTEN - * @property {number} BLEND_MODES.COLOR_DODGE - * @property {number} BLEND_MODES.COLOR_BURN - * @property {number} BLEND_MODES.HARD_LIGHT - * @property {number} BLEND_MODES.SOFT_LIGHT - * @property {number} BLEND_MODES.DIFFERENCE - * @property {number} BLEND_MODES.EXCLUSION - * @property {number} BLEND_MODES.HUE - * @property {number} BLEND_MODES.SATURATION - * @property {number} BLEND_MODES.COLOR - * @property {number} BLEND_MODES.LUMINOSITY - */ - BLEND_MODES: { - NORMAL: 0, - ADD: 1, - MULTIPLY: 2, - SCREEN: 3, - OVERLAY: 4, - DARKEN: 5, - LIGHTEN: 6, - COLOR_DODGE: 7, - COLOR_BURN: 8, - HARD_LIGHT: 9, - SOFT_LIGHT: 10, - DIFFERENCE: 11, - EXCLUSION: 12, - HUE: 13, - SATURATION: 14, - COLOR: 15, - LUMINOSITY: 16 - }, - - /** - * Various webgl draw modes. These can be used to specify which GL drawMode to use - * under certain situations and renderers. - * - * @static - * @constant - * @property {object} DRAW_MODES - * @property {number} DRAW_MODES.POINTS - * @property {number} DRAW_MODES.LINES - * @property {number} DRAW_MODES.LINE_LOOP - * @property {number} DRAW_MODES.LINE_STRIP - * @property {number} DRAW_MODES.TRIANGLES - * @property {number} DRAW_MODES.TRIANGLE_STRIP - * @property {number} DRAW_MODES.TRIANGLE_FAN - */ - DRAW_MODES: { - POINTS: 0, - LINES: 1, - LINE_LOOP: 2, - LINE_STRIP: 3, - TRIANGLES: 4, - TRIANGLE_STRIP: 5, - TRIANGLE_FAN: 6 - }, - - /** - * The scale modes that are supported by pixi. - * - * The DEFAULT scale mode affects the default scaling mode of future operations. - * It can be re-assigned to either LINEAR or NEAREST, depending upon suitability. - * - * @static - * @constant - * @property {object} SCALE_MODES - * @property {number} SCALE_MODES.DEFAULT=LINEAR - * @property {number} SCALE_MODES.LINEAR Smooth scaling - * @property {number} SCALE_MODES.NEAREST Pixelating scaling - */ - SCALE_MODES: { - DEFAULT: 0, - LINEAR: 0, - NEAREST: 1 - }, - - /** - * The wrap modes that are supported by pixi. - * - * The DEFAULT wrap mode affects the default wraping mode of future operations. - * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability. - * If the texture is non power of two then clamp will be used regardless as webGL can only use REPEAT if the texture is po2 - * This property only affects WebGL - * @static - * @constant - * @property {object} WRAP_MODES - * @property {number} WRAP_MODES.DEFAULT=CLAMP - * @property {number} WRAP_MODES.CLAMP The textures uvs are clamped - * @property {number} WRAP_MODES.REPEAT The texture uvs tile and repeat - * @property {number} WRAP_MODES.MIRRORED_REPEAT The texture uvs tile and repeat with mirroring - */ - WRAP_MODES: { - DEFAULT: 0, - CLAMP: 0, - REPEAT: 1, - MIRRORED_REPEAT:2 - }, - - /** - * The wrap modes that are supported by pixi. - * - * The DEFAULT Garbage Collection mode for pixi textures is MANUAL - * If set to DEFAULT, the renderer will occasianally check textures usage. If they are not used for a specified period of time they will be removed from the GPU. - * They will of corse be uploaded again when they are required. This is a silent behind the scenes process that should ensure that the GPU does not get filled up. - * Handy for mobile devices! - * This property only affects WebGL - * @static - * @constant - * @property {object} GC_MODES - * @property {number} GC_MODES.DEFAULT=DEFAULT - * @property {number} GC_MODES.AUTO Garbage collection will happen periodically automatically - * @property {number} GC_MODES.MANUAL Garbage collection will need to be called manually - */ - GC_MODES: { - DEFAULT: 1, - AUTO: 0, - MANUAL: 1, - }, - - /** - * If set to true WebGL will attempt make textures mimpaped by default - * Mipmapping will only succeed if the base texture uploaded has power of two dimensions - * @static - * @constant - * @property {bool} MIPMAP_TEXTURES - */ - MIPMAP_TEXTURES:true, - - /** - * The prefix that denotes a URL is for a retina asset - * - * @static - * @constant - * @property {string} RETINA_PREFIX - */ - //example: '@2x', - RETINA_PREFIX: /@(.+)x/, - - RESOLUTION:1, - - FILTER_RESOLUTION:1, - - /** - * The default render options if none are supplied to {@link PIXI.WebGLRenderer} - * or {@link PIXI.CanvasRenderer}. - * - * @static - * @constant - * @property {object} DEFAULT_RENDER_OPTIONS - * @property {HTMLCanvasElement} DEFAULT_RENDER_OPTIONS.view=null - * @property {boolean} DEFAULT_RENDER_OPTIONS.transparent=false - * @property {boolean} DEFAULT_RENDER_OPTIONS.antialias=false - * @property {boolean} DEFAULT_RENDER_OPTIONS.forceFXAA=false - * @property {boolean} DEFAULT_RENDER_OPTIONS.preserveDrawingBuffer=false - * @property {number} DEFAULT_RENDER_OPTIONS.resolution=1 - * @property {number} DEFAULT_RENDER_OPTIONS.backgroundColor=0x000000 - * @property {boolean} DEFAULT_RENDER_OPTIONS.clearBeforeRender=true - * @property {boolean} DEFAULT_RENDER_OPTIONS.autoResize=false - */ - DEFAULT_RENDER_OPTIONS: { - view: null, - resolution: 1, - antialias: false, - forceFXAA: false, - autoResize: false, - transparent: false, - backgroundColor: 0x000000, - clearBeforeRender: true, - preserveDrawingBuffer: false, - roundPixels: false - }, - - /** - * Constants that identify shapes, mainly to prevent `instanceof` calls. - * - * @static - * @constant - * @property {object} SHAPES - * @property {object} SHAPES.POLY=0 - * @property {object} SHAPES.RECT=1 - * @property {object} SHAPES.CIRC=2 - * @property {object} SHAPES.ELIP=3 - * @property {object} SHAPES.RREC=4 - */ - SHAPES: { - POLY: 0, - RECT: 1, - CIRC: 2, - ELIP: 3, - RREC: 4 - }, - - // TODO: maybe change to SPRITE.BATCH_SIZE: 2000 - // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 - SPRITE_BATCH_SIZE: 4096, //nice balance between mobile and desktop machines - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32)//this is the MAXIMUM - various gpus will have there own limits. -}; - -module.exports = CONST; - -},{"./utils/maxRecommendedTextures":101}],34:[function(require,module,exports){ -var math = require('../math'), - utils = require('../utils'), - DisplayObject = require('./DisplayObject'), - RenderTexture = require('../textures/RenderTexture'), - _tempMatrix = new math.Matrix(); - -/** - * A Container represents a collection of display objects. - * It is the base class of all display objects that act as a container for other objects. - * - *```js - * var container = new PIXI.Container(); - * container.addChild(sprite); - * ``` - * @class - * @extends PIXI.DisplayObject - * @memberof PIXI - */ -function Container() -{ - DisplayObject.call(this); - - /** - * The array of children of this container. - * - * @member {PIXI.DisplayObject[]} - * @readonly - */ - this.children = []; -} - -// constructor -Container.prototype = Object.create(DisplayObject.prototype); -Container.prototype.constructor = Container; -module.exports = Container; - -Object.defineProperties(Container.prototype, { - /** - * The width of the Container, setting this will actually modify the scale to achieve the value set - * - * @member {number} - * @memberof PIXI.Container# - */ - width: { - get: function () - { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - var width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; - } - }, - - /** - * The height of the Container, setting this will actually modify the scale to achieve the value set - * - * @member {number} - * @memberof PIXI.Container# - */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - var height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } - } -}); - -/** - * Overridable method that can be used by Container subclasses whenever the children array is modified - * - * @private - */ -Container.prototype.onChildrenChange = function () {}; - -/** - * Adds a child to the container. - * - * You can also add multple items like so: myContainer.addChild(thinkOne, thingTwo, thingThree) - * @param child {PIXI.DisplayObject} The DisplayObject to add to the container - * @return {PIXI.DisplayObject} The child that was added. - */ -Container.prototype.addChild = function (child) -{ - var argumentsLength = arguments.length; - - // if there is only one argument we can bypass looping through the them - if(argumentsLength > 1) - { - // loop through the arguments property and add all children - // use it the right way (.length and [i]) so that this function can still be optimised by JS runtimes - for (var i = 0; i < argumentsLength; i++) - { - this.addChild( arguments[i] ); - } - } - else - { - // if the child has a parent then lets remove it as Pixi objects can only exist in one place - if (child.parent) - { - child.parent.removeChild(child); - } - - child.parent = this; - - this.children.push(child); - - // TODO - lets either do all callbacks or all events.. not both! - this.onChildrenChange(this.children.length-1); - child.emit('added', this); - } - - return child; -}; - -/** - * Adds a child to the container at a specified index. If the index is out of bounds an error will be thrown - * - * @param child {PIXI.DisplayObject} The child to add - * @param index {number} The index to place the child in - * @return {PIXI.DisplayObject} The child that was added. - */ -Container.prototype.addChildAt = function (child, index) -{ - if (index >= 0 && index <= this.children.length) - { - if (child.parent) - { - child.parent.removeChild(child); - } - - child.parent = this; - - this.children.splice(index, 0, child); - - // TODO - lets either do all callbacks or all events.. not both! - this.onChildrenChange(index); - child.emit('added', this); - - return child; - } - else - { - throw new Error(child + 'addChildAt: The index '+ index +' supplied is out of bounds ' + this.children.length); - } -}; - -/** - * Swaps the position of 2 Display Objects within this container. - * - * @param child {PIXI.DisplayObject} - * @param child2 {PIXI.DisplayObject} - */ -Container.prototype.swapChildren = function (child, child2) -{ - if (child === child2) - { - return; - } - - var index1 = this.getChildIndex(child); - var index2 = this.getChildIndex(child2); - - if (index1 < 0 || index2 < 0) - { - throw new Error('swapChildren: Both the supplied DisplayObjects must be children of the caller.'); - } - - this.children[index1] = child2; - this.children[index2] = child; - this.onChildrenChange(index1 < index2 ? index1 : index2); -}; - -/** - * Returns the index position of a child DisplayObject instance - * - * @param child {PIXI.DisplayObject} The DisplayObject instance to identify - * @return {number} The index position of the child display object to identify - */ -Container.prototype.getChildIndex = function (child) -{ - var index = this.children.indexOf(child); - - if (index === -1) - { - throw new Error('The supplied DisplayObject must be a child of the caller'); - } - - return index; -}; - -/** - * Changes the position of an existing child in the display object container - * - * @param child {PIXI.DisplayObject} The child DisplayObject instance for which you want to change the index number - * @param index {number} The resulting index number for the child display object - */ -Container.prototype.setChildIndex = function (child, index) -{ - if (index < 0 || index >= this.children.length) - { - throw new Error('The supplied index is out of bounds'); - } - - var currentIndex = this.getChildIndex(child); - - utils.removeItems(this.children, currentIndex, 1); // remove from old position - this.children.splice(index, 0, child); //add at new position - this.onChildrenChange(index); -}; - -/** - * Returns the child at the specified index - * - * @param index {number} The index to get the child at - * @return {PIXI.DisplayObject} The child at the given index, if any. - */ -Container.prototype.getChildAt = function (index) -{ - if (index < 0 || index >= this.children.length) - { - throw new Error('getChildAt: Supplied index ' + index + ' does not exist in the child list, or the supplied DisplayObject is not a child of the caller'); - } - - return this.children[index]; -}; - -/** - * Removes a child from the container. - * - * @param child {PIXI.DisplayObject} The DisplayObject to remove - * @return {PIXI.DisplayObject} The child that was removed. - */ -Container.prototype.removeChild = function (child) -{ - var argumentsLength = arguments.length; - - // if there is only one argument we can bypass looping through the them - if(argumentsLength > 1) - { - // loop through the arguments property and add all children - // use it the right way (.length and [i]) so that this function can still be optimised by JS runtimes - for (var i = 0; i < argumentsLength; i++) - { - this.removeChild( arguments[i] ); - } - } - else - { - var index = this.children.indexOf(child); - - if (index === -1) - { - return; - } - - child.parent = null; - utils.removeItems(this.children, index, 1); - - // TODO - lets either do all callbacks or all events.. not both! - this.onChildrenChange(index); - child.emit('removed', this); - } - - return child; -}; - -/** - * Removes a child from the specified index position. - * - * @param index {number} The index to get the child from - * @return {PIXI.DisplayObject} The child that was removed. - */ -Container.prototype.removeChildAt = function (index) -{ - var child = this.getChildAt(index); - - child.parent = null; - utils.removeItems(this.children, index, 1); - - // TODO - lets either do all callbacks or all events.. not both! - this.onChildrenChange(index); - child.emit('removed', this); - - return child; -}; - -/** - * Removes all children from this container that are within the begin and end indexes. - * - * @param beginIndex {number} The beginning position. Default value is 0. - * @param endIndex {number} The ending position. Default value is size of the container. - */ -Container.prototype.removeChildren = function (beginIndex, endIndex) -{ - var begin = beginIndex || 0; - var end = typeof endIndex === 'number' ? endIndex : this.children.length; - var range = end - begin; - var removed, i; - - if (range > 0 && range <= end) - { - removed = this.children.splice(begin, range); - - for (i = 0; i < removed.length; ++i) - { - removed[i].parent = null; - } - - this.onChildrenChange(beginIndex); - - for (i = 0; i < removed.length; ++i) - { - removed[i].emit('removed', this); - } - - return removed; - } - else if (range === 0 && this.children.length === 0) - { - return []; - } - else - { - throw new RangeError('removeChildren: numeric values are outside the acceptable range.'); - } -}; - -/* - * Updates the transform on all children of this container for rendering - * - * @private - */ -Container.prototype.updateTransform = function () -{ - if (!this.visible) - { - return; - } - - this.transform = this.parent.transform.updateChildTransform(this.transform); - - //TODO: check render flags, how to process stuff here - this.worldAlpha = this.alpha * this.parent.worldAlpha; - - for (var i = 0, j = this.children.length; i < j; ++i) - { - this.children[i].updateTransform(); - } - - this._currentBounds = null; -}; - -// performance increase to avoid using call.. (10x faster) -Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; - -/** -* RetrieveDs the bounds of the Container as a rectangle. The bounds calculation takes all visible children into consideration. - * - * @return {PIXI.Rectangle} The rectangular bounding area - */ -Container.prototype.getBounds = function () -{ - if(!this._currentBounds) - { - - if (this.children.length === 0) - { - return math.Rectangle.EMPTY; - } - - // TODO the bounds have already been calculated this render session so return what we have - - var minX = Infinity; - var minY = Infinity; - - var maxX = -Infinity; - var maxY = -Infinity; - - var childBounds; - var childMaxX; - var childMaxY; - - var childVisible = false; - - for (var i = 0, j = this.children.length; i < j; ++i) - { - var child = this.children[i]; - - if (!child.visible) - { - continue; - } - - childBounds = this.children[i].getBounds(); - if (childBounds === math.Rectangle.EMPTY) { - continue; - } - childVisible = true; - - minX = minX < childBounds.x ? minX : childBounds.x; - minY = minY < childBounds.y ? minY : childBounds.y; - - childMaxX = childBounds.width + childBounds.x; - childMaxY = childBounds.height + childBounds.y; - - maxX = maxX > childMaxX ? maxX : childMaxX; - maxY = maxY > childMaxY ? maxY : childMaxY; - } - - if (!childVisible) - { - return this._currentBounds = math.Rectangle.EMPTY; - } - - var bounds = this._bounds; - - bounds.x = minX; - bounds.y = minY; - bounds.width = maxX - minX; - bounds.height = maxY - minY; - - this._currentBounds = bounds; - } - - return this._currentBounds; -}; - -Container.prototype.containerGetBounds = Container.prototype.getBounds; - -/** - * Retrieves the non-global local bounds of the Container as a rectangle. - * The calculation takes all visible children into consideration. - * - * @return {PIXI.Rectangle} The rectangular bounding area - */ -Container.prototype.getLocalBounds = function () -{ - var matrixCache = this.transform.worldTransform; - - this.transform.worldTransform = math.Matrix.IDENTITY; - - for (var i = 0, j = this.children.length; i < j; ++i) - { - this.children[i].updateTransform(); - } - - this.transform.worldTransform = matrixCache; - - this._currentBounds = null; - - return this.getBounds( math.Matrix.IDENTITY ); -}; - -/** - * Renders the object using the WebGL renderer - * - * @param renderer {PIXI.WebGLRenderer} The renderer - */ -Container.prototype.renderWebGL = function (renderer) -{ - - // if the object is not visible or the alpha is 0 then no need to render this element - if (!this.visible || this.worldAlpha <= 0 || !this.renderable) - { - - return; - } - - var i, j; - - // do a quick check to see if this element has a mask or a filter. - if (this._mask || this._filters) - { - renderer.currentRenderer.flush(); - - // push filter first as we need to ensure the stencil buffer is correct for any masking - if (this._filters && this._filters.length) - { - renderer.filterManager.pushFilter(this, this._filters); - } - - if (this._mask) - { - renderer.maskManager.pushMask(this, this._mask); - } - - renderer.currentRenderer.start(); - - // add this object to the batch, only rendered if it has a texture. - this._renderWebGL(renderer); - - // now loop through the children and make sure they get rendered - for (i = 0, j = this.children.length; i < j; i++) - { - this.children[i].renderWebGL(renderer); - } - - renderer.currentRenderer.flush(); - - if (this._mask) - { - renderer.maskManager.popMask(this, this._mask); - } - - if (this._filters) - { - renderer.filterManager.popFilter(); - - } - renderer.currentRenderer.start(); - } - else - { - this._renderWebGL(renderer); - - // simple render children! - for (i = 0, j = this.children.length; i < j; ++i) - { - this.children[i].renderWebGL(renderer); - } - } -}; - -/** - * To be overridden by the subclass - * - * @param renderer {PIXI.WebGLRenderer} The renderer - * @private - */ -Container.prototype._renderWebGL = function (renderer) // jshint unused:false -{ - // this is where content itself gets rendered... -}; - -/** - * To be overridden by the subclass - * - * @param renderer {PIXI.CanvasRenderer} The renderer - * @private - */ -Container.prototype._renderCanvas = function (renderer) // jshint unused:false -{ - // this is where content itself gets rendered... -}; - - -/** - * Renders the object using the Canvas renderer - * - * @param renderer {PIXI.CanvasRenderer} The renderer - */ -Container.prototype.renderCanvas = function (renderer) -{ - // if not visible or the alpha is 0 then no need to render this - if (!this.visible || this.alpha <= 0 || !this.renderable) - { - return; - } - - if (this._mask) - { - renderer.maskManager.pushMask(this._mask, renderer); - } - - this._renderCanvas(renderer); - for (var i = 0, j = this.children.length; i < j; ++i) - { - this.children[i].renderCanvas(renderer); - } - - if (this._mask) - { - renderer.maskManager.popMask(renderer); - } -}; - -/** - * Destroys the container - * @param [destroyChildren=false] {boolean} if set to true, all the children will have their destroy method called as well - */ -Container.prototype.destroy = function (destroyChildren) -{ - DisplayObject.prototype.destroy.call(this); - - if (destroyChildren) - { - for (var i = 0, j = this.children.length; i < j; ++i) - { - this.children[i].destroy(destroyChildren); - } - } - - this.removeChildren(); - - this.children = null; -}; - -},{"../math":54,"../textures/RenderTexture":92,"../utils":100,"./DisplayObject":35}],35:[function(require,module,exports){ -var math = require('../math'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - Transform = require('./Transform'), - _tempMatrix = new math.Matrix(), - _tempDisplayObjectParent = {worldTransform:new math.Matrix(), worldAlpha:1, children:[]}; - - -/** - * The base class for all objects that are rendered on the screen. - * This is an abstract class and should not be used on its own rather it should be extended. - * - * @class - * @extends EventEmitter - * @memberof PIXI - */ -function DisplayObject() -{ - EventEmitter.call(this); - - //TODO: need to create Transform from factory - this.transform = new Transform(); - - /** - * The opacity of the object. - * - * @member {number} - */ - this.alpha = 1; - - /** - * The visibility of the object. If false the object will not be drawn, and - * the updateTransform function will not be called. - * - * @member {boolean} - */ - this.visible = true; - - /** - * Can this object be rendered, if false the object will not be drawn but the updateTransform - * methods will still be called. - * - * @member {boolean} - */ - this.renderable = true; - - /** - * The display object container that contains this display object. - * - * @member {PIXI.Container} - * @readOnly - */ - this.parent = null; - - /** - * The multiplied alpha of the displayObject - * - * @member {number} - * @readOnly - */ - this.worldAlpha = 1; - - /** - * The area the filter is applied to. This is used as more of an optimisation - * rather than figuring out the dimensions of the displayObject each frame you can set this rectangle - * - * Also works as an interaction mask - * - * @member {PIXI.Rectangle} - */ - this.filterArea = null; - - /** - * Interaction shape. Children will be hit first, then this shape will be checked. - * - * @member {PIXI.Rectangle|PIXI.Circle|PIXI.Ellipse|PIXI.Polygon|PIXI.RoundedRectangle} - */ - this.hitArea = null; - - /** - * The original, cached bounds of the object - * - * @member {PIXI.Rectangle} - * @private - */ - this._bounds = new math.Rectangle(0, 0, 1, 1); - - /** - * The most up-to-date bounds of the object - * - * @member {PIXI.Rectangle} - * @private - */ - this._currentBounds = null; - - /** - * The original, cached mask of the object - * - * @member {PIXI.Rectangle} - * @private - */ - this._mask = null; -} - -// constructor -DisplayObject.prototype = Object.create(EventEmitter.prototype); -DisplayObject.prototype.constructor = DisplayObject; -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.DisplayObject# - */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, - - /** - * The position of the displayObject on the y axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.DisplayObject# - */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, - - /** - * Current transform of the object based on world (parent) factors - * - * @member {PIXI.Matrix} - * @readOnly - */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, - - /** - * Current transform of the object based on local factors: position, scale, other stuff - * - * @member {PIXI.Matrix} - * @readOnly - */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, - - /** - * The coordinate of the object relative to the local coordinates of the parent. - * - * @member {PIXI.Point} - */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position = value; - } - }, - - /** - * The scale factor of the object. - * - * @member {PIXI.Point} - */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale = value; - } - }, - - /** - * The pivot point of the displayObject that it rotates around - * - * @member {PIXI.Point} - */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot = value; - } - }, - - /** - * The skew factor for the object in radians. - * - * @member {PIXI.Point} - */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew = value; - } - }, - - /** - * The rotation of the object in radians. - * - * @member {number} - */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, - - /** - * Indicates if the sprite is globally visible. - * - * @member {boolean} - * @memberof PIXI.DisplayObject# - * @readonly - */ - worldVisible: { - get: function () - { - var item = this; - - do { - if (!item.visible) - { - return false; - } - - item = item.parent; - } while (item); - - return true; - } - }, - - /** - * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. - * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. - * To remove a mask, set this property to null. - * - * @todo For the moment, PIXI.CanvasRenderer doesn't support PIXI.Sprite as mask. - * - * @member {PIXI.Graphics|PIXI.Sprite} - * @memberof PIXI.DisplayObject# - */ - mask: { - get: function () - { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } - } - }, - - /** - * Sets the filters for the displayObject. - * * IMPORTANT: This is a webGL only feature and will be ignored by the canvas renderer. - * To remove filters simply set this property to 'null' - * - * @member {PIXI.AbstractFilter[]} - * @memberof PIXI.DisplayObject# - */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } - } - -}); - -/* - * Updates the object transform for rendering - * - * TODO - Optimization pass! - */ -DisplayObject.prototype.updateTransform = function () -{ - this.transform = this.parent.transform.updateChildTransform(this.transform); - // multiply the alphas.. - this.worldAlpha = this.alpha * this.parent.worldAlpha; -}; - -// performance increase to avoid using call.. (10x faster) -DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; - -/** - * - * - * Retrieves the bounds of the displayObject as a rectangle object - * - * @param matrix {PIXI.Matrix} - * @return {PIXI.Rectangle} the rectangular bounding area - */ -DisplayObject.prototype.getBounds = function (matrix) // jshint unused:false -{ - return math.Rectangle.EMPTY; -}; - -/** - * Retrieves the local bounds of the displayObject as a rectangle object - * - * @return {PIXI.Rectangle} the rectangular bounding area - */ -DisplayObject.prototype.getLocalBounds = function () -{ - return this.getBounds(math.Matrix.IDENTITY); -}; - -/** - * Calculates the global position of the display object - * - * @param position {PIXI.Point} The world origin to calculate from - * @return {PIXI.Point} A point object representing the position of this object - */ -DisplayObject.prototype.toGlobal = function (position) -{ - // this parent check is for just in case the item is a root object. - // If it is we need to give it a temporary parent so that displayObjectUpdateTransform works correctly - // this is mainly to avoid a parent check in the main loop. Every little helps for performance :) - if(!this.parent) - { - this.parent = _tempDisplayObjectParent; - this.displayObjectUpdateTransform(); - this.parent = null; - } - else - { - this.displayObjectUpdateTransform(); - } - - // don't need to update the lot - return this.worldTransform.apply(position); -}; - -/** - * Calculates the local position of the display object relative to another point - * - * @param position {PIXI.Point} The world origin to calculate from - * @param [from] {PIXI.DisplayObject} The DisplayObject to calculate the global position from - * @param [point] {PIXI.Point} A Point object in which to store the value, optional (otherwise will create a new Point) - * @return {PIXI.Point} A point object representing the position of this object - */ -DisplayObject.prototype.toLocal = function (position, from, point) -{ - if (from) - { - position = from.toGlobal(position); - } - - // this parent check is for just in case the item is a root object. - // If it is we need to give it a temporary parent so that displayObjectUpdateTransform works correctly - // this is mainly to avoid a parent check in the main loop. Every little helps for performance :) - if(!this.parent) - { - this.parent = _tempDisplayObjectParent; - this.displayObjectUpdateTransform(); - this.parent = null; - } - else - { - this.displayObjectUpdateTransform(); - } - - // simply apply the matrix.. - return this.worldTransform.applyInverse(position, point); -}; - -/** - * Renders the object using the WebGL renderer - * - * @param renderer {PIXI.WebGLRenderer} The renderer - * @private - */ -DisplayObject.prototype.renderWebGL = function (renderer) // jshint unused:false -{ - // OVERWRITE; -}; - -/** - * Renders the object using the Canvas renderer - * - * @param renderer {PIXI.CanvasRenderer} The renderer - * @private - */ -DisplayObject.prototype.renderCanvas = function (renderer) // jshint unused:false -{ - // OVERWRITE; -}; - -/** - * Set the parent Container of this DisplayObject - * - * @param container {Container} The Container to add this DisplayObject to - * @return {Container} The Container that this DisplayObject was added to - */ -DisplayObject.prototype.setParent = function (container) -{ - if (!container || !container.addChild) - { - throw new Error('setParent: Argument must be a Container'); - } - - container.addChild(this); - return container; -}; - -/** - * Convenience function to set the postion, scale, skew and pivot at once. - * - * @param [x=0] {number} The X position - * @param [y=0] {number} The Y position - * @param [scaleX=1] {number} The X scale value - * @param [scaleY=1] {number} The Y scale value - * @param [rotation=0] {number} The rotation - * @param [skewX=0] {number} The X skew value - * @param [skewY=0] {number} The Y skew value - * @param [pivotX=0] {number} The X pivot value - * @param [pivotY=0] {number} The Y pivot value - * @return {PIXI.DisplayObject} - */ -DisplayObject.prototype.setTransform = function(x, y, scaleX, scaleY, rotation, skewX, skewY, pivotX, pivotY) //jshint ignore:line -{ - this.position.x = x || 0; - this.position.y = y || 0; - this.scale.x = !scaleX ? 1 : scaleX; - this.scale.y = !scaleY ? 1 : scaleY; - this.rotation = rotation || 0; - this.skew.x = skewX || 0; - this.skew.y = skewY || 0; - this.pivot.x = pivotX || 0; - this.pivot.y = pivotY || 0; - return this; -}; - -/** - * Base destroy method for generic display objects - * - */ -DisplayObject.prototype.destroy = function () -{ - - this.position = null; - this.scale = null; - this.pivot = null; - this.skew = null; - - this.parent = null; - - this._bounds = null; - this._currentBounds = null; - this._mask = null; - - this.worldTransform = null; - this.filterArea = null; -}; - -},{"../math":54,"../textures/RenderTexture":92,"./Transform":37,"eventemitter3":12}],36:[function(require,module,exports){ -/** - * The Point object represents a location in a two-dimensional coordinate system, where x represents - * the horizontal axis and y represents the vertical axis. - * - * @class - * @memberof PIXI - * @param transform {PIXI.Transform} the transform object @mat - * @param [x=0] {number} position of the point on the x axis - * @param [y=0] {number} position of the point on the y axis - */ -function ObservablePoint(cb, scope, x, y) -{ - this._x = x || 0; - this._y = y || 0; - - this.cb = cb; - this.scope = scope; -} - -ObservablePoint.prototype.constructor = ObservablePoint; -module.exports = ObservablePoint; - - - -Object.defineProperties(ObservablePoint.prototype, { - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - this._x = value; - this.cb.call(this.scope); - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - this._y = value; - this.cb.call(this.scope); - } - } -}); - -/** - * Sets the point to a new x and y position. - * If y is omitted, both x and y will be set to x. - * - * @param [x=0] {number} position of the point on the x axis - * @param [y=0] {number} position of the point on the y axis - */ -ObservablePoint.prototype.set = function (x, y) -{ - this._x = x || 0; - this._y = y || ( (y !== 0) ? this._x : 0 ); - - this.transform._versionLocal++; -}; - -},{}],37:[function(require,module,exports){ -var math = require('../math'), - ObservablePoint = require('./ObservablePoint'); - - -/** - * Generic class to deal with traditional 2D matrix transforms - * - * @class - * @memberof PIXI - * @param [x=0] {number} position of the point on the x axis - * @param [y=0] {number} position of the point on the y axis - */ -function Transform() -{ - /** - * @member {PIXI.Matrix} The global matrix transform - */ - this.worldTransform = new math.Matrix(); - /** - * @member {PIXI.Matrix} The local matrix transform - */ - this.localTransform = new math.Matrix(); - - /** - * The coordinate of the object relative to the local coordinates of the parent. - * - * @member {PIXI.Point} - */ - this.position = new math.Point(0.0); - - /** - * The scale factor of the object. - * - * @member {PIXI.Point} - */ - this.scale = new math.Point(1,1); - - - this.skew = new ObservablePoint(this.updateSkew, this, 0,0); - - /** - * The pivot point of the displayObject that it rotates around - * - * @member {PIXI.Point} - */ - this.pivot = new math.Point(0.0); - - - /** - * The rotation value of the object, in radians - * - * @member {Number} - */ - this._rotation = 0; - this._sr = Math.sin(0); - this._cr = Math.cos(0); - this._cy = Math.cos(0)//skewY); - this._sy = Math.sin(0)//skewY); - this._nsx = Math.sin(0)//skewX); - this._cx = Math.cos(0)//skewX); - - this._dirty = false; - this.updated = true; -} - -Transform.prototype.constructor = Transform; - -Transform.prototype.updateSkew = function () -{ - this._cy = Math.cos(this.skew.y); - this._sy = Math.sin(this.skew.y); - this._nsx = Math.sin(this.skew.x); - this._cx = Math.cos(this.skew.x); -} - -/** - * Updates the values of the object and applies the parent's transform. - * @param parentTransform {PIXI.Transform} The transform of the parent of this object - * - */ -Transform.prototype.updateTransform = function (parentTransform) -{ - - var pt = parentTransform.worldTransform; - var wt = this.worldTransform; - var lt = this.localTransform; - var a, b, c, d; - - a = this._cr * this.scale.x; - b = this._sr * this.scale.x; - c = -this._sr * this.scale.y; - d = this._cr * this.scale.y; - - lt.a = this._cy * a + this._sy * c; - lt.b = this._cy * b + this._sy * d; - lt.c = this._nsx * a + this._cx * c; - lt.d = this._nsx * b + this._cx * d; - - lt.tx = this.position.x - (this.pivot.x * lt.a + this.pivot.y * lt.c); - lt.ty = this.position.y - (this.pivot.x * lt.b + this.pivot.y * lt.d); - - // concat the parent matrix with the objects transform. - wt.a = lt.a * pt.a + lt.b * pt.c; - wt.b = lt.a * pt.b + lt.b * pt.d; - wt.c = lt.c * pt.a + lt.d * pt.c; - wt.d = lt.c * pt.b + lt.d * pt.d; - wt.tx = lt.tx * pt.a + lt.ty * pt.c + pt.tx; - wt.ty = lt.tx * pt.b + lt.ty * pt.d + pt.ty; -}; - -Transform.prototype.updateChildTransform = function (childTransform) -{ - childTransform.updateTransform(this); - return childTransform; -}; - -Object.defineProperties(Transform.prototype, { - /** - * The rotation of the object in radians. - * - * @member {number} - */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } - } -}); - -module.exports = Transform; - -},{"../math":54,"./ObservablePoint":36}],38:[function(require,module,exports){ -var Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderTarget = require('../renderers/canvas/utils/CanvasRenderTarget'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(); - -/** - * The Graphics class contains methods used to draw primitive shapes such as lines, circles and - * rectangles to the display, and to color and fill them. - * - * @class - * @extends PIXI.Container - * @memberof PIXI - */ -function Graphics() -{ - Container.call(this); - - /** - * The alpha value used when filling the Graphics object. - * - * @member {number} - * @default 1 - */ - this.fillAlpha = 1; - - /** - * The width (thickness) of any lines drawn. - * - * @member {number} - * @default 0 - */ - this.lineWidth = 0; - - /** - * The color of any lines drawn. - * - * @member {string} - * @default 0 - */ - this.lineColor = 0; - - /** - * Graphics data - * - * @member {PIXI.GraphicsData[]} - * @private - */ - this.graphicsData = []; - - /** - * The tint applied to the graphic shape. This is a hex value. Apply a value of 0xFFFFFF to reset the tint. - * - * @member {number} - * @default 0xFFFFFF - */ - this.tint = 0xFFFFFF; - - /** - * The previous tint applied to the graphic shape. Used to compare to the current tint and check if theres change. - * - * @member {number} - * @private - * @default 0xFFFFFF - */ - this._prevTint = 0xFFFFFF; - - /** - * The blend mode to be applied to the graphic shape. Apply a value of `PIXI.BLEND_MODES.NORMAL` to reset the blend mode. - * - * @member {number} - * @default PIXI.BLEND_MODES.NORMAL; - * @see PIXI.BLEND_MODES - */ - this.blendMode = CONST.BLEND_MODES.NORMAL; - - /** - * Current path - * - * @member {PIXI.GraphicsData} - * @private - */ - this.currentPath = null; - - /** - * Array containing some WebGL-related properties used by the WebGL renderer. - * - * @member {object} - * @private - */ - // TODO - _webgl should use a prototype object, not a random undocumented object... - this._webGL = {}; - - /** - * Whether this shape is being used as a mask. - * - * @member {boolean} - */ - this.isMask = false; - - /** - * The bounds' padding used for bounds calculation. - * - * @member {number} - */ - this.boundsPadding = 0; - - /** - * A cache of the local bounds to prevent recalculation. - * - * @member {PIXI.Rectangle} - * @private - */ - this._localBounds = new math.Rectangle(0,0,1,1); - - /** - * Used to detect if the graphics object has changed. If this is set to true then the graphics - * object will be recalculated. - * - * @member {boolean} - * @private - */ - this.dirty = true; - - /** - * Used to detect if the WebGL graphics object has changed. If this is set to true then the - * graphics object will be recalculated. - * - * @member {boolean} - * @private - */ - this.glDirty = false; - - this.boundsDirty = true; - - /** - * Used to detect if the cached sprite object needs to be updated. - * - * @member {boolean} - * @private - */ - this.cachedSpriteDirty = false; - - - this._spriteRect = null; - this._fastRect = false; - - /** - * When cacheAsBitmap is set to true the graphics object will be rendered as if it was a sprite. - * This is useful if your graphics element does not change often, as it will speed up the rendering - * of the object in exchange for taking up texture memory. It is also useful if you need the graphics - * object to be anti-aliased, because it will be rendered using canvas. This is not recommended if - * you are constantly redrawing the graphics element. - * - * @name cacheAsBitmap - * @member {boolean} - * @memberof PIXI.Graphics# - * @default false - */ -} - -Graphics._SPRITE_TEXTURE = null; - -// constructor -Graphics.prototype = Object.create(Container.prototype); -Graphics.prototype.constructor = Graphics; -module.exports = Graphics; - -/** - * Creates a new Graphics object with the same values as this one. - * Note that the only the properties of the object are cloned, not its transform (position,scale,etc) - * - * @return {PIXI.Graphics} - */ -Graphics.prototype.clone = function () -{ - var clone = new Graphics(); - - clone.renderable = this.renderable; - clone.fillAlpha = this.fillAlpha; - clone.lineWidth = this.lineWidth; - clone.lineColor = this.lineColor; - clone.tint = this.tint; - clone.blendMode = this.blendMode; - clone.isMask = this.isMask; - clone.boundsPadding = this.boundsPadding; - clone.dirty = true; - clone.glDirty = true; - clone.cachedSpriteDirty = this.cachedSpriteDirty; - - // copy graphics data - for (var i = 0; i < this.graphicsData.length; ++i) - { - clone.graphicsData.push(this.graphicsData[i].clone()); - } - - clone.currentPath = clone.graphicsData[clone.graphicsData.length - 1]; - - clone.updateLocalBounds(); - - return clone; -}; - -/** - * Specifies the line style used for subsequent calls to Graphics methods such as the lineTo() method or the drawCircle() method. - * - * @param lineWidth {number} width of the line to draw, will update the objects stored style - * @param color {number} color of the line to draw, will update the objects stored style - * @param alpha {number} alpha of the line to draw, will update the objects stored style - * @return {PIXI.Graphics} - */ -Graphics.prototype.lineStyle = function (lineWidth, color, alpha) -{ - this.lineWidth = lineWidth || 0; - this.lineColor = color || 0; - this.lineAlpha = (alpha === undefined) ? 1 : alpha; - - if (this.currentPath) - { - if (this.currentPath.shape.points.length) - { - // halfway through a line? start a new one! - var shape = new math.Polygon(this.currentPath.shape.points.slice(-2)); - shape.closed = false; - this.drawShape(shape); - } - else - { - // otherwise its empty so lets just set the line properties - this.currentPath.lineWidth = this.lineWidth; - this.currentPath.lineColor = this.lineColor; - this.currentPath.lineAlpha = this.lineAlpha; - } - } - - return this; -}; - -/** - * Moves the current drawing position to x, y. - * - * @param x {number} the X coordinate to move to - * @param y {number} the Y coordinate to move to - * @return {PIXI.Graphics} - */ -Graphics.prototype.moveTo = function (x, y) -{ - var shape = new math.Polygon([x,y]); - shape.closed = false; - this.drawShape(shape); - - return this; -}; - -/** - * Draws a line using the current line style from the current drawing position to (x, y); - * The current drawing position is then set to (x, y). - * - * @param x {number} the X coordinate to draw to - * @param y {number} the Y coordinate to draw to - * @return {PIXI.Graphics} - */ -Graphics.prototype.lineTo = function (x, y) -{ - this.currentPath.shape.points.push(x, y); - this.dirty = true; - - return this; -}; - -/** - * Calculate the points for a quadratic bezier curve and then draws it. - * Based on: https://stackoverflow.com/questions/785097/how-do-i-implement-a-bezier-curve-in-c - * - * @param cpX {number} Control point x - * @param cpY {number} Control point y - * @param toX {number} Destination point x - * @param toY {number} Destination point y - * @return {PIXI.Graphics} - */ -Graphics.prototype.quadraticCurveTo = function (cpX, cpY, toX, toY) -{ - if (this.currentPath) - { - if (this.currentPath.shape.points.length === 0) - { - this.currentPath.shape.points = [0, 0]; - } - } - else - { - this.moveTo(0,0); - } - - - var xa, - ya, - n = 20, - points = this.currentPath.shape.points; - - if (points.length === 0) - { - this.moveTo(0, 0); - } - - var fromX = points[points.length-2]; - var fromY = points[points.length-1]; - - var j = 0; - for (var i = 1; i <= n; ++i) - { - j = i / n; - - xa = fromX + ( (cpX - fromX) * j ); - ya = fromY + ( (cpY - fromY) * j ); - - points.push( xa + ( ((cpX + ( (toX - cpX) * j )) - xa) * j ), - ya + ( ((cpY + ( (toY - cpY) * j )) - ya) * j ) ); - } - - this.dirty = this.boundsDirty = true; - - return this; -}; - -/** - * Calculate the points for a bezier curve and then draws it. - * - * @param cpX {number} Control point x - * @param cpY {number} Control point y - * @param cpX2 {number} Second Control point x - * @param cpY2 {number} Second Control point y - * @param toX {number} Destination point x - * @param toY {number} Destination point y - * @return {PIXI.Graphics} - */ -Graphics.prototype.bezierCurveTo = function (cpX, cpY, cpX2, cpY2, toX, toY) -{ - if (this.currentPath) - { - if (this.currentPath.shape.points.length === 0) - { - this.currentPath.shape.points = [0, 0]; - } - } - else - { - this.moveTo(0,0); - } - - var points = this.currentPath.shape.points; - - var fromX = points[points.length-2]; - var fromY = points[points.length-1]; - - points.length -= 2; - - bezierCurveTo(fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, points); - - this.dirty = this.boundsDirty = true; - - return this; -}; - -/** - * The arcTo() method creates an arc/curve between two tangents on the canvas. - * - * "borrowed" from https://code.google.com/p/fxcanvas/ - thanks google! - * - * @param x1 {number} The x-coordinate of the beginning of the arc - * @param y1 {number} The y-coordinate of the beginning of the arc - * @param x2 {number} The x-coordinate of the end of the arc - * @param y2 {number} The y-coordinate of the end of the arc - * @param radius {number} The radius of the arc - * @return {PIXI.Graphics} - */ -Graphics.prototype.arcTo = function (x1, y1, x2, y2, radius) -{ - if (this.currentPath) - { - if (this.currentPath.shape.points.length === 0) - { - this.currentPath.shape.points.push(x1, y1); - } - } - else - { - this.moveTo(x1, y1); - } - - var points = this.currentPath.shape.points, - fromX = points[points.length-2], - fromY = points[points.length-1], - a1 = fromY - y1, - b1 = fromX - x1, - a2 = y2 - y1, - b2 = x2 - x1, - mm = Math.abs(a1 * b2 - b1 * a2); - - if (mm < 1.0e-8 || radius === 0) - { - if (points[points.length-2] !== x1 || points[points.length-1] !== y1) - { - points.push(x1, y1); - } - } - else - { - var dd = a1 * a1 + b1 * b1, - cc = a2 * a2 + b2 * b2, - tt = a1 * a2 + b1 * b2, - k1 = radius * Math.sqrt(dd) / mm, - k2 = radius * Math.sqrt(cc) / mm, - j1 = k1 * tt / dd, - j2 = k2 * tt / cc, - cx = k1 * b2 + k2 * b1, - cy = k1 * a2 + k2 * a1, - px = b1 * (k2 + j1), - py = a1 * (k2 + j1), - qx = b2 * (k1 + j2), - qy = a2 * (k1 + j2), - startAngle = Math.atan2(py - cy, px - cx), - endAngle = Math.atan2(qy - cy, qx - cx); - - this.arc(cx + x1, cy + y1, radius, startAngle, endAngle, b1 * a2 > b2 * a1); - } - - this.dirty = this.boundsDirty = true; - - return this; -}; - -/** - * The arc method creates an arc/curve (used to create circles, or parts of circles). - * - * @param cx {number} The x-coordinate of the center of the circle - * @param cy {number} The y-coordinate of the center of the circle - * @param radius {number} The radius of the circle - * @param startAngle {number} The starting angle, in radians (0 is at the 3 o'clock position of the arc's circle) - * @param endAngle {number} The ending angle, in radians - * @param anticlockwise {boolean} Optional. Specifies whether the drawing should be counterclockwise or clockwise. False is default, and indicates clockwise, while true indicates counter-clockwise. - * @return {PIXI.Graphics} - */ -Graphics.prototype.arc = function(cx, cy, radius, startAngle, endAngle, anticlockwise) -{ - anticlockwise = anticlockwise || false; - - if (startAngle === endAngle) - { - return this; - } - - if( !anticlockwise && endAngle <= startAngle ) - { - endAngle += Math.PI * 2; - } - else if( anticlockwise && startAngle <= endAngle ) - { - startAngle += Math.PI * 2; - } - - var sweep = anticlockwise ? (startAngle - endAngle) * -1 : (endAngle - startAngle); - var segs = Math.ceil(Math.abs(sweep) / (Math.PI * 2)) * 40; - - if(sweep === 0) - { - return this; - } - - var startX = cx + Math.cos(startAngle) * radius; - var startY = cy + Math.sin(startAngle) * radius; - - if (this.currentPath) - { - this.currentPath.shape.points.push(startX, startY); - } - else - { - this.moveTo(startX, startY); - } - - var points = this.currentPath.shape.points; - - var theta = sweep/(segs*2); - var theta2 = theta*2; - - var cTheta = Math.cos(theta); - var sTheta = Math.sin(theta); - - var segMinus = segs - 1; - - var remainder = ( segMinus % 1 ) / segMinus; - - for(var i=0; i<=segMinus; i++) - { - var real = i + remainder * i; - - - var angle = ((theta) + startAngle + (theta2 * real)); - - var c = Math.cos(angle); - var s = -Math.sin(angle); - - points.push(( (cTheta * c) + (sTheta * s) ) * radius + cx, - ( (cTheta * -s) + (sTheta * c) ) * radius + cy); - } - - this.dirty = this.boundsDirty = true; - - return this; -}; - -/** - * Specifies a simple one-color fill that subsequent calls to other Graphics methods - * (such as lineTo() or drawCircle()) use when drawing. - * - * @param color {number} the color of the fill - * @param alpha {number} the alpha of the fill - * @return {PIXI.Graphics} - */ -Graphics.prototype.beginFill = function (color, alpha) -{ - this.filling = true; - this.fillColor = color || 0; - this.fillAlpha = (alpha === undefined) ? 1 : alpha; - - if (this.currentPath) - { - if (this.currentPath.shape.points.length <= 2) - { - this.currentPath.fill = this.filling; - this.currentPath.fillColor = this.fillColor; - this.currentPath.fillAlpha = this.fillAlpha; - } - } - return this; -}; - -/** - * Applies a fill to the lines and shapes that were added since the last call to the beginFill() method. - * - * @return {Graphics} - */ -Graphics.prototype.endFill = function () -{ - this.filling = false; - this.fillColor = null; - this.fillAlpha = 1; - - return this; -}; - -/** - * - * @param x {number} The X coord of the top-left of the rectangle - * @param y {number} The Y coord of the top-left of the rectangle - * @param width {number} The width of the rectangle - * @param height {number} The height of the rectangle - * @return {PIXI.Graphics} - */ -Graphics.prototype.drawRect = function ( x, y, width, height ) -{ - this.drawShape(new math.Rectangle(x,y, width, height)); - - return this; -}; - -/** - * - * @param x {number} The X coord of the top-left of the rectangle - * @param y {number} The Y coord of the top-left of the rectangle - * @param width {number} The width of the rectangle - * @param height {number} The height of the rectangle - * @param radius {number} Radius of the rectangle corners - * @return {PIXI.Graphics} - */ -Graphics.prototype.drawRoundedRect = function ( x, y, width, height, radius ) -{ - this.drawShape(new math.RoundedRectangle(x, y, width, height, radius)); - - return this; -}; - -/** - * Draws a circle. - * - * @param x {number} The X coordinate of the center of the circle - * @param y {number} The Y coordinate of the center of the circle - * @param radius {number} The radius of the circle - * @return {PIXI.Graphics} - */ -Graphics.prototype.drawCircle = function (x, y, radius) -{ - this.drawShape(new math.Circle(x,y, radius)); - - return this; -}; - -/** - * Draws an ellipse. - * - * @param x {number} The X coordinate of the center of the ellipse - * @param y {number} The Y coordinate of the center of the ellipse - * @param width {number} The half width of the ellipse - * @param height {number} The half height of the ellipse - * @return {PIXI.Graphics} - */ -Graphics.prototype.drawEllipse = function (x, y, width, height) -{ - this.drawShape(new math.Ellipse(x, y, width, height)); - - return this; -}; - -/** - * Draws a polygon using the given path. - * - * @param path {number[]|PIXI.Point[]} The path data used to construct the polygon. - * @return {PIXI.Graphics} - */ -Graphics.prototype.drawPolygon = function (path) -{ - // prevents an argument assignment deopt - // see section 3.1: https://github.com/petkaantonov/bluebird/wiki/Optimization-killers#3-managing-arguments - var points = path; - - var closed = true; - - if (points instanceof math.Polygon) - { - closed = points.closed; - points = points.points; - } - - if (!Array.isArray(points)) - { - // prevents an argument leak deopt - // see section 3.2: https://github.com/petkaantonov/bluebird/wiki/Optimization-killers#3-managing-arguments - points = new Array(arguments.length); - - for (var i = 0; i < points.length; ++i) - { - points[i] = arguments[i]; - } - } - - var shape = new math.Polygon(points); - shape.closed = closed; - - this.drawShape(shape); - - return this; -}; - -/** - * Clears the graphics that were drawn to this Graphics object, and resets fill and line style settings. - * - * @return {PIXI.Graphics} - */ -Graphics.prototype.clear = function () -{ - this.lineWidth = 0; - this.filling = false; - - this.dirty = true; - this.clearDirty = true; - this.graphicsData = []; - - return this; -}; - - -/** - * Renders the object using the WebGL renderer - * - * @param renderer {PIXI.WebGLRenderer} - * @private - */ -Graphics.prototype._renderWebGL = function (renderer) -{ - // if the sprite is not visible or the alpha is 0 then no need to render this element - - if (this.glDirty) - { - this.dirty = true; - this.glDirty = false; - this._fastRect = this.graphicsData.length === 1 && this.graphicsData[0].shape.type === CONST.SHAPES.RECT && !this.graphicsData[0].lineWidth; - } - - //TODO this check can be moved to dirty? - if(this._fastRect) - { - this._renderSpriteRect(renderer); - } - else - { - renderer.setObjectRenderer(renderer.plugins.graphics); - renderer.plugins.graphics.render(this); - } - -}; - -Graphics.prototype._renderSpriteRect = function (renderer) -{ - var rect = this.graphicsData[0].shape; - if(!this._spriteRect) - { - if(!Graphics._SPRITE_TEXTURE) - { - Graphics._SPRITE_TEXTURE = RenderTexture.create(10, 10); - - var currentRenderTarget = renderer._activeRenderTarget; - renderer.bindRenderTexture(Graphics._SPRITE_TEXTURE); - renderer.clear([1,1,1,1]); - renderer.bindRenderTarget(currentRenderTarget); - } - - this._spriteRect = new Sprite(Graphics._SPRITE_TEXTURE); - this._spriteRect.tint = this.graphicsData[0].fillColor; - } - - this._spriteRect.worldAlpha = this.worldAlpha; - - Graphics._SPRITE_TEXTURE.crop.width = rect.width; - Graphics._SPRITE_TEXTURE.crop.height = rect.height; - - this._spriteRect.transform.worldTransform = this.transform.worldTransform; - - this._spriteRect.anchor.x = -rect.x / rect.width; - this._spriteRect.anchor.y = -rect.y / rect.height; - - this._spriteRect._renderWebGL(renderer); -}; - -/** - * Renders the object using the Canvas renderer - * - * @param renderer {PIXI.CanvasRenderer} - * @private - */ -Graphics.prototype._renderCanvas = function (renderer) -{ - if (this.isMask === true) - { - return; - } - - renderer.plugins.graphics.render(this); -}; - -/** - * Retrieves the bounds of the graphic shape as a rectangle object - * - * @param [matrix] {PIXI.Matrix} The world transform matrix to use, defaults to this - * object's worldTransform. - * @return {PIXI.Rectangle} the rectangular bounding area - */ -Graphics.prototype.getBounds = function (matrix) -{ - if(!this._currentBounds) - { - - // return an empty object if the item is a mask! - if (!this.renderable) - { - return math.Rectangle.EMPTY; - } - - if (this.boundsDirty) - { - this.updateLocalBounds(); - - this.glDirty = true; - this.cachedSpriteDirty = true; - this.boundsDirty = false; - } - - var bounds = this._localBounds; - - var w0 = bounds.x; - var w1 = bounds.width + bounds.x; - - var h0 = bounds.y; - var h1 = bounds.height + bounds.y; - - var worldTransform = matrix || this.worldTransform; - - var a = worldTransform.a; - var b = worldTransform.b; - var c = worldTransform.c; - var d = worldTransform.d; - var tx = worldTransform.tx; - var ty = worldTransform.ty; - - var x1 = a * w1 + c * h1 + tx; - var y1 = d * h1 + b * w1 + ty; - - var x2 = a * w0 + c * h1 + tx; - var y2 = d * h1 + b * w0 + ty; - - var x3 = a * w0 + c * h0 + tx; - var y3 = d * h0 + b * w0 + ty; - - var x4 = a * w1 + c * h0 + tx; - var y4 = d * h0 + b * w1 + ty; - - var maxX = x1; - var maxY = y1; - - var minX = x1; - var minY = y1; - - minX = x2 < minX ? x2 : minX; - minX = x3 < minX ? x3 : minX; - minX = x4 < minX ? x4 : minX; - - minY = y2 < minY ? y2 : minY; - minY = y3 < minY ? y3 : minY; - minY = y4 < minY ? y4 : minY; - - maxX = x2 > maxX ? x2 : maxX; - maxX = x3 > maxX ? x3 : maxX; - maxX = x4 > maxX ? x4 : maxX; - - maxY = y2 > maxY ? y2 : maxY; - maxY = y3 > maxY ? y3 : maxY; - maxY = y4 > maxY ? y4 : maxY; - - this._bounds.x = minX; - this._bounds.width = maxX - minX; - - this._bounds.y = minY; - this._bounds.height = maxY - minY; - - this._currentBounds = this._bounds; - } - - return this._currentBounds; -}; - -/** -* Tests if a point is inside this graphics object -* -* @param point {PIXI.Point} the point to test -* @return {boolean} the result of the test -*/ -Graphics.prototype.containsPoint = function( point ) -{ - this.worldTransform.applyInverse(point, tempPoint); - - var graphicsData = this.graphicsData; - - for (var i = 0; i < graphicsData.length; i++) - { - var data = graphicsData[i]; - - if (!data.fill) - { - continue; - } - - // only deal with fills.. - if (data.shape) - { - if ( data.shape.contains( tempPoint.x, tempPoint.y ) ) - { - return true; - } - } - } - - return false; -}; - -/** - * Update the bounds of the object - * - */ -Graphics.prototype.updateLocalBounds = function () -{ - var minX = Infinity; - var maxX = -Infinity; - - var minY = Infinity; - var maxY = -Infinity; - - if (this.graphicsData.length) - { - var shape, points, x, y, w, h; - - for (var i = 0; i < this.graphicsData.length; i++) - { - var data = this.graphicsData[i]; - var type = data.type; - var lineWidth = data.lineWidth; - shape = data.shape; - - if (type === CONST.SHAPES.RECT || type === CONST.SHAPES.RREC) - { - x = shape.x - lineWidth/2; - y = shape.y - lineWidth/2; - w = shape.width + lineWidth; - h = shape.height + lineWidth; - - minX = x < minX ? x : minX; - maxX = x + w > maxX ? x + w : maxX; - - minY = y < minY ? y : minY; - maxY = y + h > maxY ? y + h : maxY; - } - else if (type === CONST.SHAPES.CIRC) - { - x = shape.x; - y = shape.y; - w = shape.radius + lineWidth/2; - h = shape.radius + lineWidth/2; - - minX = x - w < minX ? x - w : minX; - maxX = x + w > maxX ? x + w : maxX; - - minY = y - h < minY ? y - h : minY; - maxY = y + h > maxY ? y + h : maxY; - } - else if (type === CONST.SHAPES.ELIP) - { - x = shape.x; - y = shape.y; - w = shape.width + lineWidth/2; - h = shape.height + lineWidth/2; - - minX = x - w < minX ? x - w : minX; - maxX = x + w > maxX ? x + w : maxX; - - minY = y - h < minY ? y - h : minY; - maxY = y + h > maxY ? y + h : maxY; - } - else - { - // POLY - points = shape.points; - - for (var j = 0; j < points.length; j += 2) - { - x = points[j]; - y = points[j+1]; - - minX = x-lineWidth < minX ? x-lineWidth : minX; - maxX = x+lineWidth > maxX ? x+lineWidth : maxX; - - minY = y-lineWidth < minY ? y-lineWidth : minY; - maxY = y+lineWidth > maxY ? y+lineWidth : maxY; - } - } - } - } - else - { - minX = 0; - maxX = 0; - minY = 0; - maxY = 0; - } - - var padding = this.boundsPadding; - - this._localBounds.x = minX - padding; - this._localBounds.width = (maxX - minX) + padding * 2; - - this._localBounds.y = minY - padding; - this._localBounds.height = (maxY - minY) + padding * 2; -}; - - -/** - * Draws the given shape to this Graphics object. Can be any of Circle, Rectangle, Ellipse, Line or Polygon. - * - * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Line|PIXI.Polygon} The shape object to draw. - * @return {PIXI.GraphicsData} The generated GraphicsData object. - */ -Graphics.prototype.drawShape = function (shape) -{ - if (this.currentPath) - { - // check current path! - if (this.currentPath.shape.points.length <= 2) - { - this.graphicsData.pop(); - } - } - - this.currentPath = null; - - var data = new GraphicsData(this.lineWidth, this.lineColor, this.lineAlpha, this.fillColor, this.fillAlpha, this.filling, shape); - - this.graphicsData.push(data); - - if (data.type === CONST.SHAPES.POLY) - { - data.shape.closed = data.shape.closed || this.filling; - this.currentPath = data; - } - - this.dirty = this.boundsDirty = true; - - return data; -}; - -Graphics.prototype.generateCanvasTexture = function(scaleMode, resolution) -{ - resolution = resolution || 1; - - var bounds = this.getLocalBounds(); - - var canvasBuffer = new RenderTexture.create(bounds.width * resolution, bounds.height * resolution); - - if(!canvasRenderer) - { - canvasRenderer = new CanvasRenderer(); - } - - tempMatrix.tx = -bounds.x; - tempMatrix.ty = -bounds.y; - - canvasRenderer.render(this, canvasBuffer, false, tempMatrix); - - var texture = Texture.fromCanvas(canvasBuffer.baseTexture._canvasRenderTarget.canvas, scaleMode); - texture.baseTexture.resolution = resolution; - - return texture; -} - -/** - * Destroys the Graphics object. - */ -Graphics.prototype.destroy = function () -{ - Container.prototype.destroy.apply(this, arguments); - - // destroy each of the GraphicsData objects - for (var i = 0; i < this.graphicsData.length; ++i) { - this.graphicsData[i].destroy(); - } - - // for each webgl data entry, destroy the WebGLGraphicsData - for (var id in this._webgl) { - for (var j = 0; j < this._webgl[id].data.length; ++j) { - this._webgl[id].data[j].destroy(); - } - } - - this.graphicsData = null; - - this.currentPath = null; - this._webgl = null; - this._localBounds = null; -}; - -},{"../const":33,"../display/Container":34,"../math":54,"../renderers/canvas/CanvasRenderer":61,"../renderers/canvas/utils/CanvasRenderTarget":63,"../sprites/Sprite":83,"../textures/RenderTexture":92,"../textures/Texture":93,"./GraphicsData":39,"./utils/bezierCurveTo":41}],39:[function(require,module,exports){ -/** - * A GraphicsData object. - * - * @class - * @memberof PIXI - * @param lineWidth {number} the width of the line to draw - * @param lineColor {number} the color of the line to draw - * @param lineAlpha {number} the alpha of the line to draw - * @param fillColor {number} the color of the fill - * @param fillAlpha {number} the alpha of the fill - * @param fill {boolean} whether or not the shape is filled with a colour - * @param shape {Circle|Rectangle|Ellipse|Line|Polygon} The shape object to draw. - */ -function GraphicsData(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) -{ - /* - * @member {number} the width of the line to draw - */ - this.lineWidth = lineWidth; - - /* - * @member {number} the color of the line to draw - */ - this.lineColor = lineColor; - /* - * @member {number} the alpha of the line to draw - */ - this.lineAlpha = lineAlpha; - /* - * @member {number} cached tint of the line to draw - */ - this._lineTint = lineColor; - - /* - * @member {number} the color of the fill - */ - this.fillColor = fillColor; - - /* - * @member {number} the alpha of the fill - */ - this.fillAlpha = fillAlpha; - - /* - * @member {number} cached tint of the fill - */ - this._fillTint = fillColor; - - /* - * @member {boolean} whether or not the shape is filled with a colour - */ - this.fill = fill; - - /* - * @member {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Line|PIXI.Polygon} The shape object to draw. - */ - this.shape = shape; - - /* - * @member {number} The type of the shape, see the Const.Shapes file for all the existing types, - */ - this.type = shape.type; -} - -GraphicsData.prototype.constructor = GraphicsData; -module.exports = GraphicsData; - -/** - * Creates a new GraphicsData object with the same values as this one. - * - * @return {PIXI.GraphicsData} - */ -GraphicsData.prototype.clone = function () -{ - return new GraphicsData( - this.lineWidth, - this.lineColor, - this.lineAlpha, - this.fillColor, - this.fillAlpha, - this.fill, - this.shape - ); -}; - -/** - * Destroys the Graphics data. - */ -GraphicsData.prototype.destroy = function () { - this.shape = null; -}; - -},{}],40:[function(require,module,exports){ -var CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); - -/** - * @author Mat Groves - * - * Big thanks to the very clever Matt DesLauriers https://github.com/mattdesl/ - * for creating the original pixi version! - * Also a thanks to https://github.com/bchevalier for tweaking the tint and alpha so that they now share 4 bytes on the vertex buffer - * - * Heavily inspired by LibGDX's CanvasGraphicsRenderer: - * https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/graphics/g2d/CanvasGraphicsRenderer.java - */ - -/** - * Renderer dedicated to drawing and batching graphics objects. - * - * @class - * @private - * @memberof PIXI - * @extends PIXI.ObjectRenderer - * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. - */ -function CanvasGraphicsRenderer(renderer) -{ - this.renderer = renderer; -} - - -CanvasGraphicsRenderer.prototype.constructor = CanvasGraphicsRenderer; -module.exports = CanvasGraphicsRenderer; - -CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); - -/* - * Renders a Graphics object to a canvas. - * - * @param graphics {PIXI.Graphics} the actual graphics object to render - * @param context {CanvasRenderingContext2D} the 2d drawing method of the canvas - */ -CanvasGraphicsRenderer.prototype.render = function (graphics) -{ - var renderer = this.renderer; - var context = renderer.context; - var worldAlpha = graphics.worldAlpha; - var transform = graphics.transform.worldTransform; - var resolution = renderer.resolution; - - // if the tint has changed, set the graphics object to dirty. - if (this._prevTint !== this.tint) { - this.dirty = true; - } - - context.setTransform( - transform.a * resolution, - transform.b * resolution, - transform.c * resolution, - transform.d * resolution, - transform.tx * resolution, - transform.ty * resolution - ); - - - if (graphics.dirty) - { - this.updateGraphicsTint(graphics); - graphics.dirty = false; - } - - renderer.setBlendMode(graphics.blendMode); - - for (var i = 0; i < graphics.graphicsData.length; i++) - { - var data = graphics.graphicsData[i]; - var shape = data.shape; - - var fillColor = data._fillTint; - var lineColor = data._lineTint; - - context.lineWidth = data.lineWidth; - - if (data.type === CONST.SHAPES.POLY) - { - context.beginPath(); - - var points = shape.points; - - context.moveTo(points[0], points[1]); - - for (var j=1; j < points.length/2; j++) - { - context.lineTo(points[j * 2], points[j * 2 + 1]); - } - - if (shape.closed) - { - context.lineTo(points[0], points[1]); - } - - // if the first and last point are the same close the path - much neater :) - if (points[0] === points[points.length-2] && points[1] === points[points.length-1]) - { - context.closePath(); - } - - if (data.fill) - { - context.globalAlpha = data.fillAlpha * worldAlpha; - context.fillStyle = '#' + ('00000' + ( fillColor | 0).toString(16)).substr(-6); - context.fill(); - } - if (data.lineWidth) - { - context.globalAlpha = data.lineAlpha * worldAlpha; - context.strokeStyle = '#' + ('00000' + ( lineColor | 0).toString(16)).substr(-6); - context.stroke(); - } - } - else if (data.type === CONST.SHAPES.RECT) - { - - if (data.fillColor || data.fillColor === 0) - { - context.globalAlpha = data.fillAlpha * worldAlpha; - context.fillStyle = '#' + ('00000' + ( fillColor | 0).toString(16)).substr(-6); - context.fillRect(shape.x, shape.y, shape.width, shape.height); - - } - if (data.lineWidth) - { - context.globalAlpha = data.lineAlpha * worldAlpha; - context.strokeStyle = '#' + ('00000' + ( lineColor | 0).toString(16)).substr(-6); - context.strokeRect(shape.x, shape.y, shape.width, shape.height); - } - } - else if (data.type === CONST.SHAPES.CIRC) - { - // TODO - need to be Undefined! - context.beginPath(); - context.arc(shape.x, shape.y, shape.radius,0,2*Math.PI); - context.closePath(); - - if (data.fill) - { - context.globalAlpha = data.fillAlpha * worldAlpha; - context.fillStyle = '#' + ('00000' + ( fillColor | 0).toString(16)).substr(-6); - context.fill(); - } - if (data.lineWidth) - { - context.globalAlpha = data.lineAlpha * worldAlpha; - context.strokeStyle = '#' + ('00000' + ( lineColor | 0).toString(16)).substr(-6); - context.stroke(); - } - } - else if (data.type === CONST.SHAPES.ELIP) - { - // ellipse code taken from: http://stackoverflow.com/questions/2172798/how-to-draw-an-oval-in-html5-canvas - - var w = shape.width * 2; - var h = shape.height * 2; - - var x = shape.x - w/2; - var y = shape.y - h/2; - - context.beginPath(); - - var kappa = 0.5522848, - ox = (w / 2) * kappa, // control point offset horizontal - oy = (h / 2) * kappa, // control point offset vertical - xe = x + w, // x-end - ye = y + h, // y-end - xm = x + w / 2, // x-middle - ym = y + h / 2; // y-middle - - context.moveTo(x, ym); - context.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y); - context.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym); - context.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye); - context.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym); - - context.closePath(); - - if (data.fill) - { - context.globalAlpha = data.fillAlpha * worldAlpha; - context.fillStyle = '#' + ('00000' + ( fillColor | 0).toString(16)).substr(-6); - context.fill(); - } - if (data.lineWidth) - { - context.globalAlpha = data.lineAlpha * worldAlpha; - context.strokeStyle = '#' + ('00000' + ( lineColor | 0).toString(16)).substr(-6); - context.stroke(); - } - } - else if (data.type === CONST.SHAPES.RREC) - { - var rx = shape.x; - var ry = shape.y; - var width = shape.width; - var height = shape.height; - var radius = shape.radius; - - var maxRadius = Math.min(width, height) / 2 | 0; - radius = radius > maxRadius ? maxRadius : radius; - - context.beginPath(); - context.moveTo(rx, ry + radius); - context.lineTo(rx, ry + height - radius); - context.quadraticCurveTo(rx, ry + height, rx + radius, ry + height); - context.lineTo(rx + width - radius, ry + height); - context.quadraticCurveTo(rx + width, ry + height, rx + width, ry + height - radius); - context.lineTo(rx + width, ry + radius); - context.quadraticCurveTo(rx + width, ry, rx + width - radius, ry); - context.lineTo(rx + radius, ry); - context.quadraticCurveTo(rx, ry, rx, ry + radius); - context.closePath(); - - if (data.fillColor || data.fillColor === 0) - { - context.globalAlpha = data.fillAlpha * worldAlpha; - context.fillStyle = '#' + ('00000' + ( fillColor | 0).toString(16)).substr(-6); - context.fill(); - - } - if (data.lineWidth) - { - context.globalAlpha = data.lineAlpha * worldAlpha; - context.strokeStyle = '#' + ('00000' + ( lineColor | 0).toString(16)).substr(-6); - context.stroke(); - } - } - } -}; - -/* - * Updates the tint of a graphics object - * - * @private - * @param graphics {PIXI.Graphics} the graphics that will have its tint updated - * - */ -CanvasGraphicsRenderer.prototype.updateGraphicsTint = function (graphics) -{ - if (graphics.tint === 0xFFFFFF && graphics._prevTint === graphics.tint) - { - return; - } - - graphics._prevTint = graphics.tint; - - var tintR = (graphics.tint >> 16 & 0xFF) / 255; - var tintG = (graphics.tint >> 8 & 0xFF) / 255; - var tintB = (graphics.tint & 0xFF)/ 255; - - for (var i = 0; i < graphics.graphicsData.length; i++) - { - var data = graphics.graphicsData[i]; - - var fillColor = data.fillColor | 0; - var lineColor = data.lineColor | 0; - - // super inline cos im an optimization NAZI :) - data._fillTint = (((fillColor >> 16 & 0xFF) / 255 * tintR*255 << 16) + ((fillColor >> 8 & 0xFF) / 255 * tintG*255 << 8) + (fillColor & 0xFF) / 255 * tintB*255); - data._lineTint = (((lineColor >> 16 & 0xFF) / 255 * tintR*255 << 16) + ((lineColor >> 8 & 0xFF) / 255 * tintG*255 << 8) + (lineColor & 0xFF) / 255 * tintB*255); - } -}; - -/* - * destroy graphics object - * - */ -CanvasGraphicsRenderer.prototype.destroy = function () -{ - this.renderer = null; -}; - -},{"../../const":33,"../../renderers/canvas/CanvasRenderer":61}],41:[function(require,module,exports){ - -/** - * Calculate the points for a bezier curve and then draws it. - * - * @param cpX {number} Control point x - * @param cpY {number} Control point y - * @param cpX2 {number} Second Control point x - * @param cpY2 {number} Second Control point y - * @param toX {number} Destination point x - * @param toY {number} Destination point y - * @return {PIXI.Graphics} - */ -var bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) -{ - path = path || []; - - var n = 20, - dt, - dt2, - dt3, - t2, - t3; - - path.push(fromX, fromY); - - var j = 0; - - for (var i = 1; i <= n; ++i) - { - j = i / n; - - dt = (1 - j); - dt2 = dt * dt; - dt3 = dt2 * dt; - - t2 = j * j; - t3 = t2 * j; - - path.push( dt3 * fromX + 3 * dt2 * j * cpX + 3 * dt * t2 * cpX2 + t3 * toX, - dt3 * fromY + 3 * dt2 * j * cpY + 3 * dt * t2 * cpY2 + t3 * toY); - } - - return path; -}; - -module.exports = bezierCurveTo; - -},{}],42:[function(require,module,exports){ -var utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), - - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - - -/** - * Renders the graphics object. - * - * @class - * @private - * @memberof PIXI - * @extends PIXI.ObjectRenderer - * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. - */ -function GraphicsRenderer(renderer) -{ - ObjectRenderer.call(this, renderer); - - this.graphicsDataPool = []; - - this.primitiveShader = null; - - this.gl = renderer.gl; - - // easy access! - this.CONTEXT_UID = 0; -} - -GraphicsRenderer.prototype = Object.create(ObjectRenderer.prototype); -GraphicsRenderer.prototype.constructor = GraphicsRenderer; -module.exports = GraphicsRenderer; - -WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); - -/** - * Called when there is a WebGL context change - * - * @private - * - */ -GraphicsRenderer.prototype.onContextChange = function() -{ - this.gl = this.renderer.gl; - this.CONTEXT_UID = this.renderer.CONTEXT_UID; - this.primitiveShader = new PrimitiveShader(this.gl); -}; - -/** - * Destroys this renderer. - * - */ -GraphicsRenderer.prototype.destroy = function () -{ - ObjectRenderer.prototype.destroy.call(this); - - for (var i = 0; i < this.graphicsDataPool.length; ++i) { - this.graphicsDataPool[i].destroy(); - } - - this.graphicsDataPool = null; -}; - -/** - * Renders a graphics object. - * - * @param graphics {PIXI.Graphics} The graphics object to render. - */ -GraphicsRenderer.prototype.render = function(graphics) -{ - var renderer = this.renderer; - var gl = renderer.gl; - - var webGLData; - - if (graphics.dirty || !graphics._webGL[this.CONTEXT_UID]) - { - this.updateGraphics(graphics); - } - - var webGL = graphics._webGL[this.CONTEXT_UID]; - - // This could be speeded up for sure! - var shader = this.primitiveShader; - renderer.bindShader(shader); - renderer.state.setBlendMode( graphics.blendMode ); - - for (var i = 0, n = webGL.data.length; i < n; i++) - { - webGLData = webGL.data[i]; - var shaderTemp = webGLData.shader; - - renderer.bindShader(shaderTemp); - shaderTemp.uniforms.translationMatrix = graphics.transform.worldTransform.toArray(true); - shaderTemp.uniforms.tint = utils.hex2rgb(graphics.tint); - shaderTemp.uniforms.alpha = graphics.worldAlpha; - - webGLData.vao.bind() - .draw(gl.TRIANGLE_STRIP, webGLData.indices.length) - .unbind(); - } -}; - -/** - * Updates the graphics object - * - * @private - * @param graphics {PIXI.Graphics} The graphics object to update - */ -GraphicsRenderer.prototype.updateGraphics = function(graphics) -{ - var gl = this.renderer.gl; - - // get the contexts graphics object - var webGL = graphics._webGL[this.CONTEXT_UID]; - - // if the graphics object does not exist in the webGL context time to create it! - if (!webGL) - { - webGL = graphics._webGL[this.CONTEXT_UID] = {lastIndex:0, data:[], gl:gl}; - - } - - // flag the graphics as not dirty as we are about to update it... - graphics.dirty = false; - - var i; - - // if the user cleared the graphics object we will need to clear every object - if (graphics.clearDirty) - { - graphics.clearDirty = false; - - // loop through and return all the webGLDatas to the object pool so than can be reused later on - for (i = 0; i < webGL.data.length; i++) - { - var graphicsData = webGL.data[i]; - this.graphicsDataPool.push( graphicsData ); - } - - // clear the array and reset the index.. - webGL.data = []; - webGL.lastIndex = 0; - } - - var webGLData; - - // loop through the graphics datas and construct each one.. - // if the object is a complex fill then the new stencil buffer technique will be used - // other wise graphics objects will be pushed into a batch.. - for (i = webGL.lastIndex; i < graphics.graphicsData.length; i++) - { - var data = graphics.graphicsData[i]; - - //TODO - this can be simplified - webGLData = this.getWebGLData(webGL, 0); - - if (data.type === CONST.SHAPES.POLY) - { - buildPoly(data, webGLData); - } - if (data.type === CONST.SHAPES.RECT) - { - buildRectangle(data, webGLData); - } - else if (data.type === CONST.SHAPES.CIRC || data.type === CONST.SHAPES.ELIP) - { - buildCircle(data, webGLData); - } - else if (data.type === CONST.SHAPES.RREC) - { - buildRoundedRectangle(data, webGLData); - } - - webGL.lastIndex++; - } - - // upload all the dirty data... - for (i = 0; i < webGL.data.length; i++) - { - webGLData = webGL.data[i]; - - if (webGLData.dirty) - { - webGLData.upload(); - } - } -}; - -/** - * - * @private - * @param webGL {WebGLRenderingContext} the current WebGL drawing context - * @param type {number} TODO @Alvin - */ -GraphicsRenderer.prototype.getWebGLData = function (webGL, type) -{ - var webGLData = webGL.data[webGL.data.length-1]; - - if (!webGLData || webGLData.points.length > 320000) - { - webGLData = this.graphicsDataPool.pop() || new WebGLGraphicsData(this.renderer.gl, this.primitiveShader, this.renderer.state.attribsState); - webGLData.reset(type); - webGL.data.push(webGLData); - } - - webGLData.dirty = true; - - return webGLData; -}; - -},{"../../const":33,"../../renderers/webgl/WebGLRenderer":68,"../../renderers/webgl/utils/ObjectRenderer":78,"../../utils":100,"./WebGLGraphicsData":43,"./shaders/PrimitiveShader":44,"./utils/buildCircle":45,"./utils/buildPoly":47,"./utils/buildRectangle":48,"./utils/buildRoundedRectangle":49}],43:[function(require,module,exports){ -var glCore = require('pixi-gl-core'); - - -/** - * An object containing WebGL specific properties to be used by the WebGL renderer - * - * @class - * @memberof PIXI - * @param gl {WebGLRenderingContext} the current WebGL drawing context - * @private - */ -function WebGLGraphicsData(gl, shader, attribsState) -{ - - /** - * The current WebGL drawing context - * - * @member {WebGLRenderingContext} - */ - this.gl = gl; - - //TODO does this need to be split before uploding?? - /** - * An array of color components (r,g,b) - * @member {number[]} - */ - this.color = [0,0,0]; // color split! - - /** - * An array of points to draw - * @member {PIXI.Point[]} - */ - this.points = []; - - /** - * The indices of the vertices - * @member {number[]} - */ - this.indices = []; - /** - * The main buffer - * @member {WebGLBuffer} - */ - this.buffer = glCore.GLBuffer.createVertexBuffer(gl); - - /** - * The index buffer - * @member {WebGLBuffer} - */ - this.indexBuffer = glCore.GLBuffer.createIndexBuffer(gl); - - /** - * Whether this graphics is dirty or not - * @member {boolean} - */ - this.dirty = true; - - this.glPoints = null; - this.glIndices = null; - - /** - * - * @member {PIXI.Shader} - */ - this.shader = shader; - - this.vao = new glCore.VertexArrayObject(gl, attribsState) - .addIndex(this.indexBuffer) - .addAttribute(this.buffer, shader.attributes.aVertexPosition, gl.FLOAT, false, 4 * 6, 0) - .addAttribute(this.buffer, shader.attributes.aColor, gl.FLOAT, false, 4 * 6, 2 * 4); - - -} - -WebGLGraphicsData.prototype.constructor = WebGLGraphicsData; -module.exports = WebGLGraphicsData; - -/** - * Resets the vertices and the indices - */ -WebGLGraphicsData.prototype.reset = function () -{ - this.points.length = 0; - this.indices.length = 0; -}; - -/** - * Binds the buffers and uploads the data - */ -WebGLGraphicsData.prototype.upload = function () -{ - this.glPoints = new Float32Array(this.points); - this.buffer.upload( this.glPoints ); - - this.glIndices = new Uint16Array(this.indices); - this.indexBuffer.upload( this.glIndices ); - - this.dirty = false; -}; - - - -/** - * Empties all the data - */ -WebGLGraphicsData.prototype.destroy = function () -{ - this.color = null; - this.points = null; - this.indices = null; - - this.vao.destroy(); - this.buffer.destroy(); - this.indexBuffer.destroy(); - - this.gl = null; - - this.buffer = null; - this.indexBuffer = null; - - this.glPoints = null; - this.glIndices = null; -}; - -},{"pixi-gl-core":15}],44:[function(require,module,exports){ -var Shader = require('pixi-gl-core').GLShader; - -/** - * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. - * - * @class - * @memberof PIXI - * @extends PIXI.Shader - * @param shaderManager {ShaderManager} The webgl shader manager this shader works for. - */ -function PrimitiveShader(gl) -{ - Shader.call(this, - gl, - // vertex shader - [ - 'attribute vec2 aVertexPosition;', - 'attribute vec4 aColor;', - - 'uniform mat3 translationMatrix;', - 'uniform mat3 projectionMatrix;', - - 'uniform float alpha;', - 'uniform vec3 tint;', - - 'varying vec4 vColor;', - - 'void main(void){', - ' gl_Position = vec4((projectionMatrix * translationMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);', - ' vColor = aColor * vec4(tint * alpha, alpha);', - '}' - ].join('\n'), - // fragment shader - [ - 'precision mediump float;', - - 'varying vec4 vColor;', - - 'void main(void){', - ' gl_FragColor = vColor;', - '}' - ].join('\n') - ); -} - -PrimitiveShader.prototype = Object.create(Shader.prototype); -PrimitiveShader.prototype.constructor = PrimitiveShader; - -module.exports = PrimitiveShader; - -},{"pixi-gl-core":15}],45:[function(require,module,exports){ -var buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); - -/** - * Builds a circle to draw - * - * @private - * @param graphicsData {PIXI.Graphics} The graphics object to draw - * @param webGLData {object} an object containing all the webGL-specific information to create this shape - */ -var buildCircle = function (graphicsData, webGLData) -{ - // need to convert points to a nice regular data - var circleData = graphicsData.shape; - var x = circleData.x; - var y = circleData.y; - var width; - var height; - - // TODO - bit hacky?? - if (graphicsData.type === CONST.SHAPES.CIRC) - { - width = circleData.radius; - height = circleData.radius; - } - else - { - width = circleData.width; - height = circleData.height; - } - - var totalSegs = Math.floor(30 * Math.sqrt(circleData.radius)) || Math.floor(15 * Math.sqrt(circleData.width + circleData.height)); - var seg = (Math.PI * 2) / totalSegs ; - - var i = 0; - - if (graphicsData.fill) - { - var color = utils.hex2rgb(graphicsData.fillColor); - var alpha = graphicsData.fillAlpha; - - var r = color[0] * alpha; - var g = color[1] * alpha; - var b = color[2] * alpha; - - var verts = webGLData.points; - var indices = webGLData.indices; - - var vecPos = verts.length/6; - - indices.push(vecPos); - - for (i = 0; i < totalSegs + 1 ; i++) - { - verts.push(x,y, r, g, b, alpha); - - verts.push(x + Math.sin(seg * i) * width, - y + Math.cos(seg * i) * height, - r, g, b, alpha); - - indices.push(vecPos++, vecPos++); - } - - indices.push(vecPos-1); - } - - if (graphicsData.lineWidth) - { - var tempPoints = graphicsData.points; - - graphicsData.points = []; - - for (i = 0; i < totalSegs + 1; i++) - { - graphicsData.points.push(x + Math.sin(seg * i) * width, - y + Math.cos(seg * i) * height); - } - - buildLine(graphicsData, webGLData); - - graphicsData.points = tempPoints; - } -}; - - -module.exports = buildCircle; - -},{"../../../const":33,"../../../utils":100,"./buildLine":46}],46:[function(require,module,exports){ -var math = require('../../../math'), - utils = require('../../../utils'); - -/** - * Builds a line to draw - * - * @private - * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties - * @param webGLData {object} an object containing all the webGL-specific information to create this shape - */ -var buildLine = function (graphicsData, webGLData) -{ - // TODO OPTIMISE! - var i = 0; - var points = graphicsData.points; - - if (points.length === 0) - { - return; - } - // if the line width is an odd number add 0.5 to align to a whole pixel - // commenting this out fixes #711 and #1620 - // if (graphicsData.lineWidth%2) - // { - // for (i = 0; i < points.length; i++) - // { - // points[i] += 0.5; - // } - // } - - // get first and last point.. figure out the middle! - var firstPoint = new math.Point(points[0], points[1]); - var lastPoint = new math.Point(points[points.length - 2], points[points.length - 1]); - - // if the first point is the last point - gonna have issues :) - if (firstPoint.x === lastPoint.x && firstPoint.y === lastPoint.y) - { - // need to clone as we are going to slightly modify the shape.. - points = points.slice(); - - points.pop(); - points.pop(); - - lastPoint = new math.Point(points[points.length - 2], points[points.length - 1]); - - var midPointX = lastPoint.x + (firstPoint.x - lastPoint.x) *0.5; - var midPointY = lastPoint.y + (firstPoint.y - lastPoint.y) *0.5; - - points.unshift(midPointX, midPointY); - points.push(midPointX, midPointY); - } - - var verts = webGLData.points; - var indices = webGLData.indices; - var length = points.length / 2; - var indexCount = points.length; - var indexStart = verts.length/6; - - // DRAW the Line - var width = graphicsData.lineWidth / 2; - - // sort color - var color = utils.hex2rgb(graphicsData.lineColor); - var alpha = graphicsData.lineAlpha; - var r = color[0] * alpha; - var g = color[1] * alpha; - var b = color[2] * alpha; - - var px, py, p1x, p1y, p2x, p2y, p3x, p3y; - var perpx, perpy, perp2x, perp2y, perp3x, perp3y; - var a1, b1, c1, a2, b2, c2; - var denom, pdist, dist; - - p1x = points[0]; - p1y = points[1]; - - p2x = points[2]; - p2y = points[3]; - - perpx = -(p1y - p2y); - perpy = p1x - p2x; - - dist = Math.sqrt(perpx*perpx + perpy*perpy); - - perpx /= dist; - perpy /= dist; - perpx *= width; - perpy *= width; - - // start - verts.push(p1x - perpx , p1y - perpy, - r, g, b, alpha); - - verts.push(p1x + perpx , p1y + perpy, - r, g, b, alpha); - - for (i = 1; i < length-1; i++) - { - p1x = points[(i-1)*2]; - p1y = points[(i-1)*2 + 1]; - - p2x = points[(i)*2]; - p2y = points[(i)*2 + 1]; - - p3x = points[(i+1)*2]; - p3y = points[(i+1)*2 + 1]; - - perpx = -(p1y - p2y); - perpy = p1x - p2x; - - dist = Math.sqrt(perpx*perpx + perpy*perpy); - perpx /= dist; - perpy /= dist; - perpx *= width; - perpy *= width; - - perp2x = -(p2y - p3y); - perp2y = p2x - p3x; - - dist = Math.sqrt(perp2x*perp2x + perp2y*perp2y); - perp2x /= dist; - perp2y /= dist; - perp2x *= width; - perp2y *= width; - - a1 = (-perpy + p1y) - (-perpy + p2y); - b1 = (-perpx + p2x) - (-perpx + p1x); - c1 = (-perpx + p1x) * (-perpy + p2y) - (-perpx + p2x) * (-perpy + p1y); - a2 = (-perp2y + p3y) - (-perp2y + p2y); - b2 = (-perp2x + p2x) - (-perp2x + p3x); - c2 = (-perp2x + p3x) * (-perp2y + p2y) - (-perp2x + p2x) * (-perp2y + p3y); - - denom = a1*b2 - a2*b1; - - if (Math.abs(denom) < 0.1 ) - { - - denom+=10.1; - verts.push(p2x - perpx , p2y - perpy, - r, g, b, alpha); - - verts.push(p2x + perpx , p2y + perpy, - r, g, b, alpha); - - continue; - } - - px = (b1*c2 - b2*c1)/denom; - py = (a2*c1 - a1*c2)/denom; - - - pdist = (px -p2x) * (px -p2x) + (py -p2y) * (py -p2y); - - - if (pdist > 140 * 140) - { - perp3x = perpx - perp2x; - perp3y = perpy - perp2y; - - dist = Math.sqrt(perp3x*perp3x + perp3y*perp3y); - perp3x /= dist; - perp3y /= dist; - perp3x *= width; - perp3y *= width; - - verts.push(p2x - perp3x, p2y -perp3y); - verts.push(r, g, b, alpha); - - verts.push(p2x + perp3x, p2y +perp3y); - verts.push(r, g, b, alpha); - - verts.push(p2x - perp3x, p2y -perp3y); - verts.push(r, g, b, alpha); - - indexCount++; - } - else - { - - verts.push(px , py); - verts.push(r, g, b, alpha); - - verts.push(p2x - (px-p2x), p2y - (py - p2y)); - verts.push(r, g, b, alpha); - } - } - - p1x = points[(length-2)*2]; - p1y = points[(length-2)*2 + 1]; - - p2x = points[(length-1)*2]; - p2y = points[(length-1)*2 + 1]; - - perpx = -(p1y - p2y); - perpy = p1x - p2x; - - dist = Math.sqrt(perpx*perpx + perpy*perpy); - perpx /= dist; - perpy /= dist; - perpx *= width; - perpy *= width; - - verts.push(p2x - perpx , p2y - perpy); - verts.push(r, g, b, alpha); - - verts.push(p2x + perpx , p2y + perpy); - verts.push(r, g, b, alpha); - - indices.push(indexStart); - - for (i = 0; i < indexCount; i++) - { - indices.push(indexStart++); - } - - indices.push(indexStart-1); -}; - -module.exports = buildLine; -},{"../../../math":54,"../../../utils":100}],47:[function(require,module,exports){ -var buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); - -/** - * Builds a polygon to draw - * - * @private - * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties - * @param webGLData {object} an object containing all the webGL-specific information to create this shape - */ -var buildPoly = function (graphicsData, webGLData) -{ - graphicsData.points = graphicsData.shape.points.slice(); - - var points = graphicsData.points; - - // need to add the points the the graphics object.. - if (graphicsData.shape.closed) - { - // close the poly if the value is true! - if (points[0] !== points[points.length-2] || points[1] !== points[points.length-1]) - { - points.push(points[0], points[1]); - } - } - - - if(graphicsData.fill && points.length > 6) - { - - // get first and last point.. figure out the middle! - var verts = webGLData.points; - var indices = webGLData.indices; - - var length = points.length / 2; - - // sort color - var color = utils.hex2rgb(graphicsData.fillColor); - var alpha = graphicsData.fillAlpha; - var r = color[0] * alpha; - var g = color[1] * alpha; - var b = color[2] * alpha; - - var triangles = earcut(points, null, 2); - - if (!triangles) { - return; - } - - var vertPos = verts.length / 6; - - var i = 0; - - for (i = 0; i < triangles.length; i+=3) - { - indices.push(triangles[i] + vertPos); - indices.push(triangles[i] + vertPos); - indices.push(triangles[i+1] + vertPos); - indices.push(triangles[i+2] +vertPos); - indices.push(triangles[i+2] + vertPos); - } - - for (i = 0; i < length; i++) - { - verts.push(points[i * 2], points[i * 2 + 1], - r, g, b, alpha); - } - } - - if (graphicsData.lineWidth > 0) - { - buildLine(graphicsData, webGLData); - } -}; - - -module.exports = buildPoly; - -},{"../../../utils":100,"./buildLine":46,"earcut":11}],48:[function(require,module,exports){ -var buildLine = require('./buildLine'), - utils = require('../../../utils'); - -/** - * Builds a rectangle to draw - * - * @private - * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties - * @param webGLData {object} an object containing all the webGL-specific information to create this shape - */ -var buildRectangle = function (graphicsData, webGLData) -{ - // --- // - // need to convert points to a nice regular data - // - var rectData = graphicsData.shape; - var x = rectData.x; - var y = rectData.y; - var width = rectData.width; - var height = rectData.height; - - if (graphicsData.fill) - { - var color = utils.hex2rgb(graphicsData.fillColor); - var alpha = graphicsData.fillAlpha; - - var r = color[0] * alpha; - var g = color[1] * alpha; - var b = color[2] * alpha; - - var verts = webGLData.points; - var indices = webGLData.indices; - - var vertPos = verts.length/6; - - // start - verts.push(x, y); - verts.push(r, g, b, alpha); - - verts.push(x + width, y); - verts.push(r, g, b, alpha); - - verts.push(x , y + height); - verts.push(r, g, b, alpha); - - verts.push(x + width, y + height); - verts.push(r, g, b, alpha); - - // insert 2 dead triangles.. - indices.push(vertPos, vertPos, vertPos+1, vertPos+2, vertPos+3, vertPos+3); - } - - if (graphicsData.lineWidth) - { - var tempPoints = graphicsData.points; - - graphicsData.points = [x, y, - x + width, y, - x + width, y + height, - x, y + height, - x, y]; - - - buildLine(graphicsData, webGLData); - - graphicsData.points = tempPoints; - } -}; - -module.exports = buildRectangle; -},{"../../../utils":100,"./buildLine":46}],49:[function(require,module,exports){ -var earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); - -/** - * Builds a rounded rectangle to draw - * - * @private - * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties - * @param webGLData {object} an object containing all the webGL-specific information to create this shape - */ -var buildRoundedRectangle = function (graphicsData, webGLData) -{ - var rrectData = graphicsData.shape; - var x = rrectData.x; - var y = rrectData.y; - var width = rrectData.width; - var height = rrectData.height; - - var radius = rrectData.radius; - - var recPoints = []; - recPoints.push(x, y + radius); - quadraticBezierCurve(x, y + height - radius, x, y + height, x + radius, y + height, recPoints); - quadraticBezierCurve(x + width - radius, y + height, x + width, y + height, x + width, y + height - radius, recPoints); - quadraticBezierCurve(x + width, y + radius, x + width, y, x + width - radius, y, recPoints); - quadraticBezierCurve(x + radius, y, x, y, x, y + radius + 0.0000000001, recPoints); - - // this tiny number deals with the issue that occurs when points overlap and earcut fails to triangulate the item. - // TODO - fix this properly, this is not very elegant.. but it works for now. - - if (graphicsData.fill) - { - var color = utils.hex2rgb(graphicsData.fillColor); - var alpha = graphicsData.fillAlpha; - - var r = color[0] * alpha; - var g = color[1] * alpha; - var b = color[2] * alpha; - - var verts = webGLData.points; - var indices = webGLData.indices; - - var vecPos = verts.length/6; - - var triangles = earcut(recPoints, null, 2); - - var i = 0; - for (i = 0; i < triangles.length; i+=3) - { - indices.push(triangles[i] + vecPos); - indices.push(triangles[i] + vecPos); - indices.push(triangles[i+1] + vecPos); - indices.push(triangles[i+2] + vecPos); - indices.push(triangles[i+2] + vecPos); - } - - for (i = 0; i < recPoints.length; i++) - { - verts.push(recPoints[i], recPoints[++i], r, g, b, alpha); - } - } - - if (graphicsData.lineWidth) - { - var tempPoints = graphicsData.points; - - graphicsData.points = recPoints; - - buildLine(graphicsData, webGLData); - - graphicsData.points = tempPoints; - } -}; - -/** - * Calculate the points for a quadratic bezier curve. (helper function..) - * Based on: https://stackoverflow.com/questions/785097/how-do-i-implement-a-bezier-curve-in-c - * - * @private - * @param fromX {number} Origin point x - * @param fromY {number} Origin point x - * @param cpX {number} Control point x - * @param cpY {number} Control point y - * @param toX {number} Destination point x - * @param toY {number} Destination point y - * @param [out] {number[]} The output array to add points into. If not passed, a new array is created. - * @return {number[]} an array of points - */ -var quadraticBezierCurve = function (fromX, fromY, cpX, cpY, toX, toY, out) -{ - var xa, - ya, - xb, - yb, - x, - y, - n = 20, - points = out || []; - - function getPt(n1 , n2, perc) { - var diff = n2 - n1; - - return n1 + ( diff * perc ); - } - - var j = 0; - for (var i = 0; i <= n; i++ ) { - j = i / n; - - // The Green Line - xa = getPt( fromX , cpX , j ); - ya = getPt( fromY , cpY , j ); - xb = getPt( cpX , toX , j ); - yb = getPt( cpY , toY , j ); - - // The Black Dot - x = getPt( xa , xb , j ); - y = getPt( ya , yb , j ); - - points.push(x, y); - } - - return points; -}; - - -module.exports = buildRoundedRectangle; - -},{"../../../utils":100,"./buildLine":46,"earcut":11}],50:[function(require,module,exports){ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ - -/** - * @namespace PIXI - */ -// export core and const. We assign core to const so that the non-reference types in const remain in-tact -var core = module.exports = Object.assign(require('./const'), require('./math'), { - // utils - utils: require('./utils'), - ticker: require('./ticker'), - - // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - - // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRender: require('./sprites/canvas/CanvasSpriteRenderer'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), - - // text - Text: require('./text/Text'), - - // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), - - // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), - - // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), - - // renderers - webgl - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), - - // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), - - glCore: require('pixi-gl-core'), - - /** - * This helper function will automatically detect which renderer you should be using. - * WebGL is the preferred renderer as it is a lot faster. If webGL is not supported by - * the browser then this function will return a canvas renderer - * - * @memberof PIXI - * @param width=800 {number} the width of the renderers view - * @param height=600 {number} the height of the renderers view - * @param [options] {object} The optional renderer parameters - * @param [options.view] {HTMLCanvasElement} the canvas to use as a view, optional - * @param [options.transparent=false] {boolean} If the render view is transparent, default false - * @param [options.antialias=false] {boolean} sets antialias (only applicable in chrome at the moment) - * @param [options.preserveDrawingBuffer=false] {boolean} enables drawing buffer preservation, enable this if you - * need to call toDataUrl on the webgl context - * @param [options.resolution=1] {number} the resolution of the renderer, retina would be 2 - * @param [noWebGL=false] {boolean} prevents selection of WebGL renderer, even if such is present - * - * @return {WebGLRenderer|CanvasRenderer} Returns WebGL renderer if available, otherwise CanvasRenderer - */ - autoDetectRenderer: function (width, height, options, noWebGL) - { - width = width || 800; - height = height || 600; - - if (!noWebGL && core.utils.isWebGLSupported()) - { - return new core.WebGLRenderer(width, height, options); - } - - return new core.CanvasRenderer(width, height, options); - } -}); - -},{"./const":33,"./display/Container":34,"./display/DisplayObject":35,"./graphics/Graphics":38,"./graphics/GraphicsData":39,"./graphics/canvas/CanvasGraphicsRenderer":40,"./graphics/webgl/GraphicsRenderer":42,"./math":54,"./renderers/canvas/CanvasRenderer":61,"./renderers/canvas/utils/CanvasRenderTarget":63,"./renderers/webgl/WebGLRenderer":68,"./renderers/webgl/filters/Filter":70,"./renderers/webgl/filters/spriteMask/SpriteMaskFilter":73,"./renderers/webgl/managers/WebGLManager":77,"./renderers/webgl/utils/ObjectRenderer":78,"./renderers/webgl/utils/Quad":79,"./renderers/webgl/utils/RenderTarget":80,"./sprites/Sprite":83,"./sprites/canvas/CanvasSpriteRenderer":84,"./sprites/webgl/SpriteRenderer":87,"./text/Text":89,"./textures/BaseRenderTexture":90,"./textures/BaseTexture":91,"./textures/RenderTexture":92,"./textures/Texture":93,"./textures/TextureUvs":94,"./textures/VideoBaseTexture":95,"./ticker":97,"./utils":100,"pixi-gl-core":15}],51:[function(require,module,exports){ -// Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 - -var ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; -var uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; -var vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; -var vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; -var tempMatrices = []; -var Matrix = require('./Matrix'); - -var mul = []; - -function signum(x) { - if (x < 0) { - return -1; - } - if (x > 0) { - return 1; - } - return 0; -} - -function init() { - for (var i = 0; i < 16; i++) { - var row = []; - mul.push(row); - for (var j = 0; j < 16; j++) { - var _ux = signum(ux[i] * ux[j] + vx[i] * uy[j]); - var _uy = signum(uy[i] * ux[j] + vy[i] * uy[j]); - var _vx = signum(ux[i] * vx[j] + vx[i] * vy[j]); - var _vy = signum(uy[i] * vx[j] + vy[i] * vy[j]); - for (var k = 0; k < 16; k++) { - if (ux[k] === _ux && uy[k] === _uy && vx[k] === _vx && vy[k] === _vy) { - row.push(k); - break; - } - } - } - } - - for (i=0;i<16;i++) { - var mat = new Matrix(); - mat.set(ux[i], uy[i], vx[i], vy[i], 0, 0); - tempMatrices.push(mat); - } -} - -init(); - -/** - * Implements Dihedral Group D_8, see [group D4]{@link http://mathworld.wolfram.com/DihedralGroupD4.html}, D8 is the same but with diagonals - * Used for texture rotations - * Vector xX(i), xY(i) is U-axis of sprite with rotation i - * Vector yY(i), yY(i) is V-axis of sprite with rotation i - * Rotations: 0 grad (0), 90 grad (2), 180 grad (4), 270 grad (6) - * Mirrors: vertical (8), main diagonal (10), horizontal (12), reverse diagonal (14) - * This is the small part of gameofbombs.com portal system. It works. - * @author Ivan @ivanpopelyshev - * - * @namespace PIXI.GroupD8 - */ -var GroupD8 = { - E: 0, - SE: 1, - S: 2, - SW: 3, - W: 4, - NW: 5, - N: 6, - NE: 7, - MIRROR_VERTICAL: 8, - MIRROR_HORIZONTAL: 12, - uX: function (ind) { - return ux[ind]; - }, - uY: function (ind) { - return uy[ind]; - }, - vX: function (ind) { - return vx[ind]; - }, - vY: function (ind) { - return vy[ind]; - }, - inv: function (rotation) { - if (rotation & 8) { - return rotation & 15; - } - return (-rotation) & 7; - }, - add: function (rotationSecond, rotationFirst) { - return mul[rotationSecond][rotationFirst]; - }, - sub: function (rotationSecond, rotationFirst) { - return mul[rotationSecond][GroupD8.inv(rotationFirst)]; - }, - /** - * Adds 180 degrees to rotation. Commutative operation - * @param rotation - * @returns {number} - */ - rotate180: function (rotation) { - return rotation ^ 4; - }, - /** - * I dont know why sometimes width and heights needs to be swapped. We'll fix it later. - * @param rotation - * @returns {boolean} - */ - isSwapWidthHeight: function(rotation) { - return (rotation & 3) === 2; - }, - byDirection: function (dx, dy) { - if (Math.abs(dx) * 2 <= Math.abs(dy)) { - if (dy >= 0) { - return GroupD8.S; - } - else { - return GroupD8.N; - } - } else if (Math.abs(dy) * 2 <= Math.abs(dx)) { - if (dx > 0) { - return GroupD8.E; - } - else { - return GroupD8.W; - } - } else { - if (dy > 0) { - if (dx > 0) { - return GroupD8.SE; - } - else { - return GroupD8.SW; - } - } - else if (dx > 0) { - return GroupD8.NE; - } - else { - return GroupD8.NW; - } - } - }, - /** - * Helps sprite to compensate texture packer rotation. - * @param matrix {PIXI.Matrix} sprite world matrix - * @param rotation {number} - * @param tx {number|*} sprite anchoring - * @param ty {number|*} sprite anchoring - */ - matrixAppendRotationInv: function (matrix, rotation, tx, ty) { - //Packer used "rotation", we use "inv(rotation)" - var mat = tempMatrices[GroupD8.inv(rotation)]; - tx = tx || 0; - ty = ty || 0; - mat.tx = tx; - mat.ty = ty; - matrix.append(mat); - } -}; - -module.exports = GroupD8; - -},{"./Matrix":52}],52:[function(require,module,exports){ -// @todo - ignore the too many parameters warning for now -// should either fix it or change the jshint config -// jshint -W072 - -var Point = require('./Point'); - -/** - * The pixi Matrix class as an object, which makes it a lot faster, - * here is a representation of it : - * | a | b | tx| - * | c | d | ty| - * | 0 | 0 | 1 | - * - * @class - * @memberof PIXI - */ -function Matrix() -{ - /** - * @member {number} - * @default 1 - */ - this.a = 1; - - /** - * @member {number} - * @default 0 - */ - this.b = 0; - - /** - * @member {number} - * @default 0 - */ - this.c = 0; - - /** - * @member {number} - * @default 1 - */ - this.d = 1; - - /** - * @member {number} - * @default 0 - */ - this.tx = 0; - - /** - * @member {number} - * @default 0 - */ - this.ty = 0; - -} - -Matrix.prototype.constructor = Matrix; -module.exports = Matrix; - -/** - * Creates a Matrix object based on the given array. The Element to Matrix mapping order is as follows: - * - * a = array[0] - * b = array[1] - * c = array[3] - * d = array[4] - * tx = array[2] - * ty = array[5] - * - * @param array {number[]} The array that the matrix will be populated from. - */ -Matrix.prototype.fromArray = function (array) -{ - this.a = array[0]; - this.b = array[1]; - this.c = array[3]; - this.d = array[4]; - this.tx = array[2]; - this.ty = array[5]; -}; - - -/** - * sets the matrix properties - * - * @param {number} a - * @param {number} b - * @param {number} c - * @param {number} d - * @param {number} tx - * @param {number} ty - * - * @return {PIXI.Matrix} This matrix. Good for chaining method calls. - */ -Matrix.prototype.set = function (a, b, c, d, tx, ty) -{ - this.a = a; - this.b = b; - this.c = c; - this.d = d; - this.tx = tx; - this.ty = ty; - - return this; -}; - - -/** - * Creates an array from the current Matrix object. - * - * @param transpose {boolean} Whether we need to transpose the matrix or not - * @param [out] {Array} If provided the array will be assigned to out - * @return {number[]} the newly created array which contains the matrix - */ -Matrix.prototype.toArray = function (transpose, out) -{ - if (!this.array) - { - this.array = new Float32Array(9); - } - - var array = out || this.array; - - if (transpose) - { - array[0] = this.a; - array[1] = this.b; - array[2] = 0; - array[3] = this.c; - array[4] = this.d; - array[5] = 0; - array[6] = this.tx; - array[7] = this.ty; - array[8] = 1; - } - else - { - array[0] = this.a; - array[1] = this.c; - array[2] = this.tx; - array[3] = this.b; - array[4] = this.d; - array[5] = this.ty; - array[6] = 0; - array[7] = 0; - array[8] = 1; - } - - return array; -}; - -/** - * Get a new position with the current transformation applied. - * Can be used to go from a child's coordinate space to the world coordinate space. (e.g. rendering) - * - * @param pos {PIXI.Point} The origin - * @param [newPos] {PIXI.Point} The point that the new position is assigned to (allowed to be same as input) - * @return {PIXI.Point} The new point, transformed through this matrix - */ -Matrix.prototype.apply = function (pos, newPos) -{ - newPos = newPos || new Point(); - - var x = pos.x; - var y = pos.y; - - newPos.x = this.a * x + this.c * y + this.tx; - newPos.y = this.b * x + this.d * y + this.ty; - - return newPos; -}; - -/** - * Get a new position with the inverse of the current transformation applied. - * Can be used to go from the world coordinate space to a child's coordinate space. (e.g. input) - * - * @param pos {PIXI.Point} The origin - * @param [newPos] {PIXI.Point} The point that the new position is assigned to (allowed to be same as input) - * @return {PIXI.Point} The new point, inverse-transformed through this matrix - */ -Matrix.prototype.applyInverse = function (pos, newPos) -{ - newPos = newPos || new Point(); - - var id = 1 / (this.a * this.d + this.c * -this.b); - - var x = pos.x; - var y = pos.y; - - newPos.x = this.d * id * x + -this.c * id * y + (this.ty * this.c - this.tx * this.d) * id; - newPos.y = this.a * id * y + -this.b * id * x + (-this.ty * this.a + this.tx * this.b) * id; - - return newPos; -}; - -/** - * Translates the matrix on the x and y. - * - * @param {number} x - * @param {number} y - * @return {PIXI.Matrix} This matrix. Good for chaining method calls. - */ -Matrix.prototype.translate = function (x, y) -{ - this.tx += x; - this.ty += y; - - return this; -}; - -/** - * Applies a scale transformation to the matrix. - * - * @param {number} x The amount to scale horizontally - * @param {number} y The amount to scale vertically - * @return {PIXI.Matrix} This matrix. Good for chaining method calls. - */ -Matrix.prototype.scale = function (x, y) -{ - this.a *= x; - this.d *= y; - this.c *= x; - this.b *= y; - this.tx *= x; - this.ty *= y; - - return this; -}; - - -/** - * Applies a rotation transformation to the matrix. - * - * @param {number} angle - The angle in radians. - * @return {PIXI.Matrix} This matrix. Good for chaining method calls. - */ -Matrix.prototype.rotate = function (angle) -{ - var cos = Math.cos( angle ); - var sin = Math.sin( angle ); - - var a1 = this.a; - var c1 = this.c; - var tx1 = this.tx; - - this.a = a1 * cos-this.b * sin; - this.b = a1 * sin+this.b * cos; - this.c = c1 * cos-this.d * sin; - this.d = c1 * sin+this.d * cos; - this.tx = tx1 * cos - this.ty * sin; - this.ty = tx1 * sin + this.ty * cos; - - return this; -}; - -/** - * Appends the given Matrix to this Matrix. - * - * @param {PIXI.Matrix} matrix - * @return {PIXI.Matrix} This matrix. Good for chaining method calls. - */ -Matrix.prototype.append = function (matrix) -{ - var a1 = this.a; - var b1 = this.b; - var c1 = this.c; - var d1 = this.d; - - this.a = matrix.a * a1 + matrix.b * c1; - this.b = matrix.a * b1 + matrix.b * d1; - this.c = matrix.c * a1 + matrix.d * c1; - this.d = matrix.c * b1 + matrix.d * d1; - - this.tx = matrix.tx * a1 + matrix.ty * c1 + this.tx; - this.ty = matrix.tx * b1 + matrix.ty * d1 + this.ty; - - return this; -}; - -/** - * Sets the matrix based on all the available properties - * - * @param {number} x - * @param {number} y - * @param {number} pivotX - * @param {number} pivotY - * @param {number} scaleX - * @param {number} scaleY - * @param {number} rotation - * @param {number} skewX - * @param {number} skewY - * - * @return {PIXI.Matrix} This matrix. Good for chaining method calls. - */ -Matrix.prototype.setTransform = function (x, y, pivotX, pivotY, scaleX, scaleY, rotation, skewX, skewY) -{ - var a, b, c, d, sr, cr, cy, sy, nsx, cx; - - sr = Math.sin(rotation); - cr = Math.cos(rotation); - cy = Math.cos(skewY); - sy = Math.sin(skewY); - nsx = -Math.sin(skewX); - cx = Math.cos(skewX); - - a = cr * scaleX; - b = sr * scaleX; - c = -sr * scaleY; - d = cr * scaleY; - - this.a = cy * a + sy * c; - this.b = cy * b + sy * d; - this.c = nsx * a + cx * c; - this.d = nsx * b + cx * d; - - this.tx = x + ( pivotX * a + pivotY * c ); - this.ty = y + ( pivotX * b + pivotY * d ); - - return this; -}; - -/** - * Prepends the given Matrix to this Matrix. - * - * @param {PIXI.Matrix} matrix - * @return {PIXI.Matrix} This matrix. Good for chaining method calls. - */ -Matrix.prototype.prepend = function(matrix) -{ - var tx1 = this.tx; - - if (matrix.a !== 1 || matrix.b !== 0 || matrix.c !== 0 || matrix.d !== 1) - { - var a1 = this.a; - var c1 = this.c; - this.a = a1*matrix.a+this.b*matrix.c; - this.b = a1*matrix.b+this.b*matrix.d; - this.c = c1*matrix.a+this.d*matrix.c; - this.d = c1*matrix.b+this.d*matrix.d; - } - - this.tx = tx1*matrix.a+this.ty*matrix.c+matrix.tx; - this.ty = tx1*matrix.b+this.ty*matrix.d+matrix.ty; - - return this; -}; - -/** - * Inverts this matrix - * - * @return {PIXI.Matrix} This matrix. Good for chaining method calls. - */ -Matrix.prototype.invert = function() -{ - var a1 = this.a; - var b1 = this.b; - var c1 = this.c; - var d1 = this.d; - var tx1 = this.tx; - var n = a1*d1-b1*c1; - - this.a = d1/n; - this.b = -b1/n; - this.c = -c1/n; - this.d = a1/n; - this.tx = (c1*this.ty-d1*tx1)/n; - this.ty = -(a1*this.ty-b1*tx1)/n; - - return this; -}; - - -/** - * Resets this Matix to an identity (default) matrix. - * - * @return {PIXI.Matrix} This matrix. Good for chaining method calls. - */ -Matrix.prototype.identity = function () -{ - this.a = 1; - this.b = 0; - this.c = 0; - this.d = 1; - this.tx = 0; - this.ty = 0; - - return this; -}; - -/** - * Creates a new Matrix object with the same values as this one. - * - * @return {PIXI.Matrix} A copy of this matrix. Good for chaining method calls. - */ -Matrix.prototype.clone = function () -{ - var matrix = new Matrix(); - matrix.a = this.a; - matrix.b = this.b; - matrix.c = this.c; - matrix.d = this.d; - matrix.tx = this.tx; - matrix.ty = this.ty; - - return matrix; -}; - -/** - * Changes the values of the given matrix to be the same as the ones in this matrix - * - * @return {PIXI.Matrix} The matrix given in parameter with its values updated. - */ -Matrix.prototype.copy = function (matrix) -{ - matrix.a = this.a; - matrix.b = this.b; - matrix.c = this.c; - matrix.d = this.d; - matrix.tx = this.tx; - matrix.ty = this.ty; - - return matrix; -}; - -/** - * A default (identity) matrix - * - * @static - * @const - */ -Matrix.IDENTITY = new Matrix(); - -/** - * A temp matrix - * - * @static - * @const - */ -Matrix.TEMP_MATRIX = new Matrix(); - -},{"./Point":53}],53:[function(require,module,exports){ -/** - * The Point object represents a location in a two-dimensional coordinate system, where x represents - * the horizontal axis and y represents the vertical axis. - * - * @class - * @memberof PIXI - * @param [x=0] {number} position of the point on the x axis - * @param [y=0] {number} position of the point on the y axis - */ -function Point(x, y) -{ - /** - * @member {number} - * @default 0 - */ - this.x = x || 0; - - /** - * @member {number} - * @default 0 - */ - this.y = y || 0; -} - -Point.prototype.constructor = Point; -module.exports = Point; - -/** - * Creates a clone of this point - * - * @return {PIXI.Point} a copy of the point - */ -Point.prototype.clone = function () -{ - return new Point(this.x, this.y); -}; - -/** - * Copies x and y from the given point - * - * @param p {PIXI.Point} - */ -Point.prototype.copy = function (p) { - this.set(p.x, p.y); -}; - -/** - * Returns true if the given point is equal to this point - * - * @param p {PIXI.Point} - * @returns {boolean} - */ -Point.prototype.equals = function (p) { - return (p.x === this.x) && (p.y === this.y); -}; - -/** - * Sets the point to a new x and y position. - * If y is omitted, both x and y will be set to x. - * - * @param [x=0] {number} position of the point on the x axis - * @param [y=0] {number} position of the point on the y axis - */ -Point.prototype.set = function (x, y) -{ - this.x = x || 0; - this.y = y || ( (y !== 0) ? this.x : 0 ) ; -}; - -},{}],54:[function(require,module,exports){ -/** - * Math classes and utilities mixed into PIXI namespace. - * - * @lends PIXI - */ -module.exports = { - // These will be mixed to be made publicly available, - // while this module is used internally in core - // to avoid circular dependencies and cut down on - // internal module requires. - - Point: require('./Point'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), - - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') -}; - -},{"./GroupD8":51,"./Matrix":52,"./Point":53,"./shapes/Circle":55,"./shapes/Ellipse":56,"./shapes/Polygon":57,"./shapes/Rectangle":58,"./shapes/RoundedRectangle":59}],55:[function(require,module,exports){ -var Rectangle = require('./Rectangle'), - CONST = require('../../const'); - -/** - * The Circle object can be used to specify a hit area for displayObjects - * - * @class - * @memberof PIXI - * @param x {number} The X coordinate of the center of this circle - * @param y {number} The Y coordinate of the center of this circle - * @param radius {number} The radius of the circle - */ -function Circle(x, y, radius) -{ - /** - * @member {number} - * @default 0 - */ - this.x = x || 0; - - /** - * @member {number} - * @default 0 - */ - this.y = y || 0; - - /** - * @member {number} - * @default 0 - */ - this.radius = radius || 0; - - /** - * The type of the object, mainly used to avoid `instanceof` checks - * - * @member {number} - */ - this.type = CONST.SHAPES.CIRC; -} - -Circle.prototype.constructor = Circle; -module.exports = Circle; - -/** - * Creates a clone of this Circle instance - * - * @return {PIXI.Circle} a copy of the Circle - */ -Circle.prototype.clone = function () -{ - return new Circle(this.x, this.y, this.radius); -}; - -/** - * Checks whether the x and y coordinates given are contained within this circle - * - * @param x {number} The X coordinate of the point to test - * @param y {number} The Y coordinate of the point to test - * @return {boolean} Whether the x/y coordinates are within this Circle - */ -Circle.prototype.contains = function (x, y) -{ - if (this.radius <= 0) - { - return false; - } - - var dx = (this.x - x), - dy = (this.y - y), - r2 = this.radius * this.radius; - - dx *= dx; - dy *= dy; - - return (dx + dy <= r2); -}; - -/** -* Returns the framing rectangle of the circle as a Rectangle object -* -* @return {PIXI.Rectangle} the framing rectangle -*/ -Circle.prototype.getBounds = function () -{ - return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); -}; - -},{"../../const":33,"./Rectangle":58}],56:[function(require,module,exports){ -var Rectangle = require('./Rectangle'), - CONST = require('../../const'); - -/** - * The Ellipse object can be used to specify a hit area for displayObjects - * - * @class - * @memberof PIXI - * @param x {number} The X coordinate of the center of the ellipse - * @param y {number} The Y coordinate of the center of the ellipse - * @param width {number} The half width of this ellipse - * @param height {number} The half height of this ellipse - */ -function Ellipse(x, y, width, height) -{ - /** - * @member {number} - * @default 0 - */ - this.x = x || 0; - - /** - * @member {number} - * @default 0 - */ - this.y = y || 0; - - /** - * @member {number} - * @default 0 - */ - this.width = width || 0; - - /** - * @member {number} - * @default 0 - */ - this.height = height || 0; - - /** - * The type of the object, mainly used to avoid `instanceof` checks - * - * @member {number} - */ - this.type = CONST.SHAPES.ELIP; -} - -Ellipse.prototype.constructor = Ellipse; -module.exports = Ellipse; - -/** - * Creates a clone of this Ellipse instance - * - * @return {PIXI.Ellipse} a copy of the ellipse - */ -Ellipse.prototype.clone = function () -{ - return new Ellipse(this.x, this.y, this.width, this.height); -}; - -/** - * Checks whether the x and y coordinates given are contained within this ellipse - * - * @param x {number} The X coordinate of the point to test - * @param y {number} The Y coordinate of the point to test - * @return {boolean} Whether the x/y coords are within this ellipse - */ -Ellipse.prototype.contains = function (x, y) -{ - if (this.width <= 0 || this.height <= 0) - { - return false; - } - - //normalize the coords to an ellipse with center 0,0 - var normx = ((x - this.x) / this.width), - normy = ((y - this.y) / this.height); - - normx *= normx; - normy *= normy; - - return (normx + normy <= 1); -}; - -/** - * Returns the framing rectangle of the ellipse as a Rectangle object - * - * @return {PIXI.Rectangle} the framing rectangle - */ -Ellipse.prototype.getBounds = function () -{ - return new Rectangle(this.x - this.width, this.y - this.height, this.width, this.height); -}; - -},{"../../const":33,"./Rectangle":58}],57:[function(require,module,exports){ -var Point = require('../Point'), - CONST = require('../../const'); - -/** - * @class - * @memberof PIXI - * @param points {PIXI.Point[]|number[]|...PIXI.Point|...number} This can be an array of Points that form the polygon, - * a flat array of numbers that will be interpreted as [x,y, x,y, ...], or the arguments passed can be - * all the points of the polygon e.g. `new PIXI.Polygon(new PIXI.Point(), new PIXI.Point(), ...)`, or the - * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are - * Numbers. - */ -function Polygon(points_) -{ - // prevents an argument assignment deopt - // see section 3.1: https://github.com/petkaantonov/bluebird/wiki/Optimization-killers#3-managing-arguments - var points = points_; - - //if points isn't an array, use arguments as the array - if (!Array.isArray(points)) - { - // prevents an argument leak deopt - // see section 3.2: https://github.com/petkaantonov/bluebird/wiki/Optimization-killers#3-managing-arguments - points = new Array(arguments.length); - - for (var a = 0; a < points.length; ++a) { - points[a] = arguments[a]; - } - } - - // if this is an array of points, convert it to a flat array of numbers - if (points[0] instanceof Point) - { - var p = []; - for (var i = 0, il = points.length; i < il; i++) - { - p.push(points[i].x, points[i].y); - } - - points = p; - } - - this.closed = true; - - /** - * An array of the points of this polygon - * - * @member {number[]} - */ - this.points = points; - - /** - * The type of the object, mainly used to avoid `instanceof` checks - * - * @member {number} - */ - this.type = CONST.SHAPES.POLY; -} - -Polygon.prototype.constructor = Polygon; -module.exports = Polygon; - -/** - * Creates a clone of this polygon - * - * @return {PIXI.Polygon} a copy of the polygon - */ -Polygon.prototype.clone = function () -{ - return new Polygon(this.points.slice()); -}; - -/** - * Checks whether the x and y coordinates passed to this function are contained within this polygon - * - * @param x {number} The X coordinate of the point to test - * @param y {number} The Y coordinate of the point to test - * @return {boolean} Whether the x/y coordinates are within this polygon - */ -Polygon.prototype.contains = function (x, y) -{ - var inside = false; - - // use some raycasting to test hits - // https://github.com/substack/point-in-polygon/blob/master/index.js - var length = this.points.length / 2; - - for (var i = 0, j = length - 1; i < length; j = i++) - { - var xi = this.points[i * 2], yi = this.points[i * 2 + 1], - xj = this.points[j * 2], yj = this.points[j * 2 + 1], - intersect = ((yi > y) !== (yj > y)) && (x < (xj - xi) * (y - yi) / (yj - yi) + xi); - - if (intersect) - { - inside = !inside; - } - } - - return inside; -}; - -},{"../../const":33,"../Point":53}],58:[function(require,module,exports){ -var CONST = require('../../const'); - -/** - * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. - * - * @class - * @memberof PIXI - * @param x {number} The X coordinate of the upper-left corner of the rectangle - * @param y {number} The Y coordinate of the upper-left corner of the rectangle - * @param width {number} The overall width of this rectangle - * @param height {number} The overall height of this rectangle - */ -function Rectangle(x, y, width, height) -{ - /** - * @member {number} - * @default 0 - */ - this.x = x || 0; - - /** - * @member {number} - * @default 0 - */ - this.y = y || 0; - - /** - * @member {number} - * @default 0 - */ - this.width = width || 0; - - /** - * @member {number} - * @default 0 - */ - this.height = height || 0; - - /** - * The type of the object, mainly used to avoid `instanceof` checks - * - * @member {number} - */ - this.type = CONST.SHAPES.RECT; -} - -Rectangle.prototype.constructor = Rectangle; -module.exports = Rectangle; - -/** - * A constant empty rectangle. - * - * @static - * @constant - */ -Rectangle.EMPTY = new Rectangle(0, 0, 0, 0); - - -/** - * Creates a clone of this Rectangle - * - * @return {PIXI.Rectangle} a copy of the rectangle - */ -Rectangle.prototype.clone = function () -{ - return new Rectangle(this.x, this.y, this.width, this.height); -}; - -Rectangle.prototype.copy = function (rectangle) -{ - this.x = rectangle.x; - this.x = rectangle.y; - this.width = rectangle.width; - this.height = rectangle.height; - - return this; -}; - -/** - * Checks whether the x and y coordinates given are contained within this Rectangle - * - * @param x {number} The X coordinate of the point to test - * @param y {number} The Y coordinate of the point to test - * @return {boolean} Whether the x/y coordinates are within this Rectangle - */ -Rectangle.prototype.contains = function (x, y) -{ - if (this.width <= 0 || this.height <= 0) - { - return false; - } - - if (x >= this.x && x < this.x + this.width) - { - if (y >= this.y && y < this.y + this.height) - { - return true; - } - } - - return false; -}; - -Rectangle.prototype.pad = function (paddingX, paddingY) -{ - paddingX = paddingX || 0; - paddingY = paddingY || ( (paddingY !== 0) ? paddingX : 0 ); - - this.x -= paddingX; - this.y -= paddingY; - - this.width += paddingX * 2; - this.height += paddingY * 2; -}; - -Rectangle.prototype.fit = function (rectangle) -{ - if (this.x < rectangle.x) - { - this.width += this.x; - if(this.width < 0) { - this.width = 0; - } - - this.x = rectangle.x; - } - - if (this.y < rectangle.y) - { - this.height += this.y; - if(this.height < 0) { - this.height = 0; - } - this.y = rectangle.y; - } - - if ( this.x + this.width > rectangle.x + rectangle.width ) - { - this.width = rectangle.width - this.x; - if(this.width < 0) { - this.width = 0; - } - } - - if ( this.y + this.height > rectangle.y + rectangle.height ) - { - this.height = rectangle.height - this.y; - if(this.height < 0) { - this.height = 0; - } - } -}; - -Rectangle.prototype.enlarge = function (rect) { - if (rect === Rectangle.EMPTY) return; - var x1 = Math.min(this.x, rect.x); - var x2 = Math.max(this.x + this.width, rect.x + rect.width); - var y1 = Math.min(this.y, rect.y); - var y2 = Math.max(this.y + this.height, rect.y + rect.height); - this.x = x1; - this.width = x2 - x1; - this.y = y1; - this.height = y2 - y1; -}; - -},{"../../const":33}],59:[function(require,module,exports){ -var CONST = require('../../const'); - -/** - * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. - * - * @class - * @memberof PIXI - * @param x {number} The X coordinate of the upper-left corner of the rounded rectangle - * @param y {number} The Y coordinate of the upper-left corner of the rounded rectangle - * @param width {number} The overall width of this rounded rectangle - * @param height {number} The overall height of this rounded rectangle - * @param radius {number} Controls the radius of the rounded corners - */ -function RoundedRectangle(x, y, width, height, radius) -{ - /** - * @member {number} - * @default 0 - */ - this.x = x || 0; - - /** - * @member {number} - * @default 0 - */ - this.y = y || 0; - - /** - * @member {number} - * @default 0 - */ - this.width = width || 0; - - /** - * @member {number} - * @default 0 - */ - this.height = height || 0; - - /** - * @member {number} - * @default 20 - */ - this.radius = radius || 20; - - /** - * The type of the object, mainly used to avoid `instanceof` checks - * - * @member {number} - */ - this.type = CONST.SHAPES.RREC; -} - -RoundedRectangle.prototype.constructor = RoundedRectangle; -module.exports = RoundedRectangle; - -/** - * Creates a clone of this Rounded Rectangle - * - * @return {PIXI.RoundedRectangle} a copy of the rounded rectangle - */ -RoundedRectangle.prototype.clone = function () -{ - return new RoundedRectangle(this.x, this.y, this.width, this.height, this.radius); -}; - -/** - * Checks whether the x and y coordinates given are contained within this Rounded Rectangle - * - * @param x {number} The X coordinate of the point to test - * @param y {number} The Y coordinate of the point to test - * @return {boolean} Whether the x/y coordinates are within this Rounded Rectangle - */ -RoundedRectangle.prototype.contains = function (x, y) -{ - if (this.width <= 0 || this.height <= 0) - { - return false; - } - - if (x >= this.x && x <= this.x + this.width) - { - if (y >= this.y && y <= this.y + this.height) - { - return true; - } - } - - return false; -}; - -},{"../../const":33}],60:[function(require,module,exports){ -var utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); -/** - * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. - * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) - * - * @class - * @memberof PIXI - * @param system {string} The name of the system this renderer is for. - * @param [width=800] {number} the width of the canvas view - * @param [height=600] {number} the height of the canvas view - * @param [options] {object} The optional renderer parameters - * @param [options.view] {HTMLCanvasElement} the canvas to use as a view, optional - * @param [options.transparent=false] {boolean} If the render view is transparent, default false - * @param [options.autoResize=false] {boolean} If the render view is automatically resized, default false - * @param [options.antialias=false] {boolean} sets antialias (only applicable in chrome at the moment) - * @param [options.resolution=1] {number} the resolution of the renderer retina would be 2 - * @param [options.clearBeforeRender=true] {boolean} This sets if the CanvasRenderer will clear the canvas or - * not before the new render pass. - * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). - * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. - */ -function SystemRenderer(system, width, height, options) -{ - EventEmitter.call(this); - - utils.sayHello(system); - - // prepare options - if (options) - { - for (var i in CONST.DEFAULT_RENDER_OPTIONS) - { - if (typeof options[i] === 'undefined') - { - options[i] = CONST.DEFAULT_RENDER_OPTIONS[i]; - } - } - } - else - { - options = CONST.DEFAULT_RENDER_OPTIONS; - } - - /** - * The type of the renderer. - * - * @member {number} - * @default PIXI.RENDERER_TYPE.UNKNOWN - * @see PIXI.RENDERER_TYPE - */ - this.type = CONST.RENDERER_TYPE.UNKNOWN; - - /** - * The width of the canvas view - * - * @member {number} - * @default 800 - */ - this.width = width || 800; - - /** - * The height of the canvas view - * - * @member {number} - * @default 600 - */ - this.height = height || 600; - - /** - * The canvas element that everything is drawn to - * - * @member {HTMLCanvasElement} - */ - this.view = options.view || document.createElement('canvas'); - - /** - * The resolution of the renderer - * - * @member {number} - * @default 1 - */ - this.resolution = options.resolution; - - /** - * Whether the render view is transparent - * - * @member {boolean} - */ - this.transparent = options.transparent; - - /** - * Whether the render view should be resized automatically - * - * @member {boolean} - */ - this.autoResize = options.autoResize || false; - - /** - * Tracks the blend modes useful for this renderer. - * - * @member {object} - */ - this.blendModes = null; - - /** - * The value of the preserveDrawingBuffer flag affects whether or not the contents of the stencil buffer is retained after rendering. - * - * @member {boolean} - */ - this.preserveDrawingBuffer = options.preserveDrawingBuffer; - - /** - * This sets if the CanvasRenderer will clear the canvas or not before the new render pass. - * If the scene is NOT transparent Pixi will use a canvas sized fillRect operation every frame to set the canvas background color. - * If the scene is transparent Pixi will use clearRect to clear the canvas every frame. - * Disable this by setting this to false. For example if your game has a canvas filling background image you often don't need this set. - * - * @member {boolean} - * @default - */ - this.clearBeforeRender = options.clearBeforeRender; - - /** - * If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. - * Handy for crisp pixel art and speed on legacy devices. - * - * @member {boolean} - */ - this.roundPixels = options.roundPixels; - - /** - * The background color as a number. - * - * @member {number} - * @private - */ - this._backgroundColor = 0x000000; - - /** - * The background color as an [R, G, B] array. - * - * @member {number[]} - * @private - */ - this._backgroundColorRgba = [0, 0, 0, 0]; - - /** - * The background color as a string. - * - * @member {string} - * @private - */ - this._backgroundColorString = '#000000'; - - this.backgroundColor = options.backgroundColor || this._backgroundColor; // run bg color setter - - /** - * This temporary display object used as the parent of the currently being rendered item - * - * @member {PIXI.DisplayObject} - * @private - */ - this._tempDisplayObjectParent = new Container(); - - /** - * The last root object that the renderer tried to render. - * - * @member {PIXI.DisplayObject} - * @private - */ - this._lastObjectRendered = this._tempDisplayObjectParent; -} - -// constructor -SystemRenderer.prototype = Object.create(EventEmitter.prototype); -SystemRenderer.prototype.constructor = SystemRenderer; -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { - /** - * The background color to fill if not transparent - * - * @member {number} - * @memberof PIXI.SystemRenderer# - */ - backgroundColor: - { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } - } -}); - -/** - * Resizes the canvas view to the specified width and height - * - * @param width {number} the new width of the canvas view - * @param height {number} the new height of the canvas view - */ -SystemRenderer.prototype.resize = function (width, height) { - this.width = width * this.resolution; - this.height = height * this.resolution; - - this.view.width = this.width; - this.view.height = this.height; - - if (this.autoResize) - { - this.view.style.width = this.width / this.resolution + 'px'; - this.view.style.height = this.height / this.resolution + 'px'; - } -}; - -/** - * Useful function that returns a texture of the display object that can then be used to create sprites - * This can be quite useful if your displayObject is complicated and needs to be reused multiple times. - * - * @param displayObject {number} The displayObject the object will be generated from - * @param scaleMode {number} Should be one of the scaleMode consts - * @param resolution {number} The resolution of the texture being generated - * @return {PIXI.Texture} a texture of the graphics object - */ -SystemRenderer.prototype.generateTexture = function (displayObject, scaleMode, resolution) { - - var bounds = displayObject.getLocalBounds(); - - var renderTexture = RenderTexture.create(bounds.width | 0, bounds.height | 0, scaleMode, resolution); - - tempMatrix.tx = -bounds.x; - tempMatrix.ty = -bounds.y; - - this.render(displayObject, renderTexture, false, tempMatrix, true); - - return renderTexture; -}; - -/** - * Removes everything from the renderer and optionally removes the Canvas DOM element. - * - * @param [removeView=false] {boolean} Removes the Canvas element from the DOM. - */ -SystemRenderer.prototype.destroy = function (removeView) { - if (removeView && this.view.parentNode) - { - this.view.parentNode.removeChild(this.view); - } - - this.type = CONST.RENDERER_TYPE.UNKNOWN; - - this.width = 0; - this.height = 0; - - this.view = null; - - this.resolution = 0; - - this.transparent = false; - - this.autoResize = false; - - this.blendModes = null; - - this.preserveDrawingBuffer = false; - this.clearBeforeRender = false; - - this.roundPixels = false; - - this._backgroundColor = 0; - this._backgroundColorRgba = null; - this._backgroundColorString = null; - - this.backgroundColor = 0; - this._tempDisplayObjectParent = null; - this._lastObjectRendered = null; -}; - -},{"../const":33,"../display/Container":34,"../math":54,"../textures/RenderTexture":92,"../utils":100,"eventemitter3":12}],61:[function(require,module,exports){ -var SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); - -/** - * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. - * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) - * - * @class - * @memberof PIXI - * @extends PIXI.SystemRenderer - * @param [width=800] {number} the width of the canvas view - * @param [height=600] {number} the height of the canvas view - * @param [options] {object} The optional renderer parameters - * @param [options.view] {HTMLCanvasElement} the canvas to use as a view, optional - * @param [options.transparent=false] {boolean} If the render view is transparent, default false - * @param [options.autoResize=false] {boolean} If the render view is automatically resized, default false - * @param [options.antialias=false] {boolean} sets antialias (only applicable in chrome at the moment) - * @param [options.resolution=1] {number} the resolution of the renderer retina would be 2 - * @param [options.clearBeforeRender=true] {boolean} This sets if the CanvasRenderer will clear the canvas or - * not before the new render pass. - * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. - */ -function CanvasRenderer(width, height, options) -{ - options = options || {}; - - SystemRenderer.call(this, 'Canvas', width, height, options); - - this.type = CONST.RENDERER_TYPE.CANVAS; - - /** - * The canvas 2d context that everything is drawn with. - * - * @member {CanvasRenderingContext2D} - */ - this.rootContext = this.view.getContext('2d', { alpha: this.transparent }); - this.rootResolution = this.resolution; - - /** - * Boolean flag controlling canvas refresh. - * - * @member {boolean} - */ - this.refresh = true; - - /** - * Instance of a CanvasMaskManager, handles masking when using the canvas renderer. - * - * @member {PIXI.CanvasMaskManager} - */ - this.maskManager = new CanvasMaskManager(this); - - /** - * The canvas property used to set the canvas smoothing property. - * - * @member {string} - */ - this.smoothProperty = 'imageSmoothingEnabled'; - - if (!this.rootContext.imageSmoothingEnabled) - { - if (this.rootContext.webkitImageSmoothingEnabled) - { - this.smoothProperty = 'webkitImageSmoothingEnabled'; - } - else if (this.rootContext.mozImageSmoothingEnabled) - { - this.smoothProperty = 'mozImageSmoothingEnabled'; - } - else if (this.rootContext.oImageSmoothingEnabled) - { - this.smoothProperty = 'oImageSmoothingEnabled'; - } - else if (this.rootContext.msImageSmoothingEnabled) - { - this.smoothProperty = 'msImageSmoothingEnabled'; - } - } - - this.initPlugins(); - - this.blendModes = mapCanvasBlendModesToPixi(); - this._activeBlendMode = null; - - this.context = null; - this.renderingToScreen = false; - - this.resize(width, height); -} - -// constructor -CanvasRenderer.prototype = Object.create(SystemRenderer.prototype); -CanvasRenderer.prototype.constructor = CanvasRenderer; -module.exports = CanvasRenderer; -utils.pluginTarget.mixin(CanvasRenderer); - - -/** - * Renders the object to this canvas view - * - * @param object {PIXI.DisplayObject} the object to be rendered - */ -CanvasRenderer.prototype.render = function (displayObject, renderTexture, clear, transform, skipUpdateTransform) -{ - - if (!this.view){ - return; - } - - // can be handy to know! - this.renderingToScreen = !renderTexture; - - this.emit('prerender'); - - if(renderTexture) - { - renderTexture = renderTexture.baseTexture || renderTexture; - - if(!renderTexture._canvasRenderTarget) - { - - renderTexture._canvasRenderTarget = new CanvasRenderTarget(renderTexture.width, renderTexture.height, renderTexture.resolution); - renderTexture.source = renderTexture._canvasRenderTarget.canvas; - renderTexture.valid = true; - } - - this.context = renderTexture._canvasRenderTarget.context; - this.resolution = renderTexture._canvasRenderTarget.resolution; - } - else - { - - this.context = this.rootContext; - this.resolution = this.rootResolution; - } - - var context = this.context; - - - - this._lastObjectRendered = displayObject; - - - - if(!skipUpdateTransform) - { - // update the scene graph - var cacheParent = displayObject.parent; - var tempWt = this._tempDisplayObjectParent.transform.worldTransform; - - if(transform) - { - transform.copy(tempWt); - } - else - { - tempWt.identity(); - } - - displayObject.parent = this._tempDisplayObjectParent; - displayObject.updateTransform(); - displayObject.parent = cacheParent; - // displayObject.hitArea = //TODO add a temp hit area - } - - - context.setTransform(1, 0, 0, 1, 0, 0); - context.globalAlpha = 1; - context.globalCompositeOperation = this.blendModes[CONST.BLEND_MODES.NORMAL]; - - if (navigator.isCocoonJS && this.view.screencanvas) - { - context.fillStyle = 'black'; - context.clear(); - } - - if( clear || this.clearBeforeRender) - { - if (this.transparent) - { - context.clearRect(0, 0, this.width, this.height); - } - else - { - context.fillStyle = this._backgroundColorString; - context.fillRect(0, 0, this.width , this.height); - } - } - - // TODO RENDER TARGET STUFF HERE.. - var tempContext = this.context; - - this.context = context; - displayObject.renderCanvas(this); - this.context = tempContext; - - this.emit('postrender'); -}; - - -CanvasRenderer.prototype.setBlendMode = function (blendMode) -{ - if(this._activeBlendMode === blendMode) { - return; - } - - this.context.globalCompositeOperation = this.blendModes[blendMode]; -}; - -/** - * Removes everything from the renderer and optionally removes the Canvas DOM element. - * - * @param [removeView=false] {boolean} Removes the Canvas element from the DOM. - */ -CanvasRenderer.prototype.destroy = function (removeView) -{ - this.destroyPlugins(); - - // call the base destroy - SystemRenderer.prototype.destroy.call(this, removeView); - - this.context = null; - - this.refresh = true; - - this.maskManager.destroy(); - this.maskManager = null; - - this.smoothProperty = null; -}; - -/** - * @extends PIXI.SystemRenderer#resize - * - * @param {number} w - * @param {number} h - */ -CanvasRenderer.prototype.resize = function (w, h) -{ - SystemRenderer.prototype.resize.call(this, w, h); - - //reset the scale mode.. oddly this seems to be reset when the canvas is resized. - //surely a browser bug?? Let pixi fix that for you.. - if(this.smoothProperty) - { - this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); - } - -}; - -},{"../../const":33,"../../utils":100,"../SystemRenderer":60,"./utils/CanvasMaskManager":62,"./utils/CanvasRenderTarget":63,"./utils/mapCanvasBlendModesToPixi":65}],62:[function(require,module,exports){ -var CONST = require('../../../const'); -/** - * A set of functions used to handle masking. - * - * @class - * @memberof PIXI - */ -function CanvasMaskManager(renderer) -{ - this.renderer = renderer; -} - -CanvasMaskManager.prototype.constructor = CanvasMaskManager; -module.exports = CanvasMaskManager; - -/** - * This method adds it to the current stack of masks. - * - * @param maskData {object} the maskData that will be pushed - * @param renderer {PIXI.WebGLRenderer|PIXI.CanvasRenderer} The renderer context to use. - */ -CanvasMaskManager.prototype.pushMask = function (maskData) -{ - var renderer = this.renderer; - - renderer.context.save(); - - var cacheAlpha = maskData.alpha; - var transform = maskData.transform.worldTransform; - var resolution = renderer.resolution; - - renderer.context.setTransform( - transform.a * resolution, - transform.b * resolution, - transform.c * resolution, - transform.d * resolution, - transform.tx * resolution, - transform.ty * resolution - ); - - //TODO suport sprite alpha masks?? - //lots of effort required. If demand is great enough.. - if(!maskData._texture) - { - this.renderGraphicsShape(maskData); - renderer.context.clip(); - } - - maskData.worldAlpha = cacheAlpha; -}; - -CanvasMaskManager.prototype.renderGraphicsShape = function (graphics) -{ - var context = this.renderer.context; - var len = graphics.graphicsData.length; - - if (len === 0) - { - return; - } - - context.beginPath(); - - for (var i = 0; i < len; i++) - { - var data = graphics.graphicsData[i]; - var shape = data.shape; - - if (data.type === CONST.SHAPES.POLY) - { - - var points = shape.points; - - context.moveTo(points[0], points[1]); - - for (var j=1; j < points.length/2; j++) - { - context.lineTo(points[j * 2], points[j * 2 + 1]); - } - - // if the first and last point are the same close the path - much neater :) - if (points[0] === points[points.length-2] && points[1] === points[points.length-1]) - { - context.closePath(); - } - - } - else if (data.type === CONST.SHAPES.RECT) - { - context.rect(shape.x, shape.y, shape.width, shape.height); - context.closePath(); - } - else if (data.type === CONST.SHAPES.CIRC) - { - // TODO - need to be Undefined! - context.arc(shape.x, shape.y, shape.radius, 0, 2 * Math.PI); - context.closePath(); - } - else if (data.type === CONST.SHAPES.ELIP) - { - - // ellipse code taken from: http://stackoverflow.com/questions/2172798/how-to-draw-an-oval-in-html5-canvas - - var w = shape.width * 2; - var h = shape.height * 2; - - var x = shape.x - w/2; - var y = shape.y - h/2; - - var kappa = 0.5522848, - ox = (w / 2) * kappa, // control point offset horizontal - oy = (h / 2) * kappa, // control point offset vertical - xe = x + w, // x-end - ye = y + h, // y-end - xm = x + w / 2, // x-middle - ym = y + h / 2; // y-middle - - context.moveTo(x, ym); - context.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y); - context.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym); - context.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye); - context.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym); - context.closePath(); - } - else if (data.type === CONST.SHAPES.RREC) - { - - var rx = shape.x; - var ry = shape.y; - var width = shape.width; - var height = shape.height; - var radius = shape.radius; - - var maxRadius = Math.min(width, height) / 2 | 0; - radius = radius > maxRadius ? maxRadius : radius; - - context.moveTo(rx, ry + radius); - context.lineTo(rx, ry + height - radius); - context.quadraticCurveTo(rx, ry + height, rx + radius, ry + height); - context.lineTo(rx + width - radius, ry + height); - context.quadraticCurveTo(rx + width, ry + height, rx + width, ry + height - radius); - context.lineTo(rx + width, ry + radius); - context.quadraticCurveTo(rx + width, ry, rx + width - radius, ry); - context.lineTo(rx + radius, ry); - context.quadraticCurveTo(rx, ry, rx, ry + radius); - context.closePath(); - } - } -}; - -/** - * Restores the current drawing context to the state it was before the mask was applied. - * - * @param renderer {PIXI.WebGLRenderer|PIXI.CanvasRenderer} The renderer context to use. - */ -CanvasMaskManager.prototype.popMask = function (renderer) -{ - renderer.context.restore(); -}; - -CanvasMaskManager.prototype.destroy = function () {}; - -},{"../../../const":33}],63:[function(require,module,exports){ -var CONST = require('../../../const'); - -/** - * Creates a Canvas element of the given size. - * - * @class - * @memberof PIXI - * @param width {number} the width for the newly created canvas - * @param height {number} the height for the newly created canvas - */ -function CanvasRenderTarget(width, height, resolution) -{ - /** - * The Canvas object that belongs to this CanvasRenderTarget. - * - * @member {HTMLCanvasElement} - */ - this.canvas = document.createElement('canvas'); - - /** - * A CanvasRenderingContext2D object representing a two-dimensional rendering context. - * - * @member {CanvasRenderingContext2D} - */ - this.context = this.canvas.getContext('2d'); - - this.resolution = resolution || CONST.RESOLUTION; - - this.resize(width, height); -} - -CanvasRenderTarget.prototype.constructor = CanvasRenderTarget; -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { - /** - * The width of the canvas buffer in pixels. - * - * @member {number} - * @memberof PIXI.CanvasRenderTarget# - */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, - /** - * The height of the canvas buffer in pixels. - * - * @member {number} - * @memberof PIXI.CanvasRenderTarget# - */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } - } -}); - -/** - * Clears the canvas that was created by the CanvasRenderTarget class. - * - * @private - */ -CanvasRenderTarget.prototype.clear = function () -{ - this.context.setTransform(1, 0, 0, 1, 0, 0); - this.context.clearRect(0,0, this.canvas.width, this.canvas.height); -}; - -/** - * Resizes the canvas to the specified width and height. - * - * @param width {number} the new width of the canvas - * @param height {number} the new height of the canvas - */ -CanvasRenderTarget.prototype.resize = function (width, height) -{ - - this.canvas.width = width * this.resolution; - this.canvas.height = height * this.resolution; -}; - -/** - * Destroys this canvas. - * - */ -CanvasRenderTarget.prototype.destroy = function () -{ - this.context = null; - this.canvas = null; -}; - -},{"../../../const":33}],64:[function(require,module,exports){ - -/** - * Checks whether the Canvas BlendModes are supported by the current browser - * - * @return {boolean} whether they are supported - */ -var canUseNewCanvasBlendModes = function () -{ - if (typeof document === 'undefined') - { - return false; - } - - var pngHead = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAABAQMAAADD8p2OAAAAA1BMVEX/'; - var pngEnd = 'AAAACklEQVQI12NgAAAAAgAB4iG8MwAAAABJRU5ErkJggg=='; - - var magenta = new Image(); - magenta.src = pngHead + 'AP804Oa6' + pngEnd; - - var yellow = new Image(); - yellow.src = pngHead + '/wCKxvRF' + pngEnd; - - var canvas = document.createElement('canvas'); - canvas.width = 6; - canvas.height = 1; - - var context = canvas.getContext('2d'); - context.globalCompositeOperation = 'multiply'; - context.drawImage(magenta, 0, 0); - context.drawImage(yellow, 2, 0); - - var data = context.getImageData(2,0,1,1).data; - - return (data[0] === 255 && data[1] === 0 && data[2] === 0); -}; - -module.exports = canUseNewCanvasBlendModes; - -},{}],65:[function(require,module,exports){ -var CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); - -/** - * Maps gl blend combinations to WebGL - * @class - * @memberof PIXI - */ -function mapWebGLBlendModesToPixi(array) -{ - array = array || []; - - if (canUseNewCanvasBlendModes()) - { - array[CONST.BLEND_MODES.NORMAL] = 'source-over'; - array[CONST.BLEND_MODES.ADD] = 'lighter'; //IS THIS OK??? - array[CONST.BLEND_MODES.MULTIPLY] = 'multiply'; - array[CONST.BLEND_MODES.SCREEN] = 'screen'; - array[CONST.BLEND_MODES.OVERLAY] = 'overlay'; - array[CONST.BLEND_MODES.DARKEN] = 'darken'; - array[CONST.BLEND_MODES.LIGHTEN] = 'lighten'; - array[CONST.BLEND_MODES.COLOR_DODGE] = 'color-dodge'; - array[CONST.BLEND_MODES.COLOR_BURN] = 'color-burn'; - array[CONST.BLEND_MODES.HARD_LIGHT] = 'hard-light'; - array[CONST.BLEND_MODES.SOFT_LIGHT] = 'soft-light'; - array[CONST.BLEND_MODES.DIFFERENCE] = 'difference'; - array[CONST.BLEND_MODES.EXCLUSION] = 'exclusion'; - array[CONST.BLEND_MODES.HUE] = 'hue'; - array[CONST.BLEND_MODES.SATURATION] = 'saturate'; - array[CONST.BLEND_MODES.COLOR] = 'color'; - array[CONST.BLEND_MODES.LUMINOSITY] = 'luminosity'; - } - else - { - // this means that the browser does not support the cool new blend modes in canvas 'cough' ie 'cough' - array[CONST.BLEND_MODES.NORMAL] = 'source-over'; - array[CONST.BLEND_MODES.ADD] = 'lighter'; //IS THIS OK??? - array[CONST.BLEND_MODES.MULTIPLY] = 'source-over'; - array[CONST.BLEND_MODES.SCREEN] = 'source-over'; - array[CONST.BLEND_MODES.OVERLAY] = 'source-over'; - array[CONST.BLEND_MODES.DARKEN] = 'source-over'; - array[CONST.BLEND_MODES.LIGHTEN] = 'source-over'; - array[CONST.BLEND_MODES.COLOR_DODGE] = 'source-over'; - array[CONST.BLEND_MODES.COLOR_BURN] = 'source-over'; - array[CONST.BLEND_MODES.HARD_LIGHT] = 'source-over'; - array[CONST.BLEND_MODES.SOFT_LIGHT] = 'source-over'; - array[CONST.BLEND_MODES.DIFFERENCE] = 'source-over'; - array[CONST.BLEND_MODES.EXCLUSION] = 'source-over'; - array[CONST.BLEND_MODES.HUE] = 'source-over'; - array[CONST.BLEND_MODES.SATURATION] = 'source-over'; - array[CONST.BLEND_MODES.COLOR] = 'source-over'; - array[CONST.BLEND_MODES.LUMINOSITY] = 'source-over'; - } - - return array; -} - -module.exports = mapWebGLBlendModesToPixi; - -},{"../../../const":33,"./canUseNewCanvasBlendModes":64}],66:[function(require,module,exports){ - -var CONST = require('../../const'); - -/** - * @class - * @memberof PIXI - * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. - */ -function TextureGarbageCollector(renderer) -{ - this.renderer = renderer; - - this.count = 0; - this.checkCount = 0; - this.maxIdle = 60 * 60; - this.checkCountMax = 60 * 10; - - this.mode = CONST.GC_MODES.DEFAULT; -} - -TextureGarbageCollector.prototype.constructor = TextureGarbageCollector; -module.exports = TextureGarbageCollector; - -TextureGarbageCollector.prototype.update = function() -{ - this.count++; - if(this.mode === CONST.GC_MODES.MANUAL)return; - - this.checkCount++; - - - if(this.checkCount > this.checkCountMax) - { - this.checkCount = 0; - - this.run(); - } -}; - -TextureGarbageCollector.prototype.run = function() -{ - var tm = this.renderer.textureManager; - var managedTextures = tm._managedTextures; - var wasRemoved = false; - var i,j; - - for (i = 0; i < managedTextures.length; i++) - { - var texture = managedTextures[i]; - - // only supports non generated textures at the moment! - if (!texture._glRenderTargets && this.count - texture.touched > this.maxIdle) - { - tm.destroyTexture(texture, true); - managedTextures[i] = null; - wasRemoved = true; - } - } - - if (wasRemoved) - { - j = 0; - - for (i = 0; i < managedTextures.length; i++) - { - if (managedTextures[i] !== null) - { - managedTextures[j++] = managedTextures[i]; - } - } - - managedTextures.length = j; - } -}; - -},{"../../const":33}],67:[function(require,module,exports){ -var GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); - -/** - * Helper class to create a webGL Texture - * - * @class - * @memberof PIXI - * @param renderer {PIXI.WebGLRenderer} - */ -var TextureManager = function(renderer) -{ - /** - * A reference to the current renderer - * - * @member {PIXI.WebGLRenderer} - */ - this.renderer = renderer; - - /** - * The current WebGL rendering context - * - * @member {WebGLRenderingContext} - */ - this.gl = renderer.gl; - - /** - * Track textures in the renderer so we can no longer listen to them on destruction. - * - * @member {array} - * @private - */ - this._managedTextures = []; -}; - -TextureManager.prototype.bindTexture = function() -{ -}; - - -TextureManager.prototype.getTexture = function() -{ -}; - -/** - * Updates and/or Creates a WebGL texture for the renderer's context. - * - * @param texture {PIXI.BaseTexture|PIXI.Texture} the texture to update - */ -TextureManager.prototype.updateTexture = function(texture) -{ - texture = texture.baseTexture || texture; - - var isRenderTexture = !!texture._glRenderTargets; - - if (!texture.hasLoaded) - { - return; - } - - var glTexture = texture._glTextures[this.renderer.CONTEXT_UID]; - - if (!glTexture) - { - if(isRenderTexture) - { - var renderTarget = new RenderTarget(this.gl, texture.width, texture.height, texture.scaleMode, texture.resolution); - renderTarget.resize(texture.width, texture.height); - texture._glRenderTargets[this.renderer.CONTEXT_UID] = renderTarget; - glTexture = renderTarget.texture; - } - else - { - glTexture = new GLTexture(this.gl); - glTexture.premultiplyAlpha = true; - glTexture.upload(texture.source); - } - - texture._glTextures[this.renderer.CONTEXT_UID] = glTexture; - - texture.on('update', this.updateTexture, this); - texture.on('dispose', this.destroyTexture, this); - - this._managedTextures.push(texture); - - if(texture.isPowerOfTwo) - { - if(texture.mipmap) - { - glTexture.enableMipmap(); - } - - if(texture.wrapMode === CONST.WRAP_MODES.CLAMP) - { - glTexture.enableWrapClamp(); - } - else if(texture.wrapMode === CONST.WRAP_MODES.REPEAT) - { - glTexture.enableWrapRepeat(); - } - else - { - glTexture.enableWrapMirrorRepeat(); - } - } - else - { - glTexture.enableWrapClamp(); - } - - if(texture.scaleMode === CONST.SCALE_MODES.NEAREST) - { - glTexture.enableNearestScaling(); - } - else - { - glTexture.enableLinearScaling(); - } - } - else - { - // the textur ealrady exists so we only need to update it.. - if(isRenderTexture) - { - texture._glRenderTargets[this.renderer.CONTEXT_UID].resize(texture.width, texture.height); - } - else - { - glTexture.upload(texture.source); - } - } - - return glTexture; -}; - -/** - * Deletes the texture from WebGL - * - * @param texture {PIXI.BaseTexture|PIXI.Texture} the texture to destroy - */ -TextureManager.prototype.destroyTexture = function(texture, _skipRemove) -{ - texture = texture.baseTexture || texture; - - if (!texture.hasLoaded) - { - return; - } - - if (texture._glTextures[this.renderer.CONTEXT_UID]) - { - texture._glTextures[this.renderer.CONTEXT_UID].destroy(); - texture.off('update', this.updateTexture, this); - texture.off('dispose', this.destroyTexture, this); - - - delete texture._glTextures[this.renderer.CONTEXT_UID]; - - if (!_skipRemove) - { - var i = this._managedTextures.indexOf(texture); - if (i !== -1) { - utils.removeItems(this._managedTextures, i, 1); - } - } - } -}; - -/** - * Deletes all the textures from WebGL - */ -TextureManager.prototype.removeAll = function() -{ - // empty all the old gl textures as they are useless now - for (var i = 0; i < this._managedTextures.length; ++i) - { - var texture = this._managedTextures[i]; - if (texture._glTextures[this.renderer.CONTEXT_UID]) - { - delete texture._glTextures[this.renderer.CONTEXT_UID]; - } - } -}; - -/** - * Destroys this manager and removes all its textures - */ -TextureManager.prototype.destroy = function() -{ - // destroy managed textures - for (var i = 0; i < this._managedTextures.length; ++i) - { - var texture = this._managedTextures[i]; - this.destroyTexture(texture, true); - texture.off('update', this.updateTexture, this); - texture.off('dispose', this.destroyTexture, this); - } - - this._managedTextures = null; -}; - -module.exports = TextureManager; - -},{"../../const":33,"../../utils":100,"./utils/RenderTarget":80,"pixi-gl-core":15}],68:[function(require,module,exports){ -var SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); - -var CONTEXT_UID = 0; - -/** - * The WebGLRenderer draws the scene and all its content onto a webGL enabled canvas. This renderer - * should be used for browsers that support webGL. This Render works by automatically managing webGLBatchs. - * So no need for Sprite Batches or Sprite Clouds. - * Don't forget to add the view to your DOM or you will not see anything :) - * - * @class - * @memberof PIXI - * @extends PIXI.SystemRenderer - * @param [width=0] {number} the width of the canvas view - * @param [height=0] {number} the height of the canvas view - * @param [options] {object} The optional renderer parameters - * @param [options.view] {HTMLCanvasElement} the canvas to use as a view, optional - * @param [options.transparent=false] {boolean} If the render view is transparent, default false - * @param [options.autoResize=false] {boolean} If the render view is automatically resized, default false - * @param [options.antialias=false] {boolean} sets antialias. If not available natively then FXAA antialiasing is used - * @param [options.forceFXAA=false] {boolean} forces FXAA antialiasing to be used over native. FXAA is faster, but may not always look as great - * @param [options.resolution=1] {number} the resolution of the renderer retina would be 2 - * @param [options.clearBeforeRender=true] {boolean} This sets if the CanvasRenderer will clear the canvas or - * not before the new render pass. If you wish to set this to false, you *must* set preserveDrawingBuffer to `true`. - * @param [options.preserveDrawingBuffer=false] {boolean} enables drawing buffer preservation, enable this if - * you need to call toDataUrl on the webgl context. - * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. - */ -function WebGLRenderer(width, height, options) -{ - options = options || {}; - - SystemRenderer.call(this, 'WebGL', width, height, options); - /** - * The type of this renderer as a standardised const - * - * @member {number}// - * - */ - this.type = CONST.RENDERER_TYPE.WEBGL; - - this.handleContextLost = this.handleContextLost.bind(this); - this.handleContextRestored = this.handleContextRestored.bind(this); - - this.view.addEventListener('webglcontextlost', this.handleContextLost, false); - this.view.addEventListener('webglcontextrestored', this.handleContextRestored, false); - - /** - * The options passed in to create a new webgl context. - * - * @member {object} - * @private - */ - this._contextOptions = { - alpha: this.transparent, - antialias: options.antialias, - premultipliedAlpha: this.transparent && this.transparent !== 'notMultiplied', - stencil: true, - preserveDrawingBuffer: options.preserveDrawingBuffer - }; - - this._backgroundColorRgba[3] = this.transparent ? 0 : 1; - - /** - * Manages the masks using the stencil buffer. - * - * @member {PIXI.MaskManager} - */ - this.maskManager = new MaskManager(this); - - /** - * Manages the stencil buffer. - * - * @member {PIXI.StencilManager} - */ - this.stencilManager = new StencilManager(this); - - /** - * An empty renderer. - * - * @member {PIXI.ObjectRenderer} - */ - this.emptyRenderer = new ObjectRenderer(this); - - /** - * The currently active ObjectRenderer. - * - * @member {PIXI.ObjectRenderer} - */ - this.currentRenderer = this.emptyRenderer; - - this.initPlugins(); - - /** - * The current WebGL rendering context, it is created here - * - * @member {WebGLRenderingContext} - */ - // initialize the context so it is ready for the managers. - this.gl = options.context || createContext(this.view, this._contextOptions); - - this.CONTEXT_UID = CONTEXT_UID++; - - /** - * The currently active ObjectRenderer. - * - * @member {PIXI.WebGLState} - */ - this.state = new WebGLState(this.gl); - - this.renderingToScreen = true; - - - - this._initContext(); - - /** - * Manages the filters. - * - * @member {PIXI.FilterManager} - */ - this.filterManager = new FilterManager(this); - // map some webGL blend and drawmodes.. - this.drawModes = mapWebGLDrawModesToPixi(this.gl); - - - /** - * Holds the current shader - * - * @member {PIXI.Shader} - */ - this._activeShader = null; - - /** - * Holds the current render target - * - * @member {PIXI.RenderTarget} - */ - this._activeRenderTarget = null; - this._activeTextureLocation = 999; - this._activeTexture = null; - - this.setBlendMode(0); - - -} - -// constructor -WebGLRenderer.prototype = Object.create(SystemRenderer.prototype); -WebGLRenderer.prototype.constructor = WebGLRenderer; -module.exports = WebGLRenderer; -utils.pluginTarget.mixin(WebGLRenderer); - -/** - * Creates the WebGL context - * - * @private - */ -WebGLRenderer.prototype._initContext = function () -{ - var gl = this.gl; - - // create a texture manager... - this.textureManager = new TextureManager(this); - this.textureGC = new TextureGarbageCollector(this); - - this.state.resetToDefault(); - - this.rootRenderTarget = new RenderTarget(gl, this.width, this.height, null, this.resolution, true); - this.rootRenderTarget.clearColor = this._backgroundColorRgba; - - - this.bindRenderTarget(this.rootRenderTarget); - - this.emit('context', gl); - - // setup the width/height properties and gl viewport - this.resize(this.width, this.height); -}; - -/** - * Renders the object to its webGL view - * - * @param object {PIXI.DisplayObject} the object to be rendered - * @param renderTexture {PIXI.renderTexture} - * @param clear {Boolean} - * @param transform {PIXI.Transform} - * @param skipUpdateTransform {Boolean} - */ -WebGLRenderer.prototype.render = function (displayObject, renderTexture, clear, transform, skipUpdateTransform) -{ - - - // can be handy to know! - this.renderingToScreen = !renderTexture; - - this.emit('prerender'); - - - // no point rendering if our context has been blown up! - if (!this.gl || this.gl.isContextLost()) - { - return; - } - - var gl = this.gl; - - this._lastObjectRendered = displayObject; - - if(!skipUpdateTransform) - { - // update the scene graph - var cacheParent = displayObject.parent; - displayObject.parent = this._tempDisplayObjectParent; - displayObject.updateTransform(); - displayObject.parent = cacheParent; - // displayObject.hitArea = //TODO add a temp hit area - } - - this.bindRenderTexture(renderTexture, transform); - - this.currentRenderer.start(); - - if( clear || this.clearBeforeRender) - { - renderTarget.clear(); - } - - - - displayObject.renderWebGL(this); - - // apply transform.. - this.currentRenderer.flush(); - //this.setObjectRenderer(this.emptyRenderer); - - this.textureGC.update(); - - this.emit('postrender'); -}; - -/** - * Changes the current renderer to the one given in parameter - * - * @param objectRenderer {PIXI.ObjectRenderer} The object renderer to use. - */ -WebGLRenderer.prototype.setObjectRenderer = function (objectRenderer) -{ - if (this.currentRenderer === objectRenderer) - { - return; - } - - this.currentRenderer.stop(); - this.currentRenderer = objectRenderer; - this.currentRenderer.start(); -}; - -/** - * This shoudl be called if you wish to do some custom rendering - * It will basically render anything that may be batched up such as sprites - * - */ -WebGLRenderer.prototype.flush = function () -{ - this.setObjectRenderer(this.emptyRenderer); -}; - -/** - * Resizes the webGL view to the specified width and height. - * - * @param width {number} the new width of the webGL view - * @param height {number} the new height of the webGL view - */ -WebGLRenderer.prototype.resize = function (width, height) -{ - // if(width * this.resolution === this.width && height * this.resolution === this.height)return; - - SystemRenderer.prototype.resize.call(this, width, height); - - this.rootRenderTarget.resize(width, height); - - if(this._activeRenderTarget === this.rootRenderTarget) - { - this.rootRenderTarget.activate(); - - if(this._activeShader) - { - this._activeShader.uniforms.projectionMatrix = this.rootRenderTarget.projectionMatrix.toArray(true); - } - } -}; - -/** - * Resizes the webGL view to the specified width and height. - * - * @param blendMode {number} the desired blend mode - */ -WebGLRenderer.prototype.setBlendMode = function (blendMode) -{ - this.state.setBlendMode(blendMode); -}; - -/** - * Erases the active render target and fills the drawing area with a colour - * - * @param clearColor {number} The colour - */ -WebGLRenderer.prototype.clear = function (clearColor) -{ - this._activeRenderTarget.clear(clearColor); -}; - -/** - * Sets the transform of the active render target to the given matrix - * - * @param matrix {PIXI.Matrix} The transformation matrix - */ -WebGLRenderer.prototype.setTransform = function (matrix) -{ - this._activeRenderTarget.transform = matrix; -}; - - -/** - * Binds a render texture for rendering - * - * @param renderTexture {PIXI.RenderTexture} The render texture to render - * @param transform {PIXI.Transform} The transform to be applied to the render texture - */ -WebGLRenderer.prototype.bindRenderTexture = function (renderTexture, transform) -{ - if(renderTexture) - { - var baseTexture = renderTexture.baseTexture; - var gl = this.gl; - - if(!baseTexture._glRenderTargets[this.CONTEXT_UID]) - { - - this.textureManager.updateTexture(baseTexture); - gl.bindTexture(gl.TEXTURE_2D, null); - } - else - { - // the texture needs to be unbound if its being rendererd too.. - this._activeTextureLocation = baseTexture._id; - gl.activeTexture(gl.TEXTURE0 + baseTexture._id); - gl.bindTexture(gl.TEXTURE_2D, null); - } - - - renderTarget = baseTexture._glRenderTargets[this.CONTEXT_UID]; - renderTarget.setFrame(renderTexture.frame); - } - else - { - renderTarget = this.rootRenderTarget; - } - - renderTarget.transform = transform; - this.bindRenderTarget(renderTarget); - - return this; -}; - -/** - * Changes the current render target to the one given in parameter - * - * @param renderTarget {PIXI.RenderTarget} the new render target - */ -WebGLRenderer.prototype.bindRenderTarget = function (renderTarget) -{ - if(renderTarget !== this._activeRenderTarget) - { - this._activeRenderTarget = renderTarget; - renderTarget.activate(); - - if(this._activeShader) - { - this._activeShader.uniforms.projectionMatrix = renderTarget.projectionMatrix.toArray(true); - } - - - this.stencilManager.setMaskStack( renderTarget.stencilMaskStack ); - } - - return this; -}; - -/** - * Changes the current shader to the one given in parameter - * - * @param shader {PIXI.Shader} the new shader - */ -WebGLRenderer.prototype.bindShader = function (shader) -{ - //TODO cache - if(this._activeShader !== shader) - { - this._activeShader = shader; - shader.bind(); - - // automatically set the projection matrix - shader.uniforms.projectionMatrix = this._activeRenderTarget.projectionMatrix.toArray(true); - } - - return this; -}; - -/** - * Binds the texture ... @mat - * - * @param texture {PIXI.Texture} the new texture - * @param location {number} the texture location - */ -WebGLRenderer.prototype.bindTexture = function (texture, location) -{ - texture = texture.baseTexture || texture; - - var gl = this.gl; - - //TODO test perf of cache? - location = location || 0; - - if(this._activeTextureLocation !== location)// - { - this._activeTextureLocation = location; - gl.activeTexture(gl.TEXTURE0 + location ); - } - - //TODO - can we cache this texture too? - this._activeTexture = texture; - - if (!texture._glTextures[this.CONTEXT_UID]) - { - // this will also bind the texture.. - this.textureManager.updateTexture(texture); - - } - else - { - texture.touched = this.textureGC.count; - // bind the current texture - texture._glTextures[this.CONTEXT_UID].bind(); - } - - return this; -}; - -WebGLRenderer.prototype.createVao = function () -{ - return new glCore.VertexArrayObject(this.gl, this.state.attribState); -} - -/** - * Resets the WebGL state so you can render things however you fancy! - */ -WebGLRenderer.prototype.reset = function () -{ - this.currentRenderer.stop(); - - this._activeShader = null; - this._activeRenderTarget = null; - this._activeTextureLocation = 999; - this._activeTexture = null; - - // bind the main frame buffer (the screen); - this.rootRenderTarget.activate(); - - this.state.resetToDefault(); - - - return this; -}; - -/** - * Handles a lost webgl context - * - * @private - */ -WebGLRenderer.prototype.handleContextLost = function (event) -{ - event.preventDefault(); -}; - -/** - * Handles a restored webgl context - * - * @private - */ -WebGLRenderer.prototype.handleContextRestored = function () -{ - this._initContext(); - this.textureManager.removeAll(); -}; - -/** - * Removes everything from the renderer (event listeners, spritebatch, etc...) - * - * @param [removeView=false] {boolean} Removes the Canvas element from the DOM. https://github.com/pixijs/pixi.js/issues/2233 - */ -WebGLRenderer.prototype.destroy = function (removeView) -{ - this.destroyPlugins(); - - // remove listeners - this.view.removeEventListener('webglcontextlost', this.handleContextLost); - this.view.removeEventListener('webglcontextrestored', this.handleContextRestored); - - this.textureManager.destroy(); - - // call base destroy - SystemRenderer.prototype.destroy.call(this, removeView); - - this.uid = 0; - - // destroy the managers - this.maskManager.destroy(); - this.stencilManager.destroy(); - this.filterManager.destroy(); - - this.maskManager = null; - this.filterManager = null; - this.textureManager = null; - this.currentRenderer = null; - - this.handleContextLost = null; - this.handleContextRestored = null; - - this._contextOptions = null; - this.gl.useProgram(null); - this.gl.getExtension('WEBGL_lose_context').loseContext(); - this.gl = null; - - // this = null; -}; - -},{"../../const":33,"../../utils":100,"../SystemRenderer":60,"./TextureGarbageCollector":66,"./TextureManager":67,"./WebGLState":69,"./managers/FilterManager":74,"./managers/MaskManager":75,"./managers/StencilManager":76,"./utils/ObjectRenderer":78,"./utils/RenderTarget":80,"./utils/mapWebGLDrawModesToPixi":82,"pixi-gl-core":15}],69:[function(require,module,exports){ - -var mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); - -/** - * A WebGL state machines - * @param gl {WebGLRenderingContext} The current WebGL rendering context - */ -var WebGLState = function(gl) -{ - - /** - * The current active state - * - * @member {Uint8Array} - */ - this.activeState = new Uint8Array(16); - - /** - * The default state - * - * @member {Uint8Array} - */ - this.defaultState = new Uint8Array(16); - - // default blend mode.. - this.defaultState[0] = 1; - - /** - * The current state index in the stack - * - * @member {number} - * @private - */ - this.stackIndex = 0; - - /** - * The stack holding all the different states - * - * @member {array} - * @private - */ - this.stack = []; - - /** - * The current WebGL rendering context - * - * @member {WebGLRenderingContext} - */ - this.gl = gl; - - this.maxAttribs = gl.getParameter(gl.MAX_VERTEX_ATTRIBS); - - this.attribState = {tempAttribState:new Array(this.maxAttribs) - ,attribState:new Array(this.maxAttribs)}; - - - - this.blendModes = mapWebGLBlendModesToPixi(gl); - - - // check we have vao.. - this.nativeVaoExtension = ( - gl.getExtension('OES_vertex_array_object') || - gl.getExtension('MOZ_OES_vertex_array_object') || - gl.getExtension('WEBKIT_OES_vertex_array_object') - ); -}; - -/** - * Pushes a new active state - */ -WebGLState.prototype.push = function() -{ - // next state.. - var state = this.state[++this.stackIndex]; - - if(!state) - { - state = this.state[this.stackIndex] = new Uint8Array(16); - } - - // copy state.. - // set active state so we can force overrides of gl state - for (var i = 0; i < this.activeState.length; i++) - { - this.activeState[i] = state[i]; - } -}; - -var BLEND = 0, - DEPTH_TEST = 1, - FRONT_FACE = 2, - CULL_FACE = 3, - BLEND_FUNC = 4; - -/** - * Pops a state out - */ -WebGLState.prototype.pop = function() -{ - var state = this.state[--this.stackIndex]; - this.setState(state); -}; - -/** - * Sets the current state - * @param state {number} - */ -WebGLState.prototype.setState = function(state) -{ - this.setBlend(state[BLEND]); - this.setDepthTest(state[DEPTH_TEST]); - this.setFrontFace(state[FRONT_FACE]); - this.setCullFace(state[CULL_FACE]); - this.setBlendMode(state[BLEND_FUNC]); -}; - -/** - * Sets the blend mode ? @mat - * @param value {number} - */ -WebGLState.prototype.setBlend = function(value) -{ - if(this.activeState[BLEND] === value|0) { - return; - } - - this.activeState[BLEND] = value|0; - - var gl = this.gl; - - if(value) - { - gl.enable(gl.BLEND); - } - else - { - gl.disable(gl.BLEND); - } -}; - -/** - * Sets the blend mode ? @mat - * @param value {number} - */ -WebGLState.prototype.setBlendMode = function(value) -{ - if(value === this.activeState[BLEND_FUNC]) { - return; - } - - this.activeState[BLEND_FUNC] = value; - - this.gl.blendFunc(this.blendModes[value][0], this.blendModes[value][1]); -}; - -/** - * Sets the depth test @mat - * @param value {number} - */ -WebGLState.prototype.setDepthTest = function(value) -{ - if(this.activeState[DEPTH_TEST] === value|0) { - return; - } - - this.activeState[DEPTH_TEST] = value|0; - - var gl = this.gl; - - if(value) - { - gl.enable(gl.DEPTH_TEST); - } - else - { - gl.disable(gl.DEPTH_TEST); - } -}; - -/** - * Sets the depth test @mat - * @param value {number} - */ -WebGLState.prototype.setCullFace = function(value) -{ - if(this.activeState[CULL_FACE] === value|0) { - return; - } - - this.activeState[CULL_FACE] = value|0; - - var gl = this.gl; - - if(value) - { - gl.enable(gl.CULL_FACE); - } - else - { - gl.disable(gl.CULL_FACE); - } -}; - -/** - * Sets the depth test @mat - * @param value {number} - */ -WebGLState.prototype.setFrontFace = function(value) -{ - if(this.activeState[FRONT_FACE] === value|0) { - return; - } - - this.activeState[FRONT_FACE] = value|0; - - var gl = this.gl; - - if(value) - { - gl.frontFace(gl.CW); - } - else - { - gl.frontFace(gl.CCW); - } -}; - -/** - * Disables all the vaos in use - */ -WebGLState.prototype.resetAttributes = function() -{ - var gl = this.gl; - - // im going to assume one is always active for performance reasons. - for (var i = 1; i < this.maxAttribs; i++) - { - gl.disableVertexAttribArray(i); - } -}; - -//used -/** - * Resets all the logic and disables the vaos - */ -WebGLState.prototype.resetToDefault = function() -{ - // unbind any VAO if they exist.. - if(this.nativeVaoExtension) - { - this.nativeVaoExtension.bindVertexArrayOES(null); - } - - var gl = this.gl; - // reset all attributs.. - this.resetAttributes(); - - // set active state so we can force overrides of gl state - for (var i = 0; i < this.activeState.length; i++) - { - this.activeState[i] = 2; - } - - this.setState(this.defaultState); -}; - -module.exports = WebGLState; - -},{"./utils/mapWebGLBlendModesToPixi":81}],70:[function(require,module,exports){ -var extractUniformsFromSrc = require('./extractUniformsFromSrc'); -// var math = require('../../../math'); -/** - * @class - * @memberof PIXI - * @extends PIXI.Shader - * @param shaderManager {PIXI.ShaderManager} The webgl shader manager this shader works for. - * @param [vertexSrc] {string} The source of the vertex shader. - * @param [fragmentSrc] {string} The source of the fragment shader. - * @param [customUniforms] {object} Custom uniforms to use to augment the built-in ones. - * @param [fragmentSrc] {string} The source of the fragment shader. - */ -function Filter(vertexSrc, fragmentSrc, uniforms) -{ - - /** - * The vertex shader. - * - * @member {string} - */ - this.vertexSrc = vertexSrc || Filter.defaultVertexSrc; - - /** - * The fragment shader. - * - * @member {string} - */ - this.fragmentSrc = fragmentSrc || Filter.defaultFragmentSrc; - - // pull out the vertex and shader uniforms if they are not specified.. - // currently this does not extract structs only default types - this.uniformData = uniforms || extractUniformsFromSrc( this.vertexSrc, this.fragmentSrc, 'projectionMatrix|uSampler'); - - this.uniforms = {}; - - for (var i in this.uniformData) - { - this.uniforms[i] = this.uniformData[i].value; - } - - // this.uniforms = - // this is where we store shader references.. - // TODO we could cache this! - this.glShaders = []; - - // used for cacheing.. - this.glShaderKey = null; - - this.padding = 4; - this.resolution = 1; -} - -// constructor -Filter.prototype.constructor = Filter; -module.exports = Filter; - -// var tempMatrix = new math.Matrix(); - -Filter.prototype.apply = function(filterManager, input, output, clear) -{ - // --- // - // this.uniforms.filterMatrix = filterManager.calculateSpriteMatrix(tempMatrix, window.panda ); - - // do as you please! - - filterManager.applyFilter(this, input, output, clear); - - // or just do a regular render.. -}; - -/** - * The default vertex shader source - * - * @static - * @constant - */ -Filter.defaultVertexSrc = [ - 'precision lowp float;', - 'attribute vec2 aVertexPosition;', - 'attribute vec2 aTextureCoord;', - - 'uniform mat3 projectionMatrix;', - 'uniform mat3 filterMatrix;', - - 'varying vec2 vTextureCoord;', - 'varying vec2 vFilterCoord;', - - 'void main(void){', - ' gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);', - ' vFilterCoord = ( filterMatrix * vec3( aTextureCoord, 1.0) ).xy;', - ' vTextureCoord = aTextureCoord ;', - '}' -].join('\n'); - -/** - * The default fragment shader source - * - * @static - * @constant - */ -Filter.defaultFragmentSrc = [ - 'precision lowp float;', - - 'varying vec2 vTextureCoord;', - 'varying vec2 vFilterCoord;', - - 'uniform sampler2D uSampler;', - 'uniform sampler2D filterSampler;', - - 'void main(void){', - ' vec4 masky = texture2D(filterSampler, vFilterCoord);', - ' vec4 sample = texture2D(uSampler, vTextureCoord);', - ' vec4 color;', - ' if(mod(vFilterCoord.x, 1.0) > 0.5)', - ' {', - ' color = vec4(1.0, 0.0, 0.0, 1.0);', - ' }', - ' else', - ' {', - ' color = vec4(0.0, 1.0, 0.0, 1.0);', - ' }', - // ' gl_FragColor = vec4(mod(vFilterCoord.x, 1.5), vFilterCoord.y,0.0,1.0);', - ' gl_FragColor = mix(sample, masky, 0.5);', - ' gl_FragColor *= sample.a;', - '}' -].join('\n'); - -},{"./extractUniformsFromSrc":71}],71:[function(require,module,exports){ -var defaultValue = require('pixi-gl-core/lib/shader/defaultValue'); -var mapSize = require('pixi-gl-core/lib/shader/mapSize'); - -function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) -{ - var vertUniforms = extractUniformsFromString(vertexSrc, mask); - var fragUniforms = extractUniformsFromString(fragmentSrc, mask); - - return Object.assign(vertUniforms, fragUniforms); -} - - -function extractUniformsFromString(string) -{ - var maskRegex = new RegExp('^(projectionMatrix|uSampler|filterArea)$'); - - var uniforms = {}; - var nameSplit; - - - // clean the lines a little - remove extra spaces / teabs etc - // then split along ';' - var lines = string.replace(/\s+/g,' ') - .split(/\s*;\s*/); - - // loop through.. - for (var i = 0; i < lines.length; i++) - { - var line = lines[i].trim(); - - if(line.indexOf('uniform') > -1) - { - var splitLine = line.split(' '); - var type = splitLine[1]; - - var name = splitLine[2]; - var size = mapSize(type); - - if(name.indexOf('[') > -1) - { - // array! - nameSplit = name.split(/\[|\]/); - name = nameSplit[0]; - size *= Number(nameSplit[1]); - } - - if(!name.match(maskRegex)) - { - uniforms[name] = { - value:defaultValue(type, size), - name:name, - type:type - }; - } - } - } - - return uniforms; -} - -module.exports = extractUniformsFromSrc; - -},{"pixi-gl-core/lib/shader/defaultValue":24,"pixi-gl-core/lib/shader/mapSize":28}],72:[function(require,module,exports){ -var math = require('../../../math'); - -/* - * Calculates the mapped matrix - * @param filterArea {Rectangle} The filter area - * @param sprite {Sprite} the target sprite - * @param outputMatrix {Matrix} @alvin - */ -// TODO playing around here.. this is temporary - (will end up in the shader) -// thia returns a matrix that will normalise map filter cords in the filter to screen space -var calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) -{ - //var worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), - // var texture = {width:1136, height:700};//sprite._texture.baseTexture; - - // TODO unwrap? - var mappedMatrix = outputMatrix.identity(); - - mappedMatrix.translate(filterArea.x / textureSize.width, filterArea.y / textureSize.height ); - - mappedMatrix.scale( textureSize.width , textureSize.height ); - - return mappedMatrix; - -}; - -var calculateNormalisedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) -{ - //var worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), - var texture = {width:800, height:600};//sprite._texture.baseTexture; - - // TODO unwrap? - var mappedMatrix = outputMatrix.identity(); - - // scale.. - var ratio = textureSize.height / textureSize.width; - - mappedMatrix.translate(filterArea.x / textureSize.width, filterArea.y / textureSize.height ); - - mappedMatrix.scale(1 , ratio); - - var translateScaleX = (textureSize.width / texture.width); - var translateScaleY = (textureSize.height / texture.height); - - // worldTransform.tx /= texture.width * translateScaleX; - - //this...? free beer for anyone who can explain why this makes sense! - // worldTransform.ty /= texture.width * translateScaleX; - // worldTransform.ty /= texture.height * translateScaleY; - - // worldTransform.invert(); - // mappedMatrix.prepend(worldTransform); - - // apply inverse scale.. - mappedMatrix.scale(1 , 1/ratio); - - mappedMatrix.scale( translateScaleX , translateScaleY ); - - // mappedMatrix.translate(sprite.anchor.x, sprite.anchor.y); - - return mappedMatrix; - -}; - -// this will map the filter coord so that a texture can be used based on the transform of a sprite -var calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) -{ - var worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), - texture = sprite._texture.baseTexture; - - // TODO unwrap? - var mappedMatrix = outputMatrix.identity(); - - // scale.. - var ratio = textureSize.height / textureSize.width; - - mappedMatrix.translate(filterArea.x / textureSize.width, filterArea.y / textureSize.height ); - - mappedMatrix.scale(1 , ratio); - - var translateScaleX = (textureSize.width / texture.width); - var translateScaleY = (textureSize.height / texture.height); - - worldTransform.tx /= texture.width * translateScaleX; - - //this...? free beer for anyone who can explain why this makes sense! - worldTransform.ty /= texture.width * translateScaleX; - // worldTransform.ty /= texture.height * translateScaleY; - - worldTransform.invert(); - mappedMatrix.prepend(worldTransform); - - // apply inverse scale.. - mappedMatrix.scale(1 , 1/ratio); - - mappedMatrix.scale( translateScaleX , translateScaleY ); - - mappedMatrix.translate(sprite.anchor.x, sprite.anchor.y); - - return mappedMatrix; -}; - -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalisedScreenSpaceMatrix:calculateNormalisedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; - -},{"../../../math":54}],73:[function(require,module,exports){ -var Filter = require('../Filter'), - math = require('../../../../math'); - -// @see https://github.com/substack/brfs/issues/25 - -/** - * The SpriteMaskFilter class - * - * @class - * @extends PIXI.AbstractFilter - * @memberof PIXI - * @param sprite {PIXI.Sprite} the target sprite - */ -function SpriteMaskFilter(sprite) -{ - var maskMatrix = new math.Matrix(); - - Filter.call(this, - "#define GLSLIFY 1\nattribute vec2 aVertexPosition;\n\nattribute vec2 aTextureCoord;\n\nuniform mat3 projectionMatrix;\n\nuniform mat3 otherMatrix;\n\nvarying vec2 vMaskCoord;\n\nvarying vec2 vTextureCoord;\n\nvoid main(void)\n\n{\n\n gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\n\n vTextureCoord = aTextureCoord;\n\n vMaskCoord = ( otherMatrix * vec3( aTextureCoord, 1.0) ).xy;\n\n}\n\n", - "precision lowp float;\n#define GLSLIFY 1\n\nvarying vec2 vMaskCoord;\n\nvarying vec2 vTextureCoord;\n\nuniform sampler2D uSampler;\n\nuniform float alpha;\n\nuniform sampler2D mask;\n\nvoid main(void)\n\n{\n\n // check clip! this will stop the mask bleeding out from the edges\r\n vec2 text = abs( vMaskCoord - 0.5 );\n\n text = step(0.5, text);\n\n float clip = 1.0 - max(text.y, text.x);\n\n vec4 original = texture2D(uSampler, vTextureCoord);\n\n vec4 masky = texture2D(mask, vMaskCoord);\n\n original *= (masky.r * masky.a * alpha * clip);\n\n gl_FragColor = original;\n\n}\n\n" - ); - - sprite.renderable = false; - - this.maskSprite = sprite; - this.maskMatrix = maskMatrix; -} - -SpriteMaskFilter.prototype = Object.create(Filter.prototype); -SpriteMaskFilter.prototype.constructor = SpriteMaskFilter; -module.exports = SpriteMaskFilter; - -/** - * Applies the filter - * - * @param renderer {PIXI.WebGLRenderer} The renderer to retrieve the filter from - * @param input {PIXI.RenderTarget} - * @param output {PIXI.RenderTarget} - */ -SpriteMaskFilter.prototype.apply = function (filterManager, input, output) -{ - var maskSprite = this.maskSprite; - - this.uniforms.mask = maskSprite._texture; - this.uniforms.otherMatrix = filterManager.calculateSpriteMatrix(this.maskMatrix, maskSprite ); - this.uniforms.alpha = maskSprite.worldAlpha; - - filterManager.applyFilter(this, input, output); -}; - -},{"../../../../math":54,"../Filter":70}],74:[function(require,module,exports){ - -var WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('pixi-gl-core').GLShader, - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -var FilterState = function() -{ - this.renderTarget = null; - this.sourceFrame = new math.Rectangle(); - this.destinationFrame = new math.Rectangle(); - this.filters = []; - this.target = null; - this.resolution = 1; -}; - -FilterManager.pool = {}; - -/** - * @class - * @memberof PIXI - * @extends PIXI.WebGLManager - * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. - */ -function FilterManager(renderer) -{ - WebGLManager.call(this, renderer); - - this.gl = this.renderer.gl; - // know about sprites! - this.quad = new Quad(this.gl, renderer.state.attribState); - - var rootState = new FilterState(); - rootState.sourceFrame = rootState.destinationFrame = this.renderer.rootRenderTarget.size; - rootState.renderTarget = renderer.rootRenderTarget; - - this.stack = [rootState]; - - this.stackIndex = 0; - - this.shaderCache = {}; - // todo add default! -} - -FilterManager.prototype = Object.create(WebGLManager.prototype); -FilterManager.prototype.constructor = FilterManager; -module.exports = FilterManager; - -FilterManager.prototype.pushFilter = function(target, filters) -{ - var renderer = this.renderer; - - // get the current filter state.. - var currentState = this.stack[++this.stackIndex]; - if(!currentState) - { - currentState = this.stack[this.stackIndex] = new FilterState(); - } - - // for now we go off the filter of the first resolution.. - var resolution = filters[0].resolution; - var padding = filters[0].padding; - - var targetBounds = target.filterArea || target.getBounds(); - - var sourceFrame = currentState.sourceFrame; - var destinationFrame = currentState.destinationFrame; - - - - - - sourceFrame.x = ((targetBounds.x * resolution) | 0) / resolution; - sourceFrame.y = ((targetBounds.y * resolution) | 0) / resolution; - sourceFrame.width = ((targetBounds.width * resolution) | 0) / resolution; - sourceFrame.height = ((targetBounds.height * resolution) | 0) / resolution; - - sourceFrame.pad(padding * resolution); - sourceFrame.fit(this.stack[0].destinationFrame); - - destinationFrame.width = sourceFrame.width; - destinationFrame.height = sourceFrame.height; - - var renderTarget = FilterManager.getPotRenderTarget(renderer.gl, sourceFrame.width, sourceFrame.height, resolution); - - currentState.target = target; - currentState.filters = filters; - currentState.resolution = resolution; - currentState.renderTarget = renderTarget; - - // bind the render taget to draw the shape in the top corner.. - - renderTarget.setFrame(destinationFrame, sourceFrame); - // bind the render target - renderer.bindRenderTarget(renderTarget); - - // clear the renderTarget - renderer.clear();//[0.5,0.5,0.5, 1.0]); -}; - -FilterManager.prototype.popFilter = function() -{ - var lastState = this.stack[this.stackIndex-1]; - var currentState = this.stack[this.stackIndex]; - - this.quad.map(currentState.renderTarget.size, currentState.sourceFrame).upload(); - - var filters = currentState.filters; - - if(filters.length === 1) - { - filters[0].apply(this, currentState.renderTarget, lastState.renderTarget, false); - FilterManager.freePotRenderTarget(currentState.renderTarget); - } - else - { - var flip = currentState.renderTarget; - var flop = FilterManager.getPotRenderTarget(this.renderer.gl, currentState.sourceFrame.width, currentState.sourceFrame.height, 1); - flop.setFrame(currentState.destinationFrame, currentState.sourceFrame); - - for (var i = 0; i < filters.length-1; i++) - { - filters[i].apply(this, flip, flop, true); - - var t = flip; - flip = flop; - flop = t; - } - - filters[i].apply(this, flip, lastState.renderTarget, false); - - FilterManager.freePotRenderTarget(flip); - FilterManager.freePotRenderTarget(flop); - } - - this.stackIndex--; -}; - -FilterManager.prototype.applyFilter = function (filter, input, output, clear) -{ - var renderer = this.renderer; - var shader = filter.glShaders[renderer.CONTEXT_UID]; - - // cacheing.. - if(!shader) - { - if(filter.glShaderKey) - { - shader = this.shaderCache[filter.glShaderKey]; - - if(!shader) - { - shader = filter.glShaders[renderer.CONTEXT_UID] = this.shaderCache[filter.glShaderKey] = new Shader(this.gl, filter.vertexSrc, filter.fragmentSrc); - } - } - else - { - shader = filter.glShaders[renderer.CONTEXT_UID] = new Shader(this.gl, filter.vertexSrc, filter.fragmentSrc); - } - - //TODO - this only needs to be done once? - this.quad.initVao(shader); - } - - renderer.bindRenderTarget(output); - - if(clear) - { - renderer.clear();//[1, 1, 1, 1]); - } - - renderer.bindShader(shader); - - // this syncs the pixi filters uniforms with glsl uniforms - this.syncUniforms(shader, filter); - - // bind the input texture.. - input.texture.bind(0); - - this.quad.draw(); -}; - -// thia returns a matrix that will normalise map filter cords in the filter to screen space -FilterManager.prototype.syncUniforms = function (shader, filter) -{ - var uniformData = filter.uniformData; - var uniforms = filter.uniforms; - - // 0 is reserverd for the pixi texture so we start at 1! - var textureCount = 1; - - if(shader.uniforms.data.filterArea) - { - var currentState = this.stack[this.stackIndex]; - var filterArea = shader.uniforms.filterArea; - - filterArea[0] = currentState.renderTarget.size.width; - filterArea[1] = currentState.renderTarget.size.height; - filterArea[2] = currentState.sourceFrame.x; - filterArea[3] = currentState.sourceFrame.y; - - shader.uniforms.filterArea = filterArea; - } - - var val; - //TODO Cacheing layer.. - for(var i in uniformData) - { - if(uniformData[i].type === 'sampler2D') - { - shader.uniforms[i] = textureCount; - this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); - - textureCount++; - } - else if(uniformData[i].type === 'mat3') - { - // check if its pixi matrix.. - if(uniforms[i].a) - { - shader.uniforms[i] = uniforms[i].toArray(true); - } - else - { - shader.uniforms[i] = uniforms[i]; - } - } - else if(uniformData[i].type === 'vec2') - { - //check if its a point.. - if(uniforms[i].x) - { - val = shader.uniforms[i]; - val[0] = uniforms[i].x; - val[1] = uniforms[i].y; - shader.uniforms[i] = val; - } - else - { - shader.uniforms[i] = uniforms[i]; - } - } - else if(uniformData[i].type === 'float') - { - if(shader.uniforms.data[i].value !== uniformData[i]) - { - shader.uniforms[i] = uniforms[i]; - } - } - else - { - shader.uniforms[i] = uniforms[i]; - } - } -}; - - -FilterManager.prototype.getRenderTarget = function() -{ - var currentState = this.stack[this.stackIndex]; - var renderTarget = FilterManager.getPotRenderTarget(this.renderer.gl, currentState.sourceFrame.width, currentState.sourceFrame.height, currentState.resolution); - renderTarget.setFrame(currentState.destinationFrame, currentState.sourceFrame); - - return renderTarget; -}; - -FilterManager.prototype.returnRenderTarget = function(renderTarget) -{ - return FilterManager.freePotRenderTarget(renderTarget); -}; - -/* - * Calculates the mapped matrix - * @param filterArea {Rectangle} The filter area - * @param sprite {Sprite} the target sprite - * @param outputMatrix {Matrix} @alvin - */ -// TODO playing around here.. this is temporary - (will end up in the shader) -// thia returns a matrix that will normalise map filter cords in the filter to screen space -FilterManager.prototype.calculateScreenSpaceMatrix = function (outputMatrix) -{ - var currentState = this.stack[this.stackIndex]; - return filterTransforms.calculateScreenSpaceMatrix(outputMatrix, currentState.sourceFrame, currentState.renderTarget.size); -}; - -FilterManager.prototype.calculateNormalisedScreenSpaceMatrix = function (outputMatrix) -{ - var currentState = this.stack[this.stackIndex]; - - - - return filterTransforms.calculateNormalisedScreenSpaceMatrix(outputMatrix, currentState.sourceFrame, currentState.renderTarget.size, currentState.destinationFrame); -}; - -// this will map the filter coord so that a texture can be used based on the transform of a sprite -FilterManager.prototype.calculateSpriteMatrix = function (outputMatrix, sprite) -{ - var currentState = this.stack[this.stackIndex]; - return filterTransforms.calculateSpriteMatrix(outputMatrix, currentState.sourceFrame, currentState.renderTarget.size, sprite); -}; - -FilterManager.prototype.destroy = function() -{ -}; - -//TODO move to a seperate class could be on renderer? -//also - could cause issue with multiple contexts? -FilterManager.getPotRenderTarget = function(gl, minWidth, minHeight, resolution) -{ - //TODO you coud return a bigger texture if there is not one in the pool? - minWidth = bitTwiddle.nextPow2(minWidth * resolution); - minHeight = bitTwiddle.nextPow2(minHeight * resolution); - - var key = ((minWidth & 0xFFFF) << 16) | ( minHeight & 0xFFFF); - - // console.log(minWidth + " " + minHeight) - if(!FilterManager.pool[key]) { - FilterManager.pool[key] = []; - } - - var renderTarget = FilterManager.pool[key].pop() || new RenderTarget(gl, minWidth, minHeight, null, 1); - - //manually tweak the resolution... - //this will not modify the size of the frame buffer, just its resolution. - renderTarget.resolution = resolution; - renderTarget.defaultFrame.width = renderTarget.size.width = minWidth / resolution; - renderTarget.defaultFrame.height = renderTarget.size.height = minHeight / resolution; - - return renderTarget; -}; - -FilterManager.freePotRenderTarget = function(renderTarget) -{ - var minWidth = renderTarget.size.width * renderTarget.resolution; - var minHeight = renderTarget.size.height * renderTarget.resolution; - - var key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); - FilterManager.pool[key].push(renderTarget); -}; - -},{"../../../math":54,"../filters/filterTransforms":72,"../utils/Quad":79,"../utils/RenderTarget":80,"./WebGLManager":77,"bit-twiddle":3,"pixi-gl-core":15}],75:[function(require,module,exports){ -var WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); - -/** - * @class - * @memberof PIXI - * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. - */ -function MaskManager(renderer) -{ - WebGLManager.call(this, renderer); - - this.scissor = false; - - this.enableScissor = true; - - this.alphaMaskPool = []; - this.alphaMaskIndex = 0; -} - -MaskManager.prototype = Object.create(WebGLManager.prototype); -MaskManager.prototype.constructor = MaskManager; -module.exports = MaskManager; - -/** - * Applies the Mask and adds it to the current filter stack. - * - * @param graphics {PIXI.Graphics} - * @param webGLData {any[]} - */ -MaskManager.prototype.pushMask = function (target, maskData) -{ - if (maskData.texture) - { - this.pushSpriteMask(target, maskData); - } - else - { - // console.log( maskData.graphicsData[0].shape.type) - if(this.enableScissor && !this.scissor && !this.renderer.stencilManager.stencilMaskStack.length && maskData.graphicsData[0].shape.type === 1) - { - var matrix = maskData.worldTransform; - - var rot = Math.atan2(matrix.b, matrix.a); - - // use the nearest degree! - rot = Math.round(rot * (180/Math.PI)); - - if(rot % 90) - { - this.pushStencilMask(maskData); - } - else - { - this.pushScissorMask(target, maskData); - } - } - else - { - this.pushStencilMask(maskData); - } - } -}; - -/** - * Removes the last mask from the mask stack and doesn't return it. - * - * @param target {PIXI.RenderTarget} - * @param maskData {any[]} - */ -MaskManager.prototype.popMask = function (target, maskData) -{ - if (maskData.texture) - { - this.popSpriteMask(target, maskData); - } - else - { - if(this.enableScissor && !this.renderer.stencilManager.stencilMaskStack.length) - { - this.popScissorMask(target, maskData); - } - else - { - this.popStencilMask(target, maskData); - } - - } -}; - -/** - * Applies the Mask and adds it to the current filter stack. - * - * @param target {PIXI.RenderTarget} - * @param maskData {any[]} - */ -MaskManager.prototype.pushSpriteMask = function (target, maskData) -{ - var alphaMaskFilter = this.alphaMaskPool[this.alphaMaskIndex]; - - if (!alphaMaskFilter) - { - alphaMaskFilter = this.alphaMaskPool[this.alphaMaskIndex] = [new AlphaMaskFilter(maskData)]; - } - - alphaMaskFilter[0].maskSprite = maskData; - - //TODO - may cause issues! - target.filterArea = maskData.getBounds(); - - this.renderer.filterManager.pushFilter(target, alphaMaskFilter); - - this.alphaMaskIndex++; -}; - -/** - * Removes the last filter from the filter stack and doesn't return it. - * - */ -MaskManager.prototype.popSpriteMask = function () -{ - this.renderer.filterManager.popFilter(); - this.alphaMaskIndex--; -}; - - -/** - * Applies the Mask and adds it to the current filter stack. - * - * @param target {PIXI.RenderTarget} - * @param maskData {any[]} - */ -MaskManager.prototype.pushStencilMask = function (maskData) -{ - this.renderer.currentRenderer.stop(); - this.renderer.stencilManager.pushStencil(maskData); -}; - -/** - * Removes the last filter from the filter stack and doesn't return it. - * - * @param target {PIXI.RenderTarget} - * @param maskData {any[]} - */ -MaskManager.prototype.popStencilMask = function () -{ - this.renderer.currentRenderer.stop(); - this.renderer.stencilManager.popStencil(); -}; - -MaskManager.prototype.pushScissorMask = function (target, maskData) -{ - maskData.renderable = true; - - var renderTarget = this.renderer._activeRenderTarget; - - var bounds = maskData.getBounds(); - bounds.fit(renderTarget.size); - maskData.renderable = false; - - this.renderer.gl.enable(this.renderer.gl.SCISSOR_TEST); - - this.renderer.gl.scissor(bounds.x, - renderTarget.root ? renderTarget.size.height - bounds.y - bounds.height : bounds.y, - bounds.width , - bounds.height); - - this.scissor = true; -}; - -MaskManager.prototype.popScissorMask = function () -{ - this.scissor = false; - // must be scissor! - var gl = this.renderer.gl; - gl.disable(gl.SCISSOR_TEST); -}; - -},{"../filters/spriteMask/SpriteMaskFilter":73,"./WebGLManager":77}],76:[function(require,module,exports){ -var WebGLManager = require('./WebGLManager'); - -/** - * @class - * @memberof PIXI - * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. - */ -function StencilMaskManager(renderer) -{ - WebGLManager.call(this, renderer); - this.stencilMaskStack = null; -} - -StencilMaskManager.prototype = Object.create(WebGLManager.prototype); -StencilMaskManager.prototype.constructor = StencilMaskManager; -module.exports = StencilMaskManager; - -/** - * Changes the mask stack that is used by this manager. - * - * @param stencilMaskStack {PIXI.StencilMaskStack} The mask stack - */ -StencilMaskManager.prototype.setMaskStack = function ( stencilMaskStack ) -{ - this.stencilMaskStack = stencilMaskStack; - - var gl = this.renderer.gl; - - if (stencilMaskStack.length === 0) - { - gl.disable(gl.STENCIL_TEST); - } - else - { - gl.enable(gl.STENCIL_TEST); - } -}; - -/** - * Applies the Mask and adds it to the current filter stack. @alvin - * - * @param graphics {PIXI.Graphics} - * @param webGLData {any[]} - */ -StencilMaskManager.prototype.pushStencil = function (graphics) -{ - this.renderer.setObjectRenderer(this.renderer.plugins.graphics); - - this.renderer._activeRenderTarget.attachStencilBuffer(); - - var gl = this.renderer.gl, - sms = this.stencilMaskStack; - - if (sms.length === 0) - { - gl.enable(gl.STENCIL_TEST); - gl.clear(gl.STENCIL_BUFFER_BIT); - gl.stencilFunc(gl.ALWAYS,1,1); - } - - sms.push(graphics); - - gl.colorMask(false, false, false, false); - gl.stencilOp(gl.KEEP,gl.KEEP,gl.INCR); - - this.renderer.plugins.graphics.render(graphics); - - gl.colorMask(true, true, true, true); - gl.stencilFunc(gl.NOTEQUAL,0, sms.length); - gl.stencilOp(gl.KEEP,gl.KEEP,gl.KEEP); -}; - -/** - * TODO @alvin - * @param graphics {PIXI.Graphics} - * @param webGLData {any[]} - */ -StencilMaskManager.prototype.popStencil = function () -{ - this.renderer.setObjectRenderer(this.renderer.plugins.graphics); - - var gl = this.renderer.gl, - sms = this.stencilMaskStack; - - var graphics = sms.pop(); - - if (sms.length === 0) - { - // the stack is empty! - gl.disable(gl.STENCIL_TEST); - } - else - { - gl.colorMask(false, false, false, false); - gl.stencilOp(gl.KEEP,gl.KEEP,gl.DECR); - - this.renderer.plugins.graphics.render(graphics); - - gl.colorMask(true, true, true, true); - gl.stencilFunc(gl.NOTEQUAL, 0, sms.length); - gl.stencilOp(gl.KEEP,gl.KEEP,gl.KEEP); - } -}; - -/** - * Destroys the mask stack. - * - */ -StencilMaskManager.prototype.destroy = function () -{ - WebGLManager.prototype.destroy.call(this); - - this.stencilMaskStack.stencilStack = null; -}; - -},{"./WebGLManager":77}],77:[function(require,module,exports){ -/** - * @class - * @memberof PIXI - * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. - */ -function WebGLManager(renderer) -{ - /** - * The renderer this manager works for. - * - * @member {PIXI.WebGLRenderer} - */ - this.renderer = renderer; - - this.renderer.on('context', this.onContextChange, this); -} - -WebGLManager.prototype.constructor = WebGLManager; -module.exports = WebGLManager; - -/** - * Generic method called when there is a WebGL context change. - * - */ -WebGLManager.prototype.onContextChange = function () -{ - // do some codes init! -}; - -/** - * Generic destroy methods to be overridden by the subclass - * - */ -WebGLManager.prototype.destroy = function () -{ - this.renderer.off('context', this.onContextChange, this); - - this.renderer = null; -}; - -},{}],78:[function(require,module,exports){ -var WebGLManager = require('../managers/WebGLManager'); - -/** - * Base for a common object renderer that can be used as a system renderer plugin. - * - * @class - * @extends PIXI.WebGLManager - * @memberof PIXI - * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. - */ -function ObjectRenderer(renderer) -{ - WebGLManager.call(this, renderer); -} - - -ObjectRenderer.prototype = Object.create(WebGLManager.prototype); -ObjectRenderer.prototype.constructor = ObjectRenderer; -module.exports = ObjectRenderer; - -/** - * Starts the renderer and sets the shader - * - */ -ObjectRenderer.prototype.start = function () -{ - // set the shader.. -}; - -/** - * Stops the renderer - * - */ -ObjectRenderer.prototype.stop = function () -{ - this.flush(); -}; - -/** - * flushes - * - */ -ObjectRenderer.prototype.flush = function () -{ - // flush! -}; - -/** - * Renders an object - * - * @param object {PIXI.DisplayObject} The object to render. - */ -ObjectRenderer.prototype.render = function (object) // jshint unused:false -{ - // render the object -}; - -},{"../managers/WebGLManager":77}],79:[function(require,module,exports){ -var glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); - -/** - * Helper class to create a quad - * - * @class - * @memberof PIXI - * @param gl {WebGLRenderingContext} The gl context for this quad to use. - */ -function Quad(gl, state) -{ - /* - * the current WebGL drawing context - * - * @member {WebGLRenderingContext} - */ - this.gl = gl; - - /** - * An array of vertices - * - * @member {Float32Array} - */ - this.vertices = new Float32Array([ - -1,-1, - 1,-1, - 1,1, - -1,1 - ]); - - /** - * The Uvs of the quad - * - * @member {Float32Array} - */ - this.uvs = new Float32Array([ - 0,0, - 1,0, - 1,1, - 0,1 - ]); - - this.interleaved = new Float32Array(8 * 2); - - for (var i = 0; i < 4; i++) { - this.interleaved[i*4] = this.vertices[(i*2)]; - this.interleaved[(i*4)+1] = this.vertices[(i*2)+1]; - this.interleaved[(i*4)+2] = this.uvs[i*2]; - this.interleaved[(i*4)+3] = this.uvs[(i*2)+1]; - } - - /* - * @member {Uint16Array} An array containing the indices of the vertices - */ - this.indices = createIndicesForQuads(1); - - /* - * @member {glCore.GLBuffer} The vertex buffer - */ - this.vertexBuffer = glCore.GLBuffer.createVertexBuffer(gl, this.interleaved, gl.STATIC_DRAW); - - /* - * @member {glCore.GLBuffer} The index buffer - */ - this.indexBuffer = glCore.GLBuffer.createIndexBuffer(gl, this.indices, gl.STATIC_DRAW); - - /* - * @member {glCore.VertexArrayObject} The index buffer - */ - this.vao = new glCore.VertexArrayObject(gl, state) - -} - -Quad.prototype.constructor = Quad; - -/** - * Initialises the vaos and uses the shader - * @param shader {PIXI.Shader} the shader to use - */ -Quad.prototype.initVao = function(shader) -{ - this.vao.clear() - .addIndex(this.indexBuffer) - .addAttribute(this.vertexBuffer, shader.attributes.aVertexPosition, this.gl.FLOAT, false, 4 * 4, 0) - .addAttribute(this.vertexBuffer, shader.attributes.aTextureCoord, this.gl.FLOAT, false, 4 * 4, 2 * 4); -}; - -/** - * Maps two Rectangle to the quad - * @param rect {PIXI.Rectangle} the first rectangle - * @param rect2 {PIXI.Rectangle} the second rectangle - */ -Quad.prototype.map = function(targetTextureFrame, destinationFrame) -{ - var x = 0; //destinationFrame.x / targetTextureFrame.width; - var y = 0; //destinationFrame.y / targetTextureFrame.height; - - this.uvs[0] = x; - this.uvs[1] = y; - - this.uvs[2] = x + destinationFrame.width / targetTextureFrame.width; - this.uvs[3] = y; - - this.uvs[4] = x + destinationFrame.width / targetTextureFrame.width; - this.uvs[5] = y + destinationFrame.height / targetTextureFrame.height; - - this.uvs[6] = x; - this.uvs[7] = y + destinationFrame.height / targetTextureFrame.height; - - /// ----- - x = destinationFrame.x; - y = destinationFrame.y; - - this.vertices[0] = x; - this.vertices[1] = y; - - this.vertices[2] = x + destinationFrame.width; - this.vertices[3] = y; - - this.vertices[4] = x + destinationFrame.width; - this.vertices[5] = y + destinationFrame.height; - - this.vertices[6] = x; - this.vertices[7] = y + destinationFrame.height; - - return this; -}; - -/** - * Draws the quad - */ -Quad.prototype.draw = function() -{ - this.vao.bind() - .draw(this.gl.TRIANGLES, 6, 0) - .unbind(); - - return this; -}; - -/** - * Binds the buffer and uploads the data - */ -Quad.prototype.upload = function() -{ - for (var i = 0; i < 4; i++) { - this.interleaved[i*4] = this.vertices[(i*2)]; - this.interleaved[(i*4)+1] = this.vertices[(i*2)+1]; - this.interleaved[(i*4)+2] = this.uvs[i*2]; - this.interleaved[(i*4)+3] = this.uvs[(i*2)+1]; - } - - this.vertexBuffer.upload(this.interleaved); - - return this; -}; - -/** - * Removes this quad from WebGL - */ -Quad.prototype.destroy = function() -{ - var gl = this.gl; - - gl.deleteBuffer(this.vertexBuffer); - gl.deleteBuffer(this.indexBuffer); -}; - -module.exports = Quad; - -},{"../../../utils/createIndicesForQuads":98,"pixi-gl-core":15}],80:[function(require,module,exports){ -var math = require('../../../math'), - CONST = require('../../../const'), - GLTexture = require('pixi-gl-core').GLTexture, - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * @class - * @memberof PIXI - * @param gl {WebGLRenderingContext} the current WebGL drawing context - * @param width {number} the horizontal range of the filter - * @param height {number} the vertical range of the filter - * @param scaleMode {number} See {@link PIXI.SCALE_MODES} for possible values - * @param resolution {number} the current resolution - * @param root {boolean} Whether this object is the root element or not - */ -var RenderTarget = function(gl, width, height, scaleMode, resolution, root) -{ - //TODO Resolution could go here ( eg low res blurs ) - - /** - * The current WebGL drawing context. - * - * @member {WebGLRenderingContext} - */ - this.gl = gl; - - // next time to create a frame buffer and texture - - /** - * A frame buffer - * - * @member {WebGLFrameBuffer} - */ - this.frameBuffer = null; - - /** - * The texture - * - * @member {PIXI.Texture} - */ - this.texture = null; - - /** - * The background colour of this render target, as an array of [r,g,b,a] values - * - * @member {array} - */ - this.clearColor = [0, 0, 0, 0]; - - /** - * The size of the object as a rectangle - * - * @member {PIXI.Rectangle} - */ - this.size = new math.Rectangle(0, 0, 1, 1); - - /** - * The current resolution - * - * @member {number} - */ - this.resolution = resolution || CONST.RESOLUTION; - - /** - * The projection matrix - * - * @member {PIXI.Matrix} - */ - this.projectionMatrix = new math.Matrix(); - - /** - * The object's transform - * - * @member {PIXI.Matrix} - */ - this.transform = null; - - /** - * The frame. - * - * @member {PIXI.Rectangle} - */ - this.frame = null; - - /** - * The stencil buffer stores masking data for the render target - * - * @member {WebGLRenderBuffer} - */ - this.defaultFrame = new PIXI.Rectangle(); - this.destinationFrame = null; - this.sourceFrame = null; - - /** - * The stencil buffer stores masking data for the render target - * - * @member {WebGLRenderBuffer} - */ - this.stencilBuffer = null; - - /** - * The data structure for the stencil masks - * - * @member {PIXI.StencilMaskStack} - */ - this.stencilMaskStack = []; - - /** - * Stores filter data for the render target - * - * @member {object[]} - */ - this.filterStack = [ - { - renderTarget:this, - filter:[], - bounds:this.size - } - ]; - - - /** - * The scale mode. - * - * @member {number} - * @default PIXI.SCALE_MODES.DEFAULT - * @see PIXI.SCALE_MODES - */ - this.scaleMode = scaleMode || CONST.SCALE_MODES.DEFAULT; - - /** - * Whether this object is the root element or not - * - * @member {boolean} - */ - this.root = root; - - - if (!this.root) - { - this.frameBuffer = GLFramebuffer.createRGBA(gl, 100, 100); - - if( this.scaleMode === CONST.SCALE_MODES.NEAREST) - { - this.frameBuffer.texture.enableNearestScaling(); - } - else - { - this.frameBuffer.texture.enableLinearScaling(); - - } - /* - A frame buffer needs a target to render to.. - create a texture and bind it attach it to the framebuffer.. - */ - - // this is used by the base texture - this.texture = this.frameBuffer.texture; - } - else - { - // make it a null framebuffer.. - this.frameBuffer = new GLFramebuffer(gl, 100, 100); - this.frameBuffer.framebuffer = null; - - } - - this.setFrame(); - - this.resize(width, height); -}; - -RenderTarget.prototype.constructor = RenderTarget; -module.exports = RenderTarget; - -/** - * Clears the filter texture. - * - * @param [bind=false] {boolean} Should we bind our framebuffer before clearing? - */ -RenderTarget.prototype.clear = function(clearColor) -{ - var cc = clearColor || this.clearColor; - this.frameBuffer.clear(cc[0],cc[1],cc[2],cc[3]);//r,g,b,a); -}; - -/** - * Binds the stencil buffer. - * - */ -RenderTarget.prototype.attachStencilBuffer = function() -{ - //TODO check if stencil is done? - /** - * The stencil buffer is used for masking in pixi - * lets create one and then add attach it to the framebuffer.. - */ - if (!this.root) - { - this.frameBuffer.enableStencil(); - } -}; - -RenderTarget.prototype.setFrame = function(destinationFrame, sourceFrame) -{ - this.destinationFrame = destinationFrame || this.destinationFrame || this.defaultFrame; - this.sourceFrame = sourceFrame || this.sourceFrame || destinationFrame; -}; - -/** - * Binds the buffers and initialises the viewport. - * - */ -RenderTarget.prototype.activate = function() -{ - //TOOD refactor usage of frame.. - var gl = this.gl; - - // make surethe texture is unbound! - this.frameBuffer.bind(); - - this.calculateProjection( this.destinationFrame, this.sourceFrame ); - - if(this.transform) - { - this.projectionMatrix.append(this.transform); - } - - //TODO add a check as them may be the same! - if(this.destinationFrame !== this.sourceFrame) - { - - gl.enable(gl.SCISSOR_TEST); - gl.scissor(this.destinationFrame.x | 0,this.destinationFrame.y | 0, (this.destinationFrame.width * this.resolution) | 0, (this.destinationFrame.height* this.resolution) | 0); - } - else - { - gl.disable(gl.SCISSOR_TEST); - } - - - // TODO - does not need to be updated all the time?? - gl.viewport(this.destinationFrame.x | 0,this.destinationFrame.y | 0, (this.destinationFrame.width * this.resolution) | 0, (this.destinationFrame.height * this.resolution)|0); - - -}; - - -/** - * Updates the projection matrix based on a projection frame (which is a rectangle) - * - */ -RenderTarget.prototype.calculateProjection = function (destinationFrame, sourceFrame) -{ - var pm = this.projectionMatrix; - - sourceFrame = sourceFrame || destinationFrame; - - pm.identity(); - - // TODO: make dest scale source - if (!this.root) - { - pm.a = 1 / destinationFrame.width*2; - pm.d = 1 / destinationFrame.height*2; - - pm.tx = -1 - sourceFrame.x * pm.a; - pm.ty = -1 - sourceFrame.y * pm.d; - } - else - { - pm.a = 1 / destinationFrame.width*2; - pm.d = -1 / destinationFrame.height*2; - - pm.tx = -1 - sourceFrame.x * pm.a; - pm.ty = 1 - sourceFrame.y * pm.d; - } -}; - - -/** - * Resizes the texture to the specified width and height - * - * @param width {Number} the new width of the texture - * @param height {Number} the new height of the texture - */ -RenderTarget.prototype.resize = function (width, height) -{ - width = width | 0; - height = height | 0; - - if (this.size.width === width && this.size.height === height) - { - return; - } - - this.size.width = width; - this.size.height = height; - - this.defaultFrame.width = width; - this.defaultFrame.height = height; - - - this.frameBuffer.resize(width * this.resolution, height * this.resolution); - - var projectionFrame = this.frame || this.size; - - this.calculateProjection( projectionFrame ); -}; - -/** - * Destroys the render target. - * - */ -RenderTarget.prototype.destroy = function () -{ - this.frameBuffer.destroy(); - - this.frameBuffer = null; - this.texture = null; -}; - -},{"../../../const":33,"../../../math":54,"pixi-gl-core":15}],81:[function(require,module,exports){ -var CONST = require('../../../const'); - -/** - * Maps gl blend combinations to WebGL - * @class - * @memberof PIXI - */ -function mapWebGLBlendModesToPixi(gl, array) -{ - array = array || []; - - //TODO - premultiply alpha would be different. - //add a boolean for that! - array[CONST.BLEND_MODES.NORMAL] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; - array[CONST.BLEND_MODES.ADD] = [gl.SRC_ALPHA, gl.DST_ALPHA]; - array[CONST.BLEND_MODES.MULTIPLY] = [gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA]; - array[CONST.BLEND_MODES.SCREEN] = [gl.SRC_ALPHA, gl.ONE]; - array[CONST.BLEND_MODES.OVERLAY] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; - array[CONST.BLEND_MODES.DARKEN] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; - array[CONST.BLEND_MODES.LIGHTEN] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; - array[CONST.BLEND_MODES.COLOR_DODGE] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; - array[CONST.BLEND_MODES.COLOR_BURN] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; - array[CONST.BLEND_MODES.HARD_LIGHT] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; - array[CONST.BLEND_MODES.SOFT_LIGHT] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; - array[CONST.BLEND_MODES.DIFFERENCE] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; - array[CONST.BLEND_MODES.EXCLUSION] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; - array[CONST.BLEND_MODES.HUE] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; - array[CONST.BLEND_MODES.SATURATION] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; - array[CONST.BLEND_MODES.COLOR] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; - array[CONST.BLEND_MODES.LUMINOSITY] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; - - return array; -} - -module.exports = mapWebGLBlendModesToPixi; - -},{"../../../const":33}],82:[function(require,module,exports){ -var CONST = require('../../../const'); - -/** - * Generic Mask Stack data structure - * @class - * @memberof PIXI - */ -function mapWebGLDrawModesToPixi(gl, object) -{ - object= object || {}; - - object[CONST.DRAW_MODES.POINTS] = gl.POINTS; - object[CONST.DRAW_MODES.LINES] = gl.LINES; - object[CONST.DRAW_MODES.LINE_LOOP] = gl.LINE_LOOP; - object[CONST.DRAW_MODES.LINE_STRIP] = gl.LINE_STRIP; - object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; - object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; - object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - -} - -module.exports = mapWebGLDrawModesToPixi; - -},{"../../../const":33}],83:[function(require,module,exports){ -var math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); - -/** - * The Sprite object is the base for all textured objects that are rendered to the screen - * - * A sprite can be created directly from an image like this: - * - * ```js - * var sprite = new PIXI.Sprite.fromImage('assets/image.png'); - * ``` - * - * @class - * @extends PIXI.Container - * @memberof PIXI - * @param texture {PIXI.Texture} The texture for this sprite - */ -function Sprite(texture) -{ - Container.call(this); - - /** - * The anchor sets the origin point of the texture. - * The default is 0,0 this means the texture's origin is the top left - * Setting the anchor to 0.5,0.5 means the texture's origin is centered - * Setting the anchor to 1,1 would mean the texture's origin point will be the bottom right corner - * - * @member {PIXI.Point} - */ - this.anchor = new math.Point(); - - /** - * The texture that the sprite is using - * - * @member {PIXI.Texture} - * @private - */ - this._texture = null; - - /** - * The width of the sprite (this is initially set by the texture) - * - * @member {number} - * @private - */ - this._width = 0; - - /** - * The height of the sprite (this is initially set by the texture) - * - * @member {number} - * @private - */ - this._height = 0; - - /** - * The tint applied to the sprite. This is a hex value. A value of 0xFFFFFF will remove any tint effect. - * - * @member {number} - * @default 0xFFFFFF - */ - this.tint = 0xFFFFFF; - - /** - * The blend mode to be applied to the sprite. Apply a value of `PIXI.BLEND_MODES.NORMAL` to reset the blend mode. - * - * @member {number} - * @default PIXI.BLEND_MODES.NORMAL - * @see PIXI.BLEND_MODES - */ - this.blendMode = CONST.BLEND_MODES.NORMAL; - - /** - * The shader that will be used to render the sprite. Set to null to remove a current shader. - * - * @member {PIXI.AbstractFilter|PIXI.Shader} - */ - this.shader = null; - - /** - * An internal cached value of the tint. - * - * @member {number} - * @default 0xFFFFFF - */ - this.cachedTint = 0xFFFFFF; - - // call texture setter - this.texture = texture || Texture.EMPTY; - this.textureDirty = true; - this.vertexData = new Float32Array(8); -} - -// constructor -Sprite.prototype = Object.create(Container.prototype); -Sprite.prototype.constructor = Sprite; -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { - /** - * The width of the sprite, setting this will actually modify the scale to achieve the value set - * - * @member {number} - * @memberof PIXI.Sprite# - */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.crop.width; - }, - set: function (value) - { - var sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.crop.width; - this._width = value; - } - }, - - /** - * The height of the sprite, setting this will actually modify the scale to achieve the value set - * - * @member {number} - * @memberof PIXI.Sprite# - */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.crop.height; - }, - set: function (value) - { - var sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.crop.height; - this._height = value; - } - }, - - /** - * The texture that the sprite is using - * - * @member {PIXI.Texture} - * @memberof PIXI.Sprite# - */ - texture: { - get: function () - { - return this._texture; - }, - set: function (value) - { - if (this._texture === value) - { - return; - } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this.textureDirty = true; - - if (value) - { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } - } - } - } -}); - -/** - * When the texture is updated, this event will fire to update the scale and frame - * - * @private - */ -Sprite.prototype._onTextureUpdate = function () -{ - this.textureDirty = true; - - // so if _width is 0 then width was not set.. - if (this._width) - { - this.scale.x = utils.sign(this.scale.x) * this._width / this.texture.crop.width; - } - - if (this._height) - { - this.scale.y = utils.sign(this.scale.y) * this._height / this.texture.crop.height; - } -}; - -Sprite.prototype.caclulateVertices = function () -{ - var texture = this._texture, - wt = this.transform.worldTransform, - a = wt.a, b = wt.b, c = wt.c, d = wt.d, tx = wt.tx, ty = wt.ty, - vertexData = this.vertexData, - w0, w1, h0, h1, - trim = texture.trim, - crop = texture.crop; - - if (trim) - { - // if the sprite is trimmed and is not a tilingsprite then we need to add the extra space before transforming the sprite coords.. - w1 = trim.x - this.anchor.x * crop.width; - w0 = w1 + trim.width; - - h1 = trim.y - this.anchor.y * crop.height; - h0 = h1 + trim.height; - - } - else - { - w0 = (crop.width ) * (1-this.anchor.x); - w1 = (crop.width ) * -this.anchor.x; - - h0 = crop.height * (1-this.anchor.y); - h1 = crop.height * -this.anchor.y; - } - - // xy - vertexData[0] = a * w1 + c * h1 + tx; - vertexData[1] = d * h1 + b * w1 + ty; - - // xy - vertexData[2] = a * w0 + c * h1 + tx; - vertexData[3] = d * h1 + b * w0 + ty; - - // xy - vertexData[4] = a * w0 + c * h0 + tx; - vertexData[5] = d * h0 + b * w0 + ty; - - // xy - vertexData[6] = a * w1 + c * h0 + tx; - vertexData[7] = d * h0 + b * w1 + ty; -}; - -/** -* -* Renders the object using the WebGL renderer -* -* @param renderer {PIXI.WebGLRenderer} -* @private -*/ -Sprite.prototype._renderWebGL = function (renderer) -{ - if(this.transform.updated || this.textureDirty) - { - this.textureDirty = false; - // set the vertex data - this.caclulateVertices(); - } - - renderer.setObjectRenderer(renderer.plugins.sprite); - renderer.plugins.sprite.render(this); -}; - -/** -* Renders the object using the Canvas renderer -* -* @param renderer {PIXI.CanvasRenderer} The renderer -* @private -*/ -Sprite.prototype._renderCanvas = function (renderer) -{ - renderer.plugins.sprite.render(this); -}; - - -/** - * Returns the bounds of the Sprite as a rectangle. The bounds calculation takes the worldTransform into account. - * - * @return {PIXI.Rectangle} the framing rectangle - */ -Sprite.prototype.getBounds = function () -{ - //TODO lookinto caching.. - if(!this._currentBounds) - { - // if(this.vertexDirty) - { - this.vertexDirty = false; - - // set the vertex data - this.caclulateVertices(); - - } - - var minX, maxX, minY, maxY, - w0, w1, h0, h1, - vertexData = this.vertexData; - - var x1 = vertexData[0]; - var y1 = vertexData[1]; - - var x2 = vertexData[2]; - var y2 = vertexData[3]; - - var x3 = vertexData[4]; - var y3 = vertexData[5]; - - var x4 = vertexData[6]; - var y4 = vertexData[7]; - - minX = x1; - minX = x2 < minX ? x2 : minX; - minX = x3 < minX ? x3 : minX; - minX = x4 < minX ? x4 : minX; - - minY = y1; - minY = y2 < minY ? y2 : minY; - minY = y3 < minY ? y3 : minY; - minY = y4 < minY ? y4 : minY; - - maxX = x1; - maxX = x2 > maxX ? x2 : maxX; - maxX = x3 > maxX ? x3 : maxX; - maxX = x4 > maxX ? x4 : maxX; - - maxY = y1; - maxY = y2 > maxY ? y2 : maxY; - maxY = y3 > maxY ? y3 : maxY; - maxY = y4 > maxY ? y4 : maxY; - - // check for children - if(this.children.length) - { - var childBounds = this.containerGetBounds(); - - w0 = childBounds.x; - w1 = childBounds.x + childBounds.width; - h0 = childBounds.y; - h1 = childBounds.y + childBounds.height; - - minX = (minX < w0) ? minX : w0; - minY = (minY < h0) ? minY : h0; - - maxX = (maxX > w1) ? maxX : w1; - maxY = (maxY > h1) ? maxY : h1; - } - - var bounds = this._bounds; - - bounds.x = minX; - bounds.width = maxX - minX; - - bounds.y = minY; - bounds.height = maxY - minY; - - // store a reference so that if this function gets called again in the render cycle we do not have to recalculate - this._currentBounds = bounds; - } - - return this._currentBounds; -}; - -/** - * Gets the local bounds of the sprite object. - * - */ -Sprite.prototype.getLocalBounds = function () -{ - this._bounds.x = -this._texture.crop.width * this.anchor.x; - this._bounds.y = -this._texture.crop.height * this.anchor.y; - this._bounds.width = this._texture.crop.width; - this._bounds.height = this._texture.crop.height; - return this._bounds; -}; - -/** -* Tests if a point is inside this sprite -* -* @param point {PIXI.Point} the point to test -* @return {boolean} the result of the test -*/ -Sprite.prototype.containsPoint = function( point ) -{ - this.worldTransform.applyInverse(point, tempPoint); - - var width = this._texture.crop.width; - var height = this._texture.crop.height; - var x1 = -width * this.anchor.x; - var y1; - - if ( tempPoint.x > x1 && tempPoint.x < x1 + width ) - { - y1 = -height * this.anchor.y; - - if ( tempPoint.y > y1 && tempPoint.y < y1 + height ) - { - return true; - } - } - - return false; -}; - - -/** - * Destroys this sprite and optionally its texture - * - * @param [destroyTexture=false] {boolean} Should it destroy the current texture of the sprite as well - * @param [destroyBaseTexture=false] {boolean} Should it destroy the base texture of the sprite as well - */ -Sprite.prototype.destroy = function (destroyTexture, destroyBaseTexture) -{ - Container.prototype.destroy.call(this); - - this.anchor = null; - - if (destroyTexture) - { - this._texture.destroy(destroyBaseTexture); - } - - this._texture = null; - this.shader = null; -}; - -// some helper functions.. - -/** - * Helper function that creates a new sprite based on the source you provide. - * The soucre can be - frame id, image url, video url, canvae element, video element, base texture - * - * @static - * @param source {} - * @return {PIXI.Texture} A Texture - */ -Sprite.from = function (source) -{ - return new Sprite(Texture.from(source)); -} - -/** - * Helper function that creates a sprite that will contain a texture from the TextureCache based on the frameId - * The frame ids are created when a Texture packer file has been loaded - * - * @static - * @param frameId {string} The frame Id of the texture in the cache - * @param [crossorigin=(auto)] {boolean} if you want to specify the cross-origin parameter - * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} if you want to specify the scale mode, see {@link PIXI.SCALE_MODES} for possible values - * @return {PIXI.Sprite} A new Sprite using a texture from the texture cache matching the frameId - */ -Sprite.fromFrame = function (frameId) -{ - var texture = utils.TextureCache[frameId]; - - if (!texture) - { - throw new Error('The frameId "' + frameId + '" does not exist in the texture cache'); - } - - return new Sprite(texture); -}; - -/** - * Helper function that creates a sprite that will contain a texture based on an image url - * If the image is not in the texture cache it will be loaded - * - * @static - * @param imageId {string} The image url of the texture - * @return {PIXI.Sprite} A new Sprite using a texture from the texture cache matching the image id - */ -Sprite.fromImage = function (imageId, crossorigin, scaleMode) -{ - return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); -}; - -},{"../const":33,"../display/Container":34,"../math":54,"../textures/Texture":93,"../utils":100}],84:[function(require,module,exports){ -var CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); - -/** - * @author Mat Groves - * - * Big thanks to the very clever Matt DesLauriers https://github.com/mattdesl/ - * for creating the original pixi version! - * Also a thanks to https://github.com/bchevalier for tweaking the tint and alpha so that they now share 4 bytes on the vertex buffer - * - * Heavily inspired by LibGDX's CanvasSpriteRenderer: - * https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/graphics/g2d/CanvasSpriteRenderer.java - */ - -/** - * Renderer dedicated to drawing and batching sprites. - * - * @class - * @private - * @memberof PIXI - * @extends PIXI.ObjectRenderer - * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. - */ -function CanvasSpriteRenderer(renderer) -{ - this.renderer = renderer; -} - - -CanvasSpriteRenderer.prototype.constructor = CanvasSpriteRenderer; -module.exports = CanvasSpriteRenderer; - -CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); - -/** - * Renders the sprite object. - * - * @param sprite {PIXI.Sprite} the sprite to render when using this spritebatch - */ -CanvasSpriteRenderer.prototype.render = function (sprite) -{ - var texture = sprite._texture, - renderer = this.renderer, - wt = sprite.transform.worldTransform, - dx, - dy, - width = texture._frame.width, - height = texture._frame.height; - - if (texture.crop.width <= 0 || texture.crop.height <= 0) - { - return; - } - - renderer.setBlendMode(sprite.blendMode); - - // Ignore null sources - if (texture.valid) - { - renderer.context.globalAlpha = sprite.worldAlpha; - - // If smoothingEnabled is supported and we need to change the smoothing property for sprite texture - var smoothingEnabled = texture.baseTexture.scaleMode === CONST.SCALE_MODES.LINEAR; - if (renderer.smoothProperty && renderer.context[renderer.smoothProperty] !== smoothingEnabled) - { - renderer.context[renderer.smoothProperty] = smoothingEnabled; - } - - if (texture.trim) { - dx = texture.trim.width/2 + texture.trim.x - sprite.anchor.x * texture.crop.width; - dy = texture.trim.height/2 + texture.trim.y - sprite.anchor.y * texture.crop.height; - } else { - dx = (0.5 - sprite.anchor.x) * texture.crop.width; - dy = (0.5 - sprite.anchor.y) * texture.crop.height; - } - if(texture.rotate) { - wt.copy(canvasRenderWorldTransform); - wt = canvasRenderWorldTransform; - math.GroupD8.matrixAppendRotationInv(wt, texture.rotate, dx, dy); - // the anchor has already been applied above, so lets set it to zero - dx = 0; - dy = 0; - } - dx -= width/2; - dy -= height/2; - // Allow for pixel rounding - if (renderer.roundPixels) - { - renderer.context.setTransform( - wt.a, - wt.b, - wt.c, - wt.d, - (wt.tx * renderer.resolution) | 0, - (wt.ty * renderer.resolution) | 0 - ); - - dx = dx | 0; - dy = dy | 0; - } - else - { - renderer.context.setTransform( - wt.a, - wt.b, - wt.c, - wt.d, - wt.tx * renderer.resolution, - wt.ty * renderer.resolution - ); - } - - var resolution = texture.baseTexture.resolution; - - if (sprite.tint !== 0xFFFFFF) - { - if (sprite.cachedTint !== sprite.tint) - { - sprite.cachedTint = sprite.tint; - - // TODO clean up caching - how to clean up the caches? - sprite.tintedTexture = CanvasTinter.getTintedTexture(sprite, sprite.tint); - } - - renderer.context.drawImage( - sprite.tintedTexture, - 0, - 0, - width * resolution, - height * resolution, - dx * renderer.resolution, - dy * renderer.resolution, - width * renderer.resolution, - height * renderer.resolution - ); - } - else - { - - renderer.context.drawImage( - texture.baseTexture.source, - texture._frame.x * resolution, - texture._frame.y * resolution, - width * resolution, - height * resolution, - dx * renderer.resolution, - dy * renderer.resolution, - width * renderer.resolution, - height * renderer.resolution - ); - } - } -}; - -/** - * destroy the sprite object. - * - */ -CanvasSpriteRenderer.prototype.destroy = function (){ - this.renderer = null; -}; - -},{"../../const":33,"../../math":54,"../../renderers/canvas/CanvasRenderer":61,"./CanvasTinter":85}],85:[function(require,module,exports){ -var utils = require('../../utils'), -canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); -/** - * Utility methods for Sprite/Texture tinting. - * @static - * @class - * @memberof PIXI - */ -var CanvasTinter = {}; -module.exports = CanvasTinter; - -/** - * Basically this method just needs a sprite and a color and tints the sprite with the given color. - * - * @param sprite {PIXI.Sprite} the sprite to tint - * @param color {number} the color to use to tint the sprite with - * @return {HTMLCanvasElement} The tinted canvas - */ -CanvasTinter.getTintedTexture = function (sprite, color) -{ - var texture = sprite.texture; - - color = CanvasTinter.roundColor(color); - - var stringColor = '#' + ('00000' + ( color | 0).toString(16)).substr(-6); - - texture.tintCache = texture.tintCache || {}; - - if (texture.tintCache[stringColor]) - { - return texture.tintCache[stringColor]; - } - - // clone texture.. - var canvas = CanvasTinter.canvas || document.createElement('canvas'); - - //CanvasTinter.tintWithPerPixel(texture, stringColor, canvas); - CanvasTinter.tintMethod(texture, color, canvas); - - if (CanvasTinter.convertTintToImage) - { - // is this better? - var tintImage = new Image(); - tintImage.src = canvas.toDataURL(); - - texture.tintCache[stringColor] = tintImage; - } - else - { - texture.tintCache[stringColor] = canvas; - // if we are not converting the texture to an image then we need to lose the reference to the canvas - CanvasTinter.canvas = null; - } - - return canvas; -}; - -/** - * Tint a texture using the 'multiply' operation. - * - * @param texture {PIXI.Texture} the texture to tint - * @param color {number} the color to use to tint the sprite with - * @param canvas {HTMLCanvasElement} the current canvas - */ -CanvasTinter.tintWithMultiply = function (texture, color, canvas) -{ - var context = canvas.getContext( '2d' ); - - var crop = texture._frame; - - canvas.width = crop.width; - canvas.height = crop.height; - - context.fillStyle = '#' + ('00000' + ( color | 0).toString(16)).substr(-6); - - context.fillRect(0, 0, crop.width, crop.height); - - context.globalCompositeOperation = 'multiply'; - - context.drawImage( - texture.baseTexture.source, - crop.x, - crop.y, - crop.width, - crop.height, - 0, - 0, - crop.width, - crop.height - ); - - context.globalCompositeOperation = 'destination-atop'; - - context.drawImage( - texture.baseTexture.source, - crop.x, - crop.y, - crop.width, - crop.height, - 0, - 0, - crop.width, - crop.height - ); -}; - -/** - * Tint a texture using the 'overlay' operation. - * - * @param texture {PIXI.Texture} the texture to tint - * @param color {number} the color to use to tint the sprite with - * @param canvas {HTMLCanvasElement} the current canvas - */ -CanvasTinter.tintWithOverlay = function (texture, color, canvas) -{ - var context = canvas.getContext( '2d' ); - - var crop = texture._frame; - - canvas.width = crop.width; - canvas.height = crop.height; - - context.globalCompositeOperation = 'copy'; - context.fillStyle = '#' + ('00000' + ( color | 0).toString(16)).substr(-6); - context.fillRect(0, 0, crop.width, crop.height); - - context.globalCompositeOperation = 'destination-atop'; - context.drawImage( - texture.baseTexture.source, - crop.x, - crop.y, - crop.width, - crop.height, - 0, - 0, - crop.width, - crop.height - ); - - // context.globalCompositeOperation = 'copy'; -}; - -/** - * Tint a texture pixel per pixel. - * - * @param texture {PIXI.Texture} the texture to tint - * @param color {number} the color to use to tint the sprite with - * @param canvas {HTMLCanvasElement} the current canvas - */ -CanvasTinter.tintWithPerPixel = function (texture, color, canvas) -{ - var context = canvas.getContext( '2d' ); - var crop = texture._frame; - - canvas.width = crop.width; - canvas.height = crop.height; - - context.globalCompositeOperation = 'copy'; - context.drawImage( - texture.baseTexture.source, - crop.x, - crop.y, - crop.width, - crop.height, - 0, - 0, - crop.width, - crop.height - ); - - var rgbValues = utils.hex2rgb(color); - var r = rgbValues[0], g = rgbValues[1], b = rgbValues[2]; - - var pixelData = context.getImageData(0, 0, crop.width, crop.height); - - var pixels = pixelData.data; - - for (var i = 0; i < pixels.length; i += 4) - { - pixels[i+0] *= r; - pixels[i+1] *= g; - pixels[i+2] *= b; - } - - context.putImageData(pixelData, 0, 0); -}; - -/** - * Rounds the specified color according to the CanvasTinter.cacheStepsPerColorChannel. - * - * @param color {number} the color to round, should be a hex color - */ -CanvasTinter.roundColor = function (color) -{ - var step = CanvasTinter.cacheStepsPerColorChannel; - - var rgbValues = utils.hex2rgb(color); - - rgbValues[0] = Math.min(255, (rgbValues[0] / step) * step); - rgbValues[1] = Math.min(255, (rgbValues[1] / step) * step); - rgbValues[2] = Math.min(255, (rgbValues[2] / step) * step); - - return utils.rgb2hex(rgbValues); -}; - -/** - * Number of steps which will be used as a cap when rounding colors. - * - * @member - */ -CanvasTinter.cacheStepsPerColorChannel = 8; - -/** - * Tint cache boolean flag. - * - * @member - */ -CanvasTinter.convertTintToImage = false; - -/** - * Whether or not the Canvas BlendModes are supported, consequently the ability to tint using the multiply method. - * - * @member - */ -CanvasTinter.canUseMultiply = canUseNewCanvasBlendModes(); - -/** - * The tinting method that will be used. - * - */ -CanvasTinter.tintMethod = CanvasTinter.canUseMultiply ? CanvasTinter.tintWithMultiply : CanvasTinter.tintWithPerPixel; - -},{"../../renderers/canvas/utils/canUseNewCanvasBlendModes":64,"../../utils":100}],86:[function(require,module,exports){ - - - var Buffer = function(size) - { - - this.vertices = new ArrayBuffer(size); - - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; -},{}],87:[function(require,module,exports){ -var ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); - - -/** - * Renderer dedicated to drawing and batching sprites. - * - * @class - * @private - * @memberof PIXI - * @extends PIXI.ObjectRenderer - * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. - */ -function SpriteRenderer(renderer) -{ - ObjectRenderer.call(this, renderer); - - /** - * Number of values sent in the vertex buffer. - * positionX, positionY, colorR, colorG, colorB = 5 - * - * @member {number} - */ - this.vertSize = 5; - - /** - * The size of the vertex information in bytes. - * - * @member {number} - */ - this.vertByteSize = this.vertSize * 4; - - /** - * The number of images in the SpriteBatch before it flushes. - * - * @member {number} - */ - this.size = CONST.SPRITE_BATCH_SIZE; // 2000 is a nice balance between mobile / desktop - - // the total number of bytes in our batch - // var numVerts = this.size * 4 * this.vertByteSize; - - this.buffers = []; - for (var i = 1; i <= bitTwiddle.nextPow2(this.size); i*=2) { - var numVertsTemp = i * 4 * this.vertByteSize; - this.buffers.push(new Buffer(numVertsTemp)); - } - - /** - * Holds the indices of the geometry (quads) to draw - * - * @member {Uint16Array} - */ - this.indices = createIndicesForQuads(this.size); - - /** - * The default shader that is used if a sprite doesn't have a more specific one. - * - * @member {PIXI.Shader} - */ - this.shader = null; - - this.textureCount = 0; - this.currentIndex = 0; - this.tick =0; - this.groups = []; - - for (var k = 0; k < this.size; k++) - { - this.groups[k] = {textures:[], textureCount:0, ids:[], size:0, start:0, blend:0}; - } - - this.sprites = []; - - this.vertexBuffers = []; - this.vaos = []; - - this.vaoMax = 20; - this.vertexCount = 0; -} - - -SpriteRenderer.prototype = Object.create(ObjectRenderer.prototype); -SpriteRenderer.prototype.constructor = SpriteRenderer; -module.exports = SpriteRenderer; - -WebGLRenderer.registerPlugin('sprite', SpriteRenderer); - -/** - * Sets up the renderer context and necessary buffers. - * - * @private - * @param gl {WebGLRenderingContext} the current WebGL drawing context - */ -SpriteRenderer.prototype.onContextChange = function () -{ - var gl = this.renderer.gl; - - - this.MAX_TEXTURES = Math.min(gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS), CONST.SPRITE_MAX_TEXTURES); - - this.shader = generateMultiTextureShader(gl, this.MAX_TEXTURES); - // create a couple of buffers - this.indexBuffer = glCore.GLBuffer.createIndexBuffer(gl, this.indices, gl.STATIC_DRAW); - - - - for (var i = 0; i < this.vaoMax; i++) { - this.vertexBuffers[i] = glCore.GLBuffer.createVertexBuffer(gl, null, gl.STREAM_DRAW); - // build the vao object that will render.. - this.vaos[i] = this.renderer.createVao() - .addIndex(this.indexBuffer) - .addAttribute(this.vertexBuffers[i], this.shader.attributes.aVertexPosition, gl.FLOAT, false, this.vertByteSize, 0) - .addAttribute(this.vertexBuffers[i], this.shader.attributes.aTextureCoord, gl.UNSIGNED_SHORT, true, this.vertByteSize, 2 * 4) - .addAttribute(this.vertexBuffers[i], this.shader.attributes.aColor, gl.UNSIGNED_BYTE, true, this.vertByteSize, 3 * 4) - .addAttribute(this.vertexBuffers[i], this.shader.attributes.aTextureId, gl.FLOAT, false, this.vertByteSize, 4 * 4); - } - - this.vao = this.vaos[0]; - this.currentBlendMode = 99999; -}; - -/** - * Renders the sprite object. - * - * @param sprite {PIXI.Sprite} the sprite to render when using this spritebatch - */ -SpriteRenderer.prototype.render = function (sprite) -{ - //TODO set blend modes.. - // check texture.. - if (this.currentIndex >= this.size) - { - this.flush(); - } - - - // get the uvs for the texture - - - // if the uvs have not updated then no point rendering just yet! - if (!sprite.texture._uvs) - { - return; - } - - // push a texture. - // increment the batchsize - this.sprites[this.currentIndex++] = sprite; -}; - -/** - * Renders the content and empties the current batch. - * - */ -SpriteRenderer.prototype.flush = function () -{ - if (this.currentIndex === 0) { - return; - } - - var gl = this.renderer.gl; - - var np2 = bitTwiddle.nextPow2(this.currentIndex); - var log2 = bitTwiddle.log2(np2); - var buffer = this.buffers[log2]; - - var sprites = this.sprites; - var groups = this.groups; - - var float32View = buffer.float32View; - var uint32View = buffer.uint32View; - - var index = 0; - var nextTexture; - var currentTexture; - var groupCount = 1; - var textureCount = 0; - var currentGroup = groups[0]; - var vertexData; - var tint; - var uvs; - var textureId; - var blendMode = sprites[0].blendMode; - - currentGroup.textureCount = 0; - currentGroup.start = 0; - - this.tick++; - - for (var i = 0; i < this.currentIndex; i++) - { - // upload the sprite elemetns... - // they have all ready been calculated so we just need to push them into the buffer. - var sprite = sprites[i]; - - nextTexture = sprite._texture.baseTexture; - - if(blendMode !== sprite.blendMode) - { - blendMode = sprite.blendMode; - - // force the batch to break! - currentTexture = null; - textureCount = this.MAX_TEXTURES; - this.tick++; - } - - if(currentTexture !== nextTexture) - { - currentTexture = nextTexture; - - if(nextTexture._enabled !== this.tick) - { - if(textureCount === this.MAX_TEXTURES) - { - this.tick++; - - textureCount = 0; - - currentGroup.size = i - currentGroup.start; - - currentGroup = groups[groupCount++]; - currentGroup.textureCount = 0; - currentGroup.blend = blendMode; - currentGroup.start = i; - } - - nextTexture._enabled = this.tick; - nextTexture._id = textureCount; - - currentGroup.textures[currentGroup.textureCount++] = nextTexture; - textureCount++; - } - - } - - vertexData = sprite.vertexData; - - //TODO this sum does not need to be set each frame.. - tint = (sprite.tint >> 16) + (sprite.tint & 0xff00) + ((sprite.tint & 0xff) << 16) + (sprite.worldAlpha * 255 << 24); - uvs = sprite._texture._uvs.uvs_uint32; - textureId = nextTexture._id; - - //xy - float32View[index++] = vertexData[0]; - float32View[index++] = vertexData[1]; - uint32View[index++] = uvs[0]; - uint32View[index++] = tint; - float32View[index++] = textureId; - - // xy - float32View[index++] = vertexData[2]; - float32View[index++] = vertexData[3]; - uint32View[index++] = uvs[1]; - uint32View[index++] = tint; - float32View[index++] = textureId; - - // xy - float32View[index++] = vertexData[4]; - float32View[index++] = vertexData[5]; - uint32View[index++] = uvs[2]; - uint32View[index++] = tint; - float32View[index++] = textureId; - - // xy - float32View[index++] = vertexData[6]; - float32View[index++] = vertexData[7]; - uint32View[index++] = uvs[3]; - uint32View[index++] = tint; - float32View[index++] = textureId; - } - - currentGroup.size = i - currentGroup.start; - - this.vertexCount++; - this.vertexCount %= this.vaoMax; - - this.vertexBuffers[this.vertexCount].upload(buffer.vertices, 0); - this.vao = this.vaos[this.vertexCount].bind(); - - - /// render the groups.. - for (i = 0; i < groupCount; i++) { - - var group = groups[i]; - - for (var j = 0; j < group.textureCount; j++) { - this.renderer.bindTexture(group.textures[j], j); - } - - // set the blend mode.. - this.renderer.state.setBlendMode( group.blend ); - - gl.drawElements(gl.TRIANGLES, group.size * 6, gl.UNSIGNED_SHORT, group.start * 6 * 2); - } - - // reset elements for the next flush - this.currentIndex = 0; -}; - -/** - * Starts a new sprite batch. - * - */ -SpriteRenderer.prototype.start = function () -{ - this.renderer.bindShader(this.shader); - this.tick %= 1000; -}; - -SpriteRenderer.prototype.stop = function () -{ - this.flush(); - this.vao.unbind(); -}; -/** - * Destroys the SpriteBatch. - * - */ -SpriteRenderer.prototype.destroy = function () -{ - for (var i = 0; i < this.vaoMax; i++) { - this.vertexBuffers[i].destroy(); - this.vaoMax[i].destroy(); - }; - - this.indexBuffer.destroy(); - - ObjectRenderer.prototype.destroy.call(this); - - this.shader.destroy(); - - this.renderer = null; - - this.vertexBuffer = null; - this.indexBuffer = null; - - this.sprites = null; - this.shader = null; - - for (var i = 0; i < this.buffers.length; i++) { - this.buffers[i].destroy(); - } - -}; - -},{"../../const":33,"../../renderers/webgl/WebGLRenderer":68,"../../renderers/webgl/utils/ObjectRenderer":78,"../../utils/createIndicesForQuads":98,"./BatchBuffer":86,"./generateMultiTextureShader":88,"bit-twiddle":3,"pixi-gl-core":15}],88:[function(require,module,exports){ -var Shader = require('pixi-gl-core').GLShader; - -var fragTemplate = [ - - 'precision lowp float;', - 'varying vec2 vTextureCoord;', - 'varying vec4 vColor;', - 'varying float vTextureId;', - 'uniform sampler2D uSamplers[%count%];', - - 'void main(void){', - 'vec4 color;', - '%forloop%', - 'gl_FragColor = color * vColor;', - '}' -].join('\n'); - -function generateMultiTextureShader(gl, maxTextures) -{ - var vertexSrc = "precision lowp float;\n#define GLSLIFY 1\n\nattribute vec2 aVertexPosition;\n\nattribute vec2 aTextureCoord;\n\nattribute vec4 aColor;\n\nattribute float aTextureId;\n\nuniform mat3 projectionMatrix;\n\nvarying vec2 vTextureCoord;\n\nvarying vec4 vColor;\n\nvarying float vTextureId;\n\nvoid main(void){\n\n gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\n\n vTextureCoord = aTextureCoord;\n\n vTextureId = aTextureId;\n\n vColor = vec4(aColor.rgb * aColor.a, aColor.a);\n\n}"; - var fragmentSrc = fragTemplate; - - fragmentSrc = fragmentSrc.replace(/\%count\%/gi, maxTextures); - fragmentSrc = fragmentSrc.replace(/\%forloop\%/gi, generateSampleSrc(maxTextures)); - - var shader = new Shader(gl, vertexSrc, fragmentSrc); - - var sampleValues = []; - for (var i = 0; i < maxTextures; i++) - { - sampleValues[i] = i; - } - - shader.bind(); - shader.uniforms.uSamplers = sampleValues; - - return shader; -} - -function generateSampleSrc(maxTextures) -{ - var src = ''; - - src += '\n'; - src += '\n'; - - for (var i = 0; i < maxTextures; i++) - { - if(i > 0) - { - src += '\nelse '; - } - - if(i < maxTextures-1) - { - src += 'if(vTextureId == ' + i + '.0)'; - } - - src += '\n{'; - src += '\n\tcolor = texture2D(uSamplers['+i+'], vTextureCoord);'; - src += '\n}'; - } - - src += '\n'; - src += '\n'; - - return src; -} - - - -module.exports = generateMultiTextureShader; - -},{"pixi-gl-core":15}],89:[function(require,module,exports){ -var Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'); - -/** - * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, - * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. - * - * A Text can be created directly from a string and a style object - * - * ```js - * var text = new PIXI.Text('This is a pixi text',{font : '24px Arial', fill : 0xff1010, align : 'center'}); - * ``` - * - * @class - * @extends PIXI.Sprite - * @memberof PIXI - * @param text {string} The copy that you would like the text to display - * @param [style] {object} The style parameters - * @param [style.font] {string} default 'bold 20px Arial' The style and size of the font - * @param [style.fill='black'] {String|Number} A canvas fillstyle that will be used on the text e.g 'red', '#00FF00' - * @param [style.align='left'] {string} Alignment for multiline text ('left', 'center' or 'right'), does not affect single line text - * @param [style.stroke] {String|Number} A canvas fillstyle that will be used on the text stroke e.g 'blue', '#FCFF00' - * @param [style.strokeThickness=0] {number} A number that represents the thickness of the stroke. Default is 0 (no stroke) - * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used - * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true - * @param [style.lineHeight] {number} The line height, a number that represents the vertical space that a letter uses - * @param [style.dropShadow=false] {boolean} Set a drop shadow for the text - * @param [style.dropShadowColor='#000000'] {string} A fill style to be used on the dropshadow e.g 'red', '#00FF00' - * @param [style.dropShadowAngle=Math.PI/4] {number} Set a angle of the drop shadow - * @param [style.dropShadowDistance=5] {number} Set a distance of the drop shadow - * @param [style.dropShadowBlur=0] {number} Set a shadow blur radius - * @param [style.padding=0] {number} Occasionally some fonts are cropped on top or bottom. Adding some padding will - * prevent this from happening by adding padding to the top and bottom of text height. - * @param [style.textBaseline='alphabetic'] {string} The baseline of the text that is rendered. - * @param [style.lineJoin='miter'] {string} The lineJoin property sets the type of corner created, it can resolve - * spiked text issues. Default is 'miter' (creates a sharp corner). - * @param [style.miterLimit=10] {number} The miter limit to use when using the 'miter' lineJoin mode. This can reduce - * or increase the spikiness of rendered text. - */ -function Text(text, style, resolution) -{ - /** - * The canvas element that everything is drawn to - * - * @member {HTMLCanvasElement} - */ - this.canvas = document.createElement('canvas'); - - /** - * The canvas 2d context that everything is drawn with - * @member {HTMLCanvasElement} - */ - this.context = this.canvas.getContext('2d'); - - /** - * The resolution of the canvas. - * @member {number} - */ - this.resolution = resolution || CONST.RESOLUTION; - - /** - * Private tracker for the current text. - * - * @member {string} - * @private - */ - this._text = null; - - /** - * Private tracker for the current style. - * - * @member {object} - * @private - */ - this._style = null; - - var texture = Texture.fromCanvas(this.canvas); - texture.trim = new math.Rectangle(); - Sprite.call(this, texture); - - this.text = text; - this.style = style; -} - -// constructor -Text.prototype = Object.create(Sprite.prototype); -Text.prototype.constructor = Text; -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { - /** - * The width of the Text, setting this will actually modify the scale to achieve the value set - * - * @member {number} - * @memberof PIXI.Text# - */ - width: { - get: function () - { - if (this.dirty) - { - this.updateText(); - } - - return this.scale.x * this._texture._frame.width; - }, - set: function (value) - { - this.scale.x = value / this._texture._frame.width; - this._width = value; - } - }, - - /** - * The height of the Text, setting this will actually modify the scale to achieve the value set - * - * @member {number} - * @memberof PIXI.Text# - */ - height: { - get: function () - { - if (this.dirty) - { - this.updateText(); - } - - return this.scale.y * this._texture._frame.height; - }, - set: function (value) - { - this.scale.y = value / this._texture._frame.height; - this._height = value; - } - }, - - /** - * Set the style of the text - * - * @param [style] {object} The style parameters - * @param [style.font='bold 20pt Arial'] {string} The style and size of the font - * @param [style.fill='black'] {string|number} A canvas fillstyle that will be used on the text eg 'red', '#00FF00' - * @param [style.align='left'] {string} Alignment for multiline text ('left', 'center' or 'right'), does not affect single line text - * @param [style.stroke='black'] {string|number} A canvas fillstyle that will be used on the text stroke eg 'blue', '#FCFF00' - * @param [style.strokeThickness=0] {number} A number that represents the thickness of the stroke. Default is 0 (no stroke) - * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used - * @param [style.wordWrapWidth=100] {number} The width at which text will wrap - * @param [style.lineHeight] {number} The line height, a number that represents the vertical space that a letter uses - * @param [style.dropShadow=false] {boolean} Set a drop shadow for the text - * @param [style.dropShadowColor='#000000'] {string|number} A fill style to be used on the dropshadow e.g 'red', '#00FF00' - * @param [style.dropShadowAngle=Math.PI/6] {number} Set a angle of the drop shadow - * @param [style.dropShadowDistance=5] {number} Set a distance of the drop shadow - * @param [style.dropShadowBlur=0] {number} Set a shadow blur radius - * @param [style.padding=0] {number} Occasionally some fonts are cropped on top or bottom. Adding some padding will - * prevent this from happening by adding padding to the top and bottom of text height. - * @param [style.textBaseline='alphabetic'] {string} The baseline of the text that is rendered. - * @param [style.lineJoin='miter'] {string} The lineJoin property sets the type of corner created, it can resolve - * spiked text issues. Default is 'miter' (creates a sharp corner). - * @param [style.miterLimit=10] {number} The miter limit to use when using the 'miter' lineJoin mode. This can reduce - * or increase the spikiness of rendered text. - * @memberof PIXI.Text# - */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { - style = style || {}; - - if (typeof style.fill === 'number') { - style.fill = utils.hex2string(style.fill); - } - - if (typeof style.stroke === 'number') { - style.stroke = utils.hex2string(style.stroke); - } - - if (typeof style.dropShadowColor === 'number') { - style.dropShadowColor = utils.hex2string(style.dropShadowColor); - } - - style.font = style.font || 'bold 20pt Arial'; - style.fill = style.fill || 'black'; - style.align = style.align || 'left'; - style.stroke = style.stroke || 'black'; //provide a default, see: https://github.com/pixijs/pixi.js/issues/136 - style.strokeThickness = style.strokeThickness || 0; - style.wordWrap = style.wordWrap || false; - style.wordWrapWidth = style.wordWrapWidth || 100; - - style.dropShadow = style.dropShadow || false; - style.dropShadowColor = style.dropShadowColor || '#000000'; - style.dropShadowAngle = style.dropShadowAngle !== undefined ? style.dropShadowAngle : Math.PI / 6; - style.dropShadowDistance = style.dropShadowDistance !== undefined ? style.dropShadowDistance : 5; - style.dropShadowBlur = style.dropShadowBlur !== undefined ? style.dropShadowBlur : 0; //shadowBlur is '0' by default according to HTML - - style.padding = style.padding || 0; - - style.textBaseline = style.textBaseline || 'alphabetic'; - - style.lineJoin = style.lineJoin || 'miter'; - style.miterLimit = style.miterLimit || 10; - - this._style = style; - this.dirty = true; - } - }, - - /** - * Set the copy for the text object. To split a line you can use '\n'. - * - * @param text {string} The copy that you would like the text to display - * @memberof PIXI.Text# - */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } - } -}); - -/** - * Renders text and updates it when needed - * - * @private - */ -Text.prototype.updateText = function () -{ - var style = this._style; - this.context.font = style.font; - - // word wrap - // preserve original text - var outputText = style.wordWrap ? this.wordWrap(this._text) : this._text; - - // split text into lines - var lines = outputText.split(/(?:\r\n|\r|\n)/); - - // calculate text width - var lineWidths = new Array(lines.length); - var maxLineWidth = 0; - var fontProperties = this.determineFontProperties(style.font); - for (var i = 0; i < lines.length; i++) - { - var lineWidth = this.context.measureText(lines[i]).width; - lineWidths[i] = lineWidth; - maxLineWidth = Math.max(maxLineWidth, lineWidth); - } - - var width = maxLineWidth + style.strokeThickness; - if (style.dropShadow) - { - width += style.dropShadowDistance; - } - - this.canvas.width = ( width + this.context.lineWidth ) * this.resolution; - - // calculate text height - var lineHeight = this.style.lineHeight || fontProperties.fontSize + style.strokeThickness; - - var height = lineHeight * lines.length; - if (style.dropShadow) - { - height += style.dropShadowDistance; - } - - this.canvas.height = ( height + this._style.padding * 2 ) * this.resolution; - - this.context.scale( this.resolution, this.resolution); - - if (navigator.isCocoonJS) - { - this.context.clearRect(0, 0, this.canvas.width, this.canvas.height); - - } - - //this.context.fillStyle="#FF0000"; - //this.context.fillRect(0, 0, this.canvas.width, this.canvas.height); - - this.context.font = style.font; - this.context.strokeStyle = style.stroke; - this.context.lineWidth = style.strokeThickness; - this.context.textBaseline = style.textBaseline; - this.context.lineJoin = style.lineJoin; - this.context.miterLimit = style.miterLimit; - - var linePositionX; - var linePositionY; - - if (style.dropShadow) - { - if (style.dropShadowBlur > 0) { - this.context.shadowColor = style.dropShadowColor; - this.context.shadowBlur = style.dropShadowBlur; - } else { - this.context.fillStyle = style.dropShadowColor; - } - - var xShadowOffset = Math.cos(style.dropShadowAngle) * style.dropShadowDistance; - var yShadowOffset = Math.sin(style.dropShadowAngle) * style.dropShadowDistance; - - for (i = 0; i < lines.length; i++) - { - linePositionX = style.strokeThickness / 2; - linePositionY = (style.strokeThickness / 2 + i * lineHeight) + fontProperties.ascent; - - if (style.align === 'right') - { - linePositionX += maxLineWidth - lineWidths[i]; - } - else if (style.align === 'center') - { - linePositionX += (maxLineWidth - lineWidths[i]) / 2; - } - - if (style.fill) - { - this.context.fillText(lines[i], linePositionX + xShadowOffset, linePositionY + yShadowOffset + this._style.padding); - } - } - } - - //set canvas text styles - this.context.fillStyle = style.fill; - - //draw lines line by line - for (i = 0; i < lines.length; i++) - { - linePositionX = style.strokeThickness / 2; - linePositionY = (style.strokeThickness / 2 + i * lineHeight) + fontProperties.ascent; - - if (style.align === 'right') - { - linePositionX += maxLineWidth - lineWidths[i]; - } - else if (style.align === 'center') - { - linePositionX += (maxLineWidth - lineWidths[i]) / 2; - } - - if (style.stroke && style.strokeThickness) - { - this.context.strokeText(lines[i], linePositionX, linePositionY + this._style.padding); - } - - if (style.fill) - { - this.context.fillText(lines[i], linePositionX, linePositionY + this._style.padding); - } - } - - this.updateTexture(); -}; - -/** - * Updates texture size based on canvas size - * - * @private - */ -Text.prototype.updateTexture = function () -{ - var texture = this._texture; - - texture.baseTexture.hasLoaded = true; - texture.baseTexture.resolution = this.resolution; - - texture.baseTexture.width = this.canvas.width / this.resolution; - texture.baseTexture.height = this.canvas.height / this.resolution; - texture.crop.width = texture._frame.width = this.canvas.width / this.resolution; - texture.crop.height = texture._frame.height = this.canvas.height / this.resolution; - - texture.trim.x = 0; - texture.trim.y = -this._style.padding; - - texture.trim.width = texture._frame.width; - texture.trim.height = texture._frame.height - this._style.padding*2; - - this._width = this.canvas.width / this.resolution; - this._height = this.canvas.height / this.resolution; - - texture.baseTexture.emit('update', texture.baseTexture); - - this.dirty = false; -}; - -/** - * Renders the object using the WebGL renderer - * - * @param renderer {PIXI.WebGLRenderer} - */ -Text.prototype.renderWebGL = function (renderer) -{ - if (this.dirty) - { - //this.resolution = 1//renderer.resolution; - - this.updateText(); - } - - Sprite.prototype.renderWebGL.call(this, renderer); -}; - -/** - * Renders the object using the Canvas renderer - * - * @param renderer {PIXI.CanvasRenderer} - * @private - */ -Text.prototype._renderCanvas = function (renderer) -{ - if (this.dirty) - { - // this.resolution = 1//renderer.resolution; - - this.updateText(); - } - - Sprite.prototype._renderCanvas.call(this, renderer); -}; - -/** - * Calculates the ascent, descent and fontSize of a given fontStyle - * - * @param fontStyle {object} - * @private - */ -Text.prototype.determineFontProperties = function (fontStyle) -{ - var properties = Text.fontPropertiesCache[fontStyle]; - - if (!properties) - { - properties = {}; - - var canvas = Text.fontPropertiesCanvas; - var context = Text.fontPropertiesContext; - - context.font = fontStyle; - - var width = Math.ceil(context.measureText('|MÉq').width); - var baseline = Math.ceil(context.measureText('M').width); - var height = 2 * baseline; - - baseline = baseline * 1.4 | 0; - - canvas.width = width; - canvas.height = height; - - context.fillStyle = '#f00'; - context.fillRect(0, 0, width, height); - - context.font = fontStyle; - - context.textBaseline = 'alphabetic'; - context.fillStyle = '#000'; - context.fillText('|MÉq', 0, baseline); - - var imagedata = context.getImageData(0, 0, width, height).data; - var pixels = imagedata.length; - var line = width * 4; - - var i, j; - - var idx = 0; - var stop = false; - - // ascent. scan from top to bottom until we find a non red pixel - for (i = 0; i < baseline; i++) - { - for (j = 0; j < line; j += 4) - { - if (imagedata[idx + j] !== 255) - { - stop = true; - break; - } - } - if (!stop) - { - idx += line; - } - else - { - break; - } - } - - properties.ascent = baseline - i; - - idx = pixels - line; - stop = false; - - // descent. scan from bottom to top until we find a non red pixel - for (i = height; i > baseline; i--) - { - for (j = 0; j < line; j += 4) - { - if (imagedata[idx + j] !== 255) - { - stop = true; - break; - } - } - if (!stop) - { - idx -= line; - } - else - { - break; - } - } - - properties.descent = i - baseline; - properties.fontSize = properties.ascent + properties.descent; - - Text.fontPropertiesCache[fontStyle] = properties; - } - - return properties; -}; +// state object// +var setVertexAttribArrays = require( './setVertexAttribArrays' ); + +/** + * Helper class to work with WebGL VertexArrayObjects (vaos) + * Only works if WebGL extensions are enabled (they usually are) + * + * @class + * @memberof pixi.gl + * @param gl {WebGLRenderingContext} The current WebGL rendering context + */ +function VertexArrayObject(gl, state) +{ + this.nativeVaoExtension = null; + + if(!VertexArrayObject.FORCE_NATIVE) + { + this.nativeVaoExtension = gl.getExtension('OES_vertex_array_object') || + gl.getExtension('MOZ_OES_vertex_array_object') || + gl.getExtension('WEBKIT_OES_vertex_array_object'); + } + + this.nativeState = state; + + if(this.nativeVaoExtension) + { + this.nativeVao = this.nativeVaoExtension.createVertexArrayOES(); + + var maxAttribs = gl.getParameter(gl.MAX_VERTEX_ATTRIBS); + + // VAO - overwrite the state.. + this.nativeState = { + tempAttribState: new Array(maxAttribs), + attribState: new Array(maxAttribs) + }; + } + + /** + * The current WebGL rendering context + * + * @member {WebGLRenderingContext} + */ + this.gl = gl; + + /** + * An array of attributes + * + * @member {Array} + */ + this.attributes = []; + + /** + * @member {Array} + */ + this.indexBuffer = null; + + /** + * A boolean flag + * + * @member {Boolean} + */ + this.dirty = false; +} + +VertexArrayObject.prototype.constructor = VertexArrayObject; +module.exports = VertexArrayObject; + +/** +* Some devices behave a bit funny when using the newer extensions (im looking at you ipad 2!) +* If you find on older devices that things have gone a bit weird then set this to true. +*/ +/** + * Lets the VAO know if you should use the WebGL extension or the native methods. + * Some devices behave a bit funny when using the newer extensions (im looking at you ipad 2!) + * If you find on older devices that things have gone a bit weird then set this to true. + * @static + * @property {Boolean} FORCE_NATIVE + */ +VertexArrayObject.FORCE_NATIVE = false; + +/** + * Binds the buffer + */ +VertexArrayObject.prototype.bind = function() +{ + if(this.nativeVao) + { + this.nativeVaoExtension.bindVertexArrayOES(this.nativeVao); + + if(this.dirty) + { + this.dirty = false; + this.activate(); + } + } + else + { + + this.activate(); + } + + return this; +}; + +/** + * Unbinds the buffer + */ +VertexArrayObject.prototype.unbind = function() +{ + if(this.nativeVao) + { + this.nativeVaoExtension.bindVertexArrayOES(null); + } + + return this; +}; + +/** + * Uses this vao + */ +VertexArrayObject.prototype.activate = function() +{ + + var gl = this.gl; + var lastBuffer = null; + + for (var i = 0; i < this.attributes.length; i++) + { + var attrib = this.attributes[i]; + + if(lastBuffer !== attrib.buffer) + { + attrib.buffer.bind(); + lastBuffer = attrib.buffer; + } + + //attrib.attribute.pointer(attrib.type, attrib.normalized, attrib.stride, attrib.start); + gl.vertexAttribPointer(attrib.attribute.location, + attrib.attribute.size, attrib.type || gl.FLOAT, + attrib.normalized || false, + attrib.stride || 0, + attrib.start || 0); + + + } + + setVertexAttribArrays(gl, this.attributes, this.nativeState); + + this.indexBuffer.bind(); + + return this; +}; + +/** + * + * @param buffer {WebGLBuffer} + * @param attribute {*} + * @param type {String} + * @param normalized {Boolean} + * @param stride {Number} + * @param start {Number} + */ +VertexArrayObject.prototype.addAttribute = function(buffer, attribute, type, normalized, stride, start) +{ + this.attributes.push({ + buffer: buffer, + attribute: attribute, + + location: attribute.location, + type: type || this.gl.FLOAT, + normalized: normalized || false, + stride: stride || 0, + start: start || 0 + }); + + this.dirty = true; + + return this; +}; + +/** + * + * @param buffer {WebGLBuffer} + * @param options {Object} + */ +VertexArrayObject.prototype.addIndex = function(buffer/*, options*/) +{ + this.indexBuffer = buffer; + + this.dirty = true; + + return this; +}; + +/** + * Unbinds this vao and disables it + */ +VertexArrayObject.prototype.clear = function() +{ + // var gl = this.gl; + + // TODO - should this function unbind after clear? + // for now, no but lets see what happens in the real world! + if(this.nativeVao) + { + this.nativeVaoExtension.bindVertexArrayOES(this.nativeVao); + } + + this.attributes.length = 0; + this.indexBuffer = null; + + return this; +}; + +/** + * @param type {Number} + * @param size {Number} + * @param start {Number} + */ +VertexArrayObject.prototype.draw = function(type, size, start) +{ + var gl = this.gl; + gl.drawElements(type, size, gl.UNSIGNED_SHORT, start || 0); + + return this; +}; + +/** + * Destroy this vao + */ +VertexArrayObject.prototype.destroy = function() +{ + // lose references + this.gl = null; + this.indexBuffer = null; + this.attributes = null; + this.nativeState = null; + + if(this.nativeVao) + { + this.nativeVaoExtension.deleteVertexArrayOES(this.nativeVao); + } + + this.nativeVaoExtension = null; + this.nativeVao = null; +}; + +},{"./setVertexAttribArrays":15}],13:[function(require,module,exports){ + +/** + * Helper class to create a webGL Context + * + * @class + * @memberof pixi.gl + * @param canvas {HTMLCanvasElement} the canvas element that we will get the context from + * @param options {Object} An options object that gets passed in to the canvas element containing the context attributes, + * see https://developer.mozilla.org/en/docs/Web/API/HTMLCanvasElement/getContext for the options available + * @return {WebGLRenderingContext} the WebGL context + */ +var createContext = function(canvas, options) +{ + var gl = canvas.getContext('webgl', options) || + canvas.getContext('experimental-webgl', options); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + + return gl; +}; + +module.exports = createContext; + +},{}],14:[function(require,module,exports){ +var gl = { + createContext: require('./createContext'), + setVertexAttribArrays: require('./setVertexAttribArrays'), + GLBuffer: require('./GLBuffer'), + GLFramebuffer: require('./GLFramebuffer'), + GLShader: require('./GLShader'), + GLTexture: require('./GLTexture'), + VertexArrayObject: require('./VertexArrayObject'), + shader: require('./shader') +}; + +// Export for Node-compatible environments +if (typeof module !== 'undefined' && module.exports) +{ + // Export the module + module.exports = gl; +} + +// Add to the browser window pixi.gl +if (typeof window !== 'undefined') +{ + // add the window object + window.pixi = { gl: gl }; +} +},{"./GLBuffer":8,"./GLFramebuffer":9,"./GLShader":10,"./GLTexture":11,"./VertexArrayObject":12,"./createContext":13,"./setVertexAttribArrays":15,"./shader":21}],15:[function(require,module,exports){ +// var GL_MAP = {}; + +/** + * @param gl {WebGLRenderingContext} The current WebGL context + * @param attribs {*} + * @param state {*} + */ +var setVertexAttribArrays = function (gl, attribs, state) +{ + var i; + if(state) + { + var tempAttribState = state.tempAttribState, + attribState = state.attribState; + + for (i = 0; i < tempAttribState.length; i++) + { + tempAttribState[i] = false; + } + + // set the new attribs + for (i = 0; i < attribs.length; i++) + { + tempAttribState[attribs[i].attribute.location] = true; + } + + for (i = 0; i < attribState.length; i++) + { + if (attribState[i] !== tempAttribState[i]) + { + attribState[i] = tempAttribState[i]; + + if (state.attribState[i]) + { + gl.enableVertexAttribArray(i); + } + else + { + gl.disableVertexAttribArray(i); + } + } + } + + } + else + { + for (i = 0; i < attribs.length; i++) + { + var attrib = attribs[i]; + gl.enableVertexAttribArray(attrib.attribute.location); + } + } +}; + +module.exports = setVertexAttribArrays; + +},{}],16:[function(require,module,exports){ + +/** + * @class + * @memberof pixi.gl.shader + * @param gl {WebGLRenderingContext} The current WebGL context {WebGLProgram} + * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. + * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. + * @return {WebGLProgram} the shader program + */ +var compileProgram = function(gl, vertexSrc, fragmentSrc) +{ + var glVertShader = compileShader(gl, gl.VERTEX_SHADER, vertexSrc); + var glFragShader = compileShader(gl, gl.FRAGMENT_SHADER, fragmentSrc); + + var program = gl.createProgram(); + + gl.attachShader(program, glVertShader); + gl.attachShader(program, glFragShader); + gl.linkProgram(program); + + // if linking fails, then log and cleanup + if (!gl.getProgramParameter(program, gl.LINK_STATUS)) + { + console.error('Pixi.js Error: Could not initialize shader.'); + console.error('gl.VALIDATE_STATUS', gl.getProgramParameter(program, gl.VALIDATE_STATUS)); + console.error('gl.getError()', gl.getError()); + + // if there is a program info log, log it + if (gl.getProgramInfoLog(program) !== '') + { + console.warn('Pixi.js Warning: gl.getProgramInfoLog()', gl.getProgramInfoLog(program)); + } + + gl.deleteProgram(program); + program = null; + } + + // clean up some shaders + gl.deleteShader(glVertShader); + gl.deleteShader(glFragShader); + + return program; +}; + +/** + * @private + * @param gl {WebGLRenderingContext} The current WebGL context {WebGLProgram} + * @param type {Number} the type, can be either VERTEX_SHADER or FRAGMENT_SHADER + * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. + * @return {WebGLShader} the shader + */ +var compileShader = function (gl, type, src) +{ + var shader = gl.createShader(type); + + gl.shaderSource(shader, src); + gl.compileShader(shader); + + if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) + { + console.log(gl.getShaderInfoLog(shader)); + return null; + } + + return shader; +}; + +module.exports = compileProgram; + +},{}],17:[function(require,module,exports){ +/** + * @class + * @memberof pixi.gl.shader + * @param type {String} Type of value + * @param size {Number} + */ +var defaultValue = function(type, size) +{ + switch (type) + { + case 'float': + return 0; + + case 'vec2': + return new Float32Array(2 * size); + + case 'vec3': + return new Float32Array(3 * size); + + case 'vec4': + return new Float32Array(4 * size); + + case 'int': + case 'sampler2D': + return 0; + + case 'ivec2': + return new Int32Array(2 * size); + + case 'ivec3': + return new Int32Array(3 * size); + + case 'ivec4': + return new Int32Array(4 * size); + + case 'bool': + return false; + + case 'bvec2': + + return booleanArray( 2 * size); + + case 'bvec3': + return booleanArray(3 * size); + + case 'bvec4': + return booleanArray(4 * size); + + case 'mat2': + return new Float32Array([1, 0, + 0, 1]); + + case 'mat3': + return new Float32Array([1, 0, 0, + 0, 1, 0, + 0, 0, 1]); + + case 'mat4': + return new Float32Array([1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1]); + } +}; + +var booleanArray = function(size) +{ + var array = new Array(size); + + for (var i = 0; i < array.length; i++) + { + array[i] = false; + } + + return array; +}; + +module.exports = defaultValue; + +},{}],18:[function(require,module,exports){ + +var mapType = require('./mapType'); +var mapSize = require('./mapSize'); + +/** + * Extracts the attributes + * @class + * @memberof pixi.gl.shader + * @param gl {WebGLRenderingContext} The current WebGL rendering context + * @param program {WebGLProgram} The shader program to get the attributes from + * @return attributes {Object} + */ +var extractAttributes = function(gl, program) +{ + var attributes = {}; + + var totalAttributes = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES); + + for (var i = 0; i < totalAttributes; i++) + { + var attribData = gl.getActiveAttrib(program, i); + var type = mapType(gl, attribData.type); + + attributes[attribData.name] = { + type:type, + size:mapSize(type), + location:gl.getAttribLocation(program, attribData.name), + //TODO - make an attribute object + pointer: pointer + }; + } + + return attributes; +}; + +var pointer = function(type, normalized, stride, start){ + // console.log(this.location) + gl.vertexAttribPointer(this.location,this.size, type || gl.FLOAT, normalized || false, stride || 0, start || 0); +}; + +module.exports = extractAttributes; + +},{"./mapSize":22,"./mapType":23}],19:[function(require,module,exports){ +var mapType = require('./mapType'); +var defaultValue = require('./defaultValue'); + +/** + * Extracts the uniforms + * @class + * @memberof pixi.gl.shader + * @param gl {WebGLRenderingContext} The current WebGL rendering context + * @param program {WebGLProgram} The shader program to get the uniforms from + * @return uniforms {Object} + */ +var extractUniforms = function(gl, program) +{ + var uniforms = {}; + + var totalUniforms = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS); + + for (var i = 0; i < totalUniforms; i++) + { + var uniformData = gl.getActiveUniform(program, i); + var name = uniformData.name.replace(/\[.*?\]/, ""); + var type = mapType(gl, uniformData.type ); + + uniforms[name] = { + type:type, + size:uniformData.size, + location:gl.getUniformLocation(program, name), + value:defaultValue(type, uniformData.size) + }; + } + + return uniforms; +}; + +module.exports = extractUniforms; + +},{"./defaultValue":17,"./mapType":23}],20:[function(require,module,exports){ +/** + * Extracts the attributes + * @class + * @memberof pixi.gl.shader + * @param gl {WebGLRenderingContext} The current WebGL rendering context + * @param uniforms {Array} @mat ? + * @return attributes {Object} + */ +var generateUniformAccessObject = function(gl, uniformData) +{ + // this is the object we will be sending back. + // an object hierachy will be created for structs + var uniforms = {data:{}}; + + uniforms.gl = gl; + + var uniformKeys= Object.keys(uniformData); + + for (var i = 0; i < uniformKeys.length; i++) + { + var fullName = uniformKeys[i]; + + var nameTokens = fullName.split('.'); + var name = nameTokens[nameTokens.length - 1]; + + var uniformGroup = getUniformGroup(nameTokens, uniforms); + + var uniform = uniformData[fullName]; + uniformGroup.data[name] = uniform; + + uniformGroup.gl = gl; + + Object.defineProperty(uniformGroup, name, { + get: generateGetter(name), + set: generateSetter(name, uniform) + }); + } + + return uniforms; +}; + +var generateGetter = function(name) +{ + var template = getterTemplate.replace('%%', name); + return new Function(template); // jshint ignore:line +}; + +var generateSetter = function(name, uniform) +{ + var template = setterTemplate.replace(/%%/g, name); + var setTemplate; + + if(uniform.size === 1) + { + setTemplate = GLSL_TO_SINGLE_SETTERS[uniform.type]; + } + else + { + setTemplate = GLSL_TO_ARRAY_SETTERS[uniform.type]; + } + + if(setTemplate) + { + template += "\nthis.gl." + setTemplate + ";"; + } + + return new Function('value', template); // jshint ignore:line +}; + +var getUniformGroup = function(nameTokens, uniform) +{ + var cur = uniform; + + for (var i = 0; i < nameTokens.length - 1; i++) + { + var o = cur[nameTokens[i]] || {data:{}}; + cur[nameTokens[i]] = o; + cur = o; + } + + return cur; +}; + +var getterTemplate = [ + 'return this.data.%%.value;', +].join('\n'); + +var setterTemplate = [ + 'this.data.%%.value = value;', + 'var location = this.data.%%.location;' +].join('\n'); + + +var GLSL_TO_SINGLE_SETTERS = { + + 'float': 'uniform1f(location, value)', + + 'vec2': 'uniform2f(location, value[0], value[1])', + 'vec3': 'uniform3f(location, value[0], value[1], value[2])', + 'vec4': 'uniform4f(location, value[0], value[1], value[2], value[3])', + + 'int': 'uniform1i(location, value)', + 'ivec2': 'uniform2i(location, value[0], value[1])', + 'ivec3': 'uniform3i(location, value[0], value[1], value[2])', + 'ivec4': 'uniform4i(location, value[0], value[1], value[2], value[3])', + + 'bool': 'uniform1i(location, value)', + 'bvec2': 'uniform2i(location, value[0], value[1])', + 'bvec3': 'uniform3i(location, value[0], value[1], value[2])', + 'bvec4': 'uniform4i(location, value[0], value[1], value[2], value[3])', + + 'mat2': 'uniformMatrix2fv(location, false, value)', + 'mat3': 'uniformMatrix3fv(location, false, value)', + 'mat4': 'uniformMatrix4fv(location, false, value)', + + 'sampler2D':'uniform1i(location, value)' +}; + +var GLSL_TO_ARRAY_SETTERS = { + + 'float': 'uniform1fv(location, value)', + + 'vec2': 'uniform2fv(location, value)', + 'vec3': 'uniform3fv(location, value)', + 'vec4': 'uniform4fv(location, value)', + + 'int': 'uniform1iv(location, value)', + 'ivec2': 'uniform2iv(location, value)', + 'ivec3': 'uniform3iv(location, value)', + 'ivec4': 'uniform4iv(location, value)', + + 'bool': 'uniform1iv(location, value)', + 'bvec2': 'uniform2iv(location, value)', + 'bvec3': 'uniform3iv(location, value)', + 'bvec4': 'uniform4iv(location, value)', + + 'sampler2D':'uniform1iv(location, value)' +}; + +module.exports = generateUniformAccessObject; + +},{}],21:[function(require,module,exports){ +module.exports = { + compileProgram: require('./compileProgram'), + defaultValue: require('./defaultValue'), + extractAttributes: require('./extractAttributes'), + extractUniforms: require('./extractUniforms'), + generateUniformAccessObject: require('./generateUniformAccessObject'), + mapSize: require('./mapSize'), + mapType: require('./mapType') +}; +},{"./compileProgram":16,"./defaultValue":17,"./extractAttributes":18,"./extractUniforms":19,"./generateUniformAccessObject":20,"./mapSize":22,"./mapType":23}],22:[function(require,module,exports){ +/** + * @class + * @memberof pixi.gl.shader + * @param type {String} + * @return {Number} + */ +var mapSize = function(type) +{ + return GLSL_TO_SIZE[type]; +}; + + +var GLSL_TO_SIZE = { + 'float': 1, + 'vec2': 2, + 'vec3': 3, + 'vec4': 4, + + 'int': 1, + 'ivec2': 2, + 'ivec3': 3, + 'ivec4': 4, + + 'bool': 1, + 'bvec2': 2, + 'bvec3': 3, + 'bvec4': 4, + + 'mat2': 4, + 'mat3': 9, + 'mat4': 16, + + 'sampler2D': 1 +}; + +module.exports = mapSize; + +},{}],23:[function(require,module,exports){ + + +var mapSize = function(gl, type) +{ + if(!GL_TABLE) + { + var typeNames = Object.keys(GL_TO_GLSL_TYPES); + + GL_TABLE = {}; + + for(var i = 0; i < typeNames.length; ++i) + { + var tn = typeNames[i]; + GL_TABLE[ gl[tn] ] = GL_TO_GLSL_TYPES[tn]; + } + } + + return GL_TABLE[type]; +}; + +var GL_TABLE = null; + +var GL_TO_GLSL_TYPES = { + 'FLOAT': 'float', + 'FLOAT_VEC2': 'vec2', + 'FLOAT_VEC3': 'vec3', + 'FLOAT_VEC4': 'vec4', + + 'INT': 'int', + 'INT_VEC2': 'ivec2', + 'INT_VEC3': 'ivec3', + 'INT_VEC4': 'ivec4', + + 'BOOL': 'bool', + 'BOOL_VEC2': 'bvec2', + 'BOOL_VEC3': 'bvec3', + 'BOOL_VEC4': 'bvec4', + + 'FLOAT_MAT2': 'mat2', + 'FLOAT_MAT3': 'mat3', + 'FLOAT_MAT4': 'mat4', + + 'SAMPLER_2D': 'sampler2D' +}; + +module.exports = mapSize; + +},{}],24:[function(require,module,exports){ +// shim for using process in browser +var process = module.exports = {}; + +// cached from whatever global is present so that test runners that stub it +// don't break things. But we need to wrap it in a try catch in case it is +// wrapped in strict mode code which doesn't define any globals. It's inside a +// function because try/catches deoptimize in certain engines. + +var cachedSetTimeout; +var cachedClearTimeout; + +(function () { + try { + cachedSetTimeout = setTimeout; + } catch (e) { + cachedSetTimeout = function () { + throw new Error('setTimeout is not defined'); + } + } + try { + cachedClearTimeout = clearTimeout; + } catch (e) { + cachedClearTimeout = function () { + throw new Error('clearTimeout is not defined'); + } + } +} ()) +function runTimeout(fun) { + if (cachedSetTimeout === setTimeout) { + return setTimeout(fun, 0); + } else { + return cachedSetTimeout.call(null, fun, 0); + } +} +function runClearTimeout(marker) { + if (cachedClearTimeout === clearTimeout) { + clearTimeout(marker); + } else { + cachedClearTimeout.call(null, marker); + } +} +var queue = []; +var draining = false; +var currentQueue; +var queueIndex = -1; + +function cleanUpNextTick() { + if (!draining || !currentQueue) { + return; + } + draining = false; + if (currentQueue.length) { + queue = currentQueue.concat(queue); + } else { + queueIndex = -1; + } + if (queue.length) { + drainQueue(); + } +} + +function drainQueue() { + if (draining) { + return; + } + var timeout = runTimeout(cleanUpNextTick); + draining = true; + + var len = queue.length; + while(len) { + currentQueue = queue; + queue = []; + while (++queueIndex < len) { + if (currentQueue) { + currentQueue[queueIndex].run(); + } + } + queueIndex = -1; + len = queue.length; + } + currentQueue = null; + draining = false; + runClearTimeout(timeout); +} + +process.nextTick = function (fun) { + var args = new Array(arguments.length - 1); + if (arguments.length > 1) { + for (var i = 1; i < arguments.length; i++) { + args[i - 1] = arguments[i]; + } + } + queue.push(new Item(fun, args)); + if (queue.length === 1 && !draining) { + runTimeout(drainQueue); + } +}; + +// v8 likes predictible objects +function Item(fun, array) { + this.fun = fun; + this.array = array; +} +Item.prototype.run = function () { + this.fun.apply(null, this.array); +}; +process.title = 'browser'; +process.browser = true; +process.env = {}; +process.argv = []; +process.version = ''; // empty string to avoid regexp issues +process.versions = {}; + +function noop() {} + +process.on = noop; +process.addListener = noop; +process.once = noop; +process.off = noop; +process.removeListener = noop; +process.removeAllListeners = noop; +process.emit = noop; + +process.binding = function (name) { + throw new Error('process.binding is not supported'); +}; + +process.cwd = function () { return '/' }; +process.chdir = function (dir) { + throw new Error('process.chdir is not supported'); +}; +process.umask = function() { return 0; }; + +},{}],25:[function(require,module,exports){ +(function (global){ +/*! https://mths.be/punycode v1.4.1 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 new 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. + * https://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.4.1', + /** + * 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, io.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 : {}) + +},{}],26:[function(require,module,exports){ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +'use strict'; + +// If obj.hasOwnProperty has been overridden, then calling +// obj.hasOwnProperty(prop) will break. +// See: https://github.com/joyent/node/issues/1707 +function hasOwnProperty(obj, prop) { + return Object.prototype.hasOwnProperty.call(obj, prop); +} + +module.exports = function(qs, sep, eq, options) { + sep = sep || '&'; + eq = eq || '='; + var obj = {}; + + if (typeof qs !== 'string' || qs.length === 0) { + return obj; + } + + var regexp = /\+/g; + qs = qs.split(sep); + + var maxKeys = 1000; + if (options && typeof options.maxKeys === 'number') { + maxKeys = options.maxKeys; + } + + var len = qs.length; + // maxKeys <= 0 means that we should not limit keys count + if (maxKeys > 0 && len > maxKeys) { + len = maxKeys; + } + + for (var i = 0; i < len; ++i) { + var x = qs[i].replace(regexp, '%20'), + idx = x.indexOf(eq), + kstr, vstr, k, v; + + if (idx >= 0) { + kstr = x.substr(0, idx); + vstr = x.substr(idx + 1); + } else { + kstr = x; + vstr = ''; + } + + k = decodeURIComponent(kstr); + v = decodeURIComponent(vstr); + + if (!hasOwnProperty(obj, k)) { + obj[k] = v; + } else if (isArray(obj[k])) { + obj[k].push(v); + } else { + obj[k] = [obj[k], v]; + } + } + + return obj; +}; + +var isArray = Array.isArray || function (xs) { + return Object.prototype.toString.call(xs) === '[object Array]'; +}; + +},{}],27:[function(require,module,exports){ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +'use strict'; + +var stringifyPrimitive = function(v) { + switch (typeof v) { + case 'string': + return v; + + case 'boolean': + return v ? 'true' : 'false'; + + case 'number': + return isFinite(v) ? v : ''; + + default: + return ''; + } +}; + +module.exports = function(obj, sep, eq, name) { + sep = sep || '&'; + eq = eq || '='; + if (obj === null) { + obj = undefined; + } + + if (typeof obj === 'object') { + return map(objectKeys(obj), function(k) { + var ks = encodeURIComponent(stringifyPrimitive(k)) + eq; + if (isArray(obj[k])) { + return map(obj[k], function(v) { + return ks + encodeURIComponent(stringifyPrimitive(v)); + }).join(sep); + } else { + return ks + encodeURIComponent(stringifyPrimitive(obj[k])); + } + }).join(sep); + + } + + if (!name) return ''; + return encodeURIComponent(stringifyPrimitive(name)) + eq + + encodeURIComponent(stringifyPrimitive(obj)); +}; + +var isArray = Array.isArray || function (xs) { + return Object.prototype.toString.call(xs) === '[object Array]'; +}; + +function map (xs, f) { + if (xs.map) return xs.map(f); + var res = []; + for (var i = 0; i < xs.length; i++) { + res.push(f(xs[i], i)); + } + return res; +} + +var objectKeys = Object.keys || function (obj) { + var res = []; + for (var key in obj) { + if (Object.prototype.hasOwnProperty.call(obj, key)) res.push(key); + } + return res; +}; + +},{}],28:[function(require,module,exports){ +'use strict'; + +exports.decode = exports.parse = require('./decode'); +exports.encode = exports.stringify = require('./encode'); + +},{"./decode":26,"./encode":27}],29:[function(require,module,exports){ +(function (process,global){ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : + typeof define === 'function' && define.amd ? define(['exports'], factory) : + (factory((global.async = global.async || {}))); +}(this, function (exports) { 'use strict'; + + /** + * A faster alternative to `Function#apply`, this function invokes `func` + * with the `this` binding of `thisArg` and the arguments of `args`. + * + * @private + * @param {Function} func The function to invoke. + * @param {*} thisArg The `this` binding of `func`. + * @param {Array} args The arguments to invoke `func` with. + * @returns {*} Returns the result of `func`. + */ + function apply(func, thisArg, args) { + var length = args.length; + switch (length) { + case 0: return func.call(thisArg); + case 1: return func.call(thisArg, args[0]); + case 2: return func.call(thisArg, args[0], args[1]); + case 3: return func.call(thisArg, args[0], args[1], args[2]); + } + return func.apply(thisArg, args); + } + + /** + * Checks if `value` is the + * [language type](http://www.ecma-international.org/ecma-262/6.0/#sec-ecmascript-language-types) + * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is an object, else `false`. + * @example + * + * _.isObject({}); + * // => true + * + * _.isObject([1, 2, 3]); + * // => true + * + * _.isObject(_.noop); + * // => true + * + * _.isObject(null); + * // => false + */ + function isObject(value) { + var type = typeof value; + return !!value && (type == 'object' || type == 'function'); + } + + var funcTag = '[object Function]'; + var genTag = '[object GeneratorFunction]'; + /** Used for built-in method references. */ + var objectProto = Object.prototype; + + /** + * Used to resolve the + * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) + * of values. + */ + var objectToString = objectProto.toString; + + /** + * Checks if `value` is classified as a `Function` object. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is correctly classified, + * else `false`. + * @example + * + * _.isFunction(_); + * // => true + * + * _.isFunction(/abc/); + * // => false + */ + function isFunction(value) { + // The use of `Object#toString` avoids issues with the `typeof` operator + // in Safari 8 which returns 'object' for typed array and weak map constructors, + // and PhantomJS 1.9 which returns 'function' for `NodeList` instances. + var tag = isObject(value) ? objectToString.call(value) : ''; + return tag == funcTag || tag == genTag; + } + + /** + * Checks if `value` is object-like. A value is object-like if it's not `null` + * and has a `typeof` result of "object". + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is object-like, else `false`. + * @example + * + * _.isObjectLike({}); + * // => true + * + * _.isObjectLike([1, 2, 3]); + * // => true + * + * _.isObjectLike(_.noop); + * // => false + * + * _.isObjectLike(null); + * // => false + */ + function isObjectLike(value) { + return !!value && typeof value == 'object'; + } + + /** `Object#toString` result references. */ + var symbolTag = '[object Symbol]'; + + /** Used for built-in method references. */ + var objectProto$1 = Object.prototype; + + /** + * Used to resolve the + * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) + * of values. + */ + var objectToString$1 = objectProto$1.toString; + + /** + * Checks if `value` is classified as a `Symbol` primitive or object. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is correctly classified, + * else `false`. + * @example + * + * _.isSymbol(Symbol.iterator); + * // => true + * + * _.isSymbol('abc'); + * // => false + */ + function isSymbol(value) { + return typeof value == 'symbol' || + (isObjectLike(value) && objectToString$1.call(value) == symbolTag); + } + + /** Used as references for various `Number` constants. */ + var NAN = 0 / 0; + + /** Used to match leading and trailing whitespace. */ + var reTrim = /^\s+|\s+$/g; + + /** Used to detect bad signed hexadecimal string values. */ + var reIsBadHex = /^[-+]0x[0-9a-f]+$/i; + + /** Used to detect binary string values. */ + var reIsBinary = /^0b[01]+$/i; + + /** Used to detect octal string values. */ + var reIsOctal = /^0o[0-7]+$/i; + + /** Built-in method references without a dependency on `root`. */ + var freeParseInt = parseInt; + + /** + * Converts `value` to a number. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to process. + * @returns {number} Returns the number. + * @example + * + * _.toNumber(3.2); + * // => 3.2 + * + * _.toNumber(Number.MIN_VALUE); + * // => 5e-324 + * + * _.toNumber(Infinity); + * // => Infinity + * + * _.toNumber('3.2'); + * // => 3.2 + */ + function toNumber(value) { + if (typeof value == 'number') { + return value; + } + if (isSymbol(value)) { + return NAN; + } + if (isObject(value)) { + var other = isFunction(value.valueOf) ? value.valueOf() : value; + value = isObject(other) ? (other + '') : other; + } + if (typeof value != 'string') { + return value === 0 ? value : +value; + } + value = value.replace(reTrim, ''); + var isBinary = reIsBinary.test(value); + return (isBinary || reIsOctal.test(value)) + ? freeParseInt(value.slice(2), isBinary ? 2 : 8) + : (reIsBadHex.test(value) ? NAN : +value); + } + + var INFINITY = 1 / 0; + var MAX_INTEGER = 1.7976931348623157e+308; + /** + * Converts `value` to a finite number. + * + * @static + * @memberOf _ + * @since 4.12.0 + * @category Lang + * @param {*} value The value to convert. + * @returns {number} Returns the converted number. + * @example + * + * _.toFinite(3.2); + * // => 3.2 + * + * _.toFinite(Number.MIN_VALUE); + * // => 5e-324 + * + * _.toFinite(Infinity); + * // => 1.7976931348623157e+308 + * + * _.toFinite('3.2'); + * // => 3.2 + */ + function toFinite(value) { + if (!value) { + return value === 0 ? value : 0; + } + value = toNumber(value); + if (value === INFINITY || value === -INFINITY) { + var sign = (value < 0 ? -1 : 1); + return sign * MAX_INTEGER; + } + return value === value ? value : 0; + } + + /** + * Converts `value` to an integer. + * + * **Note:** This method is loosely based on + * [`ToInteger`](http://www.ecma-international.org/ecma-262/6.0/#sec-tointeger). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to convert. + * @returns {number} Returns the converted integer. + * @example + * + * _.toInteger(3.2); + * // => 3 + * + * _.toInteger(Number.MIN_VALUE); + * // => 0 + * + * _.toInteger(Infinity); + * // => 1.7976931348623157e+308 + * + * _.toInteger('3.2'); + * // => 3 + */ + function toInteger(value) { + var result = toFinite(value), + remainder = result % 1; + + return result === result ? (remainder ? result - remainder : result) : 0; + } + + /** Used as the `TypeError` message for "Functions" methods. */ + var FUNC_ERROR_TEXT = 'Expected a function'; + + /* Built-in method references for those with the same name as other `lodash` methods. */ + var nativeMax = Math.max; + + /** + * Creates a function that invokes `func` with the `this` binding of the + * created function and arguments from `start` and beyond provided as + * an array. + * + * **Note:** This method is based on the + * [rest parameter](https://mdn.io/rest_parameters). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Function + * @param {Function} func The function to apply a rest parameter to. + * @param {number} [start=func.length-1] The start position of the rest parameter. + * @returns {Function} Returns the new function. + * @example + * + * var say = _.rest(function(what, names) { + * return what + ' ' + _.initial(names).join(', ') + + * (_.size(names) > 1 ? ', & ' : '') + _.last(names); + * }); + * + * say('hello', 'fred', 'barney', 'pebbles'); + * // => 'hello fred, barney, & pebbles' + */ + function rest(func, start) { + if (typeof func != 'function') { + throw new TypeError(FUNC_ERROR_TEXT); + } + start = nativeMax(start === undefined ? (func.length - 1) : toInteger(start), 0); + return function() { + var args = arguments, + index = -1, + length = nativeMax(args.length - start, 0), + array = Array(length); + + while (++index < length) { + array[index] = args[start + index]; + } + switch (start) { + case 0: return func.call(this, array); + case 1: return func.call(this, args[0], array); + case 2: return func.call(this, args[0], args[1], array); + } + var otherArgs = Array(start + 1); + index = -1; + while (++index < start) { + otherArgs[index] = args[index]; + } + otherArgs[start] = array; + return apply(func, this, otherArgs); + }; + } + + function initialParams (fn) { + return rest(function (args /*..., callback*/) { + var callback = args.pop(); + fn.call(this, args, callback); + }); + } + + function applyEach$1(eachfn) { + return rest(function (fns, args) { + var go = initialParams(function (args, callback) { + var that = this; + return eachfn(fns, function (fn, cb) { + fn.apply(that, args.concat([cb])); + }, callback); + }); + if (args.length) { + return go.apply(this, args); + } else { + return go; + } + }); + } + + /** + * The base implementation of `_.property` without support for deep paths. + * + * @private + * @param {string} key The key of the property to get. + * @returns {Function} Returns the new accessor function. + */ + function baseProperty(key) { + return function(object) { + return object == null ? undefined : object[key]; + }; + } + + /** + * Gets the "length" property value of `object`. + * + * **Note:** This function is used to avoid a + * [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792) that affects + * Safari on at least iOS 8.1-8.3 ARM64. + * + * @private + * @param {Object} object The object to query. + * @returns {*} Returns the "length" value. + */ + var getLength = baseProperty('length'); + + /** Used as references for various `Number` constants. */ + var MAX_SAFE_INTEGER = 9007199254740991; + + /** + * Checks if `value` is a valid array-like length. + * + * **Note:** This function is loosely based on + * [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a valid length, + * else `false`. + * @example + * + * _.isLength(3); + * // => true + * + * _.isLength(Number.MIN_VALUE); + * // => false + * + * _.isLength(Infinity); + * // => false + * + * _.isLength('3'); + * // => false + */ + function isLength(value) { + return typeof value == 'number' && + value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER; + } + + /** + * Checks if `value` is array-like. A value is considered array-like if it's + * not a function and has a `value.length` that's an integer greater than or + * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is array-like, else `false`. + * @example + * + * _.isArrayLike([1, 2, 3]); + * // => true + * + * _.isArrayLike(document.body.children); + * // => true + * + * _.isArrayLike('abc'); + * // => true + * + * _.isArrayLike(_.noop); + * // => false + */ + function isArrayLike(value) { + return value != null && isLength(getLength(value)) && !isFunction(value); + } + + /** + * A method that returns `undefined`. + * + * @static + * @memberOf _ + * @since 2.3.0 + * @category Util + * @example + * + * _.times(2, _.noop); + * // => [undefined, undefined] + */ + function noop() { + // No operation performed. + } + + function once(fn) { + return function () { + if (fn === null) return; + var callFn = fn; + fn = null; + callFn.apply(this, arguments); + }; + } + + var iteratorSymbol = typeof Symbol === 'function' && Symbol.iterator; + + function getIterator (coll) { + return iteratorSymbol && coll[iteratorSymbol] && coll[iteratorSymbol](); + } + + /* Built-in method references for those with the same name as other `lodash` methods. */ + var nativeGetPrototype = Object.getPrototypeOf; + + /** + * Gets the `[[Prototype]]` of `value`. + * + * @private + * @param {*} value The value to query. + * @returns {null|Object} Returns the `[[Prototype]]`. + */ + function getPrototype(value) { + return nativeGetPrototype(Object(value)); + } + + /** Used for built-in method references. */ + var objectProto$2 = Object.prototype; + + /** Used to check objects for own properties. */ + var hasOwnProperty = objectProto$2.hasOwnProperty; + + /** + * The base implementation of `_.has` without support for deep paths. + * + * @private + * @param {Object} [object] The object to query. + * @param {Array|string} key The key to check. + * @returns {boolean} Returns `true` if `key` exists, else `false`. + */ + function baseHas(object, key) { + // Avoid a bug in IE 10-11 where objects with a [[Prototype]] of `null`, + // that are composed entirely of index properties, return `false` for + // `hasOwnProperty` checks of them. + return object != null && + (hasOwnProperty.call(object, key) || + (typeof object == 'object' && key in object && getPrototype(object) === null)); + } + + /* Built-in method references for those with the same name as other `lodash` methods. */ + var nativeKeys = Object.keys; + + /** + * The base implementation of `_.keys` which doesn't skip the constructor + * property of prototypes or treat sparse arrays as dense. + * + * @private + * @param {Object} object The object to query. + * @returns {Array} Returns the array of property names. + */ + function baseKeys(object) { + return nativeKeys(Object(object)); + } + + /** + * The base implementation of `_.times` without support for iteratee shorthands + * or max array length checks. + * + * @private + * @param {number} n The number of times to invoke `iteratee`. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Array} Returns the array of results. + */ + function baseTimes(n, iteratee) { + var index = -1, + result = Array(n); + + while (++index < n) { + result[index] = iteratee(index); + } + return result; + } + + /** + * This method is like `_.isArrayLike` except that it also checks if `value` + * is an object. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is an array-like object, + * else `false`. + * @example + * + * _.isArrayLikeObject([1, 2, 3]); + * // => true + * + * _.isArrayLikeObject(document.body.children); + * // => true + * + * _.isArrayLikeObject('abc'); + * // => false + * + * _.isArrayLikeObject(_.noop); + * // => false + */ + function isArrayLikeObject(value) { + return isObjectLike(value) && isArrayLike(value); + } + + /** `Object#toString` result references. */ + var argsTag = '[object Arguments]'; + + /** Used for built-in method references. */ + var objectProto$3 = Object.prototype; + + /** Used to check objects for own properties. */ + var hasOwnProperty$1 = objectProto$3.hasOwnProperty; + + /** + * Used to resolve the + * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) + * of values. + */ + var objectToString$2 = objectProto$3.toString; + + /** Built-in value references. */ + var propertyIsEnumerable = objectProto$3.propertyIsEnumerable; + + /** + * Checks if `value` is likely an `arguments` object. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is correctly classified, + * else `false`. + * @example + * + * _.isArguments(function() { return arguments; }()); + * // => true + * + * _.isArguments([1, 2, 3]); + * // => false + */ + function isArguments(value) { + // Safari 8.1 incorrectly makes `arguments.callee` enumerable in strict mode. + return isArrayLikeObject(value) && hasOwnProperty$1.call(value, 'callee') && + (!propertyIsEnumerable.call(value, 'callee') || objectToString$2.call(value) == argsTag); + } + + /** + * Checks if `value` is classified as an `Array` object. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @type {Function} + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is correctly classified, + * else `false`. + * @example + * + * _.isArray([1, 2, 3]); + * // => true + * + * _.isArray(document.body.children); + * // => false + * + * _.isArray('abc'); + * // => false + * + * _.isArray(_.noop); + * // => false + */ + var isArray = Array.isArray; + + /** `Object#toString` result references. */ + var stringTag = '[object String]'; + + /** Used for built-in method references. */ + var objectProto$4 = Object.prototype; + + /** + * Used to resolve the + * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) + * of values. + */ + var objectToString$3 = objectProto$4.toString; + + /** + * Checks if `value` is classified as a `String` primitive or object. + * + * @static + * @since 0.1.0 + * @memberOf _ + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is correctly classified, + * else `false`. + * @example + * + * _.isString('abc'); + * // => true + * + * _.isString(1); + * // => false + */ + function isString(value) { + return typeof value == 'string' || + (!isArray(value) && isObjectLike(value) && objectToString$3.call(value) == stringTag); + } + + /** + * Creates an array of index keys for `object` values of arrays, + * `arguments` objects, and strings, otherwise `null` is returned. + * + * @private + * @param {Object} object The object to query. + * @returns {Array|null} Returns index keys, else `null`. + */ + function indexKeys(object) { + var length = object ? object.length : undefined; + if (isLength(length) && + (isArray(object) || isString(object) || isArguments(object))) { + return baseTimes(length, String); + } + return null; + } + + /** Used as references for various `Number` constants. */ + var MAX_SAFE_INTEGER$1 = 9007199254740991; + + /** Used to detect unsigned integer values. */ + var reIsUint = /^(?:0|[1-9]\d*)$/; + + /** + * Checks if `value` is a valid array-like index. + * + * @private + * @param {*} value The value to check. + * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index. + * @returns {boolean} Returns `true` if `value` is a valid index, else `false`. + */ + function isIndex(value, length) { + length = length == null ? MAX_SAFE_INTEGER$1 : length; + return !!length && + (typeof value == 'number' || reIsUint.test(value)) && + (value > -1 && value % 1 == 0 && value < length); + } + + /** Used for built-in method references. */ + var objectProto$5 = Object.prototype; + + /** + * Checks if `value` is likely a prototype object. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a prototype, else `false`. + */ + function isPrototype(value) { + var Ctor = value && value.constructor, + proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto$5; + + return value === proto; + } + + /** + * Creates an array of the own enumerable property names of `object`. + * + * **Note:** Non-object values are coerced to objects. See the + * [ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys) + * for more details. + * + * @static + * @since 0.1.0 + * @memberOf _ + * @category Object + * @param {Object} object The object to query. + * @returns {Array} Returns the array of property names. + * @example + * + * function Foo() { + * this.a = 1; + * this.b = 2; + * } + * + * Foo.prototype.c = 3; + * + * _.keys(new Foo); + * // => ['a', 'b'] (iteration order is not guaranteed) + * + * _.keys('hi'); + * // => ['0', '1'] + */ + function keys(object) { + var isProto = isPrototype(object); + if (!(isProto || isArrayLike(object))) { + return baseKeys(object); + } + var indexes = indexKeys(object), + skipIndexes = !!indexes, + result = indexes || [], + length = result.length; + + for (var key in object) { + if (baseHas(object, key) && + !(skipIndexes && (key == 'length' || isIndex(key, length))) && + !(isProto && key == 'constructor')) { + result.push(key); + } + } + return result; + } + + function createArrayIterator(coll) { + var i = -1; + var len = coll.length; + return function next() { + return ++i < len ? { value: coll[i], key: i } : null; + }; + } + + function createES2015Iterator(iterator) { + var i = -1; + return function next() { + var item = iterator.next(); + if (item.done) return null; + i++; + return { value: item.value, key: i }; + }; + } + + function createObjectIterator(obj) { + var okeys = keys(obj); + var i = -1; + var len = okeys.length; + return function next() { + var key = okeys[++i]; + return i < len ? { value: obj[key], key: key } : null; + }; + } + + function iterator(coll) { + if (isArrayLike(coll)) { + return createArrayIterator(coll); + } + + var iterator = getIterator(coll); + return iterator ? createES2015Iterator(iterator) : createObjectIterator(coll); + } + + function onlyOnce(fn) { + return function () { + if (fn === null) throw new Error("Callback was already called."); + var callFn = fn; + fn = null; + callFn.apply(this, arguments); + }; + } + + function _eachOfLimit(limit) { + return function (obj, iteratee, callback) { + callback = once(callback || noop); + if (limit <= 0 || !obj) { + return callback(null); + } + var nextElem = iterator(obj); + var done = false; + var running = 0; + + function iterateeCallback(err) { + running -= 1; + if (err) { + done = true; + callback(err); + } else if (done && running <= 0) { + return callback(null); + } else { + replenish(); + } + } + + function replenish() { + while (running < limit && !done) { + var elem = nextElem(); + if (elem === null) { + done = true; + if (running <= 0) { + callback(null); + } + return; + } + running += 1; + iteratee(elem.value, elem.key, onlyOnce(iterateeCallback)); + } + } + + replenish(); + }; + } + + /** + * The same as [`eachOf`]{@link module:Collections.eachOf} but runs a maximum of `limit` async operations at a + * time. + * + * @name eachOfLimit + * @static + * @memberOf module:Collections + * @method + * @see [async.eachOf]{@link module:Collections.eachOf} + * @alias forEachOfLimit + * @category Collection + * @param {Array|Iterable|Object} coll - A collection to iterate over. + * @param {number} limit - The maximum number of async operations at a time. + * @param {Function} iteratee - A function to apply to each + * item in `coll`. The `key` is the item's key, or index in the case of an + * array. The iteratee is passed a `callback(err)` which must be called once it + * has completed. If no error has occurred, the callback should be run without + * arguments or with an explicit `null` argument. Invoked with + * (item, key, callback). + * @param {Function} [callback] - A callback which is called when all + * `iteratee` functions have finished, or an error occurs. Invoked with (err). + */ + function eachOfLimit(coll, limit, iteratee, callback) { + _eachOfLimit(limit)(coll, iteratee, callback); + } + + function doLimit(fn, limit) { + return function (iterable, iteratee, callback) { + return fn(iterable, limit, iteratee, callback); + }; + } + + /** Used as the `TypeError` message for "Functions" methods. */ + var FUNC_ERROR_TEXT$1 = 'Expected a function'; + + /** + * Creates a function that invokes `func`, with the `this` binding and arguments + * of the created function, while it's called less than `n` times. Subsequent + * calls to the created function return the result of the last `func` invocation. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Function + * @param {number} n The number of calls at which `func` is no longer invoked. + * @param {Function} func The function to restrict. + * @returns {Function} Returns the new restricted function. + * @example + * + * jQuery(element).on('click', _.before(5, addContactToList)); + * // => allows adding up to 4 contacts to the list + */ + function before(n, func) { + var result; + if (typeof func != 'function') { + throw new TypeError(FUNC_ERROR_TEXT$1); + } + n = toInteger(n); + return function() { + if (--n > 0) { + result = func.apply(this, arguments); + } + if (n <= 1) { + func = undefined; + } + return result; + }; + } + + /** + * Creates a function that is restricted to invoking `func` once. Repeat calls + * to the function return the value of the first invocation. The `func` is + * invoked with the `this` binding and arguments of the created function. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Function + * @param {Function} func The function to restrict. + * @returns {Function} Returns the new restricted function. + * @example + * + * var initialize = _.once(createApplication); + * initialize(); + * initialize(); + * // `initialize` invokes `createApplication` once + */ + function once$1(func) { + return before(2, func); + } + + // eachOf implementation optimized for array-likes + function eachOfArrayLike(coll, iteratee, callback) { + callback = once$1(callback || noop); + var index = 0, + completed = 0, + length = coll.length; + if (length === 0) { + callback(null); + } + + function iteratorCallback(err) { + if (err) { + callback(err); + } else if (++completed === length) { + callback(null); + } + } + + for (; index < length; index++) { + iteratee(coll[index], index, onlyOnce(iteratorCallback)); + } + } + + // a generic version of eachOf which can handle array, object, and iterator cases. + var eachOfGeneric = doLimit(eachOfLimit, Infinity); + + /** + * Like [`each`]{@link module:Collections.each}, except that it passes the key (or index) as the second argument + * to the iteratee. + * + * @name eachOf + * @static + * @memberOf module:Collections + * @method + * @alias forEachOf + * @category Collection + * @see [async.each]{@link module:Collections.each} + * @param {Array|Iterable|Object} coll - A collection to iterate over. + * @param {Function} iteratee - A function to apply to each + * item in `coll`. The `key` is the item's key, or index in the case of an + * array. The iteratee is passed a `callback(err)` which must be called once it + * has completed. If no error has occurred, the callback should be run without + * arguments or with an explicit `null` argument. Invoked with + * (item, key, callback). + * @param {Function} [callback] - A callback which is called when all + * `iteratee` functions have finished, or an error occurs. Invoked with (err). + * @example + * + * var obj = {dev: "/dev.json", test: "/test.json", prod: "/prod.json"}; + * var configs = {}; + * + * async.forEachOf(obj, function (value, key, callback) { + * fs.readFile(__dirname + value, "utf8", function (err, data) { + * if (err) return callback(err); + * try { + * configs[key] = JSON.parse(data); + * } catch (e) { + * return callback(e); + * } + * callback(); + * }); + * }, function (err) { + * if (err) console.error(err.message); + * // configs is now a map of JSON data + * doSomethingWith(configs); + * }); + */ + function eachOf (coll, iteratee, callback) { + var eachOfImplementation = isArrayLike(coll) ? eachOfArrayLike : eachOfGeneric; + eachOfImplementation(coll, iteratee, callback); + } + + function doParallel(fn) { + return function (obj, iteratee, callback) { + return fn(eachOf, obj, iteratee, callback); + }; + } + + function _asyncMap(eachfn, arr, iteratee, callback) { + callback = once(callback || noop); + arr = arr || []; + var results = []; + var counter = 0; + + eachfn(arr, function (value, _, callback) { + var index = counter++; + iteratee(value, function (err, v) { + results[index] = v; + callback(err); + }); + }, function (err) { + callback(err, results); + }); + } + + /** + * Produces a new collection of values by mapping each value in `coll` through + * the `iteratee` function. The `iteratee` is called with an item from `coll` + * and a callback for when it has finished processing. Each of these callback + * takes 2 arguments: an `error`, and the transformed item from `coll`. If + * `iteratee` passes an error to its callback, the main `callback` (for the + * `map` function) is immediately called with the error. + * + * Note, that since this function applies the `iteratee` to each item in + * parallel, there is no guarantee that the `iteratee` functions will complete + * in order. However, the results array will be in the same order as the + * original `coll`. + * + * If `map` is passed an Object, the results will be an Array. The results + * will roughly be in the order of the original Objects' keys (but this can + * vary across JavaScript engines) + * + * @name map + * @static + * @memberOf module:Collections + * @method + * @category Collection + * @param {Array|Iterable|Object} coll - A collection to iterate over. + * @param {Function} iteratee - A function to apply to each item in `coll`. + * The iteratee is passed a `callback(err, transformed)` which must be called + * once it has completed with an error (which can be `null`) and a + * transformed item. Invoked with (item, callback). + * @param {Function} [callback] - A callback which is called when all `iteratee` + * functions have finished, or an error occurs. Results is an Array of the + * transformed items from the `coll`. Invoked with (err, results). + * @example + * + * async.map(['file1','file2','file3'], fs.stat, function(err, results) { + * // results is now an array of stats for each file + * }); + */ + var map = doParallel(_asyncMap); + + /** + * Applies the provided arguments to each function in the array, calling + * `callback` after all functions have completed. If you only provide the first + * argument, then it will return a function which lets you pass in the + * arguments as if it were a single function call. + * + * @name applyEach + * @static + * @memberOf module:ControlFlow + * @method + * @category Control Flow + * @param {Array|Iterable|Object} fns - A collection of asynchronous functions to all + * call with the same arguments + * @param {...*} [args] - any number of separate arguments to pass to the + * function. + * @param {Function} [callback] - the final argument should be the callback, + * called when all functions have completed processing. + * @returns {Function} - If only the first argument is provided, it will return + * a function which lets you pass in the arguments as if it were a single + * function call. + * @example + * + * async.applyEach([enableSearch, updateSchema], 'bucket', callback); + * + * // partial application example: + * async.each( + * buckets, + * async.applyEach([enableSearch, updateSchema]), + * callback + * ); + */ + var applyEach = applyEach$1(map); + + function doParallelLimit(fn) { + return function (obj, limit, iteratee, callback) { + return fn(_eachOfLimit(limit), obj, iteratee, callback); + }; + } + + /** + * The same as [`map`]{@link module:Collections.map} but runs a maximum of `limit` async operations at a time. + * + * @name mapLimit + * @static + * @memberOf module:Collections + * @method + * @see [async.map]{@link module:Collections.map} + * @category Collection + * @param {Array|Iterable|Object} coll - A collection to iterate over. + * @param {number} limit - The maximum number of async operations at a time. + * @param {Function} iteratee - A function to apply to each item in `coll`. + * The iteratee is passed a `callback(err, transformed)` which must be called + * once it has completed with an error (which can be `null`) and a transformed + * item. Invoked with (item, callback). + * @param {Function} [callback] - A callback which is called when all `iteratee` + * functions have finished, or an error occurs. Results is an array of the + * transformed items from the `coll`. Invoked with (err, results). + */ + var mapLimit = doParallelLimit(_asyncMap); + + /** + * The same as [`map`]{@link module:Collections.map} but runs only a single async operation at a time. + * + * @name mapSeries + * @static + * @memberOf module:Collections + * @method + * @see [async.map]{@link module:Collections.map} + * @category Collection + * @param {Array|Iterable|Object} coll - A collection to iterate over. + * @param {Function} iteratee - A function to apply to each item in `coll`. + * The iteratee is passed a `callback(err, transformed)` which must be called + * once it has completed with an error (which can be `null`) and a + * transformed item. Invoked with (item, callback). + * @param {Function} [callback] - A callback which is called when all `iteratee` + * functions have finished, or an error occurs. Results is an array of the + * transformed items from the `coll`. Invoked with (err, results). + */ + var mapSeries = doLimit(mapLimit, 1); + + /** + * The same as [`applyEach`]{@link module:ControlFlow.applyEach} but runs only a single async operation at a time. + * + * @name applyEachSeries + * @static + * @memberOf module:ControlFlow + * @method + * @see [async.applyEach]{@link module:ControlFlow.applyEach} + * @category Control Flow + * @param {Array|Iterable|Object} fns - A collection of asynchronous functions to all + * call with the same arguments + * @param {...*} [args] - any number of separate arguments to pass to the + * function. + * @param {Function} [callback] - the final argument should be the callback, + * called when all functions have completed processing. + * @returns {Function} - If only the first argument is provided, it will return + * a function which lets you pass in the arguments as if it were a single + * function call. + */ + var applyEachSeries = applyEach$1(mapSeries); + + /** + * Creates a continuation function with some arguments already applied. + * + * Useful as a shorthand when combined with other control flow functions. Any + * arguments passed to the returned function are added to the arguments + * originally passed to apply. + * + * @name apply + * @static + * @memberOf module:Utils + * @method + * @category Util + * @param {Function} function - The function you want to eventually apply all + * arguments to. Invokes with (arguments...). + * @param {...*} arguments... - Any number of arguments to automatically apply + * when the continuation is called. + * @example + * + * // using apply + * async.parallel([ + * async.apply(fs.writeFile, 'testfile1', 'test1'), + * async.apply(fs.writeFile, 'testfile2', 'test2') + * ]); + * + * + * // the same process without using apply + * async.parallel([ + * function(callback) { + * fs.writeFile('testfile1', 'test1', callback); + * }, + * function(callback) { + * fs.writeFile('testfile2', 'test2', callback); + * } + * ]); + * + * // It's possible to pass any number of additional arguments when calling the + * // continuation: + * + * node> var fn = async.apply(sys.puts, 'one'); + * node> fn('two', 'three'); + * one + * two + * three + */ + var apply$1 = rest(function (fn, args) { + return rest(function (callArgs) { + return fn.apply(null, args.concat(callArgs)); + }); + }); + + /** + * Take a sync function and make it async, passing its return value to a + * callback. This is useful for plugging sync functions into a waterfall, + * series, or other async functions. Any arguments passed to the generated + * function will be passed to the wrapped function (except for the final + * callback argument). Errors thrown will be passed to the callback. + * + * If the function passed to `asyncify` returns a Promise, that promises's + * resolved/rejected state will be used to call the callback, rather than simply + * the synchronous return value. + * + * This also means you can asyncify ES2016 `async` functions. + * + * @name asyncify + * @static + * @memberOf module:Utils + * @method + * @alias wrapSync + * @category Util + * @param {Function} func - The synchronous function to convert to an + * asynchronous function. + * @returns {Function} An asynchronous wrapper of the `func`. To be invoked with + * (callback). + * @example + * + * // passing a regular synchronous function + * async.waterfall([ + * async.apply(fs.readFile, filename, "utf8"), + * async.asyncify(JSON.parse), + * function (data, next) { + * // data is the result of parsing the text. + * // If there was a parsing error, it would have been caught. + * } + * ], callback); + * + * // passing a function returning a promise + * async.waterfall([ + * async.apply(fs.readFile, filename, "utf8"), + * async.asyncify(function (contents) { + * return db.model.create(contents); + * }), + * function (model, next) { + * // `model` is the instantiated model object. + * // If there was an error, this function would be skipped. + * } + * ], callback); + * + * // es6 example + * var q = async.queue(async.asyncify(async function(file) { + * var intermediateStep = await processFile(file); + * return await somePromise(intermediateStep) + * })); + * + * q.push(files); + */ + function asyncify(func) { + return initialParams(function (args, callback) { + var result; + try { + result = func.apply(this, args); + } catch (e) { + return callback(e); + } + // if result is Promise object + if (isObject(result) && typeof result.then === 'function') { + result.then(function (value) { + callback(null, value); + }, function (err) { + callback(err.message ? err : new Error(err)); + }); + } else { + callback(null, result); + } + }); + } + + /** + * A specialized version of `_.forEach` for arrays without support for + * iteratee shorthands. + * + * @private + * @param {Array} [array] The array to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Array} Returns `array`. + */ + function arrayEach(array, iteratee) { + var index = -1, + length = array ? array.length : 0; + + while (++index < length) { + if (iteratee(array[index], index, array) === false) { + break; + } + } + return array; + } + + /** + * Creates a base function for methods like `_.forIn` and `_.forOwn`. + * + * @private + * @param {boolean} [fromRight] Specify iterating from right to left. + * @returns {Function} Returns the new base function. + */ + function createBaseFor(fromRight) { + return function(object, iteratee, keysFunc) { + var index = -1, + iterable = Object(object), + props = keysFunc(object), + length = props.length; + + while (length--) { + var key = props[fromRight ? length : ++index]; + if (iteratee(iterable[key], key, iterable) === false) { + break; + } + } + return object; + }; + } + + /** + * The base implementation of `baseForOwn` which iterates over `object` + * properties returned by `keysFunc` and invokes `iteratee` for each property. + * Iteratee functions may exit iteration early by explicitly returning `false`. + * + * @private + * @param {Object} object The object to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @param {Function} keysFunc The function to get the keys of `object`. + * @returns {Object} Returns `object`. + */ + var baseFor = createBaseFor(); + + /** + * The base implementation of `_.forOwn` without support for iteratee shorthands. + * + * @private + * @param {Object} object The object to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Object} Returns `object`. + */ + function baseForOwn(object, iteratee) { + return object && baseFor(object, iteratee, keys); + } + + /** + * Gets the index at which the first occurrence of `NaN` is found in `array`. + * + * @private + * @param {Array} array The array to search. + * @param {number} fromIndex The index to search from. + * @param {boolean} [fromRight] Specify iterating from right to left. + * @returns {number} Returns the index of the matched `NaN`, else `-1`. + */ + function indexOfNaN(array, fromIndex, fromRight) { + var length = array.length, + index = fromIndex + (fromRight ? 1 : -1); + + while ((fromRight ? index-- : ++index < length)) { + var other = array[index]; + if (other !== other) { + return index; + } + } + return -1; + } + + /** + * The base implementation of `_.indexOf` without `fromIndex` bounds checks. + * + * @private + * @param {Array} array The array to search. + * @param {*} value The value to search for. + * @param {number} fromIndex The index to search from. + * @returns {number} Returns the index of the matched value, else `-1`. + */ + function baseIndexOf(array, value, fromIndex) { + if (value !== value) { + return indexOfNaN(array, fromIndex); + } + var index = fromIndex - 1, + length = array.length; + + while (++index < length) { + if (array[index] === value) { + return index; + } + } + return -1; + } + + /** + * Determines the best order for running the functions in `tasks`, based on + * their requirements. Each function can optionally depend on other functions + * being completed first, and each function is run as soon as its requirements + * are satisfied. + * + * If any of the functions pass an error to their callback, the `auto` sequence + * will stop. Further tasks will not execute (so any other functions depending + * on it will not run), and the main `callback` is immediately called with the + * error. + * + * Functions also receive an object containing the results of functions which + * have completed so far as the first argument, if they have dependencies. If a + * task function has no dependencies, it will only be passed a callback. + * + * @name auto + * @static + * @memberOf module:ControlFlow + * @method + * @category Control Flow + * @param {Object} tasks - An object. Each of its properties is either a + * function or an array of requirements, with the function itself the last item + * in the array. The object's key of a property serves as the name of the task + * defined by that property, i.e. can be used when specifying requirements for + * other tasks. The function receives one or two arguments: + * * a `results` object, containing the results of the previously executed + * functions, only passed if the task has any dependencies, + * * a `callback(err, result)` function, which must be called when finished, + * passing an `error` (which can be `null`) and the result of the function's + * execution. + * @param {number} [concurrency=Infinity] - An optional `integer` for + * determining the maximum number of tasks that can be run in parallel. By + * default, as many as possible. + * @param {Function} [callback] - An optional callback which is called when all + * the tasks have been completed. It receives the `err` argument if any `tasks` + * pass an error to their callback. Results are always returned; however, if an + * error occurs, no further `tasks` will be performed, and the results object + * will only contain partial results. Invoked with (err, results). + * @returns undefined + * @example + * + * async.auto({ + * // this function will just be passed a callback + * readData: async.apply(fs.readFile, 'data.txt', 'utf-8'), + * showData: ['readData', function(results, cb) { + * // results.readData is the file's contents + * // ... + * }] + * }, callback); + * + * async.auto({ + * get_data: function(callback) { + * console.log('in get_data'); + * // async code to get some data + * callback(null, 'data', 'converted to array'); + * }, + * make_folder: function(callback) { + * console.log('in make_folder'); + * // async code to create a directory to store a file in + * // this is run at the same time as getting the data + * callback(null, 'folder'); + * }, + * write_file: ['get_data', 'make_folder', function(results, callback) { + * console.log('in write_file', JSON.stringify(results)); + * // once there is some data and the directory exists, + * // write the data to a file in the directory + * callback(null, 'filename'); + * }], + * email_link: ['write_file', function(results, callback) { + * console.log('in email_link', JSON.stringify(results)); + * // once the file is written let's email a link to it... + * // results.write_file contains the filename returned by write_file. + * callback(null, {'file':results.write_file, 'email':'user@example.com'}); + * }] + * }, function(err, results) { + * console.log('err = ', err); + * console.log('results = ', results); + * }); + */ + function auto (tasks, concurrency, callback) { + if (typeof concurrency === 'function') { + // concurrency is optional, shift the args. + callback = concurrency; + concurrency = null; + } + callback = once(callback || noop); + var keys$$ = keys(tasks); + var numTasks = keys$$.length; + if (!numTasks) { + return callback(null); + } + if (!concurrency) { + concurrency = numTasks; + } + + var results = {}; + var runningTasks = 0; + var hasError = false; + + var listeners = {}; + + var readyTasks = []; + + // for cycle detection: + var readyToCheck = []; // tasks that have been identified as reachable + // without the possibility of returning to an ancestor task + var uncheckedDependencies = {}; + + baseForOwn(tasks, function (task, key) { + if (!isArray(task)) { + // no dependencies + enqueueTask(key, [task]); + readyToCheck.push(key); + return; + } + + var dependencies = task.slice(0, task.length - 1); + var remainingDependencies = dependencies.length; + if (remainingDependencies === 0) { + enqueueTask(key, task); + readyToCheck.push(key); + return; + } + uncheckedDependencies[key] = remainingDependencies; + + arrayEach(dependencies, function (dependencyName) { + if (!tasks[dependencyName]) { + throw new Error('async.auto task `' + key + '` has a non-existent dependency in ' + dependencies.join(', ')); + } + addListener(dependencyName, function () { + remainingDependencies--; + if (remainingDependencies === 0) { + enqueueTask(key, task); + } + }); + }); + }); + + checkForDeadlocks(); + processQueue(); + + function enqueueTask(key, task) { + readyTasks.push(function () { + runTask(key, task); + }); + } + + function processQueue() { + if (readyTasks.length === 0 && runningTasks === 0) { + return callback(null, results); + } + while (readyTasks.length && runningTasks < concurrency) { + var run = readyTasks.shift(); + run(); + } + } + + function addListener(taskName, fn) { + var taskListeners = listeners[taskName]; + if (!taskListeners) { + taskListeners = listeners[taskName] = []; + } + + taskListeners.push(fn); + } + + function taskComplete(taskName) { + var taskListeners = listeners[taskName] || []; + arrayEach(taskListeners, function (fn) { + fn(); + }); + processQueue(); + } + + function runTask(key, task) { + if (hasError) return; + + var taskCallback = onlyOnce(rest(function (err, args) { + runningTasks--; + if (args.length <= 1) { + args = args[0]; + } + if (err) { + var safeResults = {}; + baseForOwn(results, function (val, rkey) { + safeResults[rkey] = val; + }); + safeResults[key] = args; + hasError = true; + listeners = []; + + callback(err, safeResults); + } else { + results[key] = args; + taskComplete(key); + } + })); + + runningTasks++; + var taskFn = task[task.length - 1]; + if (task.length > 1) { + taskFn(results, taskCallback); + } else { + taskFn(taskCallback); + } + } + + function checkForDeadlocks() { + // Kahn's algorithm + // https://en.wikipedia.org/wiki/Topological_sorting#Kahn.27s_algorithm + // http://connalle.blogspot.com/2013/10/topological-sortingkahn-algorithm.html + var currentTask; + var counter = 0; + while (readyToCheck.length) { + currentTask = readyToCheck.pop(); + counter++; + arrayEach(getDependents(currentTask), function (dependent) { + if (--uncheckedDependencies[dependent] === 0) { + readyToCheck.push(dependent); + } + }); + } + + if (counter !== numTasks) { + throw new Error('async.auto cannot execute tasks due to a recursive dependency'); + } + } + + function getDependents(taskName) { + var result = []; + baseForOwn(tasks, function (task, key) { + if (isArray(task) && baseIndexOf(task, taskName, 0) >= 0) { + result.push(key); + } + }); + return result; + } + } + + /** + * A specialized version of `_.map` for arrays without support for iteratee + * shorthands. + * + * @private + * @param {Array} [array] The array to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Array} Returns the new mapped array. + */ + function arrayMap(array, iteratee) { + var index = -1, + length = array ? array.length : 0, + result = Array(length); + + while (++index < length) { + result[index] = iteratee(array[index], index, array); + } + return result; + } + + /** + * Copies the values of `source` to `array`. + * + * @private + * @param {Array} source The array to copy values from. + * @param {Array} [array=[]] The array to copy values to. + * @returns {Array} Returns `array`. + */ + function copyArray(source, array) { + var index = -1, + length = source.length; + + array || (array = Array(length)); + while (++index < length) { + array[index] = source[index]; + } + return array; + } + + /** + * Checks if `value` is a global object. + * + * @private + * @param {*} value The value to check. + * @returns {null|Object} Returns `value` if it's a global object, else `null`. + */ + function checkGlobal(value) { + return (value && value.Object === Object) ? value : null; + } + + /** Detect free variable `global` from Node.js. */ + var freeGlobal = checkGlobal(typeof global == 'object' && global); + + /** Detect free variable `self`. */ + var freeSelf = checkGlobal(typeof self == 'object' && self); + + /** Detect `this` as the global object. */ + var thisGlobal = checkGlobal(typeof this == 'object' && this); + + /** Used as a reference to the global object. */ + var root = freeGlobal || freeSelf || thisGlobal || Function('return this')(); + + /** Built-in value references. */ + var Symbol$1 = root.Symbol; + + /** Used as references for various `Number` constants. */ + var INFINITY$1 = 1 / 0; + + /** Used to convert symbols to primitives and strings. */ + var symbolProto = Symbol$1 ? Symbol$1.prototype : undefined; + var symbolToString = symbolProto ? symbolProto.toString : undefined; + /** + * The base implementation of `_.toString` which doesn't convert nullish + * values to empty strings. + * + * @private + * @param {*} value The value to process. + * @returns {string} Returns the string. + */ + function baseToString(value) { + // Exit early for strings to avoid a performance hit in some environments. + if (typeof value == 'string') { + return value; + } + if (isSymbol(value)) { + return symbolToString ? symbolToString.call(value) : ''; + } + var result = (value + ''); + return (result == '0' && (1 / value) == -INFINITY$1) ? '-0' : result; + } + + /** + * The base implementation of `_.slice` without an iteratee call guard. + * + * @private + * @param {Array} array The array to slice. + * @param {number} [start=0] The start position. + * @param {number} [end=array.length] The end position. + * @returns {Array} Returns the slice of `array`. + */ + function baseSlice(array, start, end) { + var index = -1, + length = array.length; + + if (start < 0) { + start = -start > length ? 0 : (length + start); + } + end = end > length ? length : end; + if (end < 0) { + end += length; + } + length = start > end ? 0 : ((end - start) >>> 0); + start >>>= 0; + + var result = Array(length); + while (++index < length) { + result[index] = array[index + start]; + } + return result; + } + + /** + * Casts `array` to a slice if it's needed. + * + * @private + * @param {Array} array The array to inspect. + * @param {number} start The start position. + * @param {number} [end=array.length] The end position. + * @returns {Array} Returns the cast slice. + */ + function castSlice(array, start, end) { + var length = array.length; + end = end === undefined ? length : end; + return (!start && end >= length) ? array : baseSlice(array, start, end); + } + + /** + * Used by `_.trim` and `_.trimEnd` to get the index of the last string symbol + * that is not found in the character symbols. + * + * @private + * @param {Array} strSymbols The string symbols to inspect. + * @param {Array} chrSymbols The character symbols to find. + * @returns {number} Returns the index of the last unmatched string symbol. + */ + function charsEndIndex(strSymbols, chrSymbols) { + var index = strSymbols.length; + + while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {} + return index; + } + + /** + * Used by `_.trim` and `_.trimStart` to get the index of the first string symbol + * that is not found in the character symbols. + * + * @private + * @param {Array} strSymbols The string symbols to inspect. + * @param {Array} chrSymbols The character symbols to find. + * @returns {number} Returns the index of the first unmatched string symbol. + */ + function charsStartIndex(strSymbols, chrSymbols) { + var index = -1, + length = strSymbols.length; + + while (++index < length && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {} + return index; + } + + /** Used to compose unicode character classes. */ + var rsAstralRange = '\\ud800-\\udfff'; + var rsComboMarksRange = '\\u0300-\\u036f\\ufe20-\\ufe23'; + var rsComboSymbolsRange = '\\u20d0-\\u20f0'; + var rsVarRange = '\\ufe0e\\ufe0f'; + var rsAstral = '[' + rsAstralRange + ']'; + var rsCombo = '[' + rsComboMarksRange + rsComboSymbolsRange + ']'; + var rsFitz = '\\ud83c[\\udffb-\\udfff]'; + var rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')'; + var rsNonAstral = '[^' + rsAstralRange + ']'; + var rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}'; + var rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]'; + var rsZWJ = '\\u200d'; + var reOptMod = rsModifier + '?'; + var rsOptVar = '[' + rsVarRange + ']?'; + var rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*'; + var rsSeq = rsOptVar + reOptMod + rsOptJoin; + var rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')'; + /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */ + var reComplexSymbol = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g'); + + /** + * Converts `string` to an array. + * + * @private + * @param {string} string The string to convert. + * @returns {Array} Returns the converted array. + */ + function stringToArray(string) { + return string.match(reComplexSymbol); + } + + /** + * Converts `value` to a string. An empty string is returned for `null` + * and `undefined` values. The sign of `-0` is preserved. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to process. + * @returns {string} Returns the string. + * @example + * + * _.toString(null); + * // => '' + * + * _.toString(-0); + * // => '-0' + * + * _.toString([1, 2, 3]); + * // => '1,2,3' + */ + function toString(value) { + return value == null ? '' : baseToString(value); + } + + /** Used to match leading and trailing whitespace. */ + var reTrim$1 = /^\s+|\s+$/g; + + /** + * Removes leading and trailing whitespace or specified characters from `string`. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category String + * @param {string} [string=''] The string to trim. + * @param {string} [chars=whitespace] The characters to trim. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. + * @returns {string} Returns the trimmed string. + * @example + * + * _.trim(' abc '); + * // => 'abc' + * + * _.trim('-_-abc-_-', '_-'); + * // => 'abc' + * + * _.map([' foo ', ' bar '], _.trim); + * // => ['foo', 'bar'] + */ + function trim(string, chars, guard) { + string = toString(string); + if (string && (guard || chars === undefined)) { + return string.replace(reTrim$1, ''); + } + if (!string || !(chars = baseToString(chars))) { + return string; + } + var strSymbols = stringToArray(string), + chrSymbols = stringToArray(chars), + start = charsStartIndex(strSymbols, chrSymbols), + end = charsEndIndex(strSymbols, chrSymbols) + 1; + + return castSlice(strSymbols, start, end).join(''); + } + + var FN_ARGS = /^(function)?\s*[^\(]*\(\s*([^\)]*)\)/m; + var FN_ARG_SPLIT = /,/; + var FN_ARG = /(=.+)?(\s*)$/; + var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg; + + function parseParams(func) { + func = func.toString().replace(STRIP_COMMENTS, ''); + func = func.match(FN_ARGS)[2].replace(' ', ''); + func = func ? func.split(FN_ARG_SPLIT) : []; + func = func.map(function (arg) { + return trim(arg.replace(FN_ARG, '')); + }); + return func; + } + + /** + * A dependency-injected version of the [async.auto]{@link module:ControlFlow.auto} function. Dependent + * tasks are specified as parameters to the function, after the usual callback + * parameter, with the parameter names matching the names of the tasks it + * depends on. This can provide even more readable task graphs which can be + * easier to maintain. + * + * If a final callback is specified, the task results are similarly injected, + * specified as named parameters after the initial error parameter. + * + * The autoInject function is purely syntactic sugar and its semantics are + * otherwise equivalent to [async.auto]{@link module:ControlFlow.auto}. + * + * @name autoInject + * @static + * @memberOf module:ControlFlow + * @method + * @see [async.auto]{@link module:ControlFlow.auto} + * @category Control Flow + * @param {Object} tasks - An object, each of whose properties is a function of + * the form 'func([dependencies...], callback). The object's key of a property + * serves as the name of the task defined by that property, i.e. can be used + * when specifying requirements for other tasks. + * * The `callback` parameter is a `callback(err, result)` which must be called + * when finished, passing an `error` (which can be `null`) and the result of + * the function's execution. The remaining parameters name other tasks on + * which the task is dependent, and the results from those tasks are the + * arguments of those parameters. + * @param {Function} [callback] - An optional callback which is called when all + * the tasks have been completed. It receives the `err` argument if any `tasks` + * pass an error to their callback, and a `results` object with any completed + * task results, similar to `auto`. + * @example + * + * // The example from `auto` can be rewritten as follows: + * async.autoInject({ + * get_data: function(callback) { + * // async code to get some data + * callback(null, 'data', 'converted to array'); + * }, + * make_folder: function(callback) { + * // async code to create a directory to store a file in + * // this is run at the same time as getting the data + * callback(null, 'folder'); + * }, + * write_file: function(get_data, make_folder, callback) { + * // once there is some data and the directory exists, + * // write the data to a file in the directory + * callback(null, 'filename'); + * }, + * email_link: function(write_file, callback) { + * // once the file is written let's email a link to it... + * // write_file contains the filename returned by write_file. + * callback(null, {'file':write_file, 'email':'user@example.com'}); + * } + * }, function(err, results) { + * console.log('err = ', err); + * console.log('email_link = ', results.email_link); + * }); + * + * // If you are using a JS minifier that mangles parameter names, `autoInject` + * // will not work with plain functions, since the parameter names will be + * // collapsed to a single letter identifier. To work around this, you can + * // explicitly specify the names of the parameters your task function needs + * // in an array, similar to Angular.js dependency injection. + * + * // This still has an advantage over plain `auto`, since the results a task + * // depends on are still spread into arguments. + * async.autoInject({ + * //... + * write_file: ['get_data', 'make_folder', function(get_data, make_folder, callback) { + * callback(null, 'filename'); + * }], + * email_link: ['write_file', function(write_file, callback) { + * callback(null, {'file':write_file, 'email':'user@example.com'}); + * }] + * //... + * }, function(err, results) { + * console.log('err = ', err); + * console.log('email_link = ', results.email_link); + * }); + */ + function autoInject(tasks, callback) { + var newTasks = {}; + + baseForOwn(tasks, function (taskFn, key) { + var params; + + if (isArray(taskFn)) { + params = copyArray(taskFn); + taskFn = params.pop(); + + newTasks[key] = params.concat(params.length > 0 ? newTask : taskFn); + } else if (taskFn.length === 1) { + // no dependencies, use the function as-is + newTasks[key] = taskFn; + } else { + params = parseParams(taskFn); + if (taskFn.length === 0 && params.length === 0) { + throw new Error("autoInject task functions require explicit parameters."); + } + + params.pop(); + + newTasks[key] = params.concat(newTask); + } + + function newTask(results, taskCb) { + var newArgs = arrayMap(params, function (name) { + return results[name]; + }); + newArgs.push(taskCb); + taskFn.apply(null, newArgs); + } + }); + + auto(newTasks, callback); + } + + var hasSetImmediate = typeof setImmediate === 'function' && setImmediate; + var hasNextTick = typeof process === 'object' && typeof process.nextTick === 'function'; + + function fallback(fn) { + setTimeout(fn, 0); + } + + function wrap(defer) { + return rest(function (fn, args) { + defer(function () { + fn.apply(null, args); + }); + }); + } + + var _defer; + + if (hasSetImmediate) { + _defer = setImmediate; + } else if (hasNextTick) { + _defer = process.nextTick; + } else { + _defer = fallback; + } + + var setImmediate$1 = wrap(_defer); + + // Simple doubly linked list (https://en.wikipedia.org/wiki/Doubly_linked_list) implementation + // used for queues. This implementation assumes that the node provided by the user can be modified + // to adjust the next and last properties. We implement only the minimal functionality + // for queue support. + function DLL() { + this.head = this.tail = null; + this.length = 0; + } + + function setInitial(dll, node) { + dll.length = 1; + dll.head = dll.tail = node; + } + + DLL.prototype.removeLink = function (node) { + if (node.prev) node.prev.next = node.next;else this.head = node.next; + if (node.next) node.next.prev = node.prev;else this.tail = node.prev; + + node.prev = node.next = null; + this.length -= 1; + return node; + }; + + DLL.prototype.empty = DLL; + + DLL.prototype.insertAfter = function (node, newNode) { + newNode.prev = node; + newNode.next = node.next; + if (node.next) node.next.prev = newNode;else this.tail = newNode; + node.next = newNode; + this.length += 1; + }; + + DLL.prototype.insertBefore = function (node, newNode) { + newNode.prev = node.prev; + newNode.next = node; + if (node.prev) node.prev.next = newNode;else this.head = newNode; + node.prev = newNode; + this.length += 1; + }; + + DLL.prototype.unshift = function (node) { + if (this.head) this.insertBefore(this.head, node);else setInitial(this, node); + }; + + DLL.prototype.push = function (node) { + if (this.tail) this.insertAfter(this.tail, node);else setInitial(this, node); + }; + + DLL.prototype.shift = function () { + return this.head && this.removeLink(this.head); + }; + + DLL.prototype.pop = function () { + return this.tail && this.removeLink(this.tail); + }; + + function queue(worker, concurrency, payload) { + if (concurrency == null) { + concurrency = 1; + } else if (concurrency === 0) { + throw new Error('Concurrency must not be zero'); + } + + function _insert(data, insertAtFront, callback) { + if (callback != null && typeof callback !== 'function') { + throw new Error('task callback must be a function'); + } + q.started = true; + if (!isArray(data)) { + data = [data]; + } + if (data.length === 0 && q.idle()) { + // call drain immediately if there are no tasks + return setImmediate$1(function () { + q.drain(); + }); + } + arrayEach(data, function (task) { + var item = { + data: task, + callback: callback || noop + }; + + if (insertAtFront) { + q._tasks.unshift(item); + } else { + q._tasks.push(item); + } + }); + setImmediate$1(q.process); + } + + function _next(tasks) { + return rest(function (args) { + workers -= 1; + + arrayEach(tasks, function (task) { + arrayEach(workersList, function (worker, index) { + if (worker === task) { + workersList.splice(index, 1); + return false; + } + }); + + task.callback.apply(task, args); + + if (args[0] != null) { + q.error(args[0], task.data); + } + }); + + if (workers <= q.concurrency - q.buffer) { + q.unsaturated(); + } + + if (q.idle()) { + q.drain(); + } + q.process(); + }); + } + + var workers = 0; + var workersList = []; + var q = { + _tasks: new DLL(), + concurrency: concurrency, + payload: payload, + saturated: noop, + unsaturated: noop, + buffer: concurrency / 4, + empty: noop, + drain: noop, + error: noop, + started: false, + paused: false, + push: function (data, callback) { + _insert(data, false, callback); + }, + kill: function () { + q.drain = noop; + q._tasks.empty(); + }, + unshift: function (data, callback) { + _insert(data, true, callback); + }, + process: function () { + while (!q.paused && workers < q.concurrency && q._tasks.length) { + var tasks = [], + data = []; + var l = q._tasks.length; + if (q.payload) l = Math.min(l, q.payload); + for (var i = 0; i < l; i++) { + var node = q._tasks.shift(); + tasks.push(node); + data.push(node.data); + } + + if (q._tasks.length === 0) { + q.empty(); + } + workers += 1; + workersList.push(tasks[0]); + + if (workers === q.concurrency) { + q.saturated(); + } + + var cb = onlyOnce(_next(tasks)); + worker(data, cb); + } + }, + length: function () { + return q._tasks.length; + }, + running: function () { + return workers; + }, + workersList: function () { + return workersList; + }, + idle: function () { + return q._tasks.length + workers === 0; + }, + pause: function () { + q.paused = true; + }, + resume: function () { + if (q.paused === false) { + return; + } + q.paused = false; + var resumeCount = Math.min(q.concurrency, q._tasks.length); + // Need to call q.process once per concurrent + // worker to preserve full concurrency after pause + for (var w = 1; w <= resumeCount; w++) { + setImmediate$1(q.process); + } + } + }; + return q; + } + + /** + * A cargo of tasks for the worker function to complete. Cargo inherits all of + * the same methods and event callbacks as [`queue`]{@link module:ControlFlow.queue}. + * @typedef {Object} CargoObject + * @memberOf module:ControlFlow + * @property {Function} length - A function returning the number of items + * waiting to be processed. Invoke like `cargo.length()`. + * @property {number} payload - An `integer` for determining how many tasks + * should be process per round. This property can be changed after a `cargo` is + * created to alter the payload on-the-fly. + * @property {Function} push - Adds `task` to the `queue`. The callback is + * called once the `worker` has finished processing the task. Instead of a + * single task, an array of `tasks` can be submitted. The respective callback is + * used for every task in the list. Invoke like `cargo.push(task, [callback])`. + * @property {Function} saturated - A callback that is called when the + * `queue.length()` hits the concurrency and further tasks will be queued. + * @property {Function} empty - A callback that is called when the last item + * from the `queue` is given to a `worker`. + * @property {Function} drain - A callback that is called when the last item + * from the `queue` has returned from the `worker`. + * @property {Function} idle - a function returning false if there are items + * waiting or being processed, or true if not. Invoke like `cargo.idle()`. + * @property {Function} pause - a function that pauses the processing of tasks + * until `resume()` is called. Invoke like `cargo.pause()`. + * @property {Function} resume - a function that resumes the processing of + * queued tasks when the queue is paused. Invoke like `cargo.resume()`. + * @property {Function} kill - a function that removes the `drain` callback and + * empties remaining tasks from the queue forcing it to go idle. Invoke like `cargo.kill()`. + */ + + /** + * Creates a `cargo` object with the specified payload. Tasks added to the + * cargo will be processed altogether (up to the `payload` limit). If the + * `worker` is in progress, the task is queued until it becomes available. Once + * the `worker` has completed some tasks, each callback of those tasks is + * called. Check out [these](https://camo.githubusercontent.com/6bbd36f4cf5b35a0f11a96dcd2e97711ffc2fb37/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f313637363837312f36383130382f62626330636662302d356632392d313165322d393734662d3333393763363464633835382e676966) [animations](https://camo.githubusercontent.com/f4810e00e1c5f5f8addbe3e9f49064fd5d102699/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f313637363837312f36383130312f38346339323036362d356632392d313165322d383134662d3964336430323431336266642e676966) + * for how `cargo` and `queue` work. + * + * While [`queue`]{@link module:ControlFlow.queue} passes only one task to one of a group of workers + * at a time, cargo passes an array of tasks to a single worker, repeating + * when the worker is finished. + * + * @name cargo + * @static + * @memberOf module:ControlFlow + * @method + * @see [async.queue]{@link module:ControlFlow.queue} + * @category Control Flow + * @param {Function} worker - An asynchronous function for processing an array + * of queued tasks, which must call its `callback(err)` argument when finished, + * with an optional `err` argument. Invoked with `(tasks, callback)`. + * @param {number} [payload=Infinity] - An optional `integer` for determining + * how many tasks should be processed per round; if omitted, the default is + * unlimited. + * @returns {module:ControlFlow.CargoObject} A cargo object to manage the tasks. Callbacks can + * attached as certain properties to listen for specific events during the + * lifecycle of the cargo and inner queue. + * @example + * + * // create a cargo object with payload 2 + * var cargo = async.cargo(function(tasks, callback) { + * for (var i=0; i true + */ + function identity(value) { + return value; + } + + function _createTester(eachfn, check, getResult) { + return function (arr, limit, iteratee, cb) { + function done(err) { + if (cb) { + if (err) { + cb(err); + } else { + cb(null, getResult(false)); + } + } + } + function wrappedIteratee(x, _, callback) { + if (!cb) return callback(); + iteratee(x, function (err, v) { + if (cb) { + if (err) { + cb(err); + cb = iteratee = false; + } else if (check(v)) { + cb(null, getResult(true, x)); + cb = iteratee = false; + } + } + callback(); + }); + } + if (arguments.length > 3) { + cb = cb || noop; + eachfn(arr, limit, wrappedIteratee, done); + } else { + cb = iteratee; + cb = cb || noop; + iteratee = limit; + eachfn(arr, wrappedIteratee, done); + } + }; + } + + function _findGetResult(v, x) { + return x; + } + + /** + * Returns the first value in `coll` that passes an async truth test. The + * `iteratee` is applied in parallel, meaning the first iteratee to return + * `true` will fire the detect `callback` with that result. That means the + * result might not be the first item in the original `coll` (in terms of order) + * that passes the test. + + * If order within the original `coll` is important, then look at + * [`detectSeries`]{@link module:Collections.detectSeries}. + * + * @name detect + * @static + * @memberOf module:Collections + * @method + * @alias find + * @category Collections + * @param {Array|Iterable|Object} coll - A collection to iterate over. + * @param {Function} iteratee - A truth test to apply to each item in `coll`. + * The iteratee is passed a `callback(err, truthValue)` which must be called + * with a boolean argument once it has completed. Invoked with (item, callback). + * @param {Function} [callback] - A callback which is called as soon as any + * iteratee returns `true`, or after all the `iteratee` functions have finished. + * Result will be the first item in the array that passes the truth test + * (iteratee) or the value `undefined` if none passed. Invoked with + * (err, result). + * @example + * + * async.detect(['file1','file2','file3'], function(filePath, callback) { + * fs.access(filePath, function(err) { + * callback(null, !err) + * }); + * }, function(err, result) { + * // result now equals the first file in the list that exists + * }); + */ + var detect = _createTester(eachOf, identity, _findGetResult); + + /** + * The same as [`detect`]{@link module:Collections.detect} but runs a maximum of `limit` async operations at a + * time. + * + * @name detectLimit + * @static + * @memberOf module:Collections + * @method + * @see [async.detect]{@link module:Collections.detect} + * @alias findLimit + * @category Collections + * @param {Array|Iterable|Object} coll - A collection to iterate over. + * @param {number} limit - The maximum number of async operations at a time. + * @param {Function} iteratee - A truth test to apply to each item in `coll`. + * The iteratee is passed a `callback(err, truthValue)` which must be called + * with a boolean argument once it has completed. Invoked with (item, callback). + * @param {Function} [callback] - A callback which is called as soon as any + * iteratee returns `true`, or after all the `iteratee` functions have finished. + * Result will be the first item in the array that passes the truth test + * (iteratee) or the value `undefined` if none passed. Invoked with + * (err, result). + */ + var detectLimit = _createTester(eachOfLimit, identity, _findGetResult); + + /** + * The same as [`detect`]{@link module:Collections.detect} but runs only a single async operation at a time. + * + * @name detectSeries + * @static + * @memberOf module:Collections + * @method + * @see [async.detect]{@link module:Collections.detect} + * @alias findSeries + * @category Collections + * @param {Array|Iterable|Object} coll - A collection to iterate over. + * @param {Function} iteratee - A truth test to apply to each item in `coll`. + * The iteratee is passed a `callback(err, truthValue)` which must be called + * with a boolean argument once it has completed. Invoked with (item, callback). + * @param {Function} [callback] - A callback which is called as soon as any + * iteratee returns `true`, or after all the `iteratee` functions have finished. + * Result will be the first item in the array that passes the truth test + * (iteratee) or the value `undefined` if none passed. Invoked with + * (err, result). + */ + var detectSeries = _createTester(eachOfSeries, identity, _findGetResult); + + function consoleFunc(name) { + return rest(function (fn, args) { + fn.apply(null, args.concat([rest(function (err, args) { + if (typeof console === 'object') { + if (err) { + if (console.error) { + console.error(err); + } + } else if (console[name]) { + arrayEach(args, function (x) { + console[name](x); + }); + } + } + })])); + }); + } + + /** + * Logs the result of an `async` function to the `console` using `console.dir` + * to display the properties of the resulting object. Only works in Node.js or + * in browsers that support `console.dir` and `console.error` (such as FF and + * Chrome). If multiple arguments are returned from the async function, + * `console.dir` is called on each argument in order. + * + * @name dir + * @static + * @memberOf module:Utils + * @method + * @category Util + * @param {Function} function - The function you want to eventually apply all + * arguments to. + * @param {...*} arguments... - Any number of arguments to apply to the function. + * @example + * + * // in a module + * var hello = function(name, callback) { + * setTimeout(function() { + * callback(null, {hello: name}); + * }, 1000); + * }; + * + * // in the node repl + * node> async.dir(hello, 'world'); + * {hello: 'world'} + */ + var dir = consoleFunc('dir'); + + /** + * The post-check version of [`during`]{@link module:ControlFlow.during}. To reflect the difference in + * the order of operations, the arguments `test` and `fn` are switched. + * + * Also a version of [`doWhilst`]{@link module:ControlFlow.doWhilst} with asynchronous `test` function. + * @name doDuring + * @static + * @memberOf module:ControlFlow + * @method + * @see [async.during]{@link module:ControlFlow.during} + * @category Control Flow + * @param {Function} fn - A function which is called each time `test` passes. + * The function is passed a `callback(err)`, which must be called once it has + * completed with an optional `err` argument. Invoked with (callback). + * @param {Function} test - asynchronous truth test to perform before each + * execution of `fn`. Invoked with (...args, callback), where `...args` are the + * non-error args from the previous callback of `fn`. + * @param {Function} [callback] - A callback which is called after the test + * function has failed and repeated execution of `fn` has stopped. `callback` + * will be passed an error if one occured, otherwise `null`. + */ + function doDuring(fn, test, callback) { + callback = onlyOnce(callback || noop); + + var next = rest(function (err, args) { + if (err) return callback(err); + args.push(check); + test.apply(this, args); + }); + + function check(err, truth) { + if (err) return callback(err); + if (!truth) return callback(null); + fn(next); + } + + check(null, true); + } + + /** + * The post-check version of [`whilst`]{@link module:ControlFlow.whilst}. To reflect the difference in + * the order of operations, the arguments `test` and `iteratee` are switched. + * + * `doWhilst` is to `whilst` as `do while` is to `while` in plain JavaScript. + * + * @name doWhilst + * @static + * @memberOf module:ControlFlow + * @method + * @see [async.whilst]{@link module:ControlFlow.whilst} + * @category Control Flow + * @param {Function} iteratee - A function which is called each time `test` + * passes. The function is passed a `callback(err)`, which must be called once + * it has completed with an optional `err` argument. Invoked with (callback). + * @param {Function} test - synchronous truth test to perform after each + * execution of `iteratee`. Invoked with Invoked with the non-error callback + * results of `iteratee`. + * @param {Function} [callback] - A callback which is called after the test + * function has failed and repeated execution of `iteratee` has stopped. + * `callback` will be passed an error and any arguments passed to the final + * `iteratee`'s callback. Invoked with (err, [results]); + */ + function doWhilst(iteratee, test, callback) { + callback = onlyOnce(callback || noop); + var next = rest(function (err, args) { + if (err) return callback(err); + if (test.apply(this, args)) return iteratee(next); + callback.apply(null, [null].concat(args)); + }); + iteratee(next); + } + + /** + * Like ['doWhilst']{@link module:ControlFlow.doWhilst}, except the `test` is inverted. Note the + * argument ordering differs from `until`. + * + * @name doUntil + * @static + * @memberOf module:ControlFlow + * @method + * @see [async.doWhilst]{@link module:ControlFlow.doWhilst} + * @category Control Flow + * @param {Function} fn - A function which is called each time `test` fails. + * The function is passed a `callback(err)`, which must be called once it has + * completed with an optional `err` argument. Invoked with (callback). + * @param {Function} test - synchronous truth test to perform after each + * execution of `fn`. Invoked with the non-error callback results of `fn`. + * @param {Function} [callback] - A callback which is called after the test + * function has passed and repeated execution of `fn` has stopped. `callback` + * will be passed an error and any arguments passed to the final `fn`'s + * callback. Invoked with (err, [results]); + */ + function doUntil(fn, test, callback) { + doWhilst(fn, function () { + return !test.apply(this, arguments); + }, callback); + } + + /** + * Like [`whilst`]{@link module:ControlFlow.whilst}, except the `test` is an asynchronous function that + * is passed a callback in the form of `function (err, truth)`. If error is + * passed to `test` or `fn`, the main callback is immediately called with the + * value of the error. + * + * @name during + * @static + * @memberOf module:ControlFlow + * @method + * @see [async.whilst]{@link module:ControlFlow.whilst} + * @category Control Flow + * @param {Function} test - asynchronous truth test to perform before each + * execution of `fn`. Invoked with (callback). + * @param {Function} fn - A function which is called each time `test` passes. + * The function is passed a `callback(err)`, which must be called once it has + * completed with an optional `err` argument. Invoked with (callback). + * @param {Function} [callback] - A callback which is called after the test + * function has failed and repeated execution of `fn` has stopped. `callback` + * will be passed an error, if one occured, otherwise `null`. + * @example + * + * var count = 0; + * + * async.during( + * function (callback) { + * return callback(null, count < 5); + * }, + * function (callback) { + * count++; + * setTimeout(callback, 1000); + * }, + * function (err) { + * // 5 seconds have passed + * } + * ); + */ + function during(test, fn, callback) { + callback = onlyOnce(callback || noop); + + function next(err) { + if (err) return callback(err); + test(check); + } + + function check(err, truth) { + if (err) return callback(err); + if (!truth) return callback(null); + fn(next); + } + + test(check); + } + + function _withoutIndex(iteratee) { + return function (value, index, callback) { + return iteratee(value, callback); + }; + } + + /** + * Applies the function `iteratee` to each item in `coll`, in parallel. + * The `iteratee` is called with an item from the list, and a callback for when + * it has finished. If the `iteratee` passes an error to its `callback`, the + * main `callback` (for the `each` function) is immediately called with the + * error. + * + * Note, that since this function applies `iteratee` to each item in parallel, + * there is no guarantee that the iteratee functions will complete in order. + * + * @name each + * @static + * @memberOf module:Collections + * @method + * @alias forEach + * @category Collection + * @param {Array|Iterable|Object} coll - A collection to iterate over. + * @param {Function} iteratee - A function to apply to each item + * in `coll`. The iteratee is passed a `callback(err)` which must be called once + * it has completed. If no error has occurred, the `callback` should be run + * without arguments or with an explicit `null` argument. The array index is not + * passed to the iteratee. Invoked with (item, callback). If you need the index, + * use `eachOf`. + * @param {Function} [callback] - A callback which is called when all + * `iteratee` functions have finished, or an error occurs. Invoked with (err). + * @example + * + * // assuming openFiles is an array of file names and saveFile is a function + * // to save the modified contents of that file: + * + * async.each(openFiles, saveFile, function(err){ + * // if any of the saves produced an error, err would equal that error + * }); + * + * // assuming openFiles is an array of file names + * async.each(openFiles, function(file, callback) { + * + * // Perform operation on file here. + * console.log('Processing file ' + file); + * + * if( file.length > 32 ) { + * console.log('This file name is too long'); + * callback('File name too long'); + * } else { + * // Do work to process file here + * console.log('File processed'); + * callback(); + * } + * }, function(err) { + * // if any of the file processing produced an error, err would equal that error + * if( err ) { + * // One of the iterations produced an error. + * // All processing will now stop. + * console.log('A file failed to process'); + * } else { + * console.log('All files have been processed successfully'); + * } + * }); + */ + function eachLimit(coll, iteratee, callback) { + eachOf(coll, _withoutIndex(iteratee), callback); + } + + /** + * The same as [`each`]{@link module:Collections.each} but runs a maximum of `limit` async operations at a time. + * + * @name eachLimit + * @static + * @memberOf module:Collections + * @method + * @see [async.each]{@link module:Collections.each} + * @alias forEachLimit + * @category Collection + * @param {Array|Iterable|Object} coll - A colleciton to iterate over. + * @param {number} limit - The maximum number of async operations at a time. + * @param {Function} iteratee - A function to apply to each item in `coll`. The + * iteratee is passed a `callback(err)` which must be called once it has + * completed. If no error has occurred, the `callback` should be run without + * arguments or with an explicit `null` argument. The array index is not passed + * to the iteratee. Invoked with (item, callback). If you need the index, use + * `eachOfLimit`. + * @param {Function} [callback] - A callback which is called when all + * `iteratee` functions have finished, or an error occurs. Invoked with (err). + */ + function eachLimit$1(coll, limit, iteratee, callback) { + _eachOfLimit(limit)(coll, _withoutIndex(iteratee), callback); + } + + /** + * The same as [`each`]{@link module:Collections.each} but runs only a single async operation at a time. + * + * @name eachSeries + * @static + * @memberOf module:Collections + * @method + * @see [async.each]{@link module:Collections.each} + * @alias forEachSeries + * @category Collection + * @param {Array|Iterable|Object} coll - A collection to iterate over. + * @param {Function} iteratee - A function to apply to each + * item in `coll`. The iteratee is passed a `callback(err)` which must be called + * once it has completed. If no error has occurred, the `callback` should be run + * without arguments or with an explicit `null` argument. The array index is + * not passed to the iteratee. Invoked with (item, callback). If you need the + * index, use `eachOfSeries`. + * @param {Function} [callback] - A callback which is called when all + * `iteratee` functions have finished, or an error occurs. Invoked with (err). + */ + var eachSeries = doLimit(eachLimit$1, 1); + + /** + * Wrap an async function and ensure it calls its callback on a later tick of + * the event loop. If the function already calls its callback on a next tick, + * no extra deferral is added. This is useful for preventing stack overflows + * (`RangeError: Maximum call stack size exceeded`) and generally keeping + * [Zalgo](http://blog.izs.me/post/59142742143/designing-apis-for-asynchrony) + * contained. + * + * @name ensureAsync + * @static + * @memberOf module:Utils + * @method + * @category Util + * @param {Function} fn - an async function, one that expects a node-style + * callback as its last argument. + * @returns {Function} Returns a wrapped function with the exact same call + * signature as the function passed in. + * @example + * + * function sometimesAsync(arg, callback) { + * if (cache[arg]) { + * return callback(null, cache[arg]); // this would be synchronous!! + * } else { + * doSomeIO(arg, callback); // this IO would be asynchronous + * } + * } + * + * // this has a risk of stack overflows if many results are cached in a row + * async.mapSeries(args, sometimesAsync, done); + * + * // this will defer sometimesAsync's callback if necessary, + * // preventing stack overflows + * async.mapSeries(args, async.ensureAsync(sometimesAsync), done); + */ + function ensureAsync(fn) { + return initialParams(function (args, callback) { + var sync = true; + args.push(function () { + var innerArgs = arguments; + if (sync) { + setImmediate$1(function () { + callback.apply(null, innerArgs); + }); + } else { + callback.apply(null, innerArgs); + } + }); + fn.apply(this, args); + sync = false; + }); + } + + function notId(v) { + return !v; + } + + /** + * Returns `true` if every element in `coll` satisfies an async test. If any + * iteratee call returns `false`, the main `callback` is immediately called. + * + * @name every + * @static + * @memberOf module:Collections + * @method + * @alias all + * @category Collection + * @param {Array|Iterable|Object} coll - A collection to iterate over. + * @param {Function} iteratee - A truth test to apply to each item in the + * collection in parallel. The iteratee is passed a `callback(err, truthValue)` + * which must be called with a boolean argument once it has completed. Invoked + * with (item, callback). + * @param {Function} [callback] - A callback which is called after all the + * `iteratee` functions have finished. Result will be either `true` or `false` + * depending on the values of the async tests. Invoked with (err, result). + * @example + * + * async.every(['file1','file2','file3'], function(filePath, callback) { + * fs.access(filePath, function(err) { + * callback(null, !err) + * }); + * }, function(err, result) { + * // if result is true then every file exists + * }); + */ + var every = _createTester(eachOf, notId, notId); + + /** + * The same as [`every`]{@link module:Collections.every} but runs a maximum of `limit` async operations at a time. + * + * @name everyLimit + * @static + * @memberOf module:Collections + * @method + * @see [async.every]{@link module:Collections.every} + * @alias allLimit + * @category Collection + * @param {Array|Iterable|Object} coll - A collection to iterate over. + * @param {number} limit - The maximum number of async operations at a time. + * @param {Function} iteratee - A truth test to apply to each item in the + * collection in parallel. The iteratee is passed a `callback(err, truthValue)` + * which must be called with a boolean argument once it has completed. Invoked + * with (item, callback). + * @param {Function} [callback] - A callback which is called after all the + * `iteratee` functions have finished. Result will be either `true` or `false` + * depending on the values of the async tests. Invoked with (err, result). + */ + var everyLimit = _createTester(eachOfLimit, notId, notId); + + /** + * The same as [`every`]{@link module:Collections.every} but runs only a single async operation at a time. + * + * @name everySeries + * @static + * @memberOf module:Collections + * @method + * @see [async.every]{@link module:Collections.every} + * @alias allSeries + * @category Collection + * @param {Array|Iterable|Object} coll - A collection to iterate over. + * @param {Function} iteratee - A truth test to apply to each item in the + * collection in parallel. The iteratee is passed a `callback(err, truthValue)` + * which must be called with a boolean argument once it has completed. Invoked + * with (item, callback). + * @param {Function} [callback] - A callback which is called after all the + * `iteratee` functions have finished. Result will be either `true` or `false` + * depending on the values of the async tests. Invoked with (err, result). + */ + var everySeries = doLimit(everyLimit, 1); + + function _filter(eachfn, arr, iteratee, callback) { + callback = once(callback || noop); + var results = []; + eachfn(arr, function (x, index, callback) { + iteratee(x, function (err, v) { + if (err) { + callback(err); + } else { + if (v) { + results.push({ index: index, value: x }); + } + callback(); + } + }); + }, function (err) { + if (err) { + callback(err); + } else { + callback(null, arrayMap(results.sort(function (a, b) { + return a.index - b.index; + }), baseProperty('value'))); + } + }); + } + + /** + * Returns a new array of all the values in `coll` which pass an async truth + * test. This operation is performed in parallel, but the results array will be + * in the same order as the original. + * + * @name filter + * @static + * @memberOf module:Collections + * @method + * @alias select + * @category Collection + * @param {Array|Iterable|Object} coll - A collection to iterate over. + * @param {Function} iteratee - A truth test to apply to each item in `coll`. + * The `iteratee` is passed a `callback(err, truthValue)`, which must be called + * with a boolean argument once it has completed. Invoked with (item, callback). + * @param {Function} [callback] - A callback which is called after all the + * `iteratee` functions have finished. Invoked with (err, results). + * @example + * + * async.filter(['file1','file2','file3'], function(filePath, callback) { + * fs.access(filePath, function(err) { + * callback(null, !err) + * }); + * }, function(err, results) { + * // results now equals an array of the existing files + * }); + */ + var filter = doParallel(_filter); + + /** + * The same as [`filter`]{@link module:Collections.filter} but runs a maximum of `limit` async operations at a + * time. + * + * @name filterLimit + * @static + * @memberOf module:Collections + * @method + * @see [async.filter]{@link module:Collections.filter} + * @alias selectLimit + * @category Collection + * @param {Array|Iterable|Object} coll - A collection to iterate over. + * @param {number} limit - The maximum number of async operations at a time. + * @param {Function} iteratee - A truth test to apply to each item in `coll`. + * The `iteratee` is passed a `callback(err, truthValue)`, which must be called + * with a boolean argument once it has completed. Invoked with (item, callback). + * @param {Function} [callback] - A callback which is called after all the + * `iteratee` functions have finished. Invoked with (err, results). + */ + var filterLimit = doParallelLimit(_filter); + + /** + * The same as [`filter`]{@link module:Collections.filter} but runs only a single async operation at a time. + * + * @name filterSeries + * @static + * @memberOf module:Collections + * @method + * @see [async.filter]{@link module:Collections.filter} + * @alias selectSeries + * @category Collection + * @param {Array|Iterable|Object} coll - A collection to iterate over. + * @param {Function} iteratee - A truth test to apply to each item in `coll`. + * The `iteratee` is passed a `callback(err, truthValue)`, which must be called + * with a boolean argument once it has completed. Invoked with (item, callback). + * @param {Function} [callback] - A callback which is called after all the + * `iteratee` functions have finished. Invoked with (err, results) + */ + var filterSeries = doLimit(filterLimit, 1); + + /** + * Calls the asynchronous function `fn` with a callback parameter that allows it + * to call itself again, in series, indefinitely. + + * If an error is passed to the + * callback then `errback` is called with the error, and execution stops, + * otherwise it will never be called. + * + * @name forever + * @static + * @memberOf module:ControlFlow + * @method + * @category Control Flow + * @param {Function} fn - a function to call repeatedly. Invoked with (next). + * @param {Function} [errback] - when `fn` passes an error to it's callback, + * this function will be called, and execution stops. Invoked with (err). + * @example + * + * async.forever( + * function(next) { + * // next is suitable for passing to things that need a callback(err [, whatever]); + * // it will result in this function being called again. + * }, + * function(err) { + * // if next is called with a value in its first parameter, it will appear + * // in here as 'err', and execution will stop. + * } + * ); + */ + function forever(fn, errback) { + var done = onlyOnce(errback || noop); + var task = ensureAsync(fn); + + function next(err) { + if (err) return done(err); + task(next); + } + next(); + } + + /** + * Logs the result of an `async` function to the `console`. Only works in + * Node.js or in browsers that support `console.log` and `console.error` (such + * as FF and Chrome). If multiple arguments are returned from the async + * function, `console.log` is called on each argument in order. + * + * @name log + * @static + * @memberOf module:Utils + * @method + * @category Util + * @param {Function} function - The function you want to eventually apply all + * arguments to. + * @param {...*} arguments... - Any number of arguments to apply to the function. + * @example + * + * // in a module + * var hello = function(name, callback) { + * setTimeout(function() { + * callback(null, 'hello ' + name); + * }, 1000); + * }; + * + * // in the node repl + * node> async.log(hello, 'world'); + * 'hello world' + */ + var log = consoleFunc('log'); + + /** + * The same as [`mapValues`]{@link module:Collections.mapValues} but runs a maximum of `limit` async operations at a + * time. + * + * @name mapValuesLimit + * @static + * @memberOf module:Collections + * @method + * @see [async.mapValues]{@link module:Collections.mapValues} + * @category Collection + * @param {Object} obj - A collection to iterate over. + * @param {number} limit - The maximum number of async operations at a time. + * @param {Function} iteratee - A function to apply to each value in `obj`. + * The iteratee is passed a `callback(err, transformed)` which must be called + * once it has completed with an error (which can be `null`) and a + * transformed value. Invoked with (value, key, callback). + * @param {Function} [callback] - A callback which is called when all `iteratee` + * functions have finished, or an error occurs. Result is an object of the + * transformed values from the `obj`. Invoked with (err, result). + */ + function mapValuesLimit(obj, limit, iteratee, callback) { + callback = once(callback || noop); + var newObj = {}; + eachOfLimit(obj, limit, function (val, key, next) { + iteratee(val, key, function (err, result) { + if (err) return next(err); + newObj[key] = result; + next(); + }); + }, function (err) { + callback(err, newObj); + }); + } + + /** + * A relative of [`map`]{@link module:Collections.map}, designed for use with objects. + * + * Produces a new Object by mapping each value of `obj` through the `iteratee` + * function. The `iteratee` is called each `value` and `key` from `obj` and a + * callback for when it has finished processing. Each of these callbacks takes + * two arguments: an `error`, and the transformed item from `obj`. If `iteratee` + * passes an error to its callback, the main `callback` (for the `mapValues` + * function) is immediately called with the error. + * + * Note, the order of the keys in the result is not guaranteed. The keys will + * be roughly in the order they complete, (but this is very engine-specific) + * + * @name mapValues + * @static + * @memberOf module:Collections + * @method + * @category Collection + * @param {Object} obj - A collection to iterate over. + * @param {Function} iteratee - A function to apply to each value and key in + * `coll`. The iteratee is passed a `callback(err, transformed)` which must be + * called once it has completed with an error (which can be `null`) and a + * transformed value. Invoked with (value, key, callback). + * @param {Function} [callback] - A callback which is called when all `iteratee` + * functions have finished, or an error occurs. Results is an array of the + * transformed items from the `obj`. Invoked with (err, result). + * @example + * + * async.mapValues({ + * f1: 'file1', + * f2: 'file2', + * f3: 'file3' + * }, function (file, key, callback) { + * fs.stat(file, callback); + * }, function(err, result) { + * // results is now a map of stats for each file, e.g. + * // { + * // f1: [stats for file1], + * // f2: [stats for file2], + * // f3: [stats for file3] + * // } + * }); + */ + + var mapValues = doLimit(mapValuesLimit, Infinity); + + /** + * The same as [`mapValues`]{@link module:Collections.mapValues} but runs only a single async operation at a time. + * + * @name mapValuesSeries + * @static + * @memberOf module:Collections + * @method + * @see [async.mapValues]{@link module:Collections.mapValues} + * @category Collection + * @param {Object} obj - A collection to iterate over. + * @param {Function} iteratee - A function to apply to each value in `obj`. + * The iteratee is passed a `callback(err, transformed)` which must be called + * once it has completed with an error (which can be `null`) and a + * transformed value. Invoked with (value, key, callback). + * @param {Function} [callback] - A callback which is called when all `iteratee` + * functions have finished, or an error occurs. Result is an object of the + * transformed values from the `obj`. Invoked with (err, result). + */ + var mapValuesSeries = doLimit(mapValuesLimit, 1); + + function has(obj, key) { + return key in obj; + } + + /** + * Caches the results of an `async` function. When creating a hash to store + * function results against, the callback is omitted from the hash and an + * optional hash function can be used. + * + * If no hash function is specified, the first argument is used as a hash key, + * which may work reasonably if it is a string or a data type that converts to a + * distinct string. Note that objects and arrays will not behave reasonably. + * Neither will cases where the other arguments are significant. In such cases, + * specify your own hash function. + * + * The cache of results is exposed as the `memo` property of the function + * returned by `memoize`. + * + * @name memoize + * @static + * @memberOf module:Utils + * @method + * @category Util + * @param {Function} fn - The function to proxy and cache results from. + * @param {Function} hasher - An optional function for generating a custom hash + * for storing results. It has all the arguments applied to it apart from the + * callback, and must be synchronous. + * @returns {Function} a memoized version of `fn` + * @example + * + * var slow_fn = function(name, callback) { + * // do something + * callback(null, result); + * }; + * var fn = async.memoize(slow_fn); + * + * // fn can now be used as if it were slow_fn + * fn('some name', function() { + * // callback + * }); + */ + function memoize(fn, hasher) { + var memo = Object.create(null); + var queues = Object.create(null); + hasher = hasher || identity; + var memoized = initialParams(function memoized(args, callback) { + var key = hasher.apply(null, args); + if (has(memo, key)) { + setImmediate$1(function () { + callback.apply(null, memo[key]); + }); + } else if (has(queues, key)) { + queues[key].push(callback); + } else { + queues[key] = [callback]; + fn.apply(null, args.concat([rest(function (args) { + memo[key] = args; + var q = queues[key]; + delete queues[key]; + for (var i = 0, l = q.length; i < l; i++) { + q[i].apply(null, args); + } + })])); + } + }); + memoized.memo = memo; + memoized.unmemoized = fn; + return memoized; + } + + /** + * Calls `callback` on a later loop around the event loop. In Node.js this just + * calls `setImmediate`. In the browser it will use `setImmediate` if + * available, otherwise `setTimeout(callback, 0)`, which means other higher + * priority events may precede the execution of `callback`. + * + * This is used internally for browser-compatibility purposes. + * + * @name nextTick + * @static + * @memberOf module:Utils + * @method + * @alias setImmediate + * @category Util + * @param {Function} callback - The function to call on a later loop around + * the event loop. Invoked with (args...). + * @param {...*} args... - any number of additional arguments to pass to the + * callback on the next tick. + * @example + * + * var call_order = []; + * async.nextTick(function() { + * call_order.push('two'); + * // call_order now equals ['one','two'] + * }); + * call_order.push('one'); + * + * async.setImmediate(function (a, b, c) { + * // a, b, and c equal 1, 2, and 3 + * }, 1, 2, 3); + */ + var _defer$1; + + if (hasNextTick) { + _defer$1 = process.nextTick; + } else if (hasSetImmediate) { + _defer$1 = setImmediate; + } else { + _defer$1 = fallback; + } + + var nextTick = wrap(_defer$1); + + function _parallel(eachfn, tasks, callback) { + callback = callback || noop; + var results = isArrayLike(tasks) ? [] : {}; + + eachfn(tasks, function (task, key, callback) { + task(rest(function (err, args) { + if (args.length <= 1) { + args = args[0]; + } + results[key] = args; + callback(err); + })); + }, function (err) { + callback(err, results); + }); + } + + /** + * Run the `tasks` collection of functions in parallel, without waiting until + * the previous function has completed. If any of the functions pass an error to + * its callback, the main `callback` is immediately called with the value of the + * error. Once the `tasks` have completed, the results are passed to the final + * `callback` as an array. + * + * **Note:** `parallel` is about kicking-off I/O tasks in parallel, not about + * parallel execution of code. If your tasks do not use any timers or perform + * any I/O, they will actually be executed in series. Any synchronous setup + * sections for each task will happen one after the other. JavaScript remains + * single-threaded. + * + * It is also possible to use an object instead of an array. Each property will + * be run as a function and the results will be passed to the final `callback` + * as an object instead of an array. This can be a more readable way of handling + * results from {@link async.parallel}. + * + * @name parallel + * @static + * @memberOf module:ControlFlow + * @method + * @category Control Flow + * @param {Array|Iterable|Object} tasks - A collection containing functions to run. + * Each function is passed a `callback(err, result)` which it must call on + * completion with an error `err` (which can be `null`) and an optional `result` + * value. + * @param {Function} [callback] - An optional callback to run once all the + * functions have completed successfully. This function gets a results array + * (or object) containing all the result arguments passed to the task callbacks. + * Invoked with (err, results). + * @example + * async.parallel([ + * function(callback) { + * setTimeout(function() { + * callback(null, 'one'); + * }, 200); + * }, + * function(callback) { + * setTimeout(function() { + * callback(null, 'two'); + * }, 100); + * } + * ], + * // optional callback + * function(err, results) { + * // the results array will equal ['one','two'] even though + * // the second function had a shorter timeout. + * }); + * + * // an example using an object instead of an array + * async.parallel({ + * one: function(callback) { + * setTimeout(function() { + * callback(null, 1); + * }, 200); + * }, + * two: function(callback) { + * setTimeout(function() { + * callback(null, 2); + * }, 100); + * } + * }, function(err, results) { + * // results is now equals to: {one: 1, two: 2} + * }); + */ + function parallelLimit(tasks, callback) { + _parallel(eachOf, tasks, callback); + } + + /** + * The same as [`parallel`]{@link module:ControlFlow.parallel} but runs a maximum of `limit` async operations at a + * time. + * + * @name parallelLimit + * @static + * @memberOf module:ControlFlow + * @method + * @see [async.parallel]{@link module:ControlFlow.parallel} + * @category Control Flow + * @param {Array|Collection} tasks - A collection containing functions to run. + * Each function is passed a `callback(err, result)` which it must call on + * completion with an error `err` (which can be `null`) and an optional `result` + * value. + * @param {number} limit - The maximum number of async operations at a time. + * @param {Function} [callback] - An optional callback to run once all the + * functions have completed successfully. This function gets a results array + * (or object) containing all the result arguments passed to the task callbacks. + * Invoked with (err, results). + */ + function parallelLimit$1(tasks, limit, callback) { + _parallel(_eachOfLimit(limit), tasks, callback); + } + + /** + * A queue of tasks for the worker function to complete. + * @typedef {Object} QueueObject + * @memberOf module:ControlFlow + * @property {Function} length - a function returning the number of items + * waiting to be processed. Invoke with `queue.length()`. + * @property {boolean} started - a boolean indicating whether or not any + * items have been pushed and processed by the queue. + * @property {Function} running - a function returning the number of items + * currently being processed. Invoke with `queue.running()`. + * @property {Function} workersList - a function returning the array of items + * currently being processed. Invoke with `queue.workersList()`. + * @property {Function} idle - a function returning false if there are items + * waiting or being processed, or true if not. Invoke with `queue.idle()`. + * @property {number} concurrency - an integer for determining how many `worker` + * functions should be run in parallel. This property can be changed after a + * `queue` is created to alter the concurrency on-the-fly. + * @property {Function} push - add a new task to the `queue`. Calls `callback` + * once the `worker` has finished processing the task. Instead of a single task, + * a `tasks` array can be submitted. The respective callback is used for every + * task in the list. Invoke with `queue.push(task, [callback])`, + * @property {Function} unshift - add a new task to the front of the `queue`. + * Invoke with `queue.unshift(task, [callback])`. + * @property {Function} saturated - a callback that is called when the number of + * running workers hits the `concurrency` limit, and further tasks will be + * queued. + * @property {Function} unsaturated - a callback that is called when the number + * of running workers is less than the `concurrency` & `buffer` limits, and + * further tasks will not be queued. + * @property {number} buffer - A minimum threshold buffer in order to say that + * the `queue` is `unsaturated`. + * @property {Function} empty - a callback that is called when the last item + * from the `queue` is given to a `worker`. + * @property {Function} drain - a callback that is called when the last item + * from the `queue` has returned from the `worker`. + * @property {Function} error - a callback that is called when a task errors. + * Has the signature `function(error, task)`. + * @property {boolean} paused - a boolean for determining whether the queue is + * in a paused state. + * @property {Function} pause - a function that pauses the processing of tasks + * until `resume()` is called. Invoke with `queue.pause()`. + * @property {Function} resume - a function that resumes the processing of + * queued tasks when the queue is paused. Invoke with `queue.resume()`. + * @property {Function} kill - a function that removes the `drain` callback and + * empties remaining tasks from the queue forcing it to go idle. Invoke with `queue.kill()`. + */ + + /** + * Creates a `queue` object with the specified `concurrency`. Tasks added to the + * `queue` are processed in parallel (up to the `concurrency` limit). If all + * `worker`s are in progress, the task is queued until one becomes available. + * Once a `worker` completes a `task`, that `task`'s callback is called. + * + * @name queue + * @static + * @memberOf module:ControlFlow + * @method + * @category Control Flow + * @param {Function} worker - An asynchronous function for processing a queued + * task, which must call its `callback(err)` argument when finished, with an + * optional `error` as an argument. If you want to handle errors from an + * individual task, pass a callback to `q.push()`. Invoked with + * (task, callback). + * @param {number} [concurrency=1] - An `integer` for determining how many + * `worker` functions should be run in parallel. If omitted, the concurrency + * defaults to `1`. If the concurrency is `0`, an error is thrown. + * @returns {module:ControlFlow.QueueObject} A queue object to manage the tasks. Callbacks can + * attached as certain properties to listen for specific events during the + * lifecycle of the queue. + * @example + * + * // create a queue object with concurrency 2 + * var q = async.queue(function(task, callback) { + * console.log('hello ' + task.name); + * callback(); + * }, 2); + * + * // assign a callback + * q.drain = function() { + * console.log('all items have been processed'); + * }; + * + * // add some items to the queue + * q.push({name: 'foo'}, function(err) { + * console.log('finished processing foo'); + * }); + * q.push({name: 'bar'}, function (err) { + * console.log('finished processing bar'); + * }); + * + * // add some items to the queue (batch-wise) + * q.push([{name: 'baz'},{name: 'bay'},{name: 'bax'}], function(err) { + * console.log('finished processing item'); + * }); + * + * // add some items to the front of the queue + * q.unshift({name: 'bar'}, function (err) { + * console.log('finished processing bar'); + * }); + */ + function queue$1 (worker, concurrency) { + return queue(function (items, cb) { + worker(items[0], cb); + }, concurrency, 1); + } + + /** + * The same as [async.queue]{@link module:ControlFlow.queue} only tasks are assigned a priority and + * completed in ascending priority order. + * + * @name priorityQueue + * @static + * @memberOf module:ControlFlow + * @method + * @see [async.queue]{@link module:ControlFlow.queue} + * @category Control Flow + * @param {Function} worker - An asynchronous function for processing a queued + * task, which must call its `callback(err)` argument when finished, with an + * optional `error` as an argument. If you want to handle errors from an + * individual task, pass a callback to `q.push()`. Invoked with + * (task, callback). + * @param {number} concurrency - An `integer` for determining how many `worker` + * functions should be run in parallel. If omitted, the concurrency defaults to + * `1`. If the concurrency is `0`, an error is thrown. + * @returns {module:ControlFlow.QueueObject} A priorityQueue object to manage the tasks. There are two + * differences between `queue` and `priorityQueue` objects: + * * `push(task, priority, [callback])` - `priority` should be a number. If an + * array of `tasks` is given, all tasks will be assigned the same priority. + * * The `unshift` method was removed. + */ + function priorityQueue (worker, concurrency) { + // Start with a normal queue + var q = queue$1(worker, concurrency); + + // Override push to accept second parameter representing priority + q.push = function (data, priority, callback) { + if (callback == null) callback = noop; + if (typeof callback !== 'function') { + throw new Error('task callback must be a function'); + } + q.started = true; + if (!isArray(data)) { + data = [data]; + } + if (data.length === 0) { + // call drain immediately if there are no tasks + return setImmediate$1(function () { + q.drain(); + }); + } + + priority = priority || 0; + var nextNode = q._tasks.head; + while (nextNode && priority >= nextNode.priority) { + nextNode = nextNode.next; + } + + arrayEach(data, function (task) { + var item = { + data: task, + priority: priority, + callback: callback + }; + + if (nextNode) { + q._tasks.insertBefore(nextNode, item); + } else { + q._tasks.push(item); + } + }); + setImmediate$1(q.process); + }; + + // Remove unshift function + delete q.unshift; + + return q; + } + + /** + * Runs the `tasks` array of functions in parallel, without waiting until the + * previous function has completed. Once any the `tasks` completed or pass an + * error to its callback, the main `callback` is immediately called. It's + * equivalent to `Promise.race()`. + * + * @name race + * @static + * @memberOf module:ControlFlow + * @method + * @category Control Flow + * @param {Array} tasks - An array containing functions to run. Each function + * is passed a `callback(err, result)` which it must call on completion with an + * error `err` (which can be `null`) and an optional `result` value. + * @param {Function} callback - A callback to run once any of the functions have + * completed. This function gets an error or result from the first function that + * completed. Invoked with (err, result). + * @returns undefined + * @example + * + * async.race([ + * function(callback) { + * setTimeout(function() { + * callback(null, 'one'); + * }, 200); + * }, + * function(callback) { + * setTimeout(function() { + * callback(null, 'two'); + * }, 100); + * } + * ], + * // main callback + * function(err, result) { + * // the result will be equal to 'two' as it finishes earlier + * }); + */ + function race(tasks, callback) { + callback = once(callback || noop); + if (!isArray(tasks)) return callback(new TypeError('First argument to race must be an array of functions')); + if (!tasks.length) return callback(); + arrayEach(tasks, function (task) { + task(callback); + }); + } + + var slice = Array.prototype.slice; + + /** + * Same as [`reduce`]{@link module:Collections.reduce}, only operates on `array` in reverse order. + * + * @name reduceRight + * @static + * @memberOf module:Collections + * @method + * @see [async.reduce]{@link module:Collections.reduce} + * @alias foldr + * @category Collection + * @param {Array} array - A collection to iterate over. + * @param {*} memo - The initial state of the reduction. + * @param {Function} iteratee - A function applied to each item in the + * array to produce the next step in the reduction. The `iteratee` is passed a + * `callback(err, reduction)` which accepts an optional error as its first + * argument, and the state of the reduction as the second. If an error is + * passed to the callback, the reduction is stopped and the main `callback` is + * immediately called with the error. Invoked with (memo, item, callback). + * @param {Function} [callback] - A callback which is called after all the + * `iteratee` functions have finished. Result is the reduced value. Invoked with + * (err, result). + */ + function reduceRight(array, memo, iteratee, callback) { + var reversed = slice.call(array).reverse(); + reduce(reversed, memo, iteratee, callback); + } + + /** + * Wraps the function in another function that always returns data even when it + * errors. + * + * The object returned has either the property `error` or `value`. + * + * @name reflect + * @static + * @memberOf module:Utils + * @method + * @category Util + * @param {Function} fn - The function you want to wrap + * @returns {Function} - A function that always passes null to it's callback as + * the error. The second argument to the callback will be an `object` with + * either an `error` or a `value` property. + * @example + * + * async.parallel([ + * async.reflect(function(callback) { + * // do some stuff ... + * callback(null, 'one'); + * }), + * async.reflect(function(callback) { + * // do some more stuff but error ... + * callback('bad stuff happened'); + * }), + * async.reflect(function(callback) { + * // do some more stuff ... + * callback(null, 'two'); + * }) + * ], + * // optional callback + * function(err, results) { + * // values + * // results[0].value = 'one' + * // results[1].error = 'bad stuff happened' + * // results[2].value = 'two' + * }); + */ + function reflect(fn) { + return initialParams(function reflectOn(args, reflectCallback) { + args.push(rest(function callback(err, cbArgs) { + if (err) { + reflectCallback(null, { + error: err + }); + } else { + var value = null; + if (cbArgs.length === 1) { + value = cbArgs[0]; + } else if (cbArgs.length > 1) { + value = cbArgs; + } + reflectCallback(null, { + value: value + }); + } + })); + + return fn.apply(this, args); + }); + } + + function reject$1(eachfn, arr, iteratee, callback) { + _filter(eachfn, arr, function (value, cb) { + iteratee(value, function (err, v) { + if (err) { + cb(err); + } else { + cb(null, !v); + } + }); + }, callback); + } + + /** + * The opposite of [`filter`]{@link module:Collections.filter}. Removes values that pass an `async` truth test. + * + * @name reject + * @static + * @memberOf module:Collections + * @method + * @see [async.filter]{@link module:Collections.filter} + * @category Collection + * @param {Array|Iterable|Object} coll - A collection to iterate over. + * @param {Function} iteratee - A truth test to apply to each item in `coll`. + * The `iteratee` is passed a `callback(err, truthValue)`, which must be called + * with a boolean argument once it has completed. Invoked with (item, callback). + * @param {Function} [callback] - A callback which is called after all the + * `iteratee` functions have finished. Invoked with (err, results). + * @example + * + * async.reject(['file1','file2','file3'], function(filePath, callback) { + * fs.access(filePath, function(err) { + * callback(null, !err) + * }); + * }, function(err, results) { + * // results now equals an array of missing files + * createFiles(results); + * }); + */ + var reject = doParallel(reject$1); + + /** + * A helper function that wraps an array or an object of functions with reflect. + * + * @name reflectAll + * @static + * @memberOf module:Utils + * @method + * @see [async.reflect]{@link module:Utils.reflect} + * @category Util + * @param {Array} tasks - The array of functions to wrap in `async.reflect`. + * @returns {Array} Returns an array of functions, each function wrapped in + * `async.reflect` + * @example + * + * let tasks = [ + * function(callback) { + * setTimeout(function() { + * callback(null, 'one'); + * }, 200); + * }, + * function(callback) { + * // do some more stuff but error ... + * callback(new Error('bad stuff happened')); + * }, + * function(callback) { + * setTimeout(function() { + * callback(null, 'two'); + * }, 100); + * } + * ]; + * + * async.parallel(async.reflectAll(tasks), + * // optional callback + * function(err, results) { + * // values + * // results[0].value = 'one' + * // results[1].error = Error('bad stuff happened') + * // results[2].value = 'two' + * }); + * + * // an example using an object instead of an array + * let tasks = { + * one: function(callback) { + * setTimeout(function() { + * callback(null, 'one'); + * }, 200); + * }, + * two: function(callback) { + * callback('two'); + * }, + * three: function(callback) { + * setTimeout(function() { + * callback(null, 'three'); + * }, 100); + * } + * }; + * + * async.parallel(async.reflectAll(tasks), + * // optional callback + * function(err, results) { + * // values + * // results.one.value = 'one' + * // results.two.error = 'two' + * // results.three.value = 'three' + * }); + */ + function reflectAll(tasks) { + var results; + if (isArray(tasks)) { + results = arrayMap(tasks, reflect); + } else { + results = {}; + baseForOwn(tasks, function (task, key) { + results[key] = reflect.call(this, task); + }); + } + return results; + } + + /** + * The same as [`reject`]{@link module:Collections.reject} but runs a maximum of `limit` async operations at a + * time. + * + * @name rejectLimit + * @static + * @memberOf module:Collections + * @method + * @see [async.reject]{@link module:Collections.reject} + * @category Collection + * @param {Array|Iterable|Object} coll - A collection to iterate over. + * @param {number} limit - The maximum number of async operations at a time. + * @param {Function} iteratee - A truth test to apply to each item in `coll`. + * The `iteratee` is passed a `callback(err, truthValue)`, which must be called + * with a boolean argument once it has completed. Invoked with (item, callback). + * @param {Function} [callback] - A callback which is called after all the + * `iteratee` functions have finished. Invoked with (err, results). + */ + var rejectLimit = doParallelLimit(reject$1); + + /** + * The same as [`reject`]{@link module:Collections.reject} but runs only a single async operation at a time. + * + * @name rejectSeries + * @static + * @memberOf module:Collections + * @method + * @see [async.reject]{@link module:Collections.reject} + * @category Collection + * @param {Array|Iterable|Object} coll - A collection to iterate over. + * @param {Function} iteratee - A truth test to apply to each item in `coll`. + * The `iteratee` is passed a `callback(err, truthValue)`, which must be called + * with a boolean argument once it has completed. Invoked with (item, callback). + * @param {Function} [callback] - A callback which is called after all the + * `iteratee` functions have finished. Invoked with (err, results). + */ + var rejectSeries = doLimit(rejectLimit, 1); + + /** + * Creates a function that returns `value`. + * + * @static + * @memberOf _ + * @since 2.4.0 + * @category Util + * @param {*} value The value to return from the new function. + * @returns {Function} Returns the new constant function. + * @example + * + * var objects = _.times(2, _.constant({ 'a': 1 })); + * + * console.log(objects); + * // => [{ 'a': 1 }, { 'a': 1 }] + * + * console.log(objects[0] === objects[1]); + * // => true + */ + function constant$1(value) { + return function() { + return value; + }; + } + + /** + * Attempts to get a successful response from `task` no more than `times` times + * before returning an error. If the task is successful, the `callback` will be + * passed the result of the successful task. If all attempts fail, the callback + * will be passed the error and result (if any) of the final attempt. + * + * @name retry + * @static + * @memberOf module:ControlFlow + * @method + * @category Control Flow + * @param {Object|number} [opts = {times: 5, interval: 0}| 5] - Can be either an + * object with `times` and `interval` or a number. + * * `times` - The number of attempts to make before giving up. The default + * is `5`. + * * `interval` - The time to wait between retries, in milliseconds. The + * default is `0`. The interval may also be specified as a function of the + * retry count (see example). + * * If `opts` is a number, the number specifies the number of times to retry, + * with the default interval of `0`. + * @param {Function} task - A function which receives two arguments: (1) a + * `callback(err, result)` which must be called when finished, passing `err` + * (which can be `null`) and the `result` of the function's execution, and (2) + * a `results` object, containing the results of the previously executed + * functions (if nested inside another control flow). Invoked with + * (callback, results). + * @param {Function} [callback] - An optional callback which is called when the + * task has succeeded, or after the final failed attempt. It receives the `err` + * and `result` arguments of the last attempt at completing the `task`. Invoked + * with (err, results). + * @example + * + * // The `retry` function can be used as a stand-alone control flow by passing + * // a callback, as shown below: + * + * // try calling apiMethod 3 times + * async.retry(3, apiMethod, function(err, result) { + * // do something with the result + * }); + * + * // try calling apiMethod 3 times, waiting 200 ms between each retry + * async.retry({times: 3, interval: 200}, apiMethod, function(err, result) { + * // do something with the result + * }); + * + * // try calling apiMethod 10 times with exponential backoff + * // (i.e. intervals of 100, 200, 400, 800, 1600, ... milliseconds) + * async.retry({ + * times: 10, + * interval: function(retryCount) { + * return 50 * Math.pow(2, retryCount); + * } + * }, apiMethod, function(err, result) { + * // do something with the result + * }); + * + * // try calling apiMethod the default 5 times no delay between each retry + * async.retry(apiMethod, function(err, result) { + * // do something with the result + * }); + * + * // It can also be embedded within other control flow functions to retry + * // individual methods that are not as reliable, like this: + * async.auto({ + * users: api.getUsers.bind(api), + * payments: async.retry(3, api.getPayments.bind(api)) + * }, function(err, results) { + * // do something with the results + * }); + */ + function retry(opts, task, callback) { + var DEFAULT_TIMES = 5; + var DEFAULT_INTERVAL = 0; + + var options = { + times: DEFAULT_TIMES, + intervalFunc: constant$1(DEFAULT_INTERVAL) + }; + + function parseTimes(acc, t) { + if (typeof t === 'object') { + acc.times = +t.times || DEFAULT_TIMES; + + acc.intervalFunc = typeof t.interval === 'function' ? t.interval : constant$1(+t.interval || DEFAULT_INTERVAL); + } else if (typeof t === 'number' || typeof t === 'string') { + acc.times = +t || DEFAULT_TIMES; + } else { + throw new Error("Invalid arguments for async.retry"); + } + } + + if (arguments.length < 3 && typeof opts === 'function') { + callback = task || noop; + task = opts; + } else { + parseTimes(options, opts); + callback = callback || noop; + } + + if (typeof task !== 'function') { + throw new Error("Invalid arguments for async.retry"); + } + + var attempt = 1; + function retryAttempt() { + task(function (err) { + if (err && attempt++ < options.times) { + setTimeout(retryAttempt, options.intervalFunc(attempt)); + } else { + callback.apply(null, arguments); + } + }); + } + + retryAttempt(); + } + + /** + * A close relative of [`retry`]{@link module:ControlFlow.retry}. This method wraps a task and makes it + * retryable, rather than immediately calling it with retries. + * + * @name retryable + * @static + * @memberOf module:ControlFlow + * @method + * @see [async.retry]{@link module:ControlFlow.retry} + * @category Control Flow + * @param {Object|number} [opts = {times: 5, interval: 0}| 5] - optional + * options, exactly the same as from `retry` + * @param {Function} task - the asynchronous function to wrap + * @returns {Functions} The wrapped function, which when invoked, will retry on + * an error, based on the parameters specified in `opts`. + * @example + * + * async.auto({ + * dep1: async.retryable(3, getFromFlakyService), + * process: ["dep1", async.retryable(3, function (results, cb) { + * maybeProcessData(results.dep1, cb); + * })] + * }, callback); + */ + function retryable (opts, task) { + if (!task) { + task = opts; + opts = null; + } + return initialParams(function (args, callback) { + function taskFn(cb) { + task.apply(null, args.concat([cb])); + } + + if (opts) retry(opts, taskFn, callback);else retry(taskFn, callback); + }); + } + + /** + * Run the functions in the `tasks` collection in series, each one running once + * the previous function has completed. If any functions in the series pass an + * error to its callback, no more functions are run, and `callback` is + * immediately called with the value of the error. Otherwise, `callback` + * receives an array of results when `tasks` have completed. + * + * It is also possible to use an object instead of an array. Each property will + * be run as a function, and the results will be passed to the final `callback` + * as an object instead of an array. This can be a more readable way of handling + * results from {@link async.series}. + * + * **Note** that while many implementations preserve the order of object + * properties, the [ECMAScript Language Specification](http://www.ecma-international.org/ecma-262/5.1/#sec-8.6) + * explicitly states that + * + * > The mechanics and order of enumerating the properties is not specified. + * + * So if you rely on the order in which your series of functions are executed, + * and want this to work on all platforms, consider using an array. + * + * @name series + * @static + * @memberOf module:ControlFlow + * @method + * @category Control Flow + * @param {Array|Iterable|Object} tasks - A collection containing functions to run, each + * function is passed a `callback(err, result)` it must call on completion with + * an error `err` (which can be `null`) and an optional `result` value. + * @param {Function} [callback] - An optional callback to run once all the + * functions have completed. This function gets a results array (or object) + * containing all the result arguments passed to the `task` callbacks. Invoked + * with (err, result). + * @example + * async.series([ + * function(callback) { + * // do some stuff ... + * callback(null, 'one'); + * }, + * function(callback) { + * // do some more stuff ... + * callback(null, 'two'); + * } + * ], + * // optional callback + * function(err, results) { + * // results is now equal to ['one', 'two'] + * }); + * + * async.series({ + * one: function(callback) { + * setTimeout(function() { + * callback(null, 1); + * }, 200); + * }, + * two: function(callback){ + * setTimeout(function() { + * callback(null, 2); + * }, 100); + * } + * }, function(err, results) { + * // results is now equal to: {one: 1, two: 2} + * }); + */ + function series(tasks, callback) { + _parallel(eachOfSeries, tasks, callback); + } + + /** + * Returns `true` if at least one element in the `coll` satisfies an async test. + * If any iteratee call returns `true`, the main `callback` is immediately + * called. + * + * @name some + * @static + * @memberOf module:Collections + * @method + * @alias any + * @category Collection + * @param {Array|Iterable|Object} coll - A collection to iterate over. + * @param {Function} iteratee - A truth test to apply to each item in the array + * in parallel. The iteratee is passed a `callback(err, truthValue)` which must + * be called with a boolean argument once it has completed. Invoked with + * (item, callback). + * @param {Function} [callback] - A callback which is called as soon as any + * iteratee returns `true`, or after all the iteratee functions have finished. + * Result will be either `true` or `false` depending on the values of the async + * tests. Invoked with (err, result). + * @example + * + * async.some(['file1','file2','file3'], function(filePath, callback) { + * fs.access(filePath, function(err) { + * callback(null, !err) + * }); + * }, function(err, result) { + * // if result is true then at least one of the files exists + * }); + */ + var some = _createTester(eachOf, Boolean, identity); + + /** + * The same as [`some`]{@link module:Collections.some} but runs a maximum of `limit` async operations at a time. + * + * @name someLimit + * @static + * @memberOf module:Collections + * @method + * @see [async.some]{@link module:Collections.some} + * @alias anyLimit + * @category Collection + * @param {Array|Iterable|Object} coll - A collection to iterate over. + * @param {number} limit - The maximum number of async operations at a time. + * @param {Function} iteratee - A truth test to apply to each item in the array + * in parallel. The iteratee is passed a `callback(err, truthValue)` which must + * be called with a boolean argument once it has completed. Invoked with + * (item, callback). + * @param {Function} [callback] - A callback which is called as soon as any + * iteratee returns `true`, or after all the iteratee functions have finished. + * Result will be either `true` or `false` depending on the values of the async + * tests. Invoked with (err, result). + */ + var someLimit = _createTester(eachOfLimit, Boolean, identity); + + /** + * The same as [`some`]{@link module:Collections.some} but runs only a single async operation at a time. + * + * @name someSeries + * @static + * @memberOf module:Collections + * @method + * @see [async.some]{@link module:Collections.some} + * @alias anySeries + * @category Collection + * @param {Array|Iterable|Object} coll - A collection to iterate over. + * @param {Function} iteratee - A truth test to apply to each item in the array + * in parallel. The iteratee is passed a `callback(err, truthValue)` which must + * be called with a boolean argument once it has completed. Invoked with + * (item, callback). + * @param {Function} [callback] - A callback which is called as soon as any + * iteratee returns `true`, or after all the iteratee functions have finished. + * Result will be either `true` or `false` depending on the values of the async + * tests. Invoked with (err, result). + */ + var someSeries = doLimit(someLimit, 1); + + /** + * Sorts a list by the results of running each `coll` value through an async + * `iteratee`. + * + * @name sortBy + * @static + * @memberOf module:Collections + * @method + * @category Collection + * @param {Array|Iterable|Object} coll - A collection to iterate over. + * @param {Function} iteratee - A function to apply to each item in `coll`. + * The iteratee is passed a `callback(err, sortValue)` which must be called once + * it has completed with an error (which can be `null`) and a value to use as + * the sort criteria. Invoked with (item, callback). + * @param {Function} callback - A callback which is called after all the + * `iteratee` functions have finished, or an error occurs. Results is the items + * from the original `coll` sorted by the values returned by the `iteratee` + * calls. Invoked with (err, results). + * @example + * + * async.sortBy(['file1','file2','file3'], function(file, callback) { + * fs.stat(file, function(err, stats) { + * callback(err, stats.mtime); + * }); + * }, function(err, results) { + * // results is now the original array of files sorted by + * // modified date + * }); + * + * // By modifying the callback parameter the + * // sorting order can be influenced: + * + * // ascending order + * async.sortBy([1,9,3,5], function(x, callback) { + * callback(null, x); + * }, function(err,result) { + * // result callback + * }); + * + * // descending order + * async.sortBy([1,9,3,5], function(x, callback) { + * callback(null, x*-1); //<- x*-1 instead of x, turns the order around + * }, function(err,result) { + * // result callback + * }); + */ + function sortBy(coll, iteratee, callback) { + map(coll, function (x, callback) { + iteratee(x, function (err, criteria) { + if (err) return callback(err); + callback(null, { value: x, criteria: criteria }); + }); + }, function (err, results) { + if (err) return callback(err); + callback(null, arrayMap(results.sort(comparator), baseProperty('value'))); + }); + + function comparator(left, right) { + var a = left.criteria, + b = right.criteria; + return a < b ? -1 : a > b ? 1 : 0; + } + } + + /** + * Sets a time limit on an asynchronous function. If the function does not call + * its callback within the specified milliseconds, it will be called with a + * timeout error. The code property for the error object will be `'ETIMEDOUT'`. + * + * @name timeout + * @static + * @memberOf module:Utils + * @method + * @category Util + * @param {Function} asyncFn - The asynchronous function you want to set the + * time limit. + * @param {number} milliseconds - The specified time limit. + * @param {*} [info] - Any variable you want attached (`string`, `object`, etc) + * to timeout Error for more information.. + * @returns {Function} Returns a wrapped function that can be used with any of + * the control flow functions. + * @example + * + * async.timeout(function(callback) { + * doAsyncTask(callback); + * }, 1000); + */ + function timeout(asyncFn, milliseconds, info) { + var originalCallback, timer; + var timedOut = false; + + function injectedCallback() { + if (!timedOut) { + originalCallback.apply(null, arguments); + clearTimeout(timer); + } + } + + function timeoutCallback() { + var name = asyncFn.name || 'anonymous'; + var error = new Error('Callback function "' + name + '" timed out.'); + error.code = 'ETIMEDOUT'; + if (info) { + error.info = info; + } + timedOut = true; + originalCallback(error); + } + + return initialParams(function (args, origCallback) { + originalCallback = origCallback; + // setup timer and call original function + timer = setTimeout(timeoutCallback, milliseconds); + asyncFn.apply(null, args.concat(injectedCallback)); + }); + } + + /* Built-in method references for those with the same name as other `lodash` methods. */ + var nativeCeil = Math.ceil; + var nativeMax$1 = Math.max; + /** + * The base implementation of `_.range` and `_.rangeRight` which doesn't + * coerce arguments to numbers. + * + * @private + * @param {number} start The start of the range. + * @param {number} end The end of the range. + * @param {number} step The value to increment or decrement by. + * @param {boolean} [fromRight] Specify iterating from right to left. + * @returns {Array} Returns the range of numbers. + */ + function baseRange(start, end, step, fromRight) { + var index = -1, + length = nativeMax$1(nativeCeil((end - start) / (step || 1)), 0), + result = Array(length); + + while (length--) { + result[fromRight ? length : ++index] = start; + start += step; + } + return result; + } + + /** + * The same as [times]{@link module:ControlFlow.times} but runs a maximum of `limit` async operations at a + * time. + * + * @name timesLimit + * @static + * @memberOf module:ControlFlow + * @method + * @see [async.times]{@link module:ControlFlow.times} + * @category Control Flow + * @param {number} count - The number of times to run the function. + * @param {number} limit - The maximum number of async operations at a time. + * @param {Function} iteratee - The function to call `n` times. Invoked with the + * iteration index and a callback (n, next). + * @param {Function} callback - see [async.map]{@link module:Collections.map}. + */ + function timeLimit(count, limit, iteratee, callback) { + mapLimit(baseRange(0, count, 1), limit, iteratee, callback); + } + + /** + * Calls the `iteratee` function `n` times, and accumulates results in the same + * manner you would use with [map]{@link module:Collections.map}. + * + * @name times + * @static + * @memberOf module:ControlFlow + * @method + * @see [async.map]{@link module:Collections.map} + * @category Control Flow + * @param {number} n - The number of times to run the function. + * @param {Function} iteratee - The function to call `n` times. Invoked with the + * iteration index and a callback (n, next). + * @param {Function} callback - see {@link module:Collections.map}. + * @example + * + * // Pretend this is some complicated async factory + * var createUser = function(id, callback) { + * callback(null, { + * id: 'user' + id + * }); + * }; + * + * // generate 5 users + * async.times(5, function(n, next) { + * createUser(n, function(err, user) { + * next(err, user); + * }); + * }, function(err, users) { + * // we should now have 5 users + * }); + */ + var times = doLimit(timeLimit, Infinity); + + /** + * The same as [times]{@link module:ControlFlow.times} but runs only a single async operation at a time. + * + * @name timesSeries + * @static + * @memberOf module:ControlFlow + * @method + * @see [async.times]{@link module:ControlFlow.times} + * @category Control Flow + * @param {number} n - The number of times to run the function. + * @param {Function} iteratee - The function to call `n` times. Invoked with the + * iteration index and a callback (n, next). + * @param {Function} callback - see {@link module:Collections.map}. + */ + var timesSeries = doLimit(timeLimit, 1); + + /** + * A relative of `reduce`. Takes an Object or Array, and iterates over each + * element in series, each step potentially mutating an `accumulator` value. + * The type of the accumulator defaults to the type of collection passed in. + * + * @name transform + * @static + * @memberOf module:Collections + * @method + * @category Collection + * @param {Array|Iterable|Object} coll - A collection to iterate over. + * @param {*} [accumulator] - The initial state of the transform. If omitted, + * it will default to an empty Object or Array, depending on the type of `coll` + * @param {Function} iteratee - A function applied to each item in the + * collection that potentially modifies the accumulator. The `iteratee` is + * passed a `callback(err)` which accepts an optional error as its first + * argument. If an error is passed to the callback, the transform is stopped + * and the main `callback` is immediately called with the error. + * Invoked with (accumulator, item, key, callback). + * @param {Function} [callback] - A callback which is called after all the + * `iteratee` functions have finished. Result is the transformed accumulator. + * Invoked with (err, result). + * @example + * + * async.transform([1,2,3], function(acc, item, index, callback) { + * // pointless async: + * process.nextTick(function() { + * acc.push(item * 2) + * callback(null) + * }); + * }, function(err, result) { + * // result is now equal to [2, 4, 6] + * }); + * + * @example + * + * async.transform({a: 1, b: 2, c: 3}, function (obj, val, key, callback) { + * setImmediate(function () { + * obj[key] = val * 2; + * callback(); + * }) + * }, function (err, result) { + * // result is equal to {a: 2, b: 4, c: 6} + * }) + */ + function transform(coll, accumulator, iteratee, callback) { + if (arguments.length === 3) { + callback = iteratee; + iteratee = accumulator; + accumulator = isArray(coll) ? [] : {}; + } + callback = once(callback || noop); + + eachOf(coll, function (v, k, cb) { + iteratee(accumulator, v, k, cb); + }, function (err) { + callback(err, accumulator); + }); + } + + /** + * Undoes a [memoize]{@link module:Utils.memoize}d function, reverting it to the original, + * unmemoized form. Handy for testing. + * + * @name unmemoize + * @static + * @memberOf module:Utils + * @method + * @see [async.memoize]{@link module:Utils.memoize} + * @category Util + * @param {Function} fn - the memoized function + * @returns {Function} a function that calls the original unmemoized function + */ + function unmemoize(fn) { + return function () { + return (fn.unmemoized || fn).apply(null, arguments); + }; + } + + /** + * Repeatedly call `fn`, while `test` returns `true`. Calls `callback` when + * stopped, or an error occurs. + * + * @name whilst + * @static + * @memberOf module:ControlFlow + * @method + * @category Control Flow + * @param {Function} test - synchronous truth test to perform before each + * execution of `fn`. Invoked with (). + * @param {Function} iteratee - A function which is called each time `test` passes. + * The function is passed a `callback(err)`, which must be called once it has + * completed with an optional `err` argument. Invoked with (callback). + * @param {Function} [callback] - A callback which is called after the test + * function has failed and repeated execution of `fn` has stopped. `callback` + * will be passed an error and any arguments passed to the final `fn`'s + * callback. Invoked with (err, [results]); + * @returns undefined + * @example + * + * var count = 0; + * async.whilst( + * function() { return count < 5; }, + * function(callback) { + * count++; + * setTimeout(function() { + * callback(null, count); + * }, 1000); + * }, + * function (err, n) { + * // 5 seconds have passed, n = 5 + * } + * ); + */ + function whilst(test, iteratee, callback) { + callback = onlyOnce(callback || noop); + if (!test()) return callback(null); + var next = rest(function (err, args) { + if (err) return callback(err); + if (test()) return iteratee(next); + callback.apply(null, [null].concat(args)); + }); + iteratee(next); + } + + /** + * Repeatedly call `fn` until `test` returns `true`. Calls `callback` when + * stopped, or an error occurs. `callback` will be passed an error and any + * arguments passed to the final `fn`'s callback. + * + * The inverse of [whilst]{@link module:ControlFlow.whilst}. + * + * @name until + * @static + * @memberOf module:ControlFlow + * @method + * @see [async.whilst]{@link module:ControlFlow.whilst} + * @category Control Flow + * @param {Function} test - synchronous truth test to perform before each + * execution of `fn`. Invoked with (). + * @param {Function} fn - A function which is called each time `test` fails. + * The function is passed a `callback(err)`, which must be called once it has + * completed with an optional `err` argument. Invoked with (callback). + * @param {Function} [callback] - A callback which is called after the test + * function has passed and repeated execution of `fn` has stopped. `callback` + * will be passed an error and any arguments passed to the final `fn`'s + * callback. Invoked with (err, [results]); + */ + function until(test, fn, callback) { + whilst(function () { + return !test.apply(this, arguments); + }, fn, callback); + } + + /** + * Runs the `tasks` array of functions in series, each passing their results to + * the next in the array. However, if any of the `tasks` pass an error to their + * own callback, the next function is not executed, and the main `callback` is + * immediately called with the error. + * + * @name waterfall + * @static + * @memberOf module:ControlFlow + * @method + * @category Control Flow + * @param {Array} tasks - An array of functions to run, each function is passed + * a `callback(err, result1, result2, ...)` it must call on completion. The + * first argument is an error (which can be `null`) and any further arguments + * will be passed as arguments in order to the next task. + * @param {Function} [callback] - An optional callback to run once all the + * functions have completed. This will be passed the results of the last task's + * callback. Invoked with (err, [results]). + * @returns undefined + * @example + * + * async.waterfall([ + * function(callback) { + * callback(null, 'one', 'two'); + * }, + * function(arg1, arg2, callback) { + * // arg1 now equals 'one' and arg2 now equals 'two' + * callback(null, 'three'); + * }, + * function(arg1, callback) { + * // arg1 now equals 'three' + * callback(null, 'done'); + * } + * ], function (err, result) { + * // result now equals 'done' + * }); + * + * // Or, with named functions: + * async.waterfall([ + * myFirstFunction, + * mySecondFunction, + * myLastFunction, + * ], function (err, result) { + * // result now equals 'done' + * }); + * function myFirstFunction(callback) { + * callback(null, 'one', 'two'); + * } + * function mySecondFunction(arg1, arg2, callback) { + * // arg1 now equals 'one' and arg2 now equals 'two' + * callback(null, 'three'); + * } + * function myLastFunction(arg1, callback) { + * // arg1 now equals 'three' + * callback(null, 'done'); + * } + */ + function waterfall (tasks, callback) { + callback = once(callback || noop); + if (!isArray(tasks)) return callback(new Error('First argument to waterfall must be an array of functions')); + if (!tasks.length) return callback(); + var taskIndex = 0; + + function nextTask(args) { + if (taskIndex === tasks.length) { + return callback.apply(null, [null].concat(args)); + } + + var taskCallback = onlyOnce(rest(function (err, args) { + if (err) { + return callback.apply(null, [err].concat(args)); + } + nextTask(args); + })); + + args.push(taskCallback); + + var task = tasks[taskIndex++]; + task.apply(null, args); + } + + nextTask([]); + } + + var index = { + applyEach: applyEach, + applyEachSeries: applyEachSeries, + apply: apply$1, + asyncify: asyncify, + auto: auto, + autoInject: autoInject, + cargo: cargo, + compose: compose, + concat: concat, + concatSeries: concatSeries, + constant: constant, + detect: detect, + detectLimit: detectLimit, + detectSeries: detectSeries, + dir: dir, + doDuring: doDuring, + doUntil: doUntil, + doWhilst: doWhilst, + during: during, + each: eachLimit, + eachLimit: eachLimit$1, + eachOf: eachOf, + eachOfLimit: eachOfLimit, + eachOfSeries: eachOfSeries, + eachSeries: eachSeries, + ensureAsync: ensureAsync, + every: every, + everyLimit: everyLimit, + everySeries: everySeries, + filter: filter, + filterLimit: filterLimit, + filterSeries: filterSeries, + forever: forever, + log: log, + map: map, + mapLimit: mapLimit, + mapSeries: mapSeries, + mapValues: mapValues, + mapValuesLimit: mapValuesLimit, + mapValuesSeries: mapValuesSeries, + memoize: memoize, + nextTick: nextTick, + parallel: parallelLimit, + parallelLimit: parallelLimit$1, + priorityQueue: priorityQueue, + queue: queue$1, + race: race, + reduce: reduce, + reduceRight: reduceRight, + reflect: reflect, + reflectAll: reflectAll, + reject: reject, + rejectLimit: rejectLimit, + rejectSeries: rejectSeries, + retry: retry, + retryable: retryable, + seq: seq, + series: series, + setImmediate: setImmediate$1, + some: some, + someLimit: someLimit, + someSeries: someSeries, + sortBy: sortBy, + timeout: timeout, + times: times, + timesLimit: timeLimit, + timesSeries: timesSeries, + transform: transform, + unmemoize: unmemoize, + until: until, + waterfall: waterfall, + whilst: whilst, + + // aliases + all: every, + any: some, + forEach: eachLimit, + forEachSeries: eachSeries, + forEachLimit: eachLimit$1, + forEachOf: eachOf, + forEachOfSeries: eachOfSeries, + forEachOfLimit: eachOfLimit, + inject: reduce, + foldl: reduce, + foldr: reduceRight, + select: filter, + selectLimit: filterLimit, + selectSeries: filterSeries, + wrapSync: asyncify + }; + + exports['default'] = index; + exports.applyEach = applyEach; + exports.applyEachSeries = applyEachSeries; + exports.apply = apply$1; + exports.asyncify = asyncify; + exports.auto = auto; + exports.autoInject = autoInject; + exports.cargo = cargo; + exports.compose = compose; + exports.concat = concat; + exports.concatSeries = concatSeries; + exports.constant = constant; + exports.detect = detect; + exports.detectLimit = detectLimit; + exports.detectSeries = detectSeries; + exports.dir = dir; + exports.doDuring = doDuring; + exports.doUntil = doUntil; + exports.doWhilst = doWhilst; + exports.during = during; + exports.each = eachLimit; + exports.eachLimit = eachLimit$1; + exports.eachOf = eachOf; + exports.eachOfLimit = eachOfLimit; + exports.eachOfSeries = eachOfSeries; + exports.eachSeries = eachSeries; + exports.ensureAsync = ensureAsync; + exports.every = every; + exports.everyLimit = everyLimit; + exports.everySeries = everySeries; + exports.filter = filter; + exports.filterLimit = filterLimit; + exports.filterSeries = filterSeries; + exports.forever = forever; + exports.log = log; + exports.map = map; + exports.mapLimit = mapLimit; + exports.mapSeries = mapSeries; + exports.mapValues = mapValues; + exports.mapValuesLimit = mapValuesLimit; + exports.mapValuesSeries = mapValuesSeries; + exports.memoize = memoize; + exports.nextTick = nextTick; + exports.parallel = parallelLimit; + exports.parallelLimit = parallelLimit$1; + exports.priorityQueue = priorityQueue; + exports.queue = queue$1; + exports.race = race; + exports.reduce = reduce; + exports.reduceRight = reduceRight; + exports.reflect = reflect; + exports.reflectAll = reflectAll; + exports.reject = reject; + exports.rejectLimit = rejectLimit; + exports.rejectSeries = rejectSeries; + exports.retry = retry; + exports.retryable = retryable; + exports.seq = seq; + exports.series = series; + exports.setImmediate = setImmediate$1; + exports.some = some; + exports.someLimit = someLimit; + exports.someSeries = someSeries; + exports.sortBy = sortBy; + exports.timeout = timeout; + exports.times = times; + exports.timesLimit = timeLimit; + exports.timesSeries = timesSeries; + exports.transform = transform; + exports.unmemoize = unmemoize; + exports.until = until; + exports.waterfall = waterfall; + exports.whilst = whilst; + exports.all = every; + exports.allLimit = everyLimit; + exports.allSeries = everySeries; + exports.any = some; + exports.anyLimit = someLimit; + exports.anySeries = someSeries; + exports.find = detect; + exports.findLimit = detectLimit; + exports.findSeries = detectSeries; + exports.forEach = eachLimit; + exports.forEachSeries = eachSeries; + exports.forEachLimit = eachLimit$1; + exports.forEachOf = eachOf; + exports.forEachOfSeries = eachOfSeries; + exports.forEachOfLimit = eachOfLimit; + exports.inject = reduce; + exports.foldl = reduce; + exports.foldr = reduceRight; + exports.select = filter; + exports.selectLimit = filterLimit; + exports.selectSeries = filterSeries; + exports.wrapSync = asyncify; + +})); +}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) + +},{"_process":24}],30:[function(require,module,exports){ +'use strict'; + +var async = require('async'); +var urlParser = require('url'); +var Resource = require('./Resource'); +var EventEmitter = require('eventemitter3'); + +// some constants +var DEFAULT_CONCURRENCY = 10; +var MAX_PROGRESS = 100; + +/** + * Manages the state and loading of multiple resources to load. + * + * @class + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +function Loader(baseUrl, concurrency) { + EventEmitter.call(this); + + concurrency = concurrency || DEFAULT_CONCURRENCY; + + /** + * The base url for all resources loaded by this loader. + * + * @member {string} + */ + this.baseUrl = baseUrl || ''; + + /** + * The progress percent of the loader going through the queue. + * + * @member {number} + */ + this.progress = 0; + + /** + * Loading state of the loader, true if it is currently loading resources. + * + * @member {boolean} + */ + this.loading = false; + + /** + * The percentage of total progress that a single resource represents. + * + * @member {number} + */ + this._progressChunk = 0; + + /** + * The middleware to run before loading each resource. + * + * @member {function[]} + */ + this._beforeMiddleware = []; + + /** + * The middleware to run after loading each resource. + * + * @member {function[]} + */ + this._afterMiddleware = []; + + /** + * The `_loadResource` function bound with this object context. + * + * @private + * @member {function} + */ + this._boundLoadResource = this._loadResource.bind(this); + + /** + * The resource buffer that fills until `load` is called to start loading resources. + * + * @private + * @member {Resource[]} + */ + this._buffer = []; + + /** + * Used to track load completion. + * + * @private + * @member {number} + */ + this._numToLoad = 0; + + /** + * The resources waiting to be loaded. + * + * @private + * @member {Resource[]} + */ + this._queue = async.queue(this._boundLoadResource, concurrency); + + /** + * All the resources for this loader keyed by name. + * + * @member {object} + */ + this.resources = {}; + + /** + * Emitted once per loaded or errored resource. + * + * @event progress + * @memberof Loader# + */ + + /** + * Emitted once per errored resource. + * + * @event error + * @memberof Loader# + */ + + /** + * Emitted once per loaded resource. + * + * @event load + * @memberof Loader# + */ + + /** + * Emitted when the loader begins to process the queue. + * + * @event start + * @memberof Loader# + */ + + /** + * Emitted when the queued resources all load. + * + * @event complete + * @memberof Loader# + */ +} + +Loader.prototype = Object.create(EventEmitter.prototype); +Loader.prototype.constructor = Loader; +module.exports = Loader; + +/** + * Adds a resource (or multiple resources) to the loader queue. + * + * This function can take a wide variety of different parameters. The only thing that is always + * required the url to load. All the following will work: + * + * ```js + * loader + * // normal param syntax + * .add('key', 'http://...', function () {}) + * .add('http://...', function () {}) + * .add('http://...') + * + * // object syntax + * .add({ + * name: 'key2', + * url: 'http://...' + * }, function () {}) + * .add({ + * url: 'http://...' + * }, function () {}) + * .add({ + * name: 'key3', + * url: 'http://...' + * onComplete: function () {} + * }) + * .add({ + * url: 'https://...', + * onComplete: function () {}, + * crossOrigin: true + * }) + * + * // you can also pass an array of objects or urls or both + * .add([ + * { name: 'key4', url: 'http://...', onComplete: function () {} }, + * { url: 'http://...', onComplete: function () {} }, + * 'http://...' + * ]) + * + * // and you can use both params and options + * .add('key', 'http://...', { crossOrigin: true }, function () {}) + * .add('http://...', { crossOrigin: true }, function () {}); + * ``` + * + * @alias enqueue + * @param {string} [name] - The name of the resource to load, if not passed the url is used. + * @param {string} [url] - The url for this resource, relative to the baseUrl of this loader. + * @param {object} [options] - The options for the load. + * @param {boolean} [options.crossOrigin] - Is this request cross-origin? Default is to determine automatically. + * @param {Resource.XHR_LOAD_TYPE} [options.loadType=Resource.LOAD_TYPE.XHR] - How should this resource be loaded? + * @param {Resource.XHR_RESPONSE_TYPE} [options.xhrType=Resource.XHR_RESPONSE_TYPE.DEFAULT] - How should the data being + * loaded be interpreted when using XHR? + * @param {function} [cb] - Function to call when this specific resource completes loading. + * @return {Loader} Returns itself. + */ +Loader.prototype.add = Loader.prototype.enqueue = function (name, url, options, cb) { + // special case of an array of objects or urls + if (Array.isArray(name)) { + for (var i = 0; i < name.length; ++i) { + this.add(name[i]); + } + + return this; + } + + // if an object is passed instead of params + if (typeof name === 'object') { + cb = url || name.callback || name.onComplete; + options = name; + url = name.url; + name = name.name || name.key || name.url; + } + + // case where no name is passed shift all args over by one. + if (typeof url !== 'string') { + cb = options; + options = url; + url = name; + } + + // now that we shifted make sure we have a proper url. + if (typeof url !== 'string') { + throw new Error('No url passed to add resource to loader.'); + } + + // options are optional so people might pass a function and no options + if (typeof options === 'function') { + cb = options; + options = null; + } + + // check if resource already exists. + if (this.resources[name]) { + throw new Error('Resource with name "' + name + '" already exists.'); + } + + // add base url if this isn't an absolute url + url = this._prepareUrl(url); + + // create the store the resource + this.resources[name] = new Resource(name, url, options); + + if (typeof cb === 'function') { + this.resources[name].once('afterMiddleware', cb); + } + + this._numToLoad++; + + // if already loading add it to the worker queue + if (this._queue.started) { + this._queue.push(this.resources[name]); + this._progressChunk = (MAX_PROGRESS - this.progress) / (this._queue.length() + this._queue.running()); + } + // otherwise buffer it to be added to the queue later + else { + this._buffer.push(this.resources[name]); + this._progressChunk = MAX_PROGRESS / this._buffer.length; + } + + return this; +}; + +/** + * Sets up a middleware function that will run *before* the + * resource is loaded. + * + * @alias pre + * @method before + * @param {function} fn - The middleware function to register. + * @return {Loader} Returns itself. + */ +Loader.prototype.before = Loader.prototype.pre = function (fn) { + this._beforeMiddleware.push(fn); + + return this; +}; + +/** + * Sets up a middleware function that will run *after* the + * resource is loaded. + * + * @alias use + * @method after + * @param {function} fn - The middleware function to register. + * @return {Loader} Returns itself. + */ +Loader.prototype.after = Loader.prototype.use = function (fn) { + this._afterMiddleware.push(fn); + + return this; +}; + +/** + * Resets the queue of the loader to prepare for a new load. + * + * @return {Loader} Returns itself. + */ +Loader.prototype.reset = function () { + // this.baseUrl = baseUrl || ''; + + this.progress = 0; + + this.loading = false; + + this._progressChunk = 0; + + // this._beforeMiddleware.length = 0; + // this._afterMiddleware.length = 0; + + this._buffer.length = 0; + + this._numToLoad = 0; + + this._queue.kill(); + this._queue.started = false; + + // abort all resource loads + for (var k in this.resources) { + var res = this.resources[k]; + + res.off('complete', this._onLoad, this); + + if (res.isLoading) { + res.abort(); + } + } + + this.resources = {}; + + return this; +}; + +/** + * Starts loading the queued resources. + * + * @fires start + * @param {function} [cb] - Optional callback that will be bound to the `complete` event. + * @return {Loader} Returns itself. + */ +Loader.prototype.load = function (cb) { + // register complete callback if they pass one + if (typeof cb === 'function') { + this.once('complete', cb); + } + + // if the queue has already started we are done here + if (this._queue.started) { + return this; + } + + // notify of start + this.emit('start', this); + + // update loading state + this.loading = true; + + // start the internal queue + for (var i = 0; i < this._buffer.length; ++i) { + this._queue.push(this._buffer[i]); + } + + // empty the buffer + this._buffer.length = 0; + + return this; +}; + +/** + * Prepares a url for usage based on the configuration of this object + * + * @private + * @param {string} url - The url to prepare. + * @return {string} The prepared url. + */ +Loader.prototype._prepareUrl = function (url) { + var parsedUrl = urlParser.parse(url); + + // absolute url, just use it as is. + if (parsedUrl.protocol || !parsedUrl.pathname || parsedUrl.pathname.indexOf('//') === 0) { + return url; + } + + // if baseUrl doesn't end in slash and url doesn't start with slash, then add a slash inbetween + if (this.baseUrl.length + && this.baseUrl.lastIndexOf('/') !== this.baseUrl.length - 1 + && url.charAt(0) !== '/' + ) { + return this.baseUrl + '/' + url; + } + + return this.baseUrl + url; +}; + +/** + * Loads a single resource. + * + * @private + * @param {Resource} resource - The resource to load. + * @param {function} dequeue - The function to call when we need to dequeue this item. + */ +Loader.prototype._loadResource = function (resource, dequeue) { + var self = this; + + resource._dequeue = dequeue; + + // run before middleware + async.eachSeries( + this._beforeMiddleware, + function (fn, next) { + fn.call(self, resource, function () { + // if the before middleware marks the resource as complete, + // break and don't process any more before middleware + next(resource.isComplete ? {} : null); + }); + }, + function () { + // resource.on('progress', self.emit.bind(self, 'progress')); + + if (resource.isComplete) { + self._onLoad(resource); + } + else { + resource.once('complete', self._onLoad, self); + resource.load(); + } + } + ); +}; + +/** + * Called once each resource has loaded. + * + * @fires complete + * @private + */ +Loader.prototype._onComplete = function () { + this.loading = false; + + this.emit('complete', this, this.resources); +}; + +/** + * Called each time a resources is loaded. + * + * @fires progress + * @fires error + * @fires load + * @private + * @param {Resource} resource - The resource that was loaded + */ +Loader.prototype._onLoad = function (resource) { + var self = this; + + // run middleware, this *must* happen before dequeue so sub-assets get added properly + async.eachSeries( + this._afterMiddleware, + function (fn, next) { + fn.call(self, resource, next); + }, + function () { + resource.emit('afterMiddleware', resource); + + self._numToLoad--; + + self.progress += self._progressChunk; + self.emit('progress', self, resource); + + if (resource.error) { + self.emit('error', resource.error, self, resource); + } + else { + self.emit('load', self, resource); + } + + // do completion check + if (self._numToLoad === 0) { + self.progress = 100; + self._onComplete(); + } + } + ); + + // remove this resource from the async queue + resource._dequeue(); +}; + +Loader.LOAD_TYPE = Resource.LOAD_TYPE; +Loader.XHR_RESPONSE_TYPE = Resource.XHR_RESPONSE_TYPE; + +},{"./Resource":31,"async":29,"eventemitter3":4,"url":36}],31:[function(require,module,exports){ +'use strict'; + +var EventEmitter = require('eventemitter3'); +var _url = require('url'); + +// tests is CORS is supported in XHR, if not we need to use XDR +var useXdr = !!(window.XDomainRequest && !('withCredentials' in (new XMLHttpRequest()))); +var tempAnchor = null; + +// some status constants +var STATUS_NONE = 0; +var STATUS_OK = 200; +var STATUS_EMPTY = 204; + +/** + * Manages the state and loading of a single resource represented by + * a single URL. + * + * @class + * @param {string} name - The name of the resource to load. + * @param {string|string[]} url - The url for this resource, for audio/video loads you can pass an array of sources. + * @param {object} [options] - The options for the load. + * @param {string|boolean} [options.crossOrigin] - Is this request cross-origin? Default is to determine automatically. + * @param {Resource.LOAD_TYPE} [options.loadType=Resource.LOAD_TYPE.XHR] - How should this resource be loaded? + * @param {Resource.XHR_RESPONSE_TYPE} [options.xhrType=Resource.XHR_RESPONSE_TYPE.DEFAULT] - How should the data being + * loaded be interpreted when using XHR? + * @param {object} [options.metadata] - Extra info for middleware. + */ +function Resource(name, url, options) { + EventEmitter.call(this); + + options = options || {}; + + if (typeof name !== 'string' || typeof url !== 'string') { + throw new Error('Both name and url are required for constructing a resource.'); + } + + /** + * The name of this resource. + * + * @member {string} + * @readonly + */ + this.name = name; + + /** + * The url used to load this resource. + * + * @member {string} + * @readonly + */ + this.url = url; + + /** + * Stores whether or not this url is a data url. + * + * @member {boolean} + * @readonly + */ + this.isDataUrl = this.url.indexOf('data:') === 0; + + /** + * The data that was loaded by the resource. + * + * @member {any} + */ + this.data = null; + + /** + * Is this request cross-origin? If unset, determined automatically. + * + * @member {string} + */ + this.crossOrigin = options.crossOrigin === true ? 'anonymous' : options.crossOrigin; + + /** + * The method of loading to use for this resource. + * + * @member {Resource.LOAD_TYPE} + */ + this.loadType = options.loadType || this._determineLoadType(); + + /** + * The type used to load the resource via XHR. If unset, determined automatically. + * + * @member {string} + */ + this.xhrType = options.xhrType; + + /** + * Extra info for middleware, and controlling specifics about how the resource loads. + * + * Note that if you pass in a `loadElement`, the Resource class takes ownership of it. + * Meaning it will modify it as it sees fit. + * + * @member {object} + * @property {HTMLImageElement|HTMLAudioElement|HTMLVideoElement} [loadElement=null] - The + * element to use for loading, instead of creating one. + * @property {boolean} [skipSource=false] - Skips adding source(s) to the load element. This + * is useful if you want to pass in a `loadElement` that you already added load sources + * to. + */ + this.metadata = options.metadata || {}; + + /** + * The error that occurred while loading (if any). + * + * @member {Error} + * @readonly + */ + this.error = null; + + /** + * The XHR object that was used to load this resource. This is only set + * when `loadType` is `Resource.LOAD_TYPE.XHR`. + * + * @member {XMLHttpRequest} + */ + this.xhr = null; + + /** + * Describes if this resource was loaded as json. Only valid after the resource + * has completely loaded. + * + * @member {boolean} + */ + this.isJson = false; + + /** + * Describes if this resource was loaded as xml. Only valid after the resource + * has completely loaded. + * + * @member {boolean} + */ + this.isXml = false; + + /** + * Describes if this resource was loaded as an image tag. Only valid after the resource + * has completely loaded. + * + * @member {boolean} + */ + this.isImage = false; + + /** + * Describes if this resource was loaded as an audio tag. Only valid after the resource + * has completely loaded. + * + * @member {boolean} + */ + this.isAudio = false; + + /** + * Describes if this resource was loaded as a video tag. Only valid after the resource + * has completely loaded. + * + * @member {boolean} + */ + this.isVideo = false; + + /** + * Describes if this resource has finished loading. Is true when the resource has completely + * loaded. + * + * @member {boolean} + */ + this.isComplete = false; + + /** + * Describes if this resource is currently loading. Is true when the resource starts loading, + * and is false again when complete. + * + * @member {boolean} + */ + this.isLoading = false; + + /** + * The `dequeue` method that will be used a storage place for the async queue dequeue method + * used privately by the loader. + * + * @private + * @member {function} + */ + this._dequeue = null; + + /** + * The `complete` function bound to this resource's context. + * + * @private + * @member {function} + */ + this._boundComplete = this.complete.bind(this); + + /** + * The `_onError` function bound to this resource's context. + * + * @private + * @member {function} + */ + this._boundOnError = this._onError.bind(this); + + /** + * The `_onProgress` function bound to this resource's context. + * + * @private + * @member {function} + */ + this._boundOnProgress = this._onProgress.bind(this); + + // xhr callbacks + this._boundXhrOnError = this._xhrOnError.bind(this); + this._boundXhrOnAbort = this._xhrOnAbort.bind(this); + this._boundXhrOnLoad = this._xhrOnLoad.bind(this); + this._boundXdrOnTimeout = this._xdrOnTimeout.bind(this); + + /** + * Emitted when the resource beings to load. + * + * @event start + * @memberof Resource# + */ + + /** + * Emitted each time progress of this resource load updates. + * Not all resources types and loader systems can support this event + * so sometimes it may not be available. If the resource + * is being loaded on a modern browser, using XHR, and the remote server + * properly sets Content-Length headers, then this will be available. + * + * @event progress + * @memberof Resource# + */ + + /** + * Emitted once this resource has loaded, if there was an error it will + * be in the `error` property. + * + * @event complete + * @memberof Resource# + */ +} + +Resource.prototype = Object.create(EventEmitter.prototype); +Resource.prototype.constructor = Resource; +module.exports = Resource; + +/** + * Marks the resource as complete. + * + * @fires complete + */ +Resource.prototype.complete = function () { + // TODO: Clean this up in a wrapper or something...gross.... + if (this.data && this.data.removeEventListener) { + this.data.removeEventListener('error', this._boundOnError); + this.data.removeEventListener('load', this._boundComplete); + this.data.removeEventListener('progress', this._boundOnProgress); + this.data.removeEventListener('canplaythrough', this._boundComplete); + } + + if (this.xhr) { + if (this.xhr.removeEventListener) { + this.xhr.removeEventListener('error', this._boundXhrOnError); + this.xhr.removeEventListener('abort', this._boundXhrOnAbort); + this.xhr.removeEventListener('progress', this._boundOnProgress); + this.xhr.removeEventListener('load', this._boundXhrOnLoad); + } + else { + this.xhr.onerror = null; + this.xhr.ontimeout = null; + this.xhr.onprogress = null; + this.xhr.onload = null; + } + } + + if (this.isComplete) { + throw new Error('Complete called again for an already completed resource.'); + } + + this.isComplete = true; + this.isLoading = false; + + this.emit('complete', this); +}; + +/** + * Aborts the loading of this resource, with an optional message. + * + * @param {string} message - The message to use for the error + */ +Resource.prototype.abort = function (message) { + // abort can be called multiple times, ignore subsequent calls. + if (this.error) { + return; + } + + // store error + this.error = new Error(message); + + // abort the actual loading + if (this.xhr) { + this.xhr.abort(); + } + else if (this.xdr) { + this.xdr.abort(); + } + else if (this.data) { + // single source + if (typeof this.data.src !== 'undefined') { + this.data.src = ''; + } + // multi-source + else { + while (this.data.firstChild) { + this.data.removeChild(this.data.firstChild); + } + } + } + + // done now. + this.complete(); +}; + +/** + * Kicks off loading of this resource. This method is asynchronous. + * + * @fires start + * @param {function} [cb] - Optional callback to call once the resource is loaded. + */ +Resource.prototype.load = function (cb) { + if (this.isLoading) { + return; + } + + if (this.isComplete) { + if (cb) { + var self = this; + + setTimeout(function () { + cb(self); + }, 1); + } + + return; + } + else if (cb) { + this.once('complete', cb); + } + + this.isLoading = true; + + this.emit('start', this); + + // if unset, determine the value + if (this.crossOrigin === false || typeof this.crossOrigin !== 'string') { + this.crossOrigin = this._determineCrossOrigin(this.url); + } + + switch (this.loadType) { + case Resource.LOAD_TYPE.IMAGE: + this._loadElement('image'); + break; + + case Resource.LOAD_TYPE.AUDIO: + this._loadSourceElement('audio'); + break; + + case Resource.LOAD_TYPE.VIDEO: + this._loadSourceElement('video'); + break; + + case Resource.LOAD_TYPE.XHR: + /* falls through */ + default: + if (useXdr && this.crossOrigin) { + this._loadXdr(); + } + else { + this._loadXhr(); + } + break; + } +}; + +/** + * Loads this resources using an element that has a single source, + * like an HTMLImageElement. + * + * @private + * @param {string} type - The type of element to use. + */ +Resource.prototype._loadElement = function (type) { + if (this.metadata.loadElement) { + this.data = this.metadata.loadElement; + } + else if (type === 'image' && typeof window.Image !== 'undefined') { + this.data = new Image(); + } + else { + this.data = document.createElement(type); + } + + if (this.crossOrigin) { + this.data.crossOrigin = this.crossOrigin; + } + + if (!this.metadata.skipSource) { + this.data.src = this.url; + } + + var typeName = 'is' + type[0].toUpperCase() + type.substring(1); + + if (this[typeName] === false) { + this[typeName] = true; + } + + this.data.addEventListener('error', this._boundOnError, false); + this.data.addEventListener('load', this._boundComplete, false); + this.data.addEventListener('progress', this._boundOnProgress, false); +}; + +/** + * Loads this resources using an element that has multiple sources, + * like an HTMLAudioElement or HTMLVideoElement. + * + * @private + * @param {string} type - The type of element to use. + */ +Resource.prototype._loadSourceElement = function (type) { + if (this.metadata.loadElement) { + this.data = this.metadata.loadElement; + } + else if (type === 'audio' && typeof window.Audio !== 'undefined') { + this.data = new Audio(); + } + else { + this.data = document.createElement(type); + } + + if (this.data === null) { + this.abort('Unsupported element ' + type); + + return; + } + + if (!this.metadata.skipSource) { + // support for CocoonJS Canvas+ runtime, lacks document.createElement('source') + if (navigator.isCocoonJS) { + this.data.src = Array.isArray(this.url) ? this.url[0] : this.url; + } + else if (Array.isArray(this.url)) { + for (var i = 0; i < this.url.length; ++i) { + this.data.appendChild(this._createSource(type, this.url[i])); + } + } + else { + this.data.appendChild(this._createSource(type, this.url)); + } + } + + this['is' + type[0].toUpperCase() + type.substring(1)] = true; + + this.data.addEventListener('error', this._boundOnError, false); + this.data.addEventListener('load', this._boundComplete, false); + this.data.addEventListener('progress', this._boundOnProgress, false); + this.data.addEventListener('canplaythrough', this._boundComplete, false); + + this.data.load(); +}; + +/** + * Loads this resources using an XMLHttpRequest. + * + * @private + */ +Resource.prototype._loadXhr = function () { + // if unset, determine the value + if (typeof this.xhrType !== 'string') { + this.xhrType = this._determineXhrType(); + } + + var xhr = this.xhr = new XMLHttpRequest(); + + // set the request type and url + xhr.open('GET', this.url, true); + + // load json as text and parse it ourselves. We do this because some browsers + // *cough* safari *cough* can't deal with it. + if (this.xhrType === Resource.XHR_RESPONSE_TYPE.JSON || this.xhrType === Resource.XHR_RESPONSE_TYPE.DOCUMENT) { + xhr.responseType = Resource.XHR_RESPONSE_TYPE.TEXT; + } + else { + xhr.responseType = this.xhrType; + } + + xhr.addEventListener('error', this._boundXhrOnError, false); + xhr.addEventListener('abort', this._boundXhrOnAbort, false); + xhr.addEventListener('progress', this._boundOnProgress, false); + xhr.addEventListener('load', this._boundXhrOnLoad, false); + + xhr.send(); +}; + +/** + * Loads this resources using an XDomainRequest. This is here because we need to support IE9 (gross). + * + * @private + */ +Resource.prototype._loadXdr = function () { + // if unset, determine the value + if (typeof this.xhrType !== 'string') { + this.xhrType = this._determineXhrType(); + } + + var xdr = this.xhr = new XDomainRequest(); + + // XDomainRequest has a few quirks. Occasionally it will abort requests + // A way to avoid this is to make sure ALL callbacks are set even if not used + // More info here: http://stackoverflow.com/questions/15786966/xdomainrequest-aborts-post-on-ie-9 + xdr.timeout = 5000; + + xdr.onerror = this._boundXhrOnError; + xdr.ontimeout = this._boundXdrOnTimeout; + xdr.onprogress = this._boundOnProgress; + xdr.onload = this._boundXhrOnLoad; + + xdr.open('GET', this.url, true); + + // Note: The xdr.send() call is wrapped in a timeout to prevent an + // issue with the interface where some requests are lost if multiple + // XDomainRequests are being sent at the same time. + // Some info here: https://github.com/photonstorm/phaser/issues/1248 + setTimeout(function () { + xdr.send(); + }, 0); +}; + +/** + * Creates a source used in loading via an element. + * + * @private + * @param {string} type - The element type (video or audio). + * @param {string} url - The source URL to load from. + * @param {string} [mime] - The mime type of the video + * @return {HTMLSourceElement} The source element. + */ +Resource.prototype._createSource = function (type, url, mime) { + if (!mime) { + mime = type + '/' + url.substr(url.lastIndexOf('.') + 1); + } + + var source = document.createElement('source'); + + source.src = url; + source.type = mime; + + return source; +}; + +/** + * Called if a load errors out. + * + * @param {Event} event - The error event from the element that emits it. + * @private + */ +Resource.prototype._onError = function (event) { + this.abort('Failed to load element using ' + event.target.nodeName); +}; + +/** + * Called if a load progress event fires for xhr/xdr. + * + * @fires progress + * @private + * @param {XMLHttpRequestProgressEvent|Event} event - Progress event. + */ +Resource.prototype._onProgress = function (event) { + if (event && event.lengthComputable) { + this.emit('progress', this, event.loaded / event.total); + } +}; + +/** + * Called if an error event fires for xhr/xdr. + * + * @private + * @param {XMLHttpRequestErrorEvent|Event} event - Error event. + */ +Resource.prototype._xhrOnError = function () { + var xhr = this.xhr; + + this.abort(reqType(xhr) + ' Request failed. Status: ' + xhr.status + ', text: "' + xhr.statusText + '"'); +}; + +/** + * Called if an abort event fires for xhr. + * + * @private + * @param {XMLHttpRequestAbortEvent} event - Abort Event + */ +Resource.prototype._xhrOnAbort = function () { + this.abort(reqType(this.xhr) + ' Request was aborted by the user.'); +}; + +/** + * Called if a timeout event fires for xdr. + * + * @private + * @param {Event} event - Timeout event. + */ +Resource.prototype._xdrOnTimeout = function () { + this.abort(reqType(this.xhr) + ' Request timed out.'); +}; + +/** + * Called when data successfully loads from an xhr/xdr request. + * + * @private + * @param {XMLHttpRequestLoadEvent|Event} event - Load event + */ +Resource.prototype._xhrOnLoad = function () { + var xhr = this.xhr; + var status = typeof xhr.status === 'undefined' ? xhr.status : STATUS_OK; // XDR has no `.status`, assume 200. + + // status can be 0 when using the file:// protocol, also check if a response was found + if (status === STATUS_OK || status === STATUS_EMPTY || (status === STATUS_NONE && xhr.responseText.length > 0)) { + // if text, just return it + if (this.xhrType === Resource.XHR_RESPONSE_TYPE.TEXT) { + this.data = xhr.responseText; + } + // if json, parse into json object + else if (this.xhrType === Resource.XHR_RESPONSE_TYPE.JSON) { + try { + this.data = JSON.parse(xhr.responseText); + this.isJson = true; + } + catch (e) { + this.abort('Error trying to parse loaded json:', e); + + return; + } + } + // if xml, parse into an xml document or div element + else if (this.xhrType === Resource.XHR_RESPONSE_TYPE.DOCUMENT) { + try { + if (window.DOMParser) { + var domparser = new DOMParser(); + + this.data = domparser.parseFromString(xhr.responseText, 'text/xml'); + } + else { + var div = document.createElement('div'); + + div.innerHTML = xhr.responseText; + this.data = div; + } + this.isXml = true; + } + catch (e) { + this.abort('Error trying to parse loaded xml:', e); + + return; + } + } + // other types just return the response + else { + this.data = xhr.response || xhr.responseText; + } + } + else { + this.abort('[' + xhr.status + ']' + xhr.statusText + ':' + xhr.responseURL); + + return; + } + + this.complete(); +}; + +/** + * Sets the `crossOrigin` property for this resource based on if the url + * for this resource is cross-origin. If crossOrigin was manually set, this + * function does nothing. + * + * @private + * @param {string} url - The url to test. + * @param {object} [loc=window.location] - The location object to test against. + * @return {string} The crossOrigin value to use (or empty string for none). + */ +Resource.prototype._determineCrossOrigin = function (url, loc) { + // data: and javascript: urls are considered same-origin + if (url.indexOf('data:') === 0) { + return ''; + } + + // default is window.location + loc = loc || window.location; + + if (!tempAnchor) { + tempAnchor = document.createElement('a'); + } + + // let the browser determine the full href for the url of this resource and then + // parse with the node url lib, we can't use the properties of the anchor element + // because they don't work in IE9 :( + tempAnchor.href = url; + url = _url.parse(tempAnchor.href); + + var samePort = (!url.port && loc.port === '') || (url.port === loc.port); + + // if cross origin + if (url.hostname !== loc.hostname || !samePort || url.protocol !== loc.protocol) { + return 'anonymous'; + } + + return ''; +}; + +/** + * Determines the responseType of an XHR request based on the extension of the + * resource being loaded. + * + * @private + * @return {Resource.XHR_RESPONSE_TYPE} The responseType to use. + */ +Resource.prototype._determineXhrType = function () { + return Resource._xhrTypeMap[this._getExtension()] || Resource.XHR_RESPONSE_TYPE.TEXT; +}; + +Resource.prototype._determineLoadType = function () { + return Resource._loadTypeMap[this._getExtension()] || Resource.LOAD_TYPE.XHR; +}; + +Resource.prototype._getExtension = function () { + var url = this.url; + var ext = ''; + + if (this.isDataUrl) { + var slashIndex = url.indexOf('/'); + + ext = url.substring(slashIndex + 1, url.indexOf(';', slashIndex)); + } + else { + var queryStart = url.indexOf('?'); + + if (queryStart !== -1) { + url = url.substring(0, queryStart); + } + + ext = url.substring(url.lastIndexOf('.') + 1); + } + + return ext.toLowerCase(); +}; + +/** + * Determines the mime type of an XHR request based on the responseType of + * resource being loaded. + * + * @private + * @param {Resource.XHR_RESPONSE_TYPE} type - The type to get a mime type for. + * @return {string} The mime type to use. + */ +Resource.prototype._getMimeFromXhrType = function (type) { + switch (type) { + case Resource.XHR_RESPONSE_TYPE.BUFFER: + return 'application/octet-binary'; + + case Resource.XHR_RESPONSE_TYPE.BLOB: + return 'application/blob'; + + case Resource.XHR_RESPONSE_TYPE.DOCUMENT: + return 'application/xml'; + + case Resource.XHR_RESPONSE_TYPE.JSON: + return 'application/json'; + + case Resource.XHR_RESPONSE_TYPE.DEFAULT: + case Resource.XHR_RESPONSE_TYPE.TEXT: + /* falls through */ + default: + return 'text/plain'; + + } +}; + +/** + * Quick helper to get string xhr type. + * + * @ignore + * @param {XMLHttpRequest|XDomainRequest} xhr - The request to check. + * @return {string} The type. + */ +function reqType(xhr) { + return xhr.toString().replace('object ', ''); +} + +/** + * The types of loading a resource can use. + * + * @static + * @readonly + * @enum {number} + */ +Resource.LOAD_TYPE = { + /** Uses XMLHttpRequest to load the resource. */ + XHR: 1, + /** Uses an `Image` object to load the resource. */ + IMAGE: 2, + /** Uses an `Audio` object to load the resource. */ + AUDIO: 3, + /** Uses a `Video` object to load the resource. */ + VIDEO: 4 +}; + +/** + * The XHR ready states, used internally. + * + * @static + * @readonly + * @enum {string} + */ +Resource.XHR_RESPONSE_TYPE = { + /** defaults to text */ + DEFAULT: 'text', + /** ArrayBuffer */ + BUFFER: 'arraybuffer', + /** Blob */ + BLOB: 'blob', + /** Document */ + DOCUMENT: 'document', + /** Object */ + JSON: 'json', + /** String */ + TEXT: 'text' +}; + +Resource._loadTypeMap = { + gif: Resource.LOAD_TYPE.IMAGE, + png: Resource.LOAD_TYPE.IMAGE, + bmp: Resource.LOAD_TYPE.IMAGE, + jpg: Resource.LOAD_TYPE.IMAGE, + jpeg: Resource.LOAD_TYPE.IMAGE, + tif: Resource.LOAD_TYPE.IMAGE, + tiff: Resource.LOAD_TYPE.IMAGE, + webp: Resource.LOAD_TYPE.IMAGE, + tga: Resource.LOAD_TYPE.IMAGE, + 'svg+xml': Resource.LOAD_TYPE.IMAGE +}; + +Resource._xhrTypeMap = { + // xml + xhtml: Resource.XHR_RESPONSE_TYPE.DOCUMENT, + html: Resource.XHR_RESPONSE_TYPE.DOCUMENT, + htm: Resource.XHR_RESPONSE_TYPE.DOCUMENT, + xml: Resource.XHR_RESPONSE_TYPE.DOCUMENT, + tmx: Resource.XHR_RESPONSE_TYPE.DOCUMENT, + tsx: Resource.XHR_RESPONSE_TYPE.DOCUMENT, + svg: Resource.XHR_RESPONSE_TYPE.DOCUMENT, + + // images + gif: Resource.XHR_RESPONSE_TYPE.BLOB, + png: Resource.XHR_RESPONSE_TYPE.BLOB, + bmp: Resource.XHR_RESPONSE_TYPE.BLOB, + jpg: Resource.XHR_RESPONSE_TYPE.BLOB, + jpeg: Resource.XHR_RESPONSE_TYPE.BLOB, + tif: Resource.XHR_RESPONSE_TYPE.BLOB, + tiff: Resource.XHR_RESPONSE_TYPE.BLOB, + webp: Resource.XHR_RESPONSE_TYPE.BLOB, + tga: Resource.XHR_RESPONSE_TYPE.BLOB, + + // json + json: Resource.XHR_RESPONSE_TYPE.JSON, + + // text + text: Resource.XHR_RESPONSE_TYPE.TEXT, + txt: Resource.XHR_RESPONSE_TYPE.TEXT +}; + +/** + * Sets the load type to be used for a specific extension. + * + * @static + * @param {string} extname - The extension to set the type for, e.g. "png" or "fnt" + * @param {Resource.LOAD_TYPE} loadType - The load type to set it to. + */ +Resource.setExtensionLoadType = function (extname, loadType) { + setExtMap(Resource._loadTypeMap, extname, loadType); +}; + +/** + * Sets the load type to be used for a specific extension. + * + * @static + * @param {string} extname - The extension to set the type for, e.g. "png" or "fnt" + * @param {Resource.XHR_RESPONSE_TYPE} xhrType - The xhr type to set it to. + */ +Resource.setExtensionXhrType = function (extname, xhrType) { + setExtMap(Resource._xhrTypeMap, extname, xhrType); +}; + +function setExtMap(map, extname, val) { + if (extname && extname.indexOf('.') === 0) { + extname = extname.substring(1); + } + + if (!extname) { + return; + } + + map[extname] = val; +} + +},{"eventemitter3":4,"url":36}],32:[function(require,module,exports){ +/* eslint no-magic-numbers: 0 */ +'use strict'; + +module.exports = { + // private property + _keyStr: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=', + + encodeBinary: function (input) { + var output = ''; + var bytebuffer; + var encodedCharIndexes = new Array(4); + var inx = 0; + var jnx = 0; + var paddingBytes = 0; + + while (inx < input.length) { + // Fill byte buffer array + bytebuffer = new Array(3); + + for (jnx = 0; jnx < bytebuffer.length; jnx++) { + if (inx < input.length) { + // throw away high-order byte, as documented at: + // https://developer.mozilla.org/En/Using_XMLHttpRequest#Handling_binary_data + bytebuffer[jnx] = input.charCodeAt(inx++) & 0xff; + } + else { + bytebuffer[jnx] = 0; + } + } + + // Get each encoded character, 6 bits at a time + // index 1: first 6 bits + encodedCharIndexes[0] = bytebuffer[0] >> 2; + // index 2: second 6 bits (2 least significant bits from input byte 1 + 4 most significant bits from byte 2) + encodedCharIndexes[1] = ((bytebuffer[0] & 0x3) << 4) | (bytebuffer[1] >> 4); + // index 3: third 6 bits (4 least significant bits from input byte 2 + 2 most significant bits from byte 3) + encodedCharIndexes[2] = ((bytebuffer[1] & 0x0f) << 2) | (bytebuffer[2] >> 6); + // index 3: forth 6 bits (6 least significant bits from input byte 3) + encodedCharIndexes[3] = bytebuffer[2] & 0x3f; + + // Determine whether padding happened, and adjust accordingly + paddingBytes = inx - (input.length - 1); + switch (paddingBytes) { + case 2: + // Set last 2 characters to padding char + encodedCharIndexes[3] = 64; + encodedCharIndexes[2] = 64; + break; + + case 1: + // Set last character to padding char + encodedCharIndexes[3] = 64; + break; + + default: + break; // No padding - proceed + } + + // Now we will grab each appropriate character out of our keystring + // based on our index array and append it to the output string + for (jnx = 0; jnx < encodedCharIndexes.length; jnx++) { + output += this._keyStr.charAt(encodedCharIndexes[jnx]); + } + } + + return output; + } +}; + +},{}],33:[function(require,module,exports){ +/* eslint global-require: 0 */ +'use strict'; + +module.exports = require('./Loader'); +module.exports.Resource = require('./Resource'); +module.exports.middleware = { + caching: { + memory: require('./middlewares/caching/memory') + }, + parsing: { + blob: require('./middlewares/parsing/blob') + } +}; + + +},{"./Loader":30,"./Resource":31,"./middlewares/caching/memory":34,"./middlewares/parsing/blob":35}],34:[function(require,module,exports){ +'use strict'; + +// a simple in-memory cache for resources +var cache = {}; + +module.exports = function () { + return function (resource, next) { + // if cached, then set data and complete the resource + if (cache[resource.url]) { + resource.data = cache[resource.url]; + resource.complete(); // marks resource load complete and stops processing before middlewares + } + // if not cached, wait for complete and store it in the cache. + else { + resource.once('complete', function () { + cache[this.url] = this.data; + }); + } + + next(); + }; +}; + +},{}],35:[function(require,module,exports){ +'use strict'; + +var Resource = require('../../Resource'); +var b64 = require('../../b64'); + +var Url = window.URL || window.webkitURL; + +// a middleware for transforming XHR loaded Blobs into more useful objects + +module.exports = function () { + return function (resource, next) { + if (!resource.data) { + next(); + + return; + } + + // if this was an XHR load of a blob + if (resource.xhr && resource.xhrType === Resource.XHR_RESPONSE_TYPE.BLOB) { + // if there is no blob support we probably got a binary string back + if (!window.Blob || typeof resource.data === 'string') { + var type = resource.xhr.getResponseHeader('content-type'); + + // this is an image, convert the binary string into a data url + if (type && type.indexOf('image') === 0) { + resource.data = new Image(); + resource.data.src = 'data:' + type + ';base64,' + b64.encodeBinary(resource.xhr.responseText); + + resource.isImage = true; + + // wait until the image loads and then callback + resource.data.onload = function () { + resource.data.onload = null; + + next(); + }; + + // next will be called on load + return; + } + } + // if content type says this is an image, then we should transform the blob into an Image object + else if (resource.data.type.indexOf('image') === 0) { + var src = Url.createObjectURL(resource.data); + + resource.blob = resource.data; + resource.data = new Image(); + resource.data.src = src; + + resource.isImage = true; + + // cleanup the no longer used blob after the image loads + resource.data.onload = function () { + Url.revokeObjectURL(src); + resource.data.onload = null; + + next(); + }; + + // next will be called on load. + return; + } + } + + next(); + }; +}; + +},{"../../Resource":31,"../../b64":32}],36:[function(require,module,exports){ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +'use strict'; + +var punycode = require('punycode'); +var util = require('./util'); + +exports.parse = urlParse; +exports.resolve = urlResolve; +exports.resolveObject = urlResolveObject; +exports.format = urlFormat; + +exports.Url = Url; + +function Url() { + this.protocol = null; + this.slashes = null; + this.auth = null; + this.host = null; + this.port = null; + this.hostname = null; + this.hash = null; + this.search = null; + this.query = null; + this.pathname = null; + this.path = null; + this.href = null; +} + +// Reference: RFC 3986, RFC 1808, RFC 2396 + +// define these here so at least they only have to be +// compiled once on the first module load. +var protocolPattern = /^([a-z0-9.+-]+:)/i, + portPattern = /:[0-9]*$/, + + // Special case for a simple path URL + simplePathPattern = /^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/, + + // RFC 2396: characters reserved for delimiting URLs. + // We actually just auto-escape these. + delims = ['<', '>', '"', '`', ' ', '\r', '\n', '\t'], + + // RFC 2396: characters not allowed for various reasons. + unwise = ['{', '}', '|', '\\', '^', '`'].concat(delims), + + // Allowed by RFCs, but cause of XSS attacks. Always escape these. + autoEscape = ['\''].concat(unwise), + // Characters that are never ever allowed in a hostname. + // Note that any invalid chars are also handled, but these + // are the ones that are *expected* to be seen, so we fast-path + // them. + nonHostChars = ['%', '/', '?', ';', '#'].concat(autoEscape), + hostEndingChars = ['/', '?', '#'], + hostnameMaxLen = 255, + hostnamePartPattern = /^[+a-z0-9A-Z_-]{0,63}$/, + hostnamePartStart = /^([+a-z0-9A-Z_-]{0,63})(.*)$/, + // protocols that can allow "unsafe" and "unwise" chars. + unsafeProtocol = { + 'javascript': true, + 'javascript:': true + }, + // protocols that never have a hostname. + hostlessProtocol = { + 'javascript': true, + 'javascript:': true + }, + // protocols that always contain a // bit. + slashedProtocol = { + 'http': true, + 'https': true, + 'ftp': true, + 'gopher': true, + 'file': true, + 'http:': true, + 'https:': true, + 'ftp:': true, + 'gopher:': true, + 'file:': true + }, + querystring = require('querystring'); + +function urlParse(url, parseQueryString, slashesDenoteHost) { + if (url && util.isObject(url) && url instanceof Url) return url; + + var u = new Url; + u.parse(url, parseQueryString, slashesDenoteHost); + return u; +} + +Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) { + if (!util.isString(url)) { + throw new TypeError("Parameter 'url' must be a string, not " + typeof url); + } + + // Copy chrome, IE, opera backslash-handling behavior. + // Back slashes before the query string get converted to forward slashes + // See: https://code.google.com/p/chromium/issues/detail?id=25916 + var queryIndex = url.indexOf('?'), + splitter = + (queryIndex !== -1 && queryIndex < url.indexOf('#')) ? '?' : '#', + uSplit = url.split(splitter), + slashRegex = /\\/g; + uSplit[0] = uSplit[0].replace(slashRegex, '/'); + url = uSplit.join(splitter); + + var rest = url; + + // trim before proceeding. + // This is to support parse stuff like " http://foo.com \n" + rest = rest.trim(); + + if (!slashesDenoteHost && url.split('#').length === 1) { + // Try fast path regexp + var simplePath = simplePathPattern.exec(rest); + if (simplePath) { + this.path = rest; + this.href = rest; + this.pathname = simplePath[1]; + if (simplePath[2]) { + this.search = simplePath[2]; + if (parseQueryString) { + this.query = querystring.parse(this.search.substr(1)); + } else { + this.query = this.search.substr(1); + } + } else if (parseQueryString) { + this.search = ''; + this.query = {}; + } + return this; + } + } + + var proto = protocolPattern.exec(rest); + if (proto) { + proto = proto[0]; + var lowerProto = proto.toLowerCase(); + this.protocol = lowerProto; + rest = rest.substr(proto.length); + } + + // figure out if it's got a host + // user@server is *always* interpreted as a hostname, and url + // resolution will treat //foo/bar as host=foo,path=bar because that's + // how the browser resolves relative URLs. + if (slashesDenoteHost || proto || rest.match(/^\/\/[^@\/]+@[^@\/]+/)) { + var slashes = rest.substr(0, 2) === '//'; + if (slashes && !(proto && hostlessProtocol[proto])) { + rest = rest.substr(2); + this.slashes = true; + } + } + + if (!hostlessProtocol[proto] && + (slashes || (proto && !slashedProtocol[proto]))) { + + // there's a hostname. + // the first instance of /, ?, ;, or # ends the host. + // + // If there is an @ in the hostname, then non-host chars *are* allowed + // to the left of the last @ sign, unless some host-ending character + // comes *before* the @-sign. + // URLs are obnoxious. + // + // ex: + // http://a@b@c/ => user:a@b host:c + // http://a@b?@c => user:a host:c path:/?@c + + // v0.12 TODO(isaacs): This is not quite how Chrome does things. + // Review our test case against browsers more comprehensively. + + // find the first instance of any hostEndingChars + var hostEnd = -1; + for (var i = 0; i < hostEndingChars.length; i++) { + var hec = rest.indexOf(hostEndingChars[i]); + if (hec !== -1 && (hostEnd === -1 || hec < hostEnd)) + hostEnd = hec; + } + + // at this point, either we have an explicit point where the + // auth portion cannot go past, or the last @ char is the decider. + var auth, atSign; + if (hostEnd === -1) { + // atSign can be anywhere. + atSign = rest.lastIndexOf('@'); + } else { + // atSign must be in auth portion. + // http://a@b/c@d => host:b auth:a path:/c@d + atSign = rest.lastIndexOf('@', hostEnd); + } + + // Now we have a portion which is definitely the auth. + // Pull that off. + if (atSign !== -1) { + auth = rest.slice(0, atSign); + rest = rest.slice(atSign + 1); + this.auth = decodeURIComponent(auth); + } + + // the host is the remaining to the left of the first non-host char + hostEnd = -1; + for (var i = 0; i < nonHostChars.length; i++) { + var hec = rest.indexOf(nonHostChars[i]); + if (hec !== -1 && (hostEnd === -1 || hec < hostEnd)) + hostEnd = hec; + } + // if we still have not hit it, then the entire thing is a host. + if (hostEnd === -1) + hostEnd = rest.length; + + this.host = rest.slice(0, hostEnd); + rest = rest.slice(hostEnd); + + // pull out port. + this.parseHost(); + + // we've indicated that there is a hostname, + // so even if it's empty, it has to be present. + this.hostname = this.hostname || ''; + + // if hostname begins with [ and ends with ] + // assume that it's an IPv6 address. + var ipv6Hostname = this.hostname[0] === '[' && + this.hostname[this.hostname.length - 1] === ']'; + + // validate a little. + if (!ipv6Hostname) { + var hostparts = this.hostname.split(/\./); + for (var i = 0, l = hostparts.length; i < l; i++) { + var part = hostparts[i]; + if (!part) continue; + if (!part.match(hostnamePartPattern)) { + var newpart = ''; + for (var j = 0, k = part.length; j < k; j++) { + if (part.charCodeAt(j) > 127) { + // we replace non-ASCII char with a temporary placeholder + // we need this to make sure size of hostname is not + // broken by replacing non-ASCII by nothing + newpart += 'x'; + } else { + newpart += part[j]; + } + } + // we test again with ASCII char only + if (!newpart.match(hostnamePartPattern)) { + var validParts = hostparts.slice(0, i); + var notHost = hostparts.slice(i + 1); + var bit = part.match(hostnamePartStart); + if (bit) { + validParts.push(bit[1]); + notHost.unshift(bit[2]); + } + if (notHost.length) { + rest = '/' + notHost.join('.') + rest; + } + this.hostname = validParts.join('.'); + break; + } + } + } + } + + if (this.hostname.length > hostnameMaxLen) { + this.hostname = ''; + } else { + // hostnames are always lower case. + this.hostname = this.hostname.toLowerCase(); + } + + if (!ipv6Hostname) { + // IDNA Support: Returns a punycoded representation of "domain". + // It only converts parts of the domain name that + // have non-ASCII characters, i.e. it doesn't matter if + // you call it with a domain that already is ASCII-only. + this.hostname = punycode.toASCII(this.hostname); + } + + var p = this.port ? ':' + this.port : ''; + var h = this.hostname || ''; + this.host = h + p; + this.href += this.host; + + // strip [ and ] from the hostname + // the host field still retains them, though + if (ipv6Hostname) { + this.hostname = this.hostname.substr(1, this.hostname.length - 2); + if (rest[0] !== '/') { + rest = '/' + rest; + } + } + } + + // now rest is set to the post-host stuff. + // chop off any delim chars. + if (!unsafeProtocol[lowerProto]) { + + // First, make 100% sure that any "autoEscape" chars get + // escaped, even if encodeURIComponent doesn't think they + // need to be. + for (var i = 0, l = autoEscape.length; i < l; i++) { + var ae = autoEscape[i]; + if (rest.indexOf(ae) === -1) + continue; + var esc = encodeURIComponent(ae); + if (esc === ae) { + esc = escape(ae); + } + rest = rest.split(ae).join(esc); + } + } + + + // chop off from the tail first. + var hash = rest.indexOf('#'); + if (hash !== -1) { + // got a fragment string. + this.hash = rest.substr(hash); + rest = rest.slice(0, hash); + } + var qm = rest.indexOf('?'); + if (qm !== -1) { + this.search = rest.substr(qm); + this.query = rest.substr(qm + 1); + if (parseQueryString) { + this.query = querystring.parse(this.query); + } + rest = rest.slice(0, qm); + } else if (parseQueryString) { + // no query string, but parseQueryString still requested + this.search = ''; + this.query = {}; + } + if (rest) this.pathname = rest; + if (slashedProtocol[lowerProto] && + this.hostname && !this.pathname) { + this.pathname = '/'; + } + + //to support http.request + if (this.pathname || this.search) { + var p = this.pathname || ''; + var s = this.search || ''; + this.path = p + s; + } + + // finally, reconstruct the href based on what has been validated. + this.href = this.format(); + return this; +}; + +// format a parsed object into a url string +function urlFormat(obj) { + // ensure it's an object, and not a string url. + // If it's an obj, this is a no-op. + // this way, you can call url_format() on strings + // to clean up potentially wonky urls. + if (util.isString(obj)) obj = urlParse(obj); + if (!(obj instanceof Url)) return Url.prototype.format.call(obj); + return obj.format(); +} + +Url.prototype.format = function() { + var auth = this.auth || ''; + if (auth) { + auth = encodeURIComponent(auth); + auth = auth.replace(/%3A/i, ':'); + auth += '@'; + } + + var protocol = this.protocol || '', + pathname = this.pathname || '', + hash = this.hash || '', + host = false, + query = ''; + + if (this.host) { + host = auth + this.host; + } else if (this.hostname) { + host = auth + (this.hostname.indexOf(':') === -1 ? + this.hostname : + '[' + this.hostname + ']'); + if (this.port) { + host += ':' + this.port; + } + } + + if (this.query && + util.isObject(this.query) && + Object.keys(this.query).length) { + query = querystring.stringify(this.query); + } + + var search = this.search || (query && ('?' + query)) || ''; + + if (protocol && protocol.substr(-1) !== ':') protocol += ':'; + + // only the slashedProtocols get the //. Not mailto:, xmpp:, etc. + // unless they had them to begin with. + if (this.slashes || + (!protocol || slashedProtocol[protocol]) && host !== false) { + host = '//' + (host || ''); + if (pathname && pathname.charAt(0) !== '/') pathname = '/' + pathname; + } else if (!host) { + host = ''; + } + + if (hash && hash.charAt(0) !== '#') hash = '#' + hash; + if (search && search.charAt(0) !== '?') search = '?' + search; + + pathname = pathname.replace(/[?#]/g, function(match) { + return encodeURIComponent(match); + }); + search = search.replace('#', '%23'); + + return protocol + host + pathname + search + hash; +}; + +function urlResolve(source, relative) { + return urlParse(source, false, true).resolve(relative); +} + +Url.prototype.resolve = function(relative) { + return this.resolveObject(urlParse(relative, false, true)).format(); +}; + +function urlResolveObject(source, relative) { + if (!source) return relative; + return urlParse(source, false, true).resolveObject(relative); +} + +Url.prototype.resolveObject = function(relative) { + if (util.isString(relative)) { + var rel = new Url(); + rel.parse(relative, false, true); + relative = rel; + } + + var result = new Url(); + var tkeys = Object.keys(this); + for (var tk = 0; tk < tkeys.length; tk++) { + var tkey = tkeys[tk]; + result[tkey] = this[tkey]; + } + + // hash is always overridden, no matter what. + // even href="" will remove it. + result.hash = relative.hash; + + // if the relative url is empty, then there's nothing left to do here. + if (relative.href === '') { + result.href = result.format(); + return result; + } + + // hrefs like //foo/bar always cut to the protocol. + if (relative.slashes && !relative.protocol) { + // take everything except the protocol from relative + var rkeys = Object.keys(relative); + for (var rk = 0; rk < rkeys.length; rk++) { + var rkey = rkeys[rk]; + if (rkey !== 'protocol') + result[rkey] = relative[rkey]; + } + + //urlParse appends trailing / to urls like http://www.example.com + if (slashedProtocol[result.protocol] && + result.hostname && !result.pathname) { + result.path = result.pathname = '/'; + } + + result.href = result.format(); + return result; + } + + if (relative.protocol && relative.protocol !== result.protocol) { + // if it's a known url protocol, then changing + // the protocol does weird things + // first, if it's not file:, then we MUST have a host, + // and if there was a path + // to begin with, then we MUST have a path. + // if it is file:, then the host is dropped, + // because that's known to be hostless. + // anything else is assumed to be absolute. + if (!slashedProtocol[relative.protocol]) { + var keys = Object.keys(relative); + for (var v = 0; v < keys.length; v++) { + var k = keys[v]; + result[k] = relative[k]; + } + result.href = result.format(); + return result; + } + + result.protocol = relative.protocol; + if (!relative.host && !hostlessProtocol[relative.protocol]) { + var relPath = (relative.pathname || '').split('/'); + while (relPath.length && !(relative.host = relPath.shift())); + if (!relative.host) relative.host = ''; + if (!relative.hostname) relative.hostname = ''; + if (relPath[0] !== '') relPath.unshift(''); + if (relPath.length < 2) relPath.unshift(''); + result.pathname = relPath.join('/'); + } else { + result.pathname = relative.pathname; + } + result.search = relative.search; + result.query = relative.query; + result.host = relative.host || ''; + result.auth = relative.auth; + result.hostname = relative.hostname || relative.host; + result.port = relative.port; + // to support http.request + if (result.pathname || result.search) { + var p = result.pathname || ''; + var s = result.search || ''; + result.path = p + s; + } + result.slashes = result.slashes || relative.slashes; + result.href = result.format(); + return result; + } + + var isSourceAbs = (result.pathname && result.pathname.charAt(0) === '/'), + isRelAbs = ( + relative.host || + relative.pathname && relative.pathname.charAt(0) === '/' + ), + mustEndAbs = (isRelAbs || isSourceAbs || + (result.host && relative.pathname)), + removeAllDots = mustEndAbs, + srcPath = result.pathname && result.pathname.split('/') || [], + relPath = relative.pathname && relative.pathname.split('/') || [], + psychotic = result.protocol && !slashedProtocol[result.protocol]; + + // if the url is a non-slashed url, then relative + // links like ../.. should be able + // to crawl up to the hostname, as well. This is strange. + // result.protocol has already been set by now. + // Later on, put the first path part into the host field. + if (psychotic) { + result.hostname = ''; + result.port = null; + if (result.host) { + if (srcPath[0] === '') srcPath[0] = result.host; + else srcPath.unshift(result.host); + } + result.host = ''; + if (relative.protocol) { + relative.hostname = null; + relative.port = null; + if (relative.host) { + if (relPath[0] === '') relPath[0] = relative.host; + else relPath.unshift(relative.host); + } + relative.host = null; + } + mustEndAbs = mustEndAbs && (relPath[0] === '' || srcPath[0] === ''); + } + + if (isRelAbs) { + // it's absolute. + result.host = (relative.host || relative.host === '') ? + relative.host : result.host; + result.hostname = (relative.hostname || relative.hostname === '') ? + relative.hostname : result.hostname; + result.search = relative.search; + result.query = relative.query; + srcPath = relPath; + // fall through to the dot-handling below. + } else if (relPath.length) { + // it's relative + // throw away the existing file, and take the new path instead. + if (!srcPath) srcPath = []; + srcPath.pop(); + srcPath = srcPath.concat(relPath); + result.search = relative.search; + result.query = relative.query; + } else if (!util.isNullOrUndefined(relative.search)) { + // just pull out the search. + // like href='?foo'. + // Put this after the other two cases because it simplifies the booleans + if (psychotic) { + result.hostname = result.host = srcPath.shift(); + //occationaly the auth can get stuck only in host + //this especially happens in cases like + //url.resolveObject('mailto:local1@domain1', 'local2@domain2') + var authInHost = result.host && result.host.indexOf('@') > 0 ? + result.host.split('@') : false; + if (authInHost) { + result.auth = authInHost.shift(); + result.host = result.hostname = authInHost.shift(); + } + } + result.search = relative.search; + result.query = relative.query; + //to support http.request + if (!util.isNull(result.pathname) || !util.isNull(result.search)) { + result.path = (result.pathname ? result.pathname : '') + + (result.search ? result.search : ''); + } + result.href = result.format(); + return result; + } + + if (!srcPath.length) { + // no path at all. easy. + // we've already handled the other stuff above. + result.pathname = null; + //to support http.request + if (result.search) { + result.path = '/' + result.search; + } else { + result.path = null; + } + result.href = result.format(); + return result; + } + + // if a url ENDs in . or .., then it must get a trailing slash. + // however, if it ends in anything else non-slashy, + // then it must NOT get a trailing slash. + var last = srcPath.slice(-1)[0]; + var hasTrailingSlash = ( + (result.host || relative.host || srcPath.length > 1) && + (last === '.' || last === '..') || last === ''); + + // strip single dots, resolve double dots to parent dir + // if the path tries to go above the root, `up` ends up > 0 + var up = 0; + for (var i = srcPath.length; i >= 0; i--) { + last = srcPath[i]; + if (last === '.') { + srcPath.splice(i, 1); + } else if (last === '..') { + srcPath.splice(i, 1); + up++; + } else if (up) { + srcPath.splice(i, 1); + up--; + } + } + + // if the path is allowed to go above the root, restore leading ..s + if (!mustEndAbs && !removeAllDots) { + for (; up--; up) { + srcPath.unshift('..'); + } + } + + if (mustEndAbs && srcPath[0] !== '' && + (!srcPath[0] || srcPath[0].charAt(0) !== '/')) { + srcPath.unshift(''); + } + + if (hasTrailingSlash && (srcPath.join('/').substr(-1) !== '/')) { + srcPath.push(''); + } + + var isAbsolute = srcPath[0] === '' || + (srcPath[0] && srcPath[0].charAt(0) === '/'); + + // put the host back + if (psychotic) { + result.hostname = result.host = isAbsolute ? '' : + srcPath.length ? srcPath.shift() : ''; + //occationaly the auth can get stuck only in host + //this especially happens in cases like + //url.resolveObject('mailto:local1@domain1', 'local2@domain2') + var authInHost = result.host && result.host.indexOf('@') > 0 ? + result.host.split('@') : false; + if (authInHost) { + result.auth = authInHost.shift(); + result.host = result.hostname = authInHost.shift(); + } + } + + mustEndAbs = mustEndAbs || (result.host && srcPath.length); + + if (mustEndAbs && !isAbsolute) { + srcPath.unshift(''); + } + + if (!srcPath.length) { + result.pathname = null; + result.path = null; + } else { + result.pathname = srcPath.join('/'); + } + + //to support request.http + if (!util.isNull(result.pathname) || !util.isNull(result.search)) { + result.path = (result.pathname ? result.pathname : '') + + (result.search ? result.search : ''); + } + result.auth = relative.auth || result.auth; + result.slashes = result.slashes || relative.slashes; + result.href = result.format(); + return result; +}; + +Url.prototype.parseHost = function() { + var host = this.host; + var port = portPattern.exec(host); + if (port) { + port = port[0]; + if (port !== ':') { + this.port = port.substr(1); + } + host = host.substr(0, host.length - port.length); + } + if (host) this.hostname = host; +}; + +},{"./util":37,"punycode":25,"querystring":28}],37:[function(require,module,exports){ +'use strict'; + +module.exports = { + isString: function(arg) { + return typeof(arg) === 'string'; + }, + isObject: function(arg) { + return typeof(arg) === 'object' && arg !== null; + }, + isNull: function(arg) { + return arg === null; + }, + isNullOrUndefined: function(arg) { + return arg == null; + } +}; + +},{}],38:[function(require,module,exports){ +var core = require('../core'); +var Device = require('ismobilejs'); -/** - * Applies newlines to a string to have it optimally fit into the horizontal - * bounds set by the Text object's wordWrapWidth property. - * - * @param text {string} - * @private - */ -Text.prototype.wordWrap = function (text) -{ - // Greedy wrapping algorithm that will wrap words as the line grows longer - // than its horizontal bounds. - var result = ''; - var lines = text.split('\n'); - var wordWrapWidth = this._style.wordWrapWidth; - for (var i = 0; i < lines.length; i++) - { - var spaceLeft = wordWrapWidth; - var words = lines[i].split(' '); - for (var j = 0; j < words.length; j++) - { - var wordWidth = this.context.measureText(words[j]).width; - var wordWidthWithSpace = wordWidth + this.context.measureText(' ').width; - if (j === 0 || wordWidthWithSpace > spaceLeft) - { - // Skip printing the newline if it's the first word of the line that is - // greater than the word wrap width. - if (j > 0) - { - result += '\n'; - } - result += words[j]; - spaceLeft = wordWrapWidth - wordWidth; - } - else - { - spaceLeft -= wordWidthWithSpace; - result += ' ' + words[j]; - } - } +// add some extra variables to the container.. +Object.assign( + core.DisplayObject.prototype, + require('./accessibleTarget') +); - if (i < lines.length-1) - { - result += '\n'; - } - } - return result; -}; /** - * Returns the bounds of the Text as a rectangle. The bounds calculation takes the worldTransform into account. + * The Accessibility manager reacreates the ability to tab and and have content read by screen readers. This is very important as it can possibly help people with disabilities access pixi content. + * Much like interaction any DisplayObject can be made accessible. This manager will map the events as if the mouse was being used, minimizing the efferot required to implement. * - * @param matrix {PIXI.Matrix} the transformation matrix of the Text - * @return {PIXI.Rectangle} the framing rectangle + * @class + * @memberof PIXI + * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -Text.prototype.getBounds = function (matrix) +function AccessibilityManager(renderer) { - if (this.dirty) - { - this.updateText(); - } + if(Device.tablet || Device.phone) + { + this.createTouchHook(); + } - return Sprite.prototype.getBounds.call(this, matrix); -}; + // first we create a div that will sit over the pixi element. This is where the div overlays will go. + var div = document.createElement('div'); -/** - * Destroys this text object. - * - * @param [destroyBaseTexture=true] {boolean} whether to destroy the base texture as well - */ -Text.prototype.destroy = function (destroyBaseTexture) -{ - // make sure to reset the the context and canvas.. dont want this hanging around in memory! - this.context = null; - this.canvas = null; + div.style.width = 100 + 'px'; + div.style.height = 100 + 'px'; + div.style.position = 'absolute'; + div.style.top = 0; + div.style.left = 0; + // + div.style.zIndex = 2; - this._style = null; + /** + * This is the dom element that will sit over the pixi element. This is where the div overlays will go. + * + * @type {HTMLElement} + * @private + */ + this.div = div; - this._texture.destroy(destroyBaseTexture === undefined ? true : destroyBaseTexture); -}; - -},{"../const":33,"../math":54,"../sprites/Sprite":83,"../textures/Texture":93,"../utils":100}],90:[function(require,module,exports){ -var BaseTexture = require('./BaseTexture'), - math = require('../math'), - CONST = require('../const'), - tempRect = new math.Rectangle(); + /** + * A simple pool for storing divs. + * + * @type {*} + * @private + */ + this.pool = []; -/** - * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. - * - * __Hint__: All DisplayObjects (i.e. Sprites) that render to a BaseRenderTexture should be preloaded - * otherwise black rectangles will be drawn instead. - * - * A BaseRenderTexture takes a snapshot of any Display Object given to its render method. The position - * and rotation of the given Display Objects is ignored. For example: - * - * ```js - * var renderer = PIXI.autoDetectRenderer(1024, 1024, { view: canvas, ratio: 1 }); - * var BaserenderTexture = new PIXI.BaseRenderTexture(renderer, 800, 600); - * var sprite = PIXI.Sprite.fromImage("spinObj_01.png"); - * - * sprite.position.x = 800/2; - * sprite.position.y = 600/2; - * sprite.anchor.x = 0.5; - * sprite.anchor.y = 0.5; - * - * BaserenderTexture.render(sprite); - * ``` - * - * The Sprite in this case will be rendered to a position of 0,0. To render this sprite at its actual - * position a Container should be used: - * - * ```js - * var doc = new PIXI.Container(); - * - * doc.addChild(sprite); - * - * var baseRenderTexture = new PIXI.BaserenderTexture(100, 100); - * var renderTexture = new PIXI.RenderTexture(baseRenderTexture); - * - * renderer.render(doc, renderTexture); // Renders to center of RenderTexture - * ``` - * - * @class - * @extends PIXI.BaseTexture - * @memberof PIXI - * @param [width=100] {number} The width of the base render texture - * @param [height=100] {number} The height of the base render texture - * @param [scaleMode] {number} See {@link PIXI.SCALE_MODES} for possible values - * @param [resolution=1] {number} The resolution of the texture being generated - */ -function BaseRenderTexture(width, height, scaleMode, resolution) -{ - BaseTexture.call(this, null, scaleMode); + /** + * This is a tick used to check if an object is no longer being rendered. + * + * @type {Number} + * @private + */ + this.renderId = 0; - this.width = width || 100; - this.height = height || 100; + /** + * Setting this to true will visually show the divs + * + * @type {boolean} + */ + this.debug = false; - this.resolution = resolution || CONST.RESOLUTION; - this.scaleMode = scaleMode || CONST.SCALE_MODES.DEFAULT; - this.hasLoaded = true; + /** + * The renderer this accessibility manager works for. + * + * @member {PIXI.SystemRenderer} + */ + this.renderer = renderer; - /** - * A map of renderer IDs to webgl renderTargets + /** + * The array of currently active accessible items. * - * @member {object} + * @member {Array<*>} * @private */ - this._glRenderTargets = []; + this.children = []; - /** - * A reference to the canvas render target (we only need one as this can be shared accross renderers) + /** + * pre-bind the functions + * + * @private + */ + this._onKeyDown = this._onKeyDown.bind(this); + this._onMouseMove = this._onMouseMove.bind(this); + + /** + * stores the state of the manager. If there are no accessible objects or the mouse is moving the will be false. * - * @member {object} + * @member {Array<*>} * @private */ - this._canvasRenderTarget = null; + this.isActive = false; + this.isMobileAccessabillity = false; - /** - * @member {boolean} - */ - this.valid = false; + // let listen for tab.. once pressed we can fire up and show the accessibility layer + window.addEventListener('keydown', this._onKeyDown, false); } -BaseRenderTexture.prototype = Object.create(BaseTexture.prototype); -BaseRenderTexture.prototype.constructor = BaseRenderTexture; -module.exports = BaseRenderTexture; -/** - * Resizes the BaseRenderTexture. - * - * @param width {number} The width to resize to. - * @param height {number} The height to resize to. - * @param updateBase {boolean} Should the baseTexture.width and height values be resized as well? - */ -BaseRenderTexture.prototype.resize = function (width, height) -{ +AccessibilityManager.prototype.constructor = AccessibilityManager; +module.exports = AccessibilityManager; - if (width === this.width && height === this.height) - { - return; - } +AccessibilityManager.prototype.createTouchHook = function() +{ + var hookDiv = document.createElement('button'); + hookDiv.style.width = 1 + 'px'; + hookDiv.style.height = 1 + 'px'; + hookDiv.style.position = 'absolute'; + hookDiv.style.top = -1000+'px'; + hookDiv.style.left = -1000+'px'; + hookDiv.style.zIndex = 2; + hookDiv.style.backgroundColor = '#FF0000'; + hookDiv.title = 'HOOK DIV'; - this.valid = (width > 0 && height > 0); + hookDiv.addEventListener('focus', function(){ - this.width = width; - this.height = height; + this.isMobileAccessabillity = true; + this.activate(); + document.body.removeChild(hookDiv); - if (!this.valid) - { - return; - } + }.bind(this)); - this.emit('update', this); + document.body.appendChild(hookDiv); - //TODO - remove this! - if(this.filterManager) - { - this.filterManager.resize(this.width, this.height); - } }; /** - * Destroys this texture - * - * @param destroyBase {boolean} Whether to destroy the base texture as well + * Activating will cause the Accessibility layer to be shown. This is called when a user preses the tab key + * @private */ -BaseRenderTexture.prototype.destroy = function () +AccessibilityManager.prototype.activate = function() { - BaseTexture.prototype.destroy.call(this, true); + if(this.isActive ) + { + return; + } - // destroy the filtermanager.. - if(this.filterManager) - { - this.filterManager.destroy(); - } + this.isActive = true; - this.renderer = null; -}; + window.document.addEventListener('mousemove', this._onMouseMove, true); + window.removeEventListener('keydown', this._onKeyDown, false); -/** - * Will return a HTML Image of the texture - * - * @return {Image} - */ -BaseRenderTexture.prototype.getImage = function (frame) -{ - var image = new Image(); - image.src = this.getBase64(frame); - return image; -}; + this.renderer.on('postrender', this.update, this); -/** - * Will return a a base64 encoded string of this texture. It works by calling BaseRenderTexture.getCanvas and then running toDataURL on that. - * - * @return {string} A base64 encoded string of the texture. - */ -BaseRenderTexture.prototype.getBase64 = function ( frame ) -{ - return this.getCanvas(frame).toDataURL(); + if(this.renderer.view.parentNode) + { + this.renderer.view.parentNode.appendChild(this.div); + } }; /** - * Creates a Canvas element, renders this BaseRenderTexture to it and then returns it. - * - * @return {HTMLCanvasElement} A Canvas element with the texture rendered on. + * Deactivating will cause the Accessibility layer to be hidden. This is called when a user moves the mouse + * @private */ -BaseRenderTexture.prototype.getCanvas = function ( frame ) +AccessibilityManager.prototype.deactivate = function() { + if(!this.isActive || this.isMobileAccessabillity) + { + return; + } - if (this.renderer.type === CONST.RENDERER_TYPE.WEBGL) - { - if(!frame) - { - frame = tempRect; - frame.width = this.textureBuffer.size.width; - frame.height = this.textureBuffer.size.height; - } - - var width = frame.width * this.resolution; - var height = frame.height * this.resolution; - - var gl = this.renderer.gl; - - var webGLPixels = new Uint8Array(4 * width * height); - - gl.bindFramebuffer(gl.FRAMEBUFFER, this.textureBuffer.frameBuffer); - gl.readPixels(frame.x * this.resolution, frame.y * this.resolution, width, height, gl.RGBA, gl.UNSIGNED_BYTE, webGLPixels); - gl.bindFramebuffer(gl.FRAMEBUFFER, null); - - var tempCanvas = new CanvasBuffer(width, height); - var canvasData = tempCanvas.context.getImageData(0, 0, width, height); - canvasData.data.set(webGLPixels); - - tempCanvas.context.putImageData(canvasData, 0, 0); - - return tempCanvas.canvas; - } - else - { - if(!frame) - { - frame = tempRect; - frame.width = this.textureBuffer.canvas.width; - frame.height = this.textureBuffer.canvas.height; - } - - if(frame.width === this.textureBuffer.canvas.width && - frame.height === this.textureBuffer.canvas.height ) - { - return this.textureBuffer.canvas; - } - else - { + this.isActive = false; - var resolution = this.resolution; + window.document.removeEventListener('mousemove', this._onMouseMove); + window.addEventListener('keydown', this._onKeyDown, false); - var tempCanvas2 = new CanvasBuffer(frame.width * resolution, frame.height * resolution); - var canvasData2 = this.textureBuffer.context.getImageData(frame.x * resolution, frame.y * resolution, frame.width * resolution, frame.height * resolution); + this.renderer.off('postrender', this.update); - tempCanvas2.context.putImageData(canvasData2, 0, 0); + if(this.div.parentNode) + { + this.div.parentNode.removeChild(this.div); + } - return tempCanvas2.canvas; - } - } }; /** - * Will return a one-dimensional array containing the pixel data of the entire texture in RGBA order, with integer values between 0 and 255 (included). - * - * @return {Uint8ClampedArray} + * This recursive function will run throught he scene graph and add any new accessible objects to the DOM layer. + * @param displayObject {PIXI.Container} the DisplayObject to check. + * @private */ -BaseRenderTexture.prototype.getPixels = function ( frame ) +AccessibilityManager.prototype.updateAccessibleObjects = function(displayObject) { - if(!frame) - { - frame = tempRect; - frame.width = this.textureBuffer.size.width; - frame.height = this.textureBuffer.size.height; - } + if(!displayObject.visible) + { + return; + } - var width = frame.width * this.resolution; - var height = frame.height * this.resolution; + if(displayObject.accessible && displayObject.interactive) + { + if(!displayObject._accessibleActive) + { + this.addChild(displayObject); + } - if (this.renderer.type === CONST.RENDERER_TYPE.WEBGL) - { - var gl = this.renderer.gl; + displayObject.renderId = this.renderId; + } - var webGLPixels = new Uint8Array(4 * width * height); + var children = displayObject.children; - gl.bindFramebuffer(gl.FRAMEBUFFER, this.textureBuffer.frameBuffer); - gl.readPixels(frame.x * this.resolution, frame.y * this.resolution, width, height, gl.RGBA, gl.UNSIGNED_BYTE, webGLPixels); - gl.bindFramebuffer(gl.FRAMEBUFFER, null); + for (var i = children.length - 1; i >= 0; i--) { - return webGLPixels; - } - else - { - return this.textureBuffer.canvas.getContext('2d').getImageData(frame.x * this.resolution, frame.y * this.resolution, width, height).data; - } + this.updateAccessibleObjects(children[i]); + } }; -/** - * Will return a one-dimensional array containing the pixel data of a pixel within the texture in RGBA order, with integer values between 0 and 255 (included). - * - * @param x {number} The x coordinate of the pixel to retrieve. - * @param y {number} The y coordinate of the pixel to retrieve. - * @return {Uint8ClampedArray} - */ -BaseRenderTexture.prototype.getPixel = function (frame, x, y) -{ - tempRect.x = x; - tempRect.y = y; - tempRect.width = 1 / this.resolution; - tempRect.height = 1 / this.resolution; - - if(frame) - { - tempRect.x += frame.x; - tempRect.y += frame.y; - } - - return this.getPixels(tempRect); -}; - -},{"../const":33,"../math":54,"./BaseTexture":91}],91:[function(require,module,exports){ -var utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); /** - * A texture stores the information that represents an image. All textures have a base texture. - * - * @class - * @memberof PIXI - * @param source {Image|Canvas} the source object of the texture. - * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values - * @param resolution {number} the resolution of the texture for devices with different pixel ratios + * Before each render this function will ensure that all divs are mapped correctly to their DisplayObjects + * @private */ -function BaseTexture(source, scaleMode, resolution) +AccessibilityManager.prototype.update = function() { - EventEmitter.call(this); - - this.uid = utils.uid(); - - this.touched = 0; - - /** - * The Resolution of the texture. - * - * @member {number} - */ - this.resolution = resolution || 1; - - /** - * The width of the base texture set when the image has loaded - * - * @member {number} - * @readOnly - */ - this.width = 100; - - /** - * The height of the base texture set when the image has loaded - * - * @member {number} - * @readOnly - */ - this.height = 100; - - // TODO docs - // used to store the actual dimensions of the source - /** - * Used to store the actual width of the source of this texture - * - * @member {number} - * @readOnly - */ - this.realWidth = 100; - /** - * Used to store the actual height of the source of this texture - * - * @member {number} - * @readOnly - */ - this.realHeight = 100; - - /** - * The scale mode to apply when scaling this texture - * - * @member {number} - * @default PIXI.SCALE_MODES.LINEAR - * @see PIXI.SCALE_MODES - */ - this.scaleMode = scaleMode || CONST.SCALE_MODES.DEFAULT; - - /** - * Set to true once the base texture has successfully loaded. - * - * This is never true if the underlying source fails to load or has no texture data. - * - * @member {boolean} - * @readOnly - */ - this.hasLoaded = false; - - /** - * Set to true if the source is currently loading. - * - * If an Image source is loading the 'loaded' or 'error' event will be - * dispatched when the operation ends. An underyling source that is - * immediately-available bypasses loading entirely. - * - * @member {boolean} - * @readonly - */ - this.isLoading = false; - - /** - * The image source that is used to create the texture. - * - * TODO: Make this a setter that calls loadSource(); - * - * @member {Image|Canvas} - * @readonly - */ - this.source = null; // set in loadSource, if at all + if(!this.renderer.renderingToScreen) { + return; + } - /** - * Controls if RGB channels should be pre-multiplied by Alpha (WebGL only) - * All blend modes, and shaders written for default value. Change it on your own risk. - * - * @member {boolean} - * @default true - */ - this.premultipliedAlpha = true; + // update children... + this.updateAccessibleObjects(this.renderer._lastObjectRendered); - /** - * @member {string} - */ - this.imageUrl = null; + var rect = this.renderer.view.getBoundingClientRect(); + var sx = rect.width / this.renderer.width; + var sy = rect.height / this.renderer.height; - /** - * Wether or not the texture is a power of two, try to use power of two textures as much as you can - * @member {boolean} - * @private - */ - this.isPowerOfTwo = false; + var div = this.div; - // used for webGL + div.style.left = rect.left + 'px'; + div.style.top = rect.top + 'px'; + div.style.width = this.renderer.width + 'px'; + div.style.height = this.renderer.height + 'px'; - /** - * - * Set this to true if a mipmap of this texture needs to be generated. This value needs to be set before the texture is used - * Also the texture must be a power of two size to work - * - * @member {boolean} - */ - this.mipmap = CONST.MIPMAP_TEXTURES; + for (var i = 0; i < this.children.length; i++) + { + var child = this.children[i]; - /** - * - * Set this to true if a mipmap of this texture needs to be generated. This value needs to be set before the texture is used - * Also the texture must be a power of two size to work - * - * @member {boolean} - */ - this.wrap = CONST.MIPMAP_TEXTURES; + if(child.renderId !== this.renderId) + { + child._accessibleActive = false; - /** - * A map of renderer IDs to webgl textures - * - * @member {object} - * @private - */ - this._glTextures = []; - this._enabled = 0; - this._id = 0; - - // if no source passed don't try to load - if (source) - { - this.loadSource(source); - } + core.utils.removeItems(this.children, i, 1); + this.div.removeChild( child._accessibleDiv ); + this.pool.push(child._accessibleDiv); + child._accessibleDiv = null; - /** - * Fired when a not-immediately-available source finishes loading. - * - * @event loaded - * @memberof PIXI.BaseTexture# - * @protected - */ + i--; - /** - * Fired when a not-immediately-available source fails to load. - * - * @event error - * @memberof PIXI.BaseTexture# - * @protected - */ -} + if(this.children.length === 0) + { + this.deactivate(); + } + } + else + { + // map div to display.. + div = child._accessibleDiv; + var hitArea = child.hitArea; + var wt = child.worldTransform; -BaseTexture.prototype = Object.create(EventEmitter.prototype); -BaseTexture.prototype.constructor = BaseTexture; -module.exports = BaseTexture; + if(child.hitArea) + { + div.style.left = ((wt.tx + (hitArea.x * wt.a)) * sx) + 'px'; + div.style.top = ((wt.ty + (hitArea.y * wt.d)) * sy) + 'px'; -/** - * Updates the texture on all the webgl renderers, this also assumes the src has changed. - * - * @fires update - */ -BaseTexture.prototype.update = function () -{ - this.realWidth = this.source.naturalWidth || this.source.width; - this.realHeight = this.source.naturalHeight || this.source.height; + div.style.width = (hitArea.width * wt.a * sx) + 'px'; + div.style.height = (hitArea.height * wt.d * sy) + 'px'; - this.width = this.realWidth / this.resolution; - this.height = this.realHeight / this.resolution; + } + else + { + hitArea = child.getBounds(); - this.isPowerOfTwo = bitTwiddle.isPow2(this.realWidth) && bitTwiddle.isPow2(this.realHeight); + this.capHitArea(hitArea); - this.emit('update', this); + div.style.left = (hitArea.x * sx) + 'px'; + div.style.top = (hitArea.y * sy) + 'px'; + + div.style.width = (hitArea.width * sx) + 'px'; + div.style.height = (hitArea.height * sy) + 'px'; + } + } + } + + // increment the render id.. + this.renderId++; }; -/** - * Load a source. - * - * If the source is not-immediately-available, such as an image that needs to be - * downloaded, then the 'loaded' or 'error' event will be dispatched in the future - * and `hasLoaded` will remain false after this call. - * - * The logic state after calling `loadSource` directly or indirectly (eg. `fromImage`, `new BaseTexture`) is: - * - * if (texture.hasLoaded) - { - * // texture ready for use - * } else if (texture.isLoading) - { - * // listen to 'loaded' and/or 'error' events on texture - * } else { - * // not loading, not going to load UNLESS the source is reloaded - * // (it may still make sense to listen to the events) - * } - * - * @protected - * @param source {Image|Canvas} the source object of the texture. - */ -BaseTexture.prototype.loadSource = function (source) +AccessibilityManager.prototype.capHitArea = function (hitArea) { - var wasLoading = this.isLoading; - this.hasLoaded = false; - this.isLoading = false; - - if (wasLoading && this.source) + if (hitArea.x < 0) { - this.source.onload = null; - this.source.onerror = null; + hitArea.width += hitArea.x; + hitArea.x = 0; } - this.source = source; + if (hitArea.y < 0) + { + hitArea.height += hitArea.y; + hitArea.y = 0; + } - // Apply source if loaded. Otherwise setup appropriate loading monitors. - if ((this.source.complete || this.source.getContext) && this.source.width && this.source.height) + if ( hitArea.x + hitArea.width > this.renderer.width ) { - this._sourceLoaded(); + hitArea.width = this.renderer.width - hitArea.x; } - else if (!source.getContext) + + if ( hitArea.y + hitArea.height > this.renderer.height ) { + hitArea.height = this.renderer.height - hitArea.y; + } +}; - // Image fail / not ready - this.isLoading = true; - var scope = this; +/** + * Adds a DisplayObject to the accessibility manager + * @private + */ +AccessibilityManager.prototype.addChild = function(displayObject) +{ +// this.activate(); - source.onload = function () - { - source.onload = null; - source.onerror = null; + var div = this.pool.pop(); - if (!scope.isLoading) - { - return; - } + if(!div) + { + div = document.createElement('button'); - scope.isLoading = false; - scope._sourceLoaded(); + div.style.width = 100 + 'px'; + div.style.height = 100 + 'px'; + div.style.backgroundColor = this.debug ? 'rgba(255,0,0,0.5)' : 'transparent'; + div.style.position = 'absolute'; + div.style.zIndex = 2; + div.style.borderStyle = 'none'; - scope.emit('loaded', scope); - }; - source.onerror = function () - { - source.onload = null; - source.onerror = null; + div.addEventListener('click', this._onClick.bind(this)); + div.addEventListener('focus', this._onFocus.bind(this)); + div.addEventListener('focusout', this._onFocusOut.bind(this)); + } - if (!scope.isLoading) - { - return; - } - scope.isLoading = false; - scope.emit('error', scope); - }; + if(displayObject.accessibleTitle) + { + div.title = displayObject.accessibleTitle; + } + else if (!displayObject.accessibleTitle && !displayObject.accessibleHint) + { + div.title = 'displayObject ' + this.tabIndex; + } - // Per http://www.w3.org/TR/html5/embedded-content-0.html#the-img-element - // "The value of `complete` can thus change while a script is executing." - // So complete needs to be re-checked after the callbacks have been added.. - // NOTE: complete will be true if the image has no src so best to check if the src is set. - if (source.complete && source.src) - { - this.isLoading = false; + if(displayObject.accessibleHint) + { + div.setAttribute('aria-label', displayObject.accessibleHint); + } - // ..and if we're complete now, no need for callbacks - source.onload = null; - source.onerror = null; - if (source.width && source.height) - { - this._sourceLoaded(); + // - // If any previous subscribers possible - if (wasLoading) - { - this.emit('loaded', this); - } - } - else - { - // If any previous subscribers possible - if (wasLoading) - { - this.emit('error', this); - } - } - } - } + displayObject._accessibleActive = true; + displayObject._accessibleDiv = div; + div.displayObject = displayObject; + + + this.children.push(displayObject); + this.div.appendChild( displayObject._accessibleDiv ); + displayObject._accessibleDiv.tabIndex = displayObject.tabIndex; }; + /** - * Used internally to update the width, height, and some other tracking vars once - * a source has successfully loaded. - * + * Maps the div button press to pixi's InteractionManager (click) * @private */ -BaseTexture.prototype._sourceLoaded = function () +AccessibilityManager.prototype._onClick = function(e) { - this.hasLoaded = true; - this.update(); + var interactionManager = this.renderer.plugins.interaction; + interactionManager.dispatchEvent(e.target.displayObject, 'click', interactionManager.eventData); }; /** - * Destroys this base texture - * + * Maps the div focus events to pixis InteractionManager (mouseover) + * @private */ -BaseTexture.prototype.destroy = function () +AccessibilityManager.prototype._onFocus = function(e) { - if (this.imageUrl) - { - delete utils.BaseTextureCache[this.imageUrl]; - delete utils.TextureCache[this.imageUrl]; - - this.imageUrl = null; - - if (!navigator.isCocoonJS) - { - this.source.src = ''; - } - } - else if (this.source && this.source._pixiId) - { - delete utils.BaseTextureCache[this.source._pixiId]; - } - - this.source = null; - - this.dispose(); + var interactionManager = this.renderer.plugins.interaction; + interactionManager.dispatchEvent(e.target.displayObject, 'mouseover', interactionManager.eventData); }; /** - * Frees the texture from WebGL memory without destroying this texture object. - * This means you can still use the texture later which will upload it to GPU - * memory again. - * + * Maps the div focus events to pixis InteractionManager (mouseout) + * @private */ -BaseTexture.prototype.dispose = function () +AccessibilityManager.prototype._onFocusOut = function(e) { - this.emit('dispose', this); - - // this should no longer be needed, the renderers should cleanup all the gl textures. - // this._glTextures = {}; + var interactionManager = this.renderer.plugins.interaction; + interactionManager.dispatchEvent(e.target.displayObject, 'mouseout', interactionManager.eventData); }; /** - * Changes the source image of the texture. - * The original source must be an Image element. + * Is called when a key is pressed * - * @param newSrc {string} the path of the image + * @private */ -BaseTexture.prototype.updateSourceImage = function (newSrc) +AccessibilityManager.prototype._onKeyDown = function(e) { - this.source.src = newSrc; + if(e.keyCode !== 9) + { + return; + } - this.loadSource(this.source); + this.activate(); }; /** - * Helper function that creates a base texture from the given image url. - * If the image is not in the base texture cache it will be created and loaded. + * Is called when the mouse moves across the renderer element * - * @static - * @param imageUrl {string} The image url of the texture - * @param [crossorigin=(auto)] {boolean} Should use anonymous CORS? Defaults to true if the URL is not a data-URI. - * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values - * @return PIXI.BaseTexture + * @private */ -BaseTexture.fromImage = function (imageUrl, crossorigin, scaleMode) +AccessibilityManager.prototype._onMouseMove = function() { - var baseTexture = utils.BaseTextureCache[imageUrl]; + this.deactivate(); +}; - if (!baseTexture) - { - // new Image() breaks tex loading in some versions of Chrome. - // See https://code.google.com/p/chromium/issues/detail?id=238071 - var image = new Image();//document.createElement('img'); - - if (crossorigin === undefined && imageUrl.indexOf('data:') !== 0) - { - image.crossOrigin = determineCrossOrigin(imageUrl); - } +/** + * Destroys the accessibility manager + * + */ +AccessibilityManager.prototype.destroy = function () +{ + this.div = null; - baseTexture = new BaseTexture(image, scaleMode); - baseTexture.imageUrl = imageUrl; + for (var i = 0; i < this.children.length; i++) + { + this.children[i].div = null; + } - image.src = imageUrl; - utils.BaseTextureCache[imageUrl] = baseTexture; + window.document.removeEventListener('mousemove', this._onMouseMove); + window.removeEventListener('keydown', this._onKeyDown); - // if there is an @2x at the end of the url we are going to assume its a highres image - baseTexture.resolution = utils.getResolutionOfUrl(imageUrl); - } + this.pool = null; + this.children = null; + this.renderer = null; - return baseTexture; }; +core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); +core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +},{"../core":61,"./accessibleTarget":39,"ismobilejs":5}],39:[function(require,module,exports){ /** - * Helper function that creates a base texture from the given canvas element. + * Default property values of accessible objects + * used by {@link PIXI.accessibility.AccessibilityManager}. * - * @static - * @param canvas {Canvas} The canvas element source of the texture - * @param scaleMode {number} See {@link PIXI.SCALE_MODES} for possible values - * @return PIXI.BaseTexture + * @mixin + * @memberof PIXI + * @example + * function MyObject() {} + * + * Object.assign( + * MyObject.prototype, + * PIXI.accessibility.accessibleTarget + * ); */ -BaseTexture.fromCanvas = function (canvas, scaleMode) -{ - if (!canvas._pixiId) - { - canvas._pixiId = 'canvas_' + utils.uid(); - } +var accessibleTarget = { - var baseTexture = utils.BaseTextureCache[canvas._pixiId]; + /** + * Flag for if the object is accessible. If true AccessibilityManager will overlay a + * shadow div with attributes set + * + * @member {boolean} + */ + accessible:false, - if (!baseTexture) - { - baseTexture = new BaseTexture(canvas, scaleMode); - utils.BaseTextureCache[canvas._pixiId] = baseTexture; - } + /** + * Sets the title attribute of the shadow div + * If accessibleTitle AND accessibleHint has not been this will default to 'displayObject [tabIndex]' + * + * @member {string} + */ + accessibleTitle:null, + + /** + * Sets the aria-label attribute of the shadow div + * + * @member {string} + */ + accessibleHint:null, + + /** + * @todo Needs docs. + */ + tabIndex:0, + + /** + * @todo Needs docs. + */ + _accessibleActive:false, + + /** + * @todo Needs docs. + */ + _accessibleDiv:false - return baseTexture; }; + +module.exports = accessibleTarget; -},{"../const":33,"../utils":100,"../utils/determineCrossOrigin":99,"bit-twiddle":3,"eventemitter3":12}],92:[function(require,module,exports){ -var BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +},{}],40:[function(require,module,exports){ +/** + * @file Main export of the PIXI accessibility library + * @author Mat Groves + * @copyright 2013-2015 GoodBoyDigital + * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} + */ /** - * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. - * - * __Hint__: All DisplayObjects (i.e. Sprites) that render to a RenderTexture should be preloaded - * otherwise black rectangles will be drawn instead. - * - * A RenderTexture takes a snapshot of any Display Object given to its render method. The position - * and rotation of the given Display Objects is ignored. For example: - * - * ```js - * var renderer = PIXI.autoDetectRenderer(1024, 1024, { view: canvas, ratio: 1 }); - * var renderTexture = PIXI.RenderTexture.create(800, 600); - * var sprite = PIXI.Sprite.fromImage("spinObj_01.png"); - * - * sprite.position.x = 800/2; - * sprite.position.y = 600/2; - * sprite.anchor.x = 0.5; - * sprite.anchor.y = 0.5; - * - * renderer.render(sprite, renderTexture); - * ``` - * - * The Sprite in this case will be rendered to a position of 0,0. To render this sprite at its actual - * position a Container should be used: - * - * ```js - * var doc = new PIXI.Container(); - * - * doc.addChild(sprite); - * - * renderer.render(doc, renderTexture); // Renders to center of renderTexture - * ``` + * @namespace PIXI.AccessibilityManager + */ +module.exports = { + accessibleTarget: require('./accessibleTarget'), + AccessibilityManager: require('./AccessibilityManager') +}; + +},{"./AccessibilityManager":38,"./accessibleTarget":39}],41:[function(require,module,exports){ +var GLShader = require('pixi-gl-core').GLShader; +var Const = require('./const'); + +function checkPrecision(src) { + if (src instanceof Array) { + if (src[0].substring(0,9) !== 'precision') { + var copy = src.slice(0); + copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); + return copy; + } + } else { + if (src.substring(0,9) !== 'precision') { + return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; + } + } + return src; +} + +/** + * Wrapper class, webGL Shader for Pixi. + * Adds precision string if vertexSrc or fragmentSrc have no mention of it. * * @class - * @extends PIXI.Texture * @memberof PIXI - * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture + * @param gl {WebGLRenderingContext} The current WebGL rendering context + * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. + * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -function RenderTexture(baseRenderTexture, frame) -{ - // suport for legacy.. - this.legacyRenderer = null; +var Shader = function(gl, vertexSrc, fragmentSrc) { + GLShader.call(this, gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); +}; + +Shader.prototype = Object.create(GLShader.prototype); +Shader.prototype.constructor = Shader; +module.exports = Shader; + +},{"./const":42,"pixi-gl-core":14}],42:[function(require,module,exports){ + +/** + * Constant values used in pixi + * + * @lends PIXI + */ +var CONST = { + /** + * String of the current PIXI version. + * + * @static + * @constant + * @type {string} + */ + VERSION: '4.0.0', - if( !(baseRenderTexture instanceof BaseRenderTexture) ) - { - var width = arguments[1]; - var height = arguments[2]; + /** + * Two Pi. + * + * @static + * @constant + * @type {number} + */ + PI_2: Math.PI * 2, - // we have an old render texture.. - console.warn('v4 RenderTexture now expects a new BaseRenderTexture. Please use RenderTexture.create('+width+', '+height+')'); - this.legacyRenderer = arguments[0]; + /** + * Conversion factor for converting radians to degrees. + * + * @static + * @constant + * @type {number} + */ + RAD_TO_DEG: 180 / Math.PI, - frame = null; - baseRenderTexture = new BaseRenderTexture(width, height, 0, 1); - - } + /** + * Conversion factor for converting degrees to radians. + * + * @static + * @constant + * @type {number} + */ + DEG_TO_RAD: Math.PI / 180, - /** - * The base texture object that this texture uses + * Target frames per millisecond. * - * @member {BaseTexture} + * @static + * @constant + * @type {number} + * @default 0.06 */ - Texture.call(this, - baseRenderTexture, - frame - ); + TARGET_FPMS: 0.06, /** - * @member {boolean} + * Constant to identify the Renderer Type. + * + * @static + * @constant + * @type {object} + * @property {number} UNKNOWN - Unknown render type. + * @property {number} WEBGL - WebGL render type. + * @property {number} CANVAS - Canvas render type. */ - this.valid = true; + RENDERER_TYPE: { + UNKNOWN: 0, + WEBGL: 1, + CANVAS: 2 + }, - this._updateUvs(); -} + /** + * Various blend modes supported by PIXI. + * + * IMPORTANT - The WebGL renderer only supports the NORMAL, ADD, MULTIPLY and SCREEN blend modes. + * Anything else will silently act like NORMAL. + * + * @static + * @constant + * @type {object} + * @property {number} NORMAL + * @property {number} ADD + * @property {number} MULTIPLY + * @property {number} SCREEN + * @property {number} OVERLAY + * @property {number} DARKEN + * @property {number} LIGHTEN + * @property {number} COLOR_DODGE + * @property {number} COLOR_BURN + * @property {number} HARD_LIGHT + * @property {number} SOFT_LIGHT + * @property {number} DIFFERENCE + * @property {number} EXCLUSION + * @property {number} HUE + * @property {number} SATURATION + * @property {number} COLOR + * @property {number} LUMINOSITY + */ + BLEND_MODES: { + NORMAL: 0, + ADD: 1, + MULTIPLY: 2, + SCREEN: 3, + OVERLAY: 4, + DARKEN: 5, + LIGHTEN: 6, + COLOR_DODGE: 7, + COLOR_BURN: 8, + HARD_LIGHT: 9, + SOFT_LIGHT: 10, + DIFFERENCE: 11, + EXCLUSION: 12, + HUE: 13, + SATURATION: 14, + COLOR: 15, + LUMINOSITY: 16 + }, -RenderTexture.prototype = Object.create(Texture.prototype); -RenderTexture.prototype.constructor = RenderTexture; -module.exports = RenderTexture; + /** + * Various webgl draw modes. These can be used to specify which GL drawMode to use + * under certain situations and renderers. + * + * @static + * @constant + * @type {object} + * @property {number} POINTS + * @property {number} LINES + * @property {number} LINE_LOOP + * @property {number} LINE_STRIP + * @property {number} TRIANGLES + * @property {number} TRIANGLE_STRIP + * @property {number} TRIANGLE_FAN + */ + DRAW_MODES: { + POINTS: 0, + LINES: 1, + LINE_LOOP: 2, + LINE_STRIP: 3, + TRIANGLES: 4, + TRIANGLE_STRIP: 5, + TRIANGLE_FAN: 6 + }, -/** - * Resizes the RenderTexture. - * - * @param width {number} The width to resize to. - * @param height {number} The height to resize to. - * @param updateBase {boolean} Should the baseTexture.width and height values be resized as well? - */ -RenderTexture.prototype.resize = function (width, height, doNotResizeBaseTexture) -{ + /** + * The scale modes that are supported by pixi. + * + * The DEFAULT scale mode affects the default scaling mode of future operations. + * It can be re-assigned to either LINEAR or NEAREST, depending upon suitability. + * + * @static + * @constant + * @type {object} + * @property {number} DEFAULT=LINEAR + * @property {number} LINEAR Smooth scaling + * @property {number} NEAREST Pixelating scaling + */ + SCALE_MODES: { + DEFAULT: 0, + LINEAR: 0, + NEAREST: 1 + }, - //TODO - could be not required.. - this.valid = (width > 0 && height > 0); + /** + * The wrap modes that are supported by pixi. + * + * The DEFAULT wrap mode affects the default wraping mode of future operations. + * It can be re-assigned to either CLAMP or REPEAT, depending upon suitability. + * If the texture is non power of two then clamp will be used regardless as webGL can only use REPEAT if the texture is po2. + * This property only affects WebGL. + * + * @static + * @constant + * @type {object} + * @property {number} DEFAULT=CLAMP + * @property {number} CLAMP - The textures uvs are clamped + * @property {number} REPEAT - The texture uvs tile and repeat + * @property {number} MIRRORED_REPEAT - The texture uvs tile and repeat with mirroring + */ + WRAP_MODES: { + DEFAULT: 0, + CLAMP: 0, + REPEAT: 1, + MIRRORED_REPEAT:2 + }, - this._frame.width = this.crop.width = width; - this._frame.height = this.crop.height = height; + /** + * The gc modes that are supported by pixi. + * + * The DEFAULT Garbage Collection mode for pixi textures is MANUAL + * If set to DEFAULT, the renderer will occasianally check textures usage. If they are not used for a specified period of time they will be removed from the GPU. + * They will of corse be uploaded again when they are required. This is a silent behind the scenes process that should ensure that the GPU does not get filled up. + * Handy for mobile devices! + * This property only affects WebGL. + * + * @static + * @constant + * @type {object} + * @property {number} DEFAULT=MANUAL + * @property {number} AUTO - Garbage collection will happen periodically automatically + * @property {number} MANUAL - Garbage collection will need to be called manually + */ + GC_MODES: { + DEFAULT: 1, + AUTO: 0, + MANUAL: 1, + }, - if (!doNotResizeBaseTexture) - { - this.baseTexture.resize(width, height); - } + /** + * If set to true WebGL will attempt make textures mimpaped by default. + * Mipmapping will only succeed if the base texture uploaded has power of two dimensions. + * + * @static + * @constant + * @type {boolean} + */ + MIPMAP_TEXTURES: true, - this._updateUvs(); -}; + /** + * The prefix that denotes a URL is for a retina asset. + * + * @static + * @constant + * @type {RegExp|string} + * @example `@2x` + */ + RETINA_PREFIX: /@(.+)x/, -/** - * A short hand way of creating a render texture.. - * @param [width=100] {number} The width of the render texture - * @param [height=100] {number} The height of the render texture - * @param [scaleMode] {number} See {@link PIXI.SCALE_MODES} for possible values - * @param [resolution=1] {number} The resolution of the texture being generated - */ -RenderTexture.create = function(width, height, scaleMode, resolution) -{ - return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); -}; - -},{"./BaseRenderTexture":90,"./Texture":93}],93:[function(require,module,exports){ -var BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); + /** + * Default resolution / device pixel ratio of the renderer. + * + * @static + * @constant + * @type {number} + */ + RESOLUTION: 1, -/** - * A texture stores the information that represents an image or part of an image. It cannot be added - * to the display list directly. Instead use it as the texture for a Sprite. If no frame is provided then the whole image is used. - * - * You can directly create a texture from an image and then reuse it multiple times like this : - * - * ```js - * var texture = PIXI.Texture.fromImage('assets/image.png'); - * var sprite1 = new PIXI.Sprite(texture); - * var sprite2 = new PIXI.Sprite(texture); - * ``` - * - * @class - * @memberof PIXI - * @param baseTexture {PIXI.BaseTexture} The base texture source to create the texture from - * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show - * @param [crop] {PIXI.Rectangle} The area of original texture - * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture - * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} - */ -function Texture(baseTexture, frame, crop, trim, rotate) -{ - EventEmitter.call(this); + /** + * Default filter resolution. + * + * @static + * @constant + * @type {number} + */ + FILTER_RESOLUTION:1, + + /** + * The default render options if none are supplied to {@link PIXI.WebGLRenderer} + * or {@link PIXI.CanvasRenderer}. + * + * @static + * @constant + * @type {object} + * @property {HTMLCanvasElement} view=null + * @property {number} resolution=1 + * @property {boolean} antialias=false + * @property {boolean} forceFXAA=false + * @property {boolean} autoResize=false + * @property {boolean} transparent=false + * @property {number} backgroundColor=0x000000 + * @property {boolean} clearBeforeRender=true + * @property {boolean} preserveDrawingBuffer=false + * @property {boolean} roundPixels=false + */ + DEFAULT_RENDER_OPTIONS: { + view: null, + resolution: 1, + antialias: false, + forceFXAA: false, + autoResize: false, + transparent: false, + backgroundColor: 0x000000, + clearBeforeRender: true, + preserveDrawingBuffer: false, + roundPixels: false + }, + + /** + * Constants that identify shapes, mainly to prevent `instanceof` calls. + * + * @static + * @constant + * @type {object} + * @property {number} POLY + * @property {number} RECT + * @property {number} CIRC + * @property {number} ELIP + * @property {number} RREC + */ + SHAPES: { + POLY: 0, + RECT: 1, + CIRC: 2, + ELIP: 3, + RREC: 4 + }, /** - * Does this Texture have any frame data assigned to it? + * Constants that specify float precision in shaders. * - * @member {boolean} + * @static + * @constant + * @type {object} + * @property {number} DEFAULT='mediump' + * @property {number} LOW='lowp' + * @property {number} MEDIUM='mediump' + * @property {number} HIGH='highp' + */ + PRECISION: { + DEFAULT: 'mediump', + LOW: 'lowp', + MEDIUM: 'mediump', + HIGH: 'highp' + }, + + /** + * Constants that specify the transform type. + * + * @static + * @constant + * @type {object} + * @property {number} DEFAULT=STATIC + * @property {number} STATIC + * @property {number} DYNAMIC */ - this.noFrame = false; + TRANSFORM_MODE:{ + DEFAULT: 0, + STATIC: 0, + DYNAMIC: 1 + }, - if (!frame) - { - this.noFrame = true; - frame = new math.Rectangle(0, 0, 1, 1); - } + /** + * Constants that define the type of gradient on text. + * + * @static + * @constant + * @type {object} + * @property {number} LINEAR_VERTICAL + * @property {number} LINEAR_HORIZONTAL + */ + TEXT_GRADIENT: { + LINEAR_VERTICAL: 0, + LINEAR_HORIZONTAL: 1 + }, - if (baseTexture instanceof Texture) - { - baseTexture = baseTexture.baseTexture; - } + // TODO: maybe change to SPRITE.BATCH_SIZE: 2000 + // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 /** - * The base texture that this texture uses. + * The default sprite batch size. * - * @member {PIXI.BaseTexture} + * The default aims to balance desktop and mobile devices. + * + * @static + * @constant + * @type {number} + * @default 4096 */ - this.baseTexture = baseTexture; + SPRITE_BATCH_SIZE: 4096, /** - * This is the area of the BaseTexture image to actually copy to the Canvas / WebGL when rendering, - * irrespective of the actual frame size or placement (which can be influenced by trimmed texture atlases) + * The maximum textures that this device supports. * - * @member {PIXI.Rectangle} + * @static + * @constant + * @type {number} */ - this._frame = frame; + SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32), /** - * This is the trimmed area of original texture, before it was put in atlas + * Name of the event that fires when a text style is changed. * - * @member {PIXI.Rectangle} + * @static + * @constant + * @type {string} */ - this.trim = trim; + TEXT_STYLE_CHANGED: 'changed' +}; +module.exports = CONST; + +},{"./utils/maxRecommendedTextures":116}],43:[function(require,module,exports){ +var math = require('../math'), + Rectangle = math.Rectangle; + +/** + * 'Builder' pattern for bounds rectangles + * Axis-Aligned Bounding Box + * It is not a shape! Its mutable thing, no 'EMPTY' or that kind of problems + * + * @class + * @memberof PIXI + */ +function Bounds() +{ /** - * This will let the renderer know if the texture is valid. If it's not then it cannot be rendered. - * - * @member {boolean} + * @member {number} + * @default 0 */ - this.valid = false; + this.minX = Infinity; /** - * This will let a renderer know that a texture has been updated (used mainly for webGL uv updates) - * - * @member {boolean} + * @member {number} + * @default 0 */ - this.requiresUpdate = false; + this.minY = Infinity; /** - * The WebGL UV data cache. - * - * @member {PIXI.TextureUvs} - * @private + * @member {number} + * @default 0 */ - this._uvs = null; + this.maxX = -Infinity; /** - * This is the area of original texture, before it was put in atlas - * - * @member {PIXI.Rectangle} + * @member {number} + * @default 0 */ - this.crop = crop || frame;//new math.Rectangle(0, 0, 1, 1); + this.maxY = -Infinity; - this._rotate = +(rotate || 0); + this.rect = null; +} - if (rotate === true) { - // this is old texturepacker legacy, some games/libraries are passing "true" for rotated textures - this._rotate = 2; - } else { - if (this._rotate % 2 !== 0) { - throw 'attempt to use diamond-shaped UVs. If you are sure, set rotation manually'; - } +Bounds.prototype.constructor = Bounds; +module.exports = Bounds; + +Bounds.prototype.isEmpty = function() +{ + return this.minX > this.maxX || this.minY > this.maxY; +}; + +Bounds.prototype.clear = function() +{ + this.updateID++; + + this.minX = Infinity; + this.minY = Infinity; + this.maxX = -Infinity; + this.maxY = -Infinity; +}; + +/** + * Can return Rectangle.EMPTY constant, either construct new rectangle, either use your rectangle + * It is not guaranteed that it will return tempRect + * @param tempRect {PIXI.Rectangle} temporary object will be used if AABB is not empty + * @returns {PIXI.Rectangle} + */ +Bounds.prototype.getRectangle = function() +{ + if (this.minX > this.maxX || this.minY > this.maxY) { + return Rectangle.EMPTY; } - if (baseTexture.hasLoaded) + if(!this.rect) { - if (this.noFrame) - { - frame = new math.Rectangle(0, 0, baseTexture.width, baseTexture.height); - - // if there is no frame we should monitor for any base texture changes.. - baseTexture.on('update', this.onBaseTextureUpdated, this); - } - this.frame = frame; + this.rect = new Rectangle(0, 0, 1, 1); } - else + + this.rect.x = this.minX; + this.rect.y = this.minY; + this.rect.width = this.maxX - this.minX; + this.rect.height = this.maxY - this.minY; + + return this.rect; +}; + +/** + * This function should be inlined when its possible + * @param point {PIXI.Point} + */ +Bounds.prototype.addPoint = function (point) +{ + this.minX = Math.min(this.minX, point.x); + this.maxX = Math.max(this.maxX, point.x); + this.minY = Math.min(this.minY, point.y); + this.maxY = Math.max(this.maxY, point.y); +}; + +/** + * Adds a quad, not transformed + * @param vertices {Float32Array} + * @returns {PIXI.Bounds} + */ +Bounds.prototype.addQuad = function(vertices) +{ + var minX = this.minX, minY = this.minY, maxX = this.maxX, maxY = this.maxY; + + var x = vertices[0]; + var y = vertices[1]; + minX = x < minX ? x : minX; + minY = y < minY ? y : minY; + maxX = x > maxX ? x : maxX; + maxY = y > maxY ? y : maxY; + + x = vertices[2]; + y = vertices[3]; + minX = x < minX ? x : minX; + minY = y < minY ? y : minY; + maxX = x > maxX ? x : maxX; + maxY = y > maxY ? y : maxY; + + x = vertices[4]; + y = vertices[5]; + minX = x < minX ? x : minX; + minY = y < minY ? y : minY; + maxX = x > maxX ? x : maxX; + maxY = y > maxY ? y : maxY; + + x = vertices[6]; + y = vertices[7]; + minX = x < minX ? x : minX; + minY = y < minY ? y : minY; + maxX = x > maxX ? x : maxX; + maxY = y > maxY ? y : maxY; + + this.minX = minX; + this.minY = minY; + this.maxX = maxX; + this.maxY = maxY; +}; + +/** + * Adds sprite frame, transformed + * @param transform {PIXI.TransformBase} + * @param x0 {number} + * @param y0 {number} + * @param x1 {number} + * @param y1 {number} + */ +Bounds.prototype.addFrame = function(transform, x0, y0, x1, y1) +{ + var matrix = transform.worldTransform; + var a = matrix.a, b = matrix.b, c = matrix.c, d = matrix.d, tx = matrix.tx, ty = matrix.ty; + var minX = this.minX, minY = this.minY, maxX = this.maxX, maxY = this.maxY; + + var x = a * x0 + c * y0 + tx; + var y = b * x0 + d * y0 + ty; + minX = x < minX ? x : minX; + minY = y < minY ? y : minY; + maxX = x > maxX ? x : maxX; + maxY = y > maxY ? y : maxY; + + x = a * x1 + c * y0 + tx; + y = b * x1 + d * y0 + ty; + minX = x < minX ? x : minX; + minY = y < minY ? y : minY; + maxX = x > maxX ? x : maxX; + maxY = y > maxY ? y : maxY; + + x = a * x0 + c * y1 + tx; + y = b * x0 + d * y1 + ty; + minX = x < minX ? x : minX; + minY = y < minY ? y : minY; + maxX = x > maxX ? x : maxX; + maxY = y > maxY ? y : maxY; + + x = a * x1 + c * y1 + tx; + y = b * x1 + d * y1 + ty; + minX = x < minX ? x : minX; + minY = y < minY ? y : minY; + maxX = x > maxX ? x : maxX; + maxY = y > maxY ? y : maxY; + + this.minX = minX; + this.minY = minY; + this.maxX = maxX; + this.maxY = maxY; +}; + +/** + * add an array of vertices + * @param transform {PIXI.TransformBase} + * @param vertices {Float32Array} + * @param beginOffset {number} + * @param endOffset {number} + */ +Bounds.prototype.addVertices = function(transform, vertices, beginOffset, endOffset) +{ + var matrix = transform.worldTransform; + var a = matrix.a, b = matrix.b, c = matrix.c, d = matrix.d, tx = matrix.tx, ty = matrix.ty; + var minX = this.minX, minY = this.minY, maxX = this.maxX, maxY = this.maxY; + + for (var i = beginOffset; i < endOffset; i += 2) { - baseTexture.once('loaded', this.onBaseTextureLoaded, this); + var rawX = vertices[i], rawY = vertices[i + 1]; + var x = (a * rawX) + (c * rawY) + tx; + var y = (d * rawY) + (b * rawX) + ty; + + minX = x < minX ? x : minX; + minY = y < minY ? y : minY; + maxX = x > maxX ? x : maxX; + maxY = y > maxY ? y : maxY; } + this.minX = minX; + this.minY = minY; + this.maxX = maxX; + this.maxY = maxY; +}; + +Bounds.prototype.addBounds = function(bounds) +{ + var minX = this.minX, minY = this.minY, maxX = this.maxX, maxY = this.maxY; + + this.minX = bounds.minX < minX ? bounds.minX : minX; + this.minY = bounds.minY < minY ? bounds.minY : minY; + this.maxX = bounds.maxX > maxX ? bounds.maxX : maxX; + this.maxY = bounds.maxY > maxY ? bounds.maxY : maxY; +}; + +},{"../math":66}],44:[function(require,module,exports){ +var utils = require('../utils'), + DisplayObject = require('./DisplayObject'); + +/** + * A Container represents a collection of display objects. + * It is the base class of all display objects that act as a container for other objects. + * + *```js + * var container = new PIXI.Container(); + * container.addChild(sprite); + * ``` + * @class + * @extends PIXI.DisplayObject + * @memberof PIXI + */ +function Container() +{ + DisplayObject.call(this); + /** - * Fired when the texture is updated. This happens if the frame or the baseTexture is updated. + * The array of children of this container. * - * @event update - * @memberof PIXI.Texture# - * @protected + * @member {PIXI.DisplayObject[]} + * @readonly */ + this.children = []; } -Texture.prototype = Object.create(EventEmitter.prototype); -Texture.prototype.constructor = Texture; -module.exports = Texture; +// constructor +Container.prototype = Object.create(DisplayObject.prototype); +Container.prototype.constructor = Container; +module.exports = Container; -Object.defineProperties(Texture.prototype, { +Object.defineProperties(Container.prototype, { /** - * The frame specifies the region of the base texture that this texture uses. + * The width of the Container, setting this will actually modify the scale to achieve the value set * - * @member {PIXI.Rectangle} - * @memberof PIXI.Texture# + * @member {number} + * @memberof PIXI.Container# */ - frame: { + width: { get: function () { - return this._frame; + return this.scale.x * this.getLocalBounds().width; }, - set: function (frame) + set: function (value) { - this._frame = frame; - this.noFrame = false; + var width = this.getLocalBounds().width; - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) + if (width !== 0) { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); + this.scale.x = value / width; } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim) + else { - this.crop = frame; + this.scale.x = 1; } - if (this.valid) - { - this._updateUvs(); - } + + this._width = value; } }, + /** - * Indicates whether the texture is rotated inside the atlas - * set to 2 to compensate for texture packer rotation - * set to 6 to compensate for spine packer rotation - * can be used to rotate or mirror sprites - * See {@link PIXI.GroupD8} for explanation + * The height of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} + * @memberof PIXI.Container# */ - rotate: { + height: { get: function () { - return this._rotate; + return this.scale.y * this.getLocalBounds().height; }, - set: function (rotate) + set: function (value) { - this._rotate = rotate; - if (this.valid) + + var height = this.getLocalBounds().height; + + if (height !== 0) { - this._updateUvs(); + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; } - } - }, - - /** - * The width of the Texture in pixels. - * - * @member {number} - */ - width: { - get: function() { - return this.crop ? this.crop.width : 0; - } - }, - /** - * The height of the Texture in pixels. - * - * @member {number} - */ - height: { - get: function() { - return this.crop ? this.crop.height : 0; + this._height = value; } } }); /** - * Updates this texture on the gpu. - * - */ -Texture.prototype.update = function () -{ - this.baseTexture.update(); -}; - -/** - * Called when the base texture is loaded + * Overridable method that can be used by Container subclasses whenever the children array is modified * * @private */ -Texture.prototype.onBaseTextureLoaded = function (baseTexture) -{ - // TODO this code looks confusing.. boo to abusing getters and setterss! - if (this.noFrame) - { - this.frame = new math.Rectangle(0, 0, baseTexture.width, baseTexture.height); - } - else - { - this.frame = this._frame; - } - - this.baseTexture.on('update', this.onBaseTextureUpdated, this); - this.emit('update', this); -}; +Container.prototype.onChildrenChange = function () {}; /** - * Called when the base texture is updated + * Adds a child or multiple children to the container. * - * @private + * Multple items can be added like so: `myContainer.addChild(thinkOne, thingTwo, thingThree)` + * @param child {...PIXI.DisplayObject} The DisplayObject(s) to add to the container + * @return {PIXI.DisplayObject} The first child that was added. */ -Texture.prototype.onBaseTextureUpdated = function (baseTexture) +Container.prototype.addChild = function (child) { - this._frame.width = baseTexture.width; - this._frame.height = baseTexture.height; - - this.emit('update', this); -}; + var argumentsLength = arguments.length; -/** - * Destroys this texture - * - * @param [destroyBase=false] {boolean} Whether to destroy the base texture as well - */ -Texture.prototype.destroy = function (destroyBase) -{ - if (this.baseTexture) + // if there is only one argument we can bypass looping through the them + if(argumentsLength > 1) { - if (destroyBase) + // loop through the arguments property and add all children + // use it the right way (.length and [i]) so that this function can still be optimised by JS runtimes + for (var i = 0; i < argumentsLength; i++) { - this.baseTexture.destroy(); + this.addChild( arguments[i] ); } - - this.baseTexture.off('update', this.onBaseTextureUpdated, this); - this.baseTexture.off('loaded', this.onBaseTextureLoaded, this); - - this.baseTexture = null; } + else + { + // if the child has a parent then lets remove it as Pixi objects can only exist in one place + if (child.parent) + { + child.parent.removeChild(child); + } - this._frame = null; - this._uvs = null; - this.trim = null; - this.crop = null; - - this.valid = false; + child.parent = this; - this.off('dispose', this.dispose, this); - this.off('update', this.update, this); -}; + // ensure a transform will be recalculated.. + this.transform._parentID = -1; -/** - * Creates a new texture object that acts the same as this one. - * - * @return {PIXI.Texture} - */ -Texture.prototype.clone = function () -{ - return new Texture(this.baseTexture, this.frame, this.crop, this.trim, this.rotate); -}; + this.children.push(child); -/** - * Updates the internal WebGL UV cache. - * - * @private - */ -Texture.prototype._updateUvs = function () -{ - if (!this._uvs) - { - this._uvs = new TextureUvs(); + // TODO - lets either do all callbacks or all events.. not both! + this.onChildrenChange(this.children.length-1); + child.emit('added', this); } - this._uvs.set(this._frame, this.baseTexture, this.rotate); + return child; }; /** - * Helper function that creates a Texture object from the given image url. - * If the image is not in the texture cache it will be created and loaded. + * Adds a child to the container at a specified index. If the index is out of bounds an error will be thrown * - * @static - * @param imageUrl {string} The image url of the texture - * @param crossorigin {boolean} Whether requests should be treated as crossorigin - * @param scaleMode {number} See {@link PIXI.SCALE_MODES} for possible values - * @return {PIXI.Texture} The newly created texture + * @param child {PIXI.DisplayObject} The child to add + * @param index {number} The index to place the child in + * @return {PIXI.DisplayObject} The child that was added. */ -Texture.fromImage = function (imageUrl, crossorigin, scaleMode) +Container.prototype.addChildAt = function (child, index) { - var texture = utils.TextureCache[imageUrl]; - - if (!texture) + if (index >= 0 && index <= this.children.length) { - texture = new Texture(BaseTexture.fromImage(imageUrl, crossorigin, scaleMode)); - utils.TextureCache[imageUrl] = texture; - } - - return texture; -}; - -/** - * Helper function that creates a sprite that will contain a texture from the TextureCache based on the frameId - * The frame ids are created when a Texture packer file has been loaded - * - * @static - * @param frameId {string} The frame Id of the texture in the cache - * @return {PIXI.Texture} The newly created texture - */ -Texture.fromFrame = function (frameId) -{ - var texture = utils.TextureCache[frameId]; + if (child.parent) + { + child.parent.removeChild(child); + } - if (!texture) - { - throw new Error('The frameId "' + frameId + '" does not exist in the texture cache'); - } + child.parent = this; - return texture; -}; + this.children.splice(index, 0, child); -/** - * Helper function that creates a new Texture based on the given canvas element. - * - * @static - * @param canvas {Canvas} The canvas element source of the texture - * @param scaleMode {number} See {@link PIXI.SCALE_MODES} for possible values - * @return {PIXI.Texture} - */ -Texture.fromCanvas = function (canvas, scaleMode) -{ - return new Texture(BaseTexture.fromCanvas(canvas, scaleMode)); -}; + // TODO - lets either do all callbacks or all events.. not both! + this.onChildrenChange(index); + child.emit('added', this); -/** - * Helper function that creates a new Texture based on the given video element. - * - * @static - * @param video {HTMLVideoElement} - * @param scaleMode {number} See {@link PIXI.SCALE_MODES} for possible values - * @return {PIXI.Texture} A Texture - */ -Texture.fromVideo = function (video, scaleMode) -{ - if (typeof video === 'string') - { - return Texture.fromVideoUrl(video, scaleMode); + return child; } else { - return new Texture(VideoBaseTexture.fromVideo(video, scaleMode)); + throw new Error(child + 'addChildAt: The index '+ index +' supplied is out of bounds ' + this.children.length); } }; /** - * Helper function that creates a new Texture based on the video url. - * - * @static - * @param videoUrl {string} - * @param scaleMode {number} See {@link PIXI.SCALE_MODES} for possible values - * @return {PIXI.Texture} A Texture - */ -Texture.fromVideoUrl = function (videoUrl, scaleMode) -{ - return new Texture(VideoBaseTexture.fromUrl(videoUrl, scaleMode)); -}; - -/** - * Helper function that creates a new Texture based on the source you provide. - * The soucre can be - frame id, image url, video url, canvae element, video element, base texture + * Swaps the position of 2 Display Objects within this container. * - * @static - * @param source {} - * @return {PIXI.Texture} A Texture + * @param child {PIXI.DisplayObject} First display object to swap + * @param child2 {PIXI.DisplayObject} Second display object to swap */ -Texture.from = function (source) +Container.prototype.swapChildren = function (child, child2) { - //TODO auto detect cross origin.. - //TODO pass in scale mode? - if(typeof source === 'string') + if (child === child2) { - var texture = utils.TextureCache[source]; - - if (!texture) - { - // check if its a video.. - var isVideo = source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/) !== null; - if(isVideo) - { - return Texture.fromVideoUrl(source); - } + return; + } - return Texture.fromImage(source); - } + var index1 = this.getChildIndex(child); + var index2 = this.getChildIndex(child2); - return texture - } - else if(source instanceof HTMLCanvasElement) - { - return Texture.fromCanvas(source); - } - else if(source instanceof HTMLVideoElement) - { - return Texture.fromVideo(source); - } - else if(source instanceof BaseTexture) + if (index1 < 0 || index2 < 0) { - return new Texture(BaseTexture); + throw new Error('swapChildren: Both the supplied DisplayObjects must be children of the caller.'); } -} - -/** - * Adds a texture to the global utils.TextureCache. This cache is shared across the whole PIXI object. - * - * @static - * @param texture {PIXI.Texture} The Texture to add to the cache. - * @param id {string} The id that the texture will be stored against. - */ -Texture.addTextureToCache = function (texture, id) -{ - utils.TextureCache[id] = texture; + this.children[index1] = child2; + this.children[index2] = child; + this.onChildrenChange(index1 < index2 ? index1 : index2); }; /** - * Remove a texture from the global utils.TextureCache. + * Returns the index position of a child DisplayObject instance * - * @static - * @param id {string} The id of the texture to be removed - * @return {PIXI.Texture} The texture that was removed + * @param child {PIXI.DisplayObject} The DisplayObject instance to identify + * @return {number} The index position of the child display object to identify */ -Texture.removeTextureFromCache = function (id) +Container.prototype.getChildIndex = function (child) { - var texture = utils.TextureCache[id]; + var index = this.children.indexOf(child); - delete utils.TextureCache[id]; - delete utils.BaseTextureCache[id]; + if (index === -1) + { + throw new Error('The supplied DisplayObject must be a child of the caller'); + } - return texture; + return index; }; /** - * An empty texture, used often to not have to create multiple empty textures. + * Changes the position of an existing child in the display object container * - * @static - * @constant + * @param child {PIXI.DisplayObject} The child DisplayObject instance for which you want to change the index number + * @param index {number} The resulting index number for the child display object */ -Texture.EMPTY = new Texture(new BaseTexture()); - -},{"../math":54,"../utils":100,"./BaseTexture":91,"./TextureUvs":94,"./VideoBaseTexture":95,"eventemitter3":12}],94:[function(require,module,exports){ +Container.prototype.setChildIndex = function (child, index) +{ + if (index < 0 || index >= this.children.length) + { + throw new Error('The supplied index is out of bounds'); + } + + var currentIndex = this.getChildIndex(child); + + utils.removeItems(this.children, currentIndex, 1); // remove from old position + this.children.splice(index, 0, child); //add at new position + this.onChildrenChange(index); +}; /** - * A standard object to store the Uvs of a texture + * Returns the child at the specified index * - * @class - * @private - * @memberof PIXI + * @param index {number} The index to get the child at + * @return {PIXI.DisplayObject} The child at the given index, if any. */ -function TextureUvs() +Container.prototype.getChildAt = function (index) { - this.x0 = 0; - this.y0 = 0; - - this.x1 = 1; - this.y1 = 0; - - this.x2 = 1; - this.y2 = 1; - - this.x3 = 0; - this.y3 = 1; - - this.xy0_uint32 = 0; - this.xy1_uint32 = 0; - this.xy2_uint32 = 0; - this.xy3_uint32 = 0; - - this.uvs_uint32 = new Uint32Array(4); -} - -module.exports = TextureUvs; + if (index < 0 || index >= this.children.length) + { + throw new Error('getChildAt: Supplied index ' + index + ' does not exist in the child list, or the supplied DisplayObject is not a child of the caller'); + } -var GroupD8 = require('../math/GroupD8'); + return this.children[index]; +}; /** - * Sets the texture Uvs based on the given frame information - * @param frame {PIXI.Rectangle} - * @param baseFrame {PIXI.Rectangle} - * @param rotate {number} Rotation of frame, see {@link PIXI.GroupD8} - * @private + * Removes a child from the container. + * + * @param child {PIXI.DisplayObject} The DisplayObject to remove + * @return {PIXI.DisplayObject} The child that was removed. */ -TextureUvs.prototype.set = function (frame, baseFrame, rotate) +Container.prototype.removeChild = function (child) { - var tw = baseFrame.width; - var th = baseFrame.height; + var argumentsLength = arguments.length; - if(rotate) + // if there is only one argument we can bypass looping through the them + if(argumentsLength > 1) { - //width and height div 2 div baseFrame size - var w2 = frame.width / 2 / tw; - var h2 = frame.height / 2 / th; - //coordinates of center - var cX = frame.x / tw + w2; - var cY = frame.y / th + h2; - rotate = GroupD8.add(rotate, GroupD8.NW); //NW is top-left corner - this.x0 = cX + w2 * GroupD8.uX(rotate); - this.y0 = cY + h2 * GroupD8.uY(rotate); - rotate = GroupD8.add(rotate, 2); //rotate 90 degrees clockwise - this.x1 = cX + w2 * GroupD8.uX(rotate); - this.y1 = cY + h2 * GroupD8.uY(rotate); - rotate = GroupD8.add(rotate, 2); - this.x2 = cX + w2 * GroupD8.uX(rotate); - this.y2 = cY + h2 * GroupD8.uY(rotate); - rotate = GroupD8.add(rotate, 2); - this.x3 = cX + w2 * GroupD8.uX(rotate); - this.y3 = cY + h2 * GroupD8.uY(rotate); + // loop through the arguments property and add all children + // use it the right way (.length and [i]) so that this function can still be optimised by JS runtimes + for (var i = 0; i < argumentsLength; i++) + { + this.removeChild( arguments[i] ); + } } else { + var index = this.children.indexOf(child); - this.x0 = frame.x / tw; - this.y0 = frame.y / th; - - this.x1 = (frame.x + frame.width) / tw; - this.y1 = frame.y / th; + if (index === -1) + { + return; + } - this.x2 = (frame.x + frame.width) / tw; - this.y2 = (frame.y + frame.height) / th; + child.parent = null; + utils.removeItems(this.children, index, 1); - this.x3 = frame.x / tw; - this.y3 = (frame.y + frame.height) / th; + // TODO - lets either do all callbacks or all events.. not both! + this.onChildrenChange(index); + child.emit('removed', this); } - this.uvs_uint32[0] = (((this.y0 * 65535) & 0xFFFF) << 16) | ((this.x0 * 65535) & 0xFFFF); - this.uvs_uint32[1] = (((this.y1 * 65535) & 0xFFFF) << 16) | ((this.x1 * 65535) & 0xFFFF); - this.uvs_uint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); - this.uvs_uint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); + return child; }; - -},{"../math/GroupD8":51}],95:[function(require,module,exports){ -var BaseTexture = require('./BaseTexture'), - utils = require('../utils'); /** - * A texture of a [playing] Video. - * - * Video base textures mimic Pixi BaseTexture.from.... method in their creation process. - * - * This can be used in several ways, such as: - * - * ```js - * var texture = PIXI.VideoBaseTexture.fromUrl('http://mydomain.com/video.mp4'); - * - * var texture = PIXI.VideoBaseTexture.fromUrl({ src: 'http://mydomain.com/video.mp4', mime: 'video/mp4' }); - * - * var texture = PIXI.VideoBaseTexture.fromUrls(['/video.webm', '/video.mp4']); - * - * var texture = PIXI.VideoBaseTexture.fromUrls([ - * { src: '/video.webm', mime: 'video/webm' }, - * { src: '/video.mp4', mime: 'video/mp4' } - * ]); - * ``` - * - * See the ["deus" demo](http://www.goodboydigital.com/pixijs/examples/deus/). + * Removes a child from the specified index position. * - * @class - * @extends PIXI.BaseTexture - * @memberof PIXI - * @param source {HTMLVideoElement} - * @param [scaleMode] {number} See {@link PIXI.SCALE_MODES} for possible values + * @param index {number} The index to get the child from + * @return {PIXI.DisplayObject} The child that was removed. */ -function VideoBaseTexture(source, scaleMode) +Container.prototype.removeChildAt = function (index) { - if (!source) - { - throw new Error('No video source element specified.'); - } - - // hook in here to check if video is already available. - // BaseTexture looks for a source.complete boolean, plus width & height. + var child = this.getChildAt(index); - if ((source.readyState === source.HAVE_ENOUGH_DATA || source.readyState === source.HAVE_FUTURE_DATA) && source.width && source.height) - { - source.complete = true; - } + child.parent = null; + utils.removeItems(this.children, index, 1); - BaseTexture.call(this, source, scaleMode); + // TODO - lets either do all callbacks or all events.. not both! + this.onChildrenChange(index); + child.emit('removed', this); - /** - * Should the base texture automatically update itself, set to true by default - * - * @member {boolean} - * @default true - */ - this.autoUpdate = false; + return child; +}; - this._onUpdate = this._onUpdate.bind(this); - this._onCanPlay = this._onCanPlay.bind(this); +/** + * Removes all children from this container that are within the begin and end indexes. + * + * @param [beginIndex=0] {number} The beginning position. + * @param [endIndex=this.children.length] {number} The ending position. Default value is size of the container. + */ +Container.prototype.removeChildren = function (beginIndex, endIndex) +{ + var begin = beginIndex || 0; + var end = typeof endIndex === 'number' ? endIndex : this.children.length; + var range = end - begin; + var removed, i; - if (!source.complete) + if (range > 0 && range <= end) { - source.addEventListener('canplay', this._onCanPlay); - source.addEventListener('canplaythrough', this._onCanPlay); + removed = this.children.splice(begin, range); - // started playing.. - source.addEventListener('play', this._onPlayStart.bind(this)); - source.addEventListener('pause', this._onPlayStop.bind(this)); - } + for (i = 0; i < removed.length; ++i) + { + removed[i].parent = null; + } - this.__loaded = false; -} + this.onChildrenChange(beginIndex); -VideoBaseTexture.prototype = Object.create(BaseTexture.prototype); -VideoBaseTexture.prototype.constructor = VideoBaseTexture; -module.exports = VideoBaseTexture; + for (i = 0; i < removed.length; ++i) + { + removed[i].emit('removed', this); + } -/** - * The internal update loop of the video base texture, only runs when autoUpdate is set to true + return removed; + } + else if (range === 0 && this.children.length === 0) + { + return []; + } + else + { + throw new RangeError('removeChildren: numeric values are outside the acceptable range.'); + } +}; + +/* + * Updates the transform on all children of this container for rendering * * @private */ -VideoBaseTexture.prototype._onUpdate = function () +Container.prototype.updateTransform = function () { - if (this.autoUpdate) + this._boundsID++; + + if (!this.visible) { - window.requestAnimationFrame(this._onUpdate); - this.update(); + return; + } + + this.transform.updateTransform(this.parent.transform); + + //TODO: check render flags, how to process stuff here + this.worldAlpha = this.alpha * this.parent.worldAlpha; + + for (var i = 0, j = this.children.length; i < j; ++i) + { + this.children[i].updateTransform(); } }; -/** - * Runs the update loop when the video is ready to play - * - * @private - */ -VideoBaseTexture.prototype._onPlayStart = function () +// performance increase to avoid using call.. (10x faster) +Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + + +Container.prototype.calculateBounds = function () { - if (!this.autoUpdate) + this._bounds.clear(); + + if(!this.visible) { - window.requestAnimationFrame(this._onUpdate); - this.autoUpdate = true; + return; + } + + this._calculateBounds(); + + for (var i = 0; i < this.children.length; i++) + { + var child = this.children[i]; + + child.calculateBounds(); + + this._bounds.addBounds(child._bounds); } + + this._boundsID = this._lastBoundsID; }; -/** - * Fired when a pause event is triggered, stops the update loop - * - * @private - */ -VideoBaseTexture.prototype._onPlayStop = function () +Container.prototype._calculateBounds = function () { - this.autoUpdate = false; + //FILL IN// }; /** - * Fired when the video is loaded and ready to play + * Renders the object using the WebGL renderer * - * @private + * @param renderer {PIXI.WebGLRenderer} The renderer */ -VideoBaseTexture.prototype._onCanPlay = function () +Container.prototype.renderWebGL = function (renderer) { - this.hasLoaded = true; - if (this.source) + // if the object is not visible or the alpha is 0 then no need to render this element + if (!this.visible || this.worldAlpha <= 0 || !this.renderable) { - this.source.removeEventListener('canplay', this._onCanPlay); - this.source.removeEventListener('canplaythrough', this._onCanPlay); - this.width = this.source.videoWidth; - this.height = this.source.videoHeight; + return; + } - this.source.play(); + var i, j; - // prevent multiple loaded dispatches.. - if (!this.__loaded) + // do a quick check to see if this element has a mask or a filter. + if (this._mask || this._filters) + { + renderer.currentRenderer.flush(); + + // push filter first as we need to ensure the stencil buffer is correct for any masking + if (this._filters && this._filters.length) { - this.__loaded = true; - this.emit('loaded', this); + renderer.filterManager.pushFilter(this, this._filters); + } + + if (this._mask) + { + renderer.maskManager.pushMask(this, this._mask); + } + + renderer.currentRenderer.start(); + + // add this object to the batch, only rendered if it has a texture. + this._renderWebGL(renderer); + + // now loop through the children and make sure they get rendered + for (i = 0, j = this.children.length; i < j; i++) + { + this.children[i].renderWebGL(renderer); + } + + renderer.currentRenderer.flush(); + + if (this._mask) + { + renderer.maskManager.popMask(this, this._mask); + } + + if (this._filters) + { + renderer.filterManager.popFilter(); + + } + renderer.currentRenderer.start(); + } + else + { + this._renderWebGL(renderer); + + // simple render children! + for (i = 0, j = this.children.length; i < j; ++i) + { + this.children[i].renderWebGL(renderer); } } }; /** - * Destroys this texture + * To be overridden by the subclass * + * @param renderer {PIXI.WebGLRenderer} The renderer + * @private */ -VideoBaseTexture.prototype.destroy = function () +Container.prototype._renderWebGL = function (renderer) // jshint unused:false { - if (this.source && this.source._pixiId) - { - delete utils.BaseTextureCache[ this.source._pixiId ]; - delete this.source._pixiId; - } + // this is where content itself gets rendered... +}; - BaseTexture.prototype.destroy.call(this); +/** + * To be overridden by the subclass + * + * @param renderer {PIXI.CanvasRenderer} The renderer + * @private + */ +Container.prototype._renderCanvas = function (renderer) // jshint unused:false +{ + // this is where content itself gets rendered... }; + /** - * Mimic Pixi BaseTexture.from.... method. + * Renders the object using the Canvas renderer * - * @static - * @param video {HTMLVideoElement} - * @param scaleMode {number} See {@link PIXI.SCALE_MODES} for possible values - * @return {PIXI.VideoBaseTexture} + * @param renderer {PIXI.CanvasRenderer} The renderer */ -VideoBaseTexture.fromVideo = function (video, scaleMode) +Container.prototype.renderCanvas = function (renderer) { - if (!video._pixiId) + // if not visible or the alpha is 0 then no need to render this + if (!this.visible || this.alpha <= 0 || !this.renderable) { - video._pixiId = 'video_' + utils.uid(); + return; } - var baseTexture = utils.BaseTextureCache[video._pixiId]; + if (this._mask) + { + renderer.maskManager.pushMask(this._mask); + } - if (!baseTexture) + this._renderCanvas(renderer); + for (var i = 0, j = this.children.length; i < j; ++i) { - baseTexture = new VideoBaseTexture(video, scaleMode); - utils.BaseTextureCache[ video._pixiId ] = baseTexture; + this.children[i].renderCanvas(renderer); } - return baseTexture; + if (this._mask) + { + renderer.maskManager.popMask(renderer); + } }; /** - * Helper function that creates a new BaseTexture based on the given video element. - * This BaseTexture can then be used to create a texture - * - * @static - * @param videoSrc {string|object|string[]|object[]} The URL(s) for the video. - * @param [videoSrc.src] {string} One of the source urls for the video - * @param [videoSrc.mime] {string} The mimetype of the video (e.g. 'video/mp4'). If not specified - * the url's extension will be used as the second part of the mime type. - * @param scaleMode {number} See {@link PIXI.SCALE_MODES} for possible values - * @return {PIXI.VideoBaseTexture} + * Destroys the container + * @param [options] {object|boolean} Options parameter. A boolean will act as if all options have been set to that value + * @param [options.children=false] {boolean} if set to true, all the children will have their destroy + * method called as well. 'options' will be passed on to those calls. */ -VideoBaseTexture.fromUrl = function (videoSrc, scaleMode) +Container.prototype.destroy = function (options) { - var video = document.createElement('video'); + DisplayObject.prototype.destroy.call(this); - // array of objects or strings - if (Array.isArray(videoSrc)) + var destroyChildren = typeof options === 'boolean' ? options : options && options.children; + if (destroyChildren) { - for (var i = 0; i < videoSrc.length; ++i) + for (var i = 0, j = this.children.length; i < j; ++i) { - video.appendChild(createSource(videoSrc[i].src || videoSrc[i], videoSrc[i].mime)); + this.children[i].destroy(options); } } - // single object or string - else - { - video.appendChild(createSource(videoSrc.src || videoSrc, videoSrc.mime)); - } - video.load(); - video.play(); + this.removeChildren(); - return VideoBaseTexture.fromVideo(video, scaleMode); + this.children = null; }; - -VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; - -function createSource(path, type) -{ - if (!type) - { - type = 'video/' + path.substr(path.lastIndexOf('.') + 1); - } - - var source = document.createElement('source'); - - source.src = path; - source.type = type; - - return source; -} -},{"../utils":100,"./BaseTexture":91}],96:[function(require,module,exports){ -var CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +},{"../utils":115,"./DisplayObject":45}],45:[function(require,module,exports){ +var EventEmitter = require('eventemitter3'), + CONST = require('../const'), + TransformStatic = require('./TransformStatic'), + Transform = require('./Transform'), + Bounds = require('./Bounds'), + _tempDisplayObjectParent = new DisplayObject(); /** - * A Ticker class that runs an update loop that other objects listen to. - * This class is composed around an EventEmitter object to add listeners - * meant for execution on the next requested animation frame. - * Animation frames are requested only when necessary, - * e.g. When the ticker is started and the emitter has listeners. + * The base class for all objects that are rendered on the screen. + * This is an abstract class and should not be used on its own rather it should be extended. * * @class - * @memberof PIXI.ticker + * @extends EventEmitter + * @mixes PIXI.interaction.interactiveTarget + * @memberof PIXI */ -function Ticker() +function DisplayObject() { - var _this = this; + EventEmitter.call(this); + + var TransformClass = CONST.TRANSFORM_MODE.DEFAULT === CONST.TRANSFORM_MODE.STATIC ? TransformStatic : Transform; + + //TODO: need to create Transform from factory + /** + * World transform and local transform of this object. + * This will be reworked in v4.1, please do not use it yet unless you know what are you doing! + * + * @member {PIXI.TransformBase} + */ + this.transform = new TransformClass(); + + /** + * The opacity of the object. + * + * @member {number} + */ + this.alpha = 1; + + /** + * The visibility of the object. If false the object will not be drawn, and + * the updateTransform function will not be called. + * + * @member {boolean} + */ + this.visible = true; + + /** + * Can this object be rendered, if false the object will not be drawn but the updateTransform + * methods will still be called. + * + * @member {boolean} + */ + this.renderable = true; + + /** + * The display object container that contains this display object. + * + * @member {PIXI.Container} + * @readonly + */ + this.parent = null; + + /** + * The multiplied alpha of the displayObject + * + * @member {number} + * @readonly + */ + this.worldAlpha = 1; + + /** + * The area the filter is applied to. This is used as more of an optimisation + * rather than figuring out the dimensions of the displayObject each frame you can set this rectangle + * + * Also works as an interaction mask + * + * @member {PIXI.Rectangle} + */ + this.filterArea = null; /** - * Internal tick method bound to ticker instance. - * This is because in early 2015, Function.bind - * is still 60% slower in high performance scenarios. - * Also separating frame requests from update method - * so listeners may be called at any time and with - * any animation API, just invoke ticker.update(time). + * The bounds object, this is used to calculate and store the bounds of the displayObject * + * @member {PIXI.Rectangle} * @private */ - this._tick = function _tick(time) { + this._bounds = new Bounds(); + this._boundsID = 0; + this._lastBoundsID = -1; - _this._requestId = null; + /** + * The original, cached mask of the object + * + * @member {PIXI.Rectangle} + * @private + */ + this._mask = null; - if (_this.started) + +} + +// constructor +DisplayObject.prototype = Object.create(EventEmitter.prototype); +DisplayObject.prototype.constructor = DisplayObject; +module.exports = DisplayObject; + + +Object.defineProperties(DisplayObject.prototype, { + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * An alias to position.x + * + * @member {number} + * @memberof PIXI.DisplayObject# + */ + x: { + get: function () { - // Invoke listeners now - _this.update(time); - // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) - { - _this._requestId = requestAnimationFrame(_this._tick); - } + return this.position.x; + }, + set: function (value) + { + this.transform.position.x = value; } - }; + }, /** - * Internal emitter used to fire 'tick' event - * @private + * The position of the displayObject on the y axis relative to the local coordinates of the parent. + * An alias to position.y + * + * @member {number} + * @memberof PIXI.DisplayObject# */ - this._emitter = new EventEmitter(); + y: { + get: function () + { + return this.position.y; + }, + set: function (value) + { + this.transform.position.y = value; + } + }, /** - * Internal current frame request ID - * @private + * Current transform of the object based on world (parent) factors + * + * @member {PIXI.Matrix} + * @memberof PIXI.DisplayObject# + * @readonly */ - this._requestId = null; + worldTransform: { + get: function () + { + return this.transform.worldTransform; + } + }, /** - * Internal value managed by minFPS property setter and getter. - * This is the maximum allowed milliseconds between updates. - * @private + * Current transform of the object based on local factors: position, scale, other stuff + * + * @member {PIXI.Matrix} + * @memberof PIXI.DisplayObject# + * @readonly */ - this._maxElapsedMS = 100; + localTransform: { + get: function () + { + return this.transform.localTransform; + } + }, /** - * Whether or not this ticker should invoke the method - * {@link PIXI.ticker.Ticker#start} automatically - * when a listener is added. + * The coordinate of the object relative to the local coordinates of the parent. + * Assignment by value since pixi-v4. * - * @member {boolean} - * @default false + * @member {PIXI.Point|PIXI.ObservablePoint} + * @memberof PIXI.DisplayObject# */ - this.autoStart = false; + position: { + get: function() + { + return this.transform.position; + }, + set: function(value) { + this.transform.position.copy(value); + } + }, /** - * Scalar time value from last frame to this frame. - * This value is capped by setting {@link PIXI.ticker.Ticker#minFPS} - * and is scaled with {@link PIXI.ticker.Ticker#speed}. - * **Note:** The cap may be exceeded by scaling. + * The scale factor of the object. + * Assignment by value since pixi-v4. * - * @member {number} - * @default 1 + * @member {PIXI.Point|PIXI.ObservablePoint} + * @memberof PIXI.DisplayObject# */ - this.deltaTime = 1; + scale: { + get: function() { + return this.transform.scale; + }, + set: function(value) { + this.transform.scale.copy(value); + } + }, /** - * Time elapsed in milliseconds from last frame to this frame. - * Opposed to what the scalar {@link PIXI.ticker.Ticker#deltaTime} - * is based, this value is neither capped nor scaled. - * If the platform supports DOMHighResTimeStamp, - * this value will have a precision of 1 µs. + * The pivot point of the displayObject that it rotates around + * Assignment by value since pixi-v4. * - * @member {DOMHighResTimeStamp|number} - * @default 1 / TARGET_FPMS + * @member {PIXI.Point|PIXI.ObservablePoint} + * @memberof PIXI.DisplayObject# */ - this.elapsedMS = 1 / CONST.TARGET_FPMS; // default to target frame time + pivot: { + get: function() { + return this.transform.pivot; + }, + set: function(value) { + this.transform.pivot.copy(value); + } + }, /** - * The last time {@link PIXI.ticker.Ticker#update} was invoked. - * This value is also reset internally outside of invoking - * update, but only when a new animation frame is requested. - * If the platform supports DOMHighResTimeStamp, - * this value will have a precision of 1 µs. + * The skew factor for the object in radians. + * Assignment by value since pixi-v4. * - * @member {DOMHighResTimeStamp|number} - * @default 0 + * @member {PIXI.ObservablePoint} + * @memberof PIXI.DisplayObject# */ - this.lastTime = 0; + skew: { + get: function() { + return this.transform.skew; + }, + set: function(value) { + this.transform.skew.copy(value); + } + }, /** - * Factor of current {@link PIXI.ticker.Ticker#deltaTime}. - * @example - * // Scales ticker.deltaTime to what would be - * // the equivalent of approximately 120 FPS - * ticker.speed = 2; + * The rotation of the object in radians. * * @member {number} - * @default 1 + * @memberof PIXI.DisplayObject# */ - this.speed = 1; + rotation: { + get: function () + { + return this.transform.rotation; + }, + set: function (value) + { + this.transform.rotation = value; + } + }, /** - * Whether or not this ticker has been started. - * `true` if {@link PIXI.ticker.Ticker#start} has been called. - * `false` if {@link PIXI.ticker.Ticker#stop} has been called. - * While `false`, this value may change to `true` in the - * event of {@link PIXI.ticker.Ticker#autoStart} being `true` - * and a listener is added. + * Indicates if the sprite is globally visible. * * @member {boolean} - * @default false + * @memberof PIXI.DisplayObject# + * @readonly */ - this.started = false; -} + worldVisible: { + get: function () + { + var item = this; + + do { + if (!item.visible) + { + return false; + } + + item = item.parent; + } while (item); + + return true; + } + }, -Object.defineProperties(Ticker.prototype, { /** - * The frames per second at which this ticker is running. - * The default is approximately 60 in most modern browsers. - * **Note:** This does not factor in the value of - * {@link PIXI.ticker.Ticker#speed}, which is specific - * to scaling {@link PIXI.ticker.Ticker#deltaTime}. + * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. + * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. + * To remove a mask, set this property to null. * - * @member - * @memberof PIXI.ticker.Ticker# - * @readonly + * @todo For the moment, PIXI.CanvasRenderer doesn't support PIXI.Sprite as mask. + * + * @member {PIXI.Graphics|PIXI.Sprite} + * @memberof PIXI.DisplayObject# */ - FPS: { - get: function() + mask: { + get: function () { - return 1000 / this.elapsedMS; + return this._mask; + }, + set: function (value) + { + if (this._mask) + { + this._mask.renderable = true; + } + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } } }, /** - * Manages the maximum amount of milliseconds allowed to - * elapse between invoking {@link PIXI.ticker.Ticker#update}. - * This value is used to cap {@link PIXI.ticker.Ticker#deltaTime}, - * but does not effect the measured value of {@link PIXI.ticker.Ticker#FPS}. - * When setting this property it is clamped to a value between - * `0` and `PIXI.TARGET_FPMS * 1000`. + * Sets the filters for the displayObject. + * * IMPORTANT: This is a webGL only feature and will be ignored by the canvas renderer. + * To remove filters simply set this property to 'null' * - * @member - * @memberof PIXI.ticker.Ticker# - * @default 10 + * @member {PIXI.AbstractFilter[]} + * @memberof PIXI.DisplayObject# */ - minFPS: { - get: function() + filters: { + get: function () { - return 1000 / this._maxElapsedMS; + return this._filters && this._filters.slice(); }, - set: function(fps) + set: function (value) { - // Clamp: 0 to TARGET_FPMS - var minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; + this._filters = value && value.slice(); } } + }); +/* + * Updates the object transform for rendering + * + * TODO - Optimization pass! + */ +DisplayObject.prototype.updateTransform = function () +{ + this.transform.updateTransform(this.parent.transform); + // multiply the alphas.. + this.worldAlpha = this.alpha * this.parent.worldAlpha; + + this._bounds.updateID++; +}; + +// performance increase to avoid using call.. (10x faster) +DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +/** + * recursively updates transform of all objects from the root to this one + * internal function for toLocal() + */ +DisplayObject.prototype._recursivePostUpdateTransform = function() +{ + if (this.parent) + { + this.parent._recursivePostUpdateTransform(); + this.transform.updateTransform(this.parent.transform); + } + else + { + this.transform.updateTransform(_tempDisplayObjectParent.transform); + } +}; + /** - * Conditionally requests a new animation frame. - * If a frame has not already been requested, and if the internal - * emitter has listeners, a new frame is requested. * - * @private + * + * Retrieves the bounds of the displayObject as a rectangle object + * + * @return {PIXI.Rectangle} the rectangular bounding area */ -Ticker.prototype._requestIfNeeded = function _requestIfNeeded() +DisplayObject.prototype.getBounds = function (skipUpdate) { - if (this._requestId === null && this._emitter.listeners(TICK, true)) + if(!skipUpdate) { - // ensure callbacks get correct delta - this.lastTime = performance.now(); - this._requestId = requestAnimationFrame(this._tick); + if(!this.parent) + { + this.parent = _tempDisplayObjectParent; + this.updateTransform(); + this.parent = null; + } + else + { + this._recursivePostUpdateTransform(); + this.updateTransform(); + } + } + + if(this._boundsID !== this._lastBoundsID) + { + this.calculateBounds(); } + + return this._bounds.getRectangle(this._bounds); }; /** - * Conditionally cancels a pending animation frame. + * Retrieves the local bounds of the displayObject as a rectangle object * - * @private + * @return {PIXI.Rectangle} the rectangular bounding area */ -Ticker.prototype._cancelIfNeeded = function _cancelIfNeeded() +DisplayObject.prototype.getLocalBounds = function () { - if (this._requestId !== null) + var transformRef = this.transform; + var parentRef = this.parent; + + this.parent = null; + this.transform = _tempDisplayObjectParent.transform; + + var bounds = this.getBounds(); + + this.parent = parentRef; + this.transform = transformRef; + + return bounds; +}; + +/** + * Calculates the global position of the display object + * + * @param position {PIXI.Point} The world origin to calculate from + * @return {PIXI.Point} A point object representing the position of this object + */ +DisplayObject.prototype.toGlobal = function (position, point, skipUpdate) +{ + if(!skipUpdate) { - cancelAnimationFrame(this._requestId); - this._requestId = null; + this._recursivePostUpdateTransform(); + + // this parent check is for just in case the item is a root object. + // If it is we need to give it a temporary parent so that displayObjectUpdateTransform works correctly + // this is mainly to avoid a parent check in the main loop. Every little helps for performance :) + if(!this.parent) + { + this.parent = _tempDisplayObjectParent; + this.displayObjectUpdateTransform(); + this.parent = null; + } + else + { + this.displayObjectUpdateTransform(); + } } + + // don't need to update the lot + return this.worldTransform.apply(position, point); }; /** - * Conditionally requests a new animation frame. - * If the ticker has been started it checks if a frame has not already - * been requested, and if the internal emitter has listeners. If these - * conditions are met, a new frame is requested. If the ticker has not - * been started, but autoStart is `true`, then the ticker starts now, - * and continues with the previous conditions to request a new frame. + * Calculates the local position of the display object relative to another point * - * @private + * @param position {PIXI.Point} The world origin to calculate from + * @param [from] {PIXI.DisplayObject} The DisplayObject to calculate the global position from + * @param [point] {PIXI.Point} A Point object in which to store the value, optional (otherwise will create a new Point) + * @return {PIXI.Point} A point object representing the position of this object */ -Ticker.prototype._startIfPossible = function _startIfPossible() +DisplayObject.prototype.toLocal = function (position, from, point, skipUpdate) { - if (this.started) + if (from) { - this._requestIfNeeded(); + position = from.toGlobal(position, point, skipUpdate); } - else if (this.autoStart) + + if(! skipUpdate) { - this.start(); + this._recursivePostUpdateTransform(); + + // this parent check is for just in case the item is a root object. + // If it is we need to give it a temporary parent so that displayObjectUpdateTransform works correctly + // this is mainly to avoid a parent check in the main loop. Every little helps for performance :) + if(!this.parent) + { + this.parent = _tempDisplayObjectParent; + this.displayObjectUpdateTransform(); + this.parent = null; + } + else + { + this.displayObjectUpdateTransform(); + } } + + // simply apply the matrix.. + return this.worldTransform.applyInverse(position, point); }; /** - * Calls {@link module:eventemitter3.EventEmitter#on} internally for the - * internal 'tick' event. It checks if the emitter has listeners, - * and if so it requests a new animation frame at this point. + * Renders the object using the WebGL renderer * - * @param fn {Function} The listener function to be added for updates - * @param [context] {Function} The listener context - * @returns {PIXI.ticker.Ticker} this + * @param renderer {PIXI.WebGLRenderer} The renderer */ -Ticker.prototype.add = function add(fn, context) +DisplayObject.prototype.renderWebGL = function (renderer) // jshint unused:false { - this._emitter.on(TICK, fn, context); + // OVERWRITE; +}; + +/** + * Renders the object using the Canvas renderer + * + * @param renderer {PIXI.CanvasRenderer} The renderer + */ +DisplayObject.prototype.renderCanvas = function (renderer) // jshint unused:false +{ + // OVERWRITE; +}; + +/** + * Set the parent Container of this DisplayObject + * + * @param container {PIXI.Container} The Container to add this DisplayObject to + * @return {PIXI.Container} The Container that this DisplayObject was added to + */ +DisplayObject.prototype.setParent = function (container) +{ + if (!container || !container.addChild) + { + throw new Error('setParent: Argument must be a Container'); + } + + container.addChild(this); + return container; +}; + +/** + * Convenience function to set the postion, scale, skew and pivot at once. + * + * @param [x=0] {number} The X position + * @param [y=0] {number} The Y position + * @param [scaleX=1] {number} The X scale value + * @param [scaleY=1] {number} The Y scale value + * @param [rotation=0] {number} The rotation + * @param [skewX=0] {number} The X skew value + * @param [skewY=0] {number} The Y skew value + * @param [pivotX=0] {number} The X pivot value + * @param [pivotY=0] {number} The Y pivot value + * @return {PIXI.DisplayObject} The DisplayObject instance + */ +DisplayObject.prototype.setTransform = function(x, y, scaleX, scaleY, rotation, skewX, skewY, pivotX, pivotY) //jshint ignore:line +{ + this.position.x = x || 0; + this.position.y = y || 0; + this.scale.x = !scaleX ? 1 : scaleX; + this.scale.y = !scaleY ? 1 : scaleY; + this.rotation = rotation || 0; + this.skew.x = skewX || 0; + this.skew.y = skewY || 0; + this.pivot.x = pivotX || 0; + this.pivot.y = pivotY || 0; + return this; +}; + +/** + * Base destroy method for generic display objects + * + */ +DisplayObject.prototype.destroy = function () +{ + this.transform = null; + + this.parent = null; + + this._bounds = null; + this._currentBounds = null; + this._mask = null; + + this.filterArea = null; +}; + +},{"../const":42,"./Bounds":43,"./Transform":46,"./TransformStatic":48,"eventemitter3":4}],46:[function(require,module,exports){ +var math = require('../math'), + TransformBase = require('./TransformBase'); + + +/** + * Generic class to deal with traditional 2D matrix transforms + * local transformation is calculated from position,scale,skew and rotation + * + * @class + * @extends PIXI.TransformBase + * @memberof PIXI + */ +function Transform() +{ + TransformBase.call(this); + + /** + * The coordinate of the object relative to the local coordinates of the parent. + * + * @member {PIXI.Point} + */ + this.position = new math.Point(0.0); + + /** + * The scale factor of the object. + * + * @member {PIXI.Point} + */ + this.scale = new math.Point(1,1); + + /** + * The skew amount, on the x and y axis. + * + * @member {PIXI.ObservablePoint} + */ + this.skew = new math.ObservablePoint(this.updateSkew, this, 0,0); + + /** + * The pivot point of the displayObject that it rotates around + * + * @member {PIXI.Point} + */ + this.pivot = new math.Point(0.0); + + /** + * The rotation value of the object, in radians + * + * @member {Number} + * @private + */ + this._rotation = 0; + + this._sr = Math.sin(0); + this._cr = Math.cos(0); + this._cy = Math.cos(0);//skewY); + this._sy = Math.sin(0);//skewY); + this._nsx = Math.sin(0);//skewX); + this._cx = Math.cos(0);//skewX); +} - this._startIfPossible(); +Transform.prototype = Object.create(TransformBase.prototype); +Transform.prototype.constructor = Transform; - return this; +Transform.prototype.updateSkew = function () +{ + this._cy = Math.cos(this.skew.y); + this._sy = Math.sin(this.skew.y); + this._nsx = Math.sin(this.skew.x); + this._cx = Math.cos(this.skew.x); }; /** - * Calls {@link module:eventemitter3.EventEmitter#once} internally for the - * internal 'tick' event. It checks if the emitter has listeners, - * and if so it requests a new animation frame at this point. - * - * @param fn {Function} The listener function to be added for one update - * @param [context] {Function} The listener context - * @returns {PIXI.ticker.Ticker} this + * Updates only local matrix */ -Ticker.prototype.addOnce = function addOnce(fn, context) -{ - this._emitter.once(TICK, fn, context); +Transform.prototype.updateLocalTransform = function() { + var lt = this.localTransform; + var a, b, c, d; - this._startIfPossible(); + a = this._cr * this.scale.x; + b = this._sr * this.scale.x; + c = -this._sr * this.scale.y; + d = this._cr * this.scale.y; - return this; + lt.a = this._cy * a + this._sy * c; + lt.b = this._cy * b + this._sy * d; + lt.c = this._nsx * a + this._cx * c; + lt.d = this._nsx * b + this._cx * d; }; /** - * Calls {@link module:eventemitter3.EventEmitter#off} internally for 'tick' event. - * It checks if the emitter has listeners for 'tick' event. - * If it does, then it cancels the animation frame. - * - * @param [fn] {Function} The listener function to be removed - * @param [context] {Function} The listener context to be removed - * @returns {PIXI.ticker.Ticker} this + * Updates the values of the object and applies the parent's transform. + * @param parentTransform {PIXI.Transform} The transform of the parent of this object */ -Ticker.prototype.remove = function remove(fn, context) +Transform.prototype.updateTransform = function (parentTransform) { - this._emitter.off(TICK, fn, context); - if (!this._emitter.listeners(TICK, true)) - { - this._cancelIfNeeded(); - } + var pt = parentTransform.worldTransform; + var wt = this.worldTransform; + var lt = this.localTransform; + var a, b, c, d; - return this; -}; + a = this._cr * this.scale.x; + b = this._sr * this.scale.x; + c = -this._sr * this.scale.y; + d = this._cr * this.scale.y; -/** - * Starts the ticker. If the ticker has listeners - * a new animation frame is requested at this point. - */ -Ticker.prototype.start = function start() -{ - if (!this.started) - { - this.started = true; - this._requestIfNeeded(); - } -}; + lt.a = this._cy * a + this._sy * c; + lt.b = this._cy * b + this._sy * d; + lt.c = this._nsx * a + this._cx * c; + lt.d = this._nsx * b + this._cx * d; -/** - * Stops the ticker. If the ticker has requested - * an animation frame it is canceled at this point. - */ -Ticker.prototype.stop = function stop() -{ - if (this.started) - { - this.started = false; - this._cancelIfNeeded(); - } + lt.tx = this.position.x - (this.pivot.x * lt.a + this.pivot.y * lt.c); + lt.ty = this.position.y - (this.pivot.x * lt.b + this.pivot.y * lt.d); + + // concat the parent matrix with the objects transform. + wt.a = lt.a * pt.a + lt.b * pt.c; + wt.b = lt.a * pt.b + lt.b * pt.d; + wt.c = lt.c * pt.a + lt.d * pt.c; + wt.d = lt.c * pt.b + lt.d * pt.d; + wt.tx = lt.tx * pt.a + lt.ty * pt.c + pt.tx; + wt.ty = lt.tx * pt.b + lt.ty * pt.d + pt.ty; + + this._worldID ++; }; /** - * Triggers an update. An update entails setting the - * current {@link PIXI.ticker.Ticker#elapsedMS}, - * the current {@link PIXI.ticker.Ticker#deltaTime}, - * invoking all listeners with current deltaTime, - * and then finally setting {@link PIXI.ticker.Ticker#lastTime} - * with the value of currentTime that was provided. - * This method will be called automatically by animation - * frame callbacks if the ticker instance has been started - * and listeners are added. - * - * @param [currentTime=performance.now()] {DOMHighResTimeStamp|number} the current time of execution + * Decomposes a matrix and sets the transforms properties based on it. + * @param {PIXI.Matrix} The matrix to decompose */ -Ticker.prototype.update = function update(currentTime) +Transform.prototype.setFromMatrix = function (matrix) { - var elapsedMS; + matrix.decompose(this); +}; - // Allow calling update directly with default currentTime. - currentTime = currentTime || performance.now(); - // Save uncapped elapsedMS for measurement - elapsedMS = this.elapsedMS = currentTime - this.lastTime; - // cap the milliseconds elapsed used for deltaTime - if (elapsedMS > this._maxElapsedMS) - { - elapsedMS = this._maxElapsedMS; +Object.defineProperties(Transform.prototype, { + /** + * The rotation of the object in radians. + * + * @member {number} + * @memberof PIXI.Transform# + */ + rotation: { + get: function () { + return this._rotation; + }, + set: function (value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } } +}); - this.deltaTime = elapsedMS * CONST.TARGET_FPMS * this.speed; - - // Invoke listeners added to internal emitter - this._emitter.emit(TICK, this.deltaTime); - - this.lastTime = currentTime; -}; - -module.exports = Ticker; +module.exports = Transform; -},{"../const":33,"eventemitter3":12}],97:[function(require,module,exports){ -var Ticker = require('./Ticker'); +},{"../math":66,"./TransformBase":47}],47:[function(require,module,exports){ +var math = require('../math'); -/** - * The shared ticker instance used by {@link PIXI.extras.MovieClip}. - * and by {@link PIXI.interaction.InteractionManager}. - * The property {@link PIXI.ticker.Ticker#autoStart} is set to `true` - * for this instance. Please follow the examples for usage, including - * how to opt-out of auto-starting the shared ticker. - * - * @example - * var ticker = PIXI.ticker.shared; - * // Set this to prevent starting this ticker when listeners are added. - * // By default this is true only for the PIXI.ticker.shared instance. - * ticker.autoStart = false; - * // FYI, call this to ensure the ticker is stopped. It should be stopped - * // if you have not attempted to render anything yet. - * ticker.stop(); - * // Call this when you are ready for a running shared ticker. - * ticker.start(); - * - * @example - * // You may use the shared ticker to render... - * var renderer = PIXI.autoDetectRenderer(800, 600); - * var stage = new PIXI.Container(); - * var interactionManager = PIXI.interaction.InteractionManager(renderer); - * document.body.appendChild(renderer.view); - * ticker.add(function (time) { - * renderer.render(stage); - * }); - * - * @example - * // Or you can just update it manually. - * ticker.autoStart = false; - * ticker.stop(); - * function animate(time) { - * ticker.update(time); - * renderer.render(stage); - * requestAnimationFrame(animate); - * } - * animate(performance.now()); - * - * @type {PIXI.ticker.Ticker} - * @memberof PIXI.ticker - */ -var shared = new Ticker(); -shared.autoStart = true; /** - * @namespace PIXI.ticker - */ -module.exports = { - shared: shared, - Ticker: Ticker -}; - -},{"./Ticker":96}],98:[function(require,module,exports){ -/** - * Generic Mask Stack data structure + * Generic class to deal with traditional 2D matrix transforms + * * @class * @memberof PIXI */ - -var createIndicesForQuads = function (size) +function TransformBase() { - // the total number of indices in our array, there are 6 points per quad. - - var totalIndices = size * 6; - - var indices = new Uint16Array(totalIndices); - - // fill the indices with the quads to draw - for (var i=0, j=0; i < totalIndices; i += 6, j += 4) - { - indices[i + 0] = j + 0; - indices[i + 1] = j + 1; - indices[i + 2] = j + 2; - indices[i + 3] = j + 0; - indices[i + 4] = j + 2; - indices[i + 5] = j + 3; - } - - return indices; -}; - -module.exports = createIndicesForQuads; - -},{}],99:[function(require,module,exports){ -var tempAnchor; -var _url = require('url'); - -/** - * Sets the `crossOrigin` property for this resource based on if the url - * for this resource is cross-origin. If crossOrigin was manually set, this - * function does nothing. - * Nipped from the resource loader! - * @private - * @param url {string} The url to test. - * @param [location=window.location] {object} The location object to test against. - * @return {string} The crossOrigin value to use (or empty string for none). - */ -var determineCrossOrigin = function (url, loc) { - // data: and javascript: urls are considered same-origin - if (url.indexOf('data:') === 0) { - return ''; - } - - // default is window.location - loc = loc || window.location; - - if (!tempAnchor) { - tempAnchor = document.createElement('a'); - } + /** + * The global matrix transform. It can be swapped temporarily by some functions like getLocalBounds() + * + * @member {PIXI.Matrix} + */ + this.worldTransform = new math.Matrix(); + /** + * The local matrix transform + * + * @member {PIXI.Matrix} + */ + this.localTransform = new math.Matrix(); - // let the browser determine the full href for the url of this resource and then - // parse with the node url lib, we can't use the properties of the anchor element - // because they don't work in IE9 :( - tempAnchor.href = url; - url = _url.parse(tempAnchor.href); + this._worldID = 0; +} - var samePort = (!url.port && loc.port === '') || (url.port === loc.port); +TransformBase.prototype.constructor = TransformBase; - // if cross origin - if (url.hostname !== loc.hostname || !samePort || url.protocol !== loc.protocol) { - return 'anonymous'; - } +/** + * TransformBase does not have decomposition, so this function wont do anything + */ +TransformBase.prototype.updateLocalTransform = function() { // jshint unused:false - return ''; }; -module.exports = determineCrossOrigin; -},{"url":10}],100:[function(require,module,exports){ -var CONST = require('../const'); - /** - * @namespace PIXI.utils + * Updates the values of the object and applies the parent's transform. + * @param parentTransform {PIXI.TransformBase} The transform of the parent of this object + * */ -var utils = module.exports = { - _uid: 0, - _saidHello: false, +TransformBase.prototype.updateTransform = function (parentTransform) +{ + var pt = parentTransform.worldTransform; + var wt = this.worldTransform; + var lt = this.localTransform; - EventEmitter: require('eventemitter3'), - pluginTarget: require('./pluginTarget'), + // concat the parent matrix with the objects transform. + wt.a = lt.a * pt.a + lt.b * pt.c; + wt.b = lt.a * pt.b + lt.b * pt.d; + wt.c = lt.c * pt.a + lt.d * pt.c; + wt.d = lt.c * pt.b + lt.d * pt.d; + wt.tx = lt.tx * pt.a + lt.ty * pt.c + pt.tx; + wt.ty = lt.tx * pt.b + lt.ty * pt.d + pt.ty; - /** - * Gets the next unique identifier - * - * @return {number} The next unique identifier to use. - */ - uid: function () - { - return ++utils._uid; - }, + this._worldID ++; +}; - /** - * Converts a hex color number to an [R, G, B] array - * - * @param hex {number} - * @param {number[]} [out=[]] - * @return {number[]} An array representing the [R, G, B] of the color. - */ - hex2rgb: function (hex, out) - { - out = out || []; +/** + * Updates the values of the object and applies the parent's transform. + * @param parentTransform {PIXI.Transform} The transform of the parent of this object + * + */ +TransformBase.prototype.updateWorldTransform = TransformBase.prototype.updateTransform; - out[0] = (hex >> 16 & 0xFF) / 255; - out[1] = (hex >> 8 & 0xFF) / 255; - out[2] = (hex & 0xFF) / 255; +TransformBase.IDENTITY = new TransformBase(); - return out; - }, +module.exports = TransformBase; + +},{"../math":66}],48:[function(require,module,exports){ +var math = require('../math'), + TransformBase = require('./TransformBase'); - /** - * Converts a hex color number to a string. +/** + * Transform that takes care about its versions + * + * @class + * @extends PIXI.TransformBase + * @memberof PIXI + */ +function TransformStatic() +{ + TransformBase.call(this); + /** + * The coordinate of the object relative to the local coordinates of the parent. * - * @param hex {number} - * @return {string} The string color. + * @member {PIXI.ObservablePoint} */ - hex2string: function (hex) - { - hex = hex.toString(16); - hex = '000000'.substr(0, 6 - hex.length) + hex; - - return '#' + hex; - }, + this.position = new math.ObservablePoint(this.onChange, this,0.0); /** - * Converts a color as an [R, G, B] array to a hex number + * The scale factor of the object. * - * @param rgb {number[]} - * @return {number} The color number + * @member {PIXI.ObservablePoint} */ - rgb2hex: function (rgb) - { - return ((rgb[0]*255 << 16) + (rgb[1]*255 << 8) + rgb[2]*255); - }, - + this.scale = new math.ObservablePoint(this.onChange, this,1,1); /** - * get the resolution of an asset by looking for the prefix - * used by spritesheets and image urls + * The pivot point of the displayObject that it rotates around * - * @param url {string} the image path - * @return {number} + * @member {PIXI.ObservablePoint} */ - getResolutionOfUrl: function (url) - { - var resolution = CONST.RETINA_PREFIX.exec(url); - - if (resolution) - { - return parseFloat(resolution[1]); - } - - return 1; - }, + this.pivot = new math.ObservablePoint(this.onChange, this,0, 0); /** - * Logs out the version and renderer information for this running instance of PIXI. - * If you don't want to see this message you can set `PIXI.utils._saidHello = true;` - * so the library thinks it already said it. Keep in mind that doing that will forever - * makes you a jerk face. + * The skew amount, on the x and y axis. * - * @param {string} type - The string renderer type to log. - * @constant - * @static + * @member {PIXI.ObservablePoint} */ - sayHello: function (type) - { - if (utils._saidHello) - { - return; - } + this.skew = new math.ObservablePoint(this.updateSkew, this,0, 0); - if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1) - { - var args = [ - '\n %c %c %c Pixi.js ' + CONST.VERSION + ' - ✰ ' + type + ' ✰ %c ' + ' %c ' + ' http://www.pixijs.com/ %c %c ♥%c♥%c♥ \n\n', - 'background: #ff66a5; padding:5px 0;', - 'background: #ff66a5; padding:5px 0;', - 'color: #ff66a5; background: #030307; padding:5px 0;', - 'background: #ff66a5; padding:5px 0;', - 'background: #ffc3dc; padding:5px 0;', - 'background: #ff66a5; padding:5px 0;', - 'color: #ff2424; background: #fff; padding:5px 0;', - 'color: #ff2424; background: #fff; padding:5px 0;', - 'color: #ff2424; background: #fff; padding:5px 0;' - ]; + this._rotation = 0; - window.console.log.apply(console, args); //jshint ignore:line - } - else if (window.console) - { - window.console.log('Pixi.js ' + CONST.VERSION + ' - ' + type + ' - http://www.pixijs.com/'); //jshint ignore:line - } + this._sr = Math.sin(0); + this._cr = Math.cos(0); + this._cy = Math.cos(0);//skewY); + this._sy = Math.sin(0);//skewY); + this._nsx = Math.sin(0);//skewX); + this._cx = Math.cos(0);//skewX); - utils._saidHello = true; - }, + this._currentLocalID = 0; +} - /** - * Helper for checking for webgl support - * - * @return {boolean} - */ - isWebGLSupported: function () - { - var contextOptions = { stencil: true }; - try - { - if (!window.WebGLRenderingContext) - { - return false; - } +TransformStatic.prototype = Object.create(TransformBase.prototype); +TransformStatic.prototype.constructor = TransformStatic; - var canvas = document.createElement('canvas'), - gl = canvas.getContext('webgl', contextOptions) || canvas.getContext('experimental-webgl', contextOptions); +TransformStatic.prototype.onChange = function () +{ + this._localID ++; +}; - return !!(gl && gl.getContextAttributes().stencil); - } - catch (e) - { - return false; - } - }, +TransformStatic.prototype.updateSkew = function () +{ + this._cy = Math.cos(this.skew.y); + this._sy = Math.sin(this.skew.y); + this._nsx = Math.sin(this.skew.x); + this._cx = Math.cos(this.skew.x); - /** - * Returns sign of number - * - * @param n {number} - * @returns {number} 0 if n is 0, -1 if n is negative, 1 if n i positive - */ - sign: function (n) - { - return n ? (n < 0 ? -1 : 1) : 0; - }, + this._localID ++; +}; - /** - * removeItems - * - * @param {array} arr The target array - * @param {number} startIdx The index to begin removing from (inclusive) - * @param {number} removeCount How many items to remove - */ - removeItems: function (arr, startIdx, removeCount) +/** + * Updates only local matrix + */ +TransformStatic.prototype.updateLocalTransform = function() { + var lt = this.localTransform; + if(this._localID !== this._currentLocalID) { - var length = arr.length; - - if (startIdx >= length || removeCount === 0) - { - return; - } + // get the matrix values of the displayobject based on its transform properties.. + var a,b,c,d; - removeCount = (startIdx+removeCount > length ? length-startIdx : removeCount); - for (var i = startIdx, len = length-removeCount; i < len; ++i) - { - arr[i] = arr[i + removeCount]; - } + a = this._cr * this.scale.x; + b = this._sr * this.scale.x; + c = -this._sr * this.scale.y; + d = this._cr * this.scale.y; - arr.length = len; - }, + lt.a = this._cy * a + this._sy * c; + lt.b = this._cy * b + this._sy * d; + lt.c = this._nsx * a + this._cx * c; + lt.d = this._nsx * b + this._cx * d; - /** - * @todo Describe property usage - * @private - */ - TextureCache: {}, + lt.tx = this.position._x - (this.pivot._x * lt.a + this.pivot._y * lt.c); + lt.ty = this.position._y - (this.pivot._x * lt.b + this.pivot._y * lt.d); + this._currentLocalID = this._localID; - /** - * @todo Describe property usage - * @private - */ - BaseTextureCache: {} + // force an update.. + this._parentID = -1; + } }; - -},{"../const":33,"./pluginTarget":102,"eventemitter3":12}],101:[function(require,module,exports){ - - -var Device = require('ismobilejs'); - -var maxRecommendedTextures = function(max) -{ - - if(Device.tablet || Device.phone) - { - // check if the res is iphone 6 or higher.. - return 2; - } - else - { - // desktop should be ok - return max; - } -} -module.exports = maxRecommendedTextures; -},{"ismobilejs":13}],102:[function(require,module,exports){ /** - * Mixins functionality to make an object have "plugins". - * - * @mixin - * @memberof PIXI.utils - * @param obj {object} The object to mix into. - * @example - * function MyObject() {} + * Updates the values of the object and applies the parent's transform. + * @param parentTransform {PIXI.Transform} The transform of the parent of this object * - * pluginTarget.mixin(MyObject); */ -function pluginTarget(obj) +TransformStatic.prototype.updateTransform = function (parentTransform) { - obj.__plugins = {}; + var pt = parentTransform.worldTransform; + var wt = this.worldTransform; + var lt = this.localTransform; - /** - * Adds a plugin to an object - * - * @param pluginName {string} The events that should be listed. - * @param ctor {Function} The constructor function for the plugin. - */ - obj.registerPlugin = function (pluginName, ctor) + if(this._localID !== this._currentLocalID) { - obj.__plugins[pluginName] = ctor; - }; + // get the matrix values of the displayobject based on its transform properties.. + var a,b,c,d; - /** - * Instantiates all the plugins of this object - * - */ - obj.prototype.initPlugins = function () - { - this.plugins = this.plugins || {}; + a = this._cr * this.scale.x; + b = this._sr * this.scale.x; + c = -this._sr * this.scale.y; + d = this._cr * this.scale.y; + + lt.a = this._cy * a + this._sy * c; + lt.b = this._cy * b + this._sy * d; + lt.c = this._nsx * a + this._cx * c; + lt.d = this._nsx * b + this._cx * d; + + lt.tx = this.position._x - (this.pivot._x * lt.a + this.pivot._y * lt.c); + lt.ty = this.position._y - (this.pivot._x * lt.b + this.pivot._y * lt.d); + this._currentLocalID = this._localID; - for (var o in obj.__plugins) - { - this.plugins[o] = new (obj.__plugins[o])(this); - } - }; + // force an update.. + this._parentID = -1; + } - /** - * Removes all the plugins of this object - * - */ - obj.prototype.destroyPlugins = function () + if(this._parentID !== parentTransform._worldID) { - for (var o in this.plugins) - { - this.plugins[o].destroy(); - this.plugins[o] = null; - } + // concat the parent matrix with the objects transform. + wt.a = lt.a * pt.a + lt.b * pt.c; + wt.b = lt.a * pt.b + lt.b * pt.d; + wt.c = lt.c * pt.a + lt.d * pt.c; + wt.d = lt.c * pt.b + lt.d * pt.d; + wt.tx = lt.tx * pt.a + lt.ty * pt.c + pt.tx; + wt.ty = lt.tx * pt.b + lt.ty * pt.d + pt.ty; - this.plugins = null; - }; -} + this._parentID = parentTransform._worldID; + // update the id of the transform.. + this._worldID ++; + } +}; -module.exports = { +/** + * Decomposes a matrix and sets the transforms properties based on it. + * @param {PIXI.Matrix} The matrix to decompose + */ +TransformStatic.prototype.setFromMatrix = function (matrix) +{ + matrix.decompose(this); + this._localID ++; +}; + +Object.defineProperties(TransformStatic.prototype, { /** - * Mixes in the properties of the pluginTarget into another object + * The rotation of the object in radians. * - * @param object {object} The obj to mix into + * @member {number} + * @memberof PIXI.TransformStatic# */ - mixin: function mixin(obj) - { - pluginTarget(obj); + rotation: { + get: function () { + return this._rotation; + }, + set: function (value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } } -}; - -},{}],103:[function(require,module,exports){ -/*global console */ -var core = require('./core'), - mesh = require('./mesh'), - particles = require('./particles'), - extras = require('./extras'), - filters = require('./filters'); - -/** - * @class - * @private - * @name SpriteBatch - * @memberof PIXI - * @see PIXI.ParticleContainer - * @throws {ReferenceError} SpriteBatch does not exist any more, please use the new ParticleContainer instead. - * @deprecated since version 3.0.0 - */ -core.SpriteBatch = function() -{ - throw new ReferenceError('SpriteBatch does not exist any more, please use the new ParticleContainer instead.'); -}; - -/** - * @class - * @private - * @name AssetLoader - * @memberof PIXI - * @see PIXI.loaders.Loader - * @throws {ReferenceError} The loader system was overhauled in pixi v3, please see the new PIXI.loaders.Loader class. - * @deprecated since version 3.0.0 - */ -core.AssetLoader = function() -{ - throw new ReferenceError('The loader system was overhauled in pixi v3, please see the new PIXI.loaders.Loader class.'); -}; - -Object.defineProperties(core, { - - /** - * @class - * @private - * @name Stage - * @memberof PIXI - * @see PIXI.Container - * @deprecated since version 3.0.0 - */ - Stage: { - get: function() - { - console.warn('You do not need to use a PIXI Stage any more, you can simply render any container.'); - return core.Container; - } - }, - - /** - * @class - * @private - * @name DisplayObjectContainer - * @memberof PIXI - * @see PIXI.Container - * @deprecated since version 3.0.0 - */ - DisplayObjectContainer: { - get: function() - { - console.warn('DisplayObjectContainer has been shortened to Container, please use Container from now on.'); - return core.Container; - } - }, - - /** - * @class - * @private - * @name Strip - * @memberof PIXI - * @see PIXI.mesh.Mesh - * @deprecated since version 3.0.0 - */ - Strip: { - get: function() - { - console.warn('The Strip class has been renamed to Mesh and moved to mesh.Mesh, please use mesh.Mesh from now on.'); - return mesh.Mesh; - } - }, - - /** - * @class - * @private - * @name Rope - * @memberof PIXI - * @see PIXI.mesh.Rope - * @deprecated since version 3.0.0 - */ - Rope: { - get: function() - { - console.warn('The Rope class has been moved to mesh.Rope, please use mesh.Rope from now on.'); - return mesh.Rope; - } - }, - - /** - * @class - * @private - * @name ParticleContainer - * @memberof PIXI - * @see PIXI.particles.ParticleContainer - * @deprecated since version 4.0.0 - */ - ParticleContainer: { - get: function() { - console.warn('The ParticleContainer class has been moved to particles.ParticleContainer, please useparticles.ParticleContainer from now on.'); - return particles.ParticleContainer; - } - }, - - /** - * @class - * @private - * @name MovieClip - * @memberof PIXI - * @see PIXI.extras.MovieClip - * @deprecated since version 3.0.0 - */ - MovieClip: { - get: function() - { - console.warn('The MovieClip class has been moved to extras.MovieClip, please use extras.MovieClip from now on.'); - return extras.MovieClip; - } - }, - - /** - * @class - * @private - * @name TilingSprite - * @memberof PIXI - * @see PIXI.extras.TilingSprite - * @deprecated since version 3.0.0 - */ - TilingSprite: { - get: function() - { - console.warn('The TilingSprite class has been moved to extras.TilingSprite, please use extras.TilingSprite from now on.'); - return extras.TilingSprite; - } - }, - - /** - * @class - * @private - * @name BitmapText - * @memberof PIXI - * @see PIXI.extras.BitmapText - * @deprecated since version 3.0.0 - */ - BitmapText: { - get: function() - { - console.warn('The BitmapText class has been moved to extras.BitmapText, please use extras.BitmapText from now on.'); - return extras.BitmapText; - } - }, - - /** - * @class - * @private - * @name blendModes - * @memberof PIXI - * @see PIXI.BLEND_MODES - * @deprecated since version 3.0.0 - */ - blendModes: { - get: function() - { - console.warn('The blendModes has been moved to BLEND_MODES, please use BLEND_MODES from now on.'); - return core.BLEND_MODES; - } - }, - - /** - * @class - * @private - * @name scaleModes - * @memberof PIXI - * @see PIXI.SCALE_MODES - * @deprecated since version 3.0.0 - */ - scaleModes: { - get: function() - { - console.warn('The scaleModes has been moved to SCALE_MODES, please use SCALE_MODES from now on.'); - return core.SCALE_MODES; - } - }, - - /** - * @class - * @private - * @name BaseTextureCache - * @memberof PIXI - * @see PIXI.utils.BaseTextureCache - * @deprecated since version 3.0.0 - */ - BaseTextureCache: { - get: function () - { - console.warn('The BaseTextureCache class has been moved to utils.BaseTextureCache, please use utils.BaseTextureCache from now on.'); - return core.utils.BaseTextureCache; - } - }, - - /** - * @class - * @private - * @name TextureCache - * @memberof PIXI - * @see PIXI.utils.TextureCache - * @deprecated since version 3.0.0 - */ - TextureCache: { - get: function () - { - console.warn('The TextureCache class has been moved to utils.TextureCache, please use utils.TextureCache from now on.'); - return core.utils.TextureCache; - } - }, - - /** - * @namespace - * @private - * @name math - * @memberof PIXI - * @see PIXI - * @deprecated since version 3.0.6 - */ - math: { - get: function () - { - console.warn('The math namespace is deprecated, please access members already accessible on PIXI.'); - return core; - } - } -}); - -core.DisplayObject.prototype.generateTexture = function(renderer, scaleMode, resolution) -{ - return renderer.generateTexture(renderer, scaleMode, resolution) - console.warn('generateTexture has moved to the renderer, please use renderer.generateTexture(displayObject)'); -}; - - -core.Graphics.prototype.generateTexture = function(scaleMode, resolution) -{ - console.warn('graphics generate texture has moved to the renderer. Or to render a graphics to a texture using canvas please use generateCanvasTexture'); - - return this.generateCanvasTexture(scaleMode, resolution) -} - -core.RenderTexture.prototype.render = function(displayObject) -{ - this.legacyRenderer.render(displayObject, this) - //displayObject, matrix, clear, updateTransform - console.warn('RenderTexture.render is now deprecated, please use renderer.render(displayObject, renderTexture)'); -}; - -/** - * @method - * @private - * @name PIXI.Sprite#setTexture - * @see PIXI.Sprite#texture - * @deprecated since version 3.0.0 - */ -core.Sprite.prototype.setTexture = function(texture) -{ - this.texture = texture; - console.warn('setTexture is now deprecated, please use the texture property, e.g : sprite.texture = texture;'); -}; - - - -/** - * @method - * @name PIXI.extras.BitmapText#setText - * @see PIXI.extras.BitmapText#text - * @deprecated since version 3.0.0 - */ -extras.BitmapText.prototype.setText = function(text) -{ - this.text = text; - console.warn('setText is now deprecated, please use the text property, e.g : myBitmapText.text = \'my text\';'); -}; - -/** - * @method - * @name PIXI.Text#setText - * @see PIXI.Text#text - * @deprecated since version 3.0.0 - */ -core.Text.prototype.setText = function(text) -{ - this.text = text; - console.warn('setText is now deprecated, please use the text property, e.g : myText.text = \'my text\';'); -}; - -/** - * @method - * @name PIXI.Text#setStyle - * @see PIXI.Text#style - * @deprecated since version 3.0.0 - */ -core.Text.prototype.setStyle = function(style) -{ - this.style = style; - console.warn('setStyle is now deprecated, please use the style property, e.g : myText.style = style;'); -}; - -/** - * @method - * @name PIXI.Texture#setFrame - * @see PIXI.Texture#setFrame - * @deprecated since version 3.0.0 - */ -core.Texture.prototype.setFrame = function(frame) -{ - this.frame = frame; - console.warn('setFrame is now deprecated, please use the frame property, e.g : myTexture.frame = frame;'); -}; - -Object.defineProperties(filters, { - - /** - * @class - * @private - * @name PIXI.filters.AbstractFilter - * @see PIXI.AbstractFilter - * @deprecated since version 3.0.6 - */ - AbstractFilter: { - get: function() - { - console.warn('filters.AbstractFilter is an undocumented alias, please use AbstractFilter from now on.'); - return core.AbstractFilter; - } - }, - - /** - * @class - * @private - * @name PIXI.filters.FXAAFilter - * @see PIXI.FXAAFilter - * @deprecated since version 3.0.6 - */ - FXAAFilter: { - get: function() - { - console.warn('filters.FXAAFilter is an undocumented alias, please use FXAAFilter from now on.'); - return core.FXAAFilter; - } - }, - - /** - * @class - * @private - * @name PIXI.filters.SpriteMaskFilter - * @see PIXI.SpriteMaskFilter - * @deprecated since version 3.0.6 - */ - SpriteMaskFilter: { - get: function() - { - console.warn('filters.SpriteMaskFilter is an undocumented alias, please use SpriteMaskFilter from now on.'); - return core.SpriteMaskFilter; - } - } -}); - -/** - * @method - * @name PIXI.utils.uuid - * @see PIXI.utils.uid - * @deprecated since version 3.0.6 - */ -core.utils.uuid = function () -{ - console.warn('utils.uuid() is deprecated, please use utils.uid() from now on.'); - return core.utils.uid(); -}; +}); + +module.exports = TransformStatic; -},{"./core":50,"./extras":110,"./filters":122,"./mesh":137,"./particles":140}],104:[function(require,module,exports){ -var core = require('../core'); +},{"../math":66,"./TransformBase":47}],49:[function(require,module,exports){ +var Container = require('../display/Container'), + RenderTexture = require('../textures/RenderTexture'), + Texture = require('../textures/Texture'), + GraphicsData = require('./GraphicsData'), + Sprite = require('../sprites/Sprite'), + math = require('../math'), + CONST = require('../const'), + Bounds = require('../display/Bounds'), + bezierCurveTo = require('./utils/bezierCurveTo'), + CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), + canvasRenderer, + tempMatrix = new math.Matrix(), + tempPoint = new math.Point(); /** - * A BitmapText object will create a line or multiple lines of text using bitmap font. To - * split a line you can use '\n', '\r' or '\r\n' in your string. You can generate the fnt files using: - * - * A BitmapText can only be created when the font is loaded - * - * ```js - * // in this case the font is in a file called 'desyrel.fnt' - * var bitmapText = new PIXI.extras.BitmapText("text using a fancy font!", {font: "35px Desyrel", align: "right"}); - * ``` - * - * - * http://www.angelcode.com/products/bmfont/ for windows or - * http://www.bmglyph.com/ for mac. - * - * @class - * @extends PIXI.Container - * @memberof PIXI.extras - * @param text {string} The copy that you would like the text to display - * @param style {object} The style parameters - * @param style.font {string|object} The font descriptor for the object, can be passed as a string of form - * "24px FontName" or "FontName" or as an object with explicit name/size properties. - * @param [style.font.name] {string} The bitmap font id - * @param [style.font.size] {number} The size of the font in pixels, e.g. 24 - * @param [style.align='left'] {string} Alignment for multiline text ('left', 'center' or 'right'), does not affect - * single line text - * @param [style.tint=0xFFFFFF] {number} The tint color + * The Graphics class contains methods used to draw primitive shapes such as lines, circles and + * rectangles to the display, and to color and fill them. + * + * @class + * @extends PIXI.Container + * @memberof PIXI */ -function BitmapText(text, style) +function Graphics() { - core.Container.call(this); - - style = style || {}; + Container.call(this); /** - * The width of the overall text, different from fontSize, - * which is defined in the style object + * The alpha value used when filling the Graphics object. * * @member {number} - * @readOnly + * @default 1 */ - this.textWidth = 0; + this.fillAlpha = 1; /** - * The height of the overall text, different from fontSize, - * which is defined in the style object + * The width (thickness) of any lines drawn. * * @member {number} - * @readOnly + * @default 0 */ - this.textHeight = 0; + this.lineWidth = 0; /** - * Private tracker for the letter sprite pool. + * The color of any lines drawn. * - * @member {PIXI.Sprite[]} - * @private + * @member {string} + * @default 0 */ - this._glyphs = []; + this.lineColor = 0; /** - * Private tracker for the current style. + * Graphics data * - * @member {object} + * @member {PIXI.GraphicsData[]} * @private */ - this._font = { - tint: style.tint !== undefined ? style.tint : 0xFFFFFF, - align: style.align || 'left', - name: null, - size: 0 - }; + this.graphicsData = []; /** - * Private tracker for the current font. + * The tint applied to the graphic shape. This is a hex value. Apply a value of 0xFFFFFF to reset the tint. * - * @member {object} - * @private + * @member {number} + * @default 0xFFFFFF */ - this.font = style.font; // run font setter + this.tint = 0xFFFFFF; /** - * Private tracker for the current text. + * The previous tint applied to the graphic shape. Used to compare to the current tint and check if theres change. * - * @member {string} + * @member {number} * @private + * @default 0xFFFFFF */ - this._text = text; + this._prevTint = 0xFFFFFF; /** - * The max width of this bitmap text in pixels. If the text provided is longer than the value provided, line breaks will be automatically inserted in the last whitespace. - * Disable by setting value to 0 + * The blend mode to be applied to the graphic shape. Apply a value of `PIXI.BLEND_MODES.NORMAL` to reset the blend mode. * * @member {number} + * @default PIXI.BLEND_MODES.NORMAL; + * @see PIXI.BLEND_MODES */ - this.maxWidth = 0; + this.blendMode = CONST.BLEND_MODES.NORMAL; /** - * The max line height. This is useful when trying to use the total height of the Text, ie: when trying to vertically align. + * Current path * - * @member {number} + * @member {PIXI.GraphicsData} + * @private */ - this.maxLineHeight = 0; + this.currentPath = null; /** - * The dirty state of this object. + * Array containing some WebGL-related properties used by the WebGL renderer. * - * @member {boolean} + * @member {object} + * @private */ - this.dirty = false; - - this.updateText(); -} + // TODO - _webgl should use a prototype object, not a random undocumented object... + this._webGL = {}; -// constructor -BitmapText.prototype = Object.create(core.Container.prototype); -BitmapText.prototype.constructor = BitmapText; -module.exports = BitmapText; + /** + * Whether this shape is being used as a mask. + * + * @member {boolean} + */ + this.isMask = false; -Object.defineProperties(BitmapText.prototype, { /** - * The tint of the BitmapText object + * The bounds' padding used for bounds calculation. * * @member {number} - * @memberof PIXI.extras.BitmapText# */ - tint: { - get: function () - { - return this._font.tint; - }, - set: function (value) - { - this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; - - this.dirty = true; - } - }, + this.boundsPadding = 0; /** - * The alignment of the BitmapText object + * A cache of the local bounds to prevent recalculation. * - * @member {string} - * @default 'left' - * @memberof PIXI.extras.BitmapText# + * @member {PIXI.Rectangle} + * @private */ - align: { - get: function () - { - return this._font.align; - }, - set: function (value) - { - this._font.align = value || 'left'; + this._localBounds = new Bounds(); - this.dirty = true; - } - }, + /** + * Used to detect if the graphics object has changed. If this is set to true then the graphics + * object will be recalculated. + * + * @member {boolean} + * @private + */ + this.dirty = true; /** - * The font descriptor of the BitmapText object + * Used to detect if the WebGL graphics object has changed. If this is set to true then the + * graphics object will be recalculated. * - * @member {Font} - * @memberof PIXI.extras.BitmapText# + * @member {boolean} + * @private */ - font: { - get: function () - { - return this._font; - }, - set: function (value) - { - if (!value) { - return; - } + this.glDirty = false; - if (typeof value === 'string') { - value = value.split(' '); + this.boundsDirty = true; - this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); - this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; - } - else { - this._font.name = value.name; - this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); - } + /** + * Used to detect if the cached sprite object needs to be updated. + * + * @member {boolean} + * @private + */ + this.cachedSpriteDirty = false; - this.dirty = true; - } - }, + + this._spriteRect = null; + this._fastRect = false; /** - * The text of the BitmapText object + * When cacheAsBitmap is set to true the graphics object will be rendered as if it was a sprite. + * This is useful if your graphics element does not change often, as it will speed up the rendering + * of the object in exchange for taking up texture memory. It is also useful if you need the graphics + * object to be anti-aliased, because it will be rendered using canvas. This is not recommended if + * you are constantly redrawing the graphics element. * - * @member {string} - * @memberof PIXI.extras.BitmapText# + * @name cacheAsBitmap + * @member {boolean} + * @memberof PIXI.Graphics# + * @default false */ - text: { - get: function () +} + +Graphics._SPRITE_TEXTURE = null; + +// constructor +Graphics.prototype = Object.create(Container.prototype); +Graphics.prototype.constructor = Graphics; +module.exports = Graphics; + +/** + * Creates a new Graphics object with the same values as this one. + * Note that the only the properties of the object are cloned, not its transform (position,scale,etc) + * + * @return {PIXI.Graphics} A clone of the graphics object + */ +Graphics.prototype.clone = function () +{ + var clone = new Graphics(); + + clone.renderable = this.renderable; + clone.fillAlpha = this.fillAlpha; + clone.lineWidth = this.lineWidth; + clone.lineColor = this.lineColor; + clone.tint = this.tint; + clone.blendMode = this.blendMode; + clone.isMask = this.isMask; + clone.boundsPadding = this.boundsPadding; + clone.dirty = true; + clone.glDirty = true; + clone.cachedSpriteDirty = this.cachedSpriteDirty; + + // copy graphics data + for (var i = 0; i < this.graphicsData.length; ++i) + { + clone.graphicsData.push(this.graphicsData[i].clone()); + } + + clone.currentPath = clone.graphicsData[clone.graphicsData.length - 1]; + + clone.updateLocalBounds(); + + return clone; +}; + +/** + * Specifies the line style used for subsequent calls to Graphics methods such as the lineTo() method or the drawCircle() method. + * + * @param lineWidth {number} width of the line to draw, will update the objects stored style + * @param color {number} color of the line to draw, will update the objects stored style + * @param alpha {number} alpha of the line to draw, will update the objects stored style + * @return {PIXI.Graphics} This Graphics object. Good for chaining method calls + */ +Graphics.prototype.lineStyle = function (lineWidth, color, alpha) +{ + this.lineWidth = lineWidth || 0; + this.lineColor = color || 0; + this.lineAlpha = (alpha === undefined) ? 1 : alpha; + + if (this.currentPath) + { + if (this.currentPath.shape.points.length) { - return this._text; - }, - set: function (value) + // halfway through a line? start a new one! + var shape = new math.Polygon(this.currentPath.shape.points.slice(-2)); + shape.closed = false; + this.drawShape(shape); + } + else { - value = value.toString() || ' '; - if (this._text === value) - { - return; - } - this._text = value; - this.dirty = true; + // otherwise its empty so lets just set the line properties + this.currentPath.lineWidth = this.lineWidth; + this.currentPath.lineColor = this.lineColor; + this.currentPath.lineAlpha = this.lineAlpha; } } -}); + + return this; +}; /** - * Renders text and updates it when needed + * Moves the current drawing position to x, y. * - * @private + * @param x {number} the X coordinate to move to + * @param y {number} the Y coordinate to move to + * @return {PIXI.Graphics} This Graphics object. Good for chaining method calls */ -BitmapText.prototype.updateText = function () +Graphics.prototype.moveTo = function (x, y) { - var data = BitmapText.fonts[this._font.name]; - var pos = new core.Point(); - var prevCharCode = null; - var chars = []; - var lastLineWidth = 0; - var maxLineWidth = 0; - var lineWidths = []; - var line = 0; - var scale = this._font.size / data.size; - var lastSpace = -1; - var maxLineHeight = 0; + var shape = new math.Polygon([x,y]); + shape.closed = false; + this.drawShape(shape); - for (var i = 0; i < this.text.length; i++) - { - var charCode = this.text.charCodeAt(i); - lastSpace = /(\s)/.test(this.text.charAt(i)) ? i : lastSpace; + return this; +}; - if (/(?:\r\n|\r|\n)/.test(this.text.charAt(i))) - { - lineWidths.push(lastLineWidth); - maxLineWidth = Math.max(maxLineWidth, lastLineWidth); - line++; +/** + * Draws a line using the current line style from the current drawing position to (x, y); + * The current drawing position is then set to (x, y). + * + * @param x {number} the X coordinate to draw to + * @param y {number} the Y coordinate to draw to + * @return {PIXI.Graphics} This Graphics object. Good for chaining method calls + */ +Graphics.prototype.lineTo = function (x, y) +{ + this.currentPath.shape.points.push(x, y); + this.dirty = true; - pos.x = 0; - pos.y += data.lineHeight; - prevCharCode = null; - continue; - } + return this; +}; - if (lastSpace !== -1 && this.maxWidth > 0 && pos.x * scale > this.maxWidth) +/** + * Calculate the points for a quadratic bezier curve and then draws it. + * Based on: https://stackoverflow.com/questions/785097/how-do-i-implement-a-bezier-curve-in-c + * + * @param cpX {number} Control point x + * @param cpY {number} Control point y + * @param toX {number} Destination point x + * @param toY {number} Destination point y + * @return {PIXI.Graphics} This Graphics object. Good for chaining method calls + */ +Graphics.prototype.quadraticCurveTo = function (cpX, cpY, toX, toY) +{ + if (this.currentPath) + { + if (this.currentPath.shape.points.length === 0) { - core.utils.removeItems(chars, lastSpace, i - lastSpace); - i = lastSpace; - lastSpace = -1; + this.currentPath.shape.points = [0, 0]; + } + } + else + { + this.moveTo(0,0); + } - lineWidths.push(lastLineWidth); - maxLineWidth = Math.max(maxLineWidth, lastLineWidth); - line++; - pos.x = 0; - pos.y += data.lineHeight; - prevCharCode = null; - continue; - } + var xa, + ya, + n = 20, + points = this.currentPath.shape.points; - var charData = data.chars[charCode]; + if (points.length === 0) + { + this.moveTo(0, 0); + } - if (!charData) - { - continue; - } + var fromX = points[points.length-2]; + var fromY = points[points.length-1]; - if (prevCharCode && charData.kerning[prevCharCode]) - { - pos.x += charData.kerning[prevCharCode]; - } + var j = 0; + for (var i = 1; i <= n; ++i) + { + j = i / n; - chars.push({texture:charData.texture, line: line, charCode: charCode, position: new core.Point(pos.x + charData.xOffset, pos.y + charData.yOffset)}); - lastLineWidth = pos.x + (charData.texture.width + charData.xOffset); - pos.x += charData.xAdvance; - maxLineHeight = Math.max(maxLineHeight, (charData.yOffset + charData.texture.height)); - prevCharCode = charCode; + xa = fromX + ( (cpX - fromX) * j ); + ya = fromY + ( (cpY - fromY) * j ); + + points.push( xa + ( ((cpX + ( (toX - cpX) * j )) - xa) * j ), + ya + ( ((cpY + ( (toY - cpY) * j )) - ya) * j ) ); } - lineWidths.push(lastLineWidth); - maxLineWidth = Math.max(maxLineWidth, lastLineWidth); + this.dirty = this.boundsDirty = true; - var lineAlignOffsets = []; + return this; +}; - for (i = 0; i <= line; i++) +/** + * Calculate the points for a bezier curve and then draws it. + * + * @param cpX {number} Control point x + * @param cpY {number} Control point y + * @param cpX2 {number} Second Control point x + * @param cpY2 {number} Second Control point y + * @param toX {number} Destination point x + * @param toY {number} Destination point y + * @return {PIXI.Graphics} This Graphics object. Good for chaining method calls + */ +Graphics.prototype.bezierCurveTo = function (cpX, cpY, cpX2, cpY2, toX, toY) +{ + if (this.currentPath) { - var alignOffset = 0; - - if (this._font.align === 'right') - { - alignOffset = maxLineWidth - lineWidths[i]; - } - else if (this._font.align === 'center') + if (this.currentPath.shape.points.length === 0) { - alignOffset = (maxLineWidth - lineWidths[i]) / 2; + this.currentPath.shape.points = [0, 0]; } - - lineAlignOffsets.push(alignOffset); + } + else + { + this.moveTo(0,0); } - var lenChars = chars.length; - var tint = this.tint; + var points = this.currentPath.shape.points; - for (i = 0; i < lenChars; i++) - { - var c = this._glyphs[i]; // get the next glyph sprite + var fromX = points[points.length-2]; + var fromY = points[points.length-1]; - if (c) - { - c.texture = chars[i].texture; - } - else + points.length -= 2; + + bezierCurveTo(fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, points); + + this.dirty = this.boundsDirty = true; + + return this; +}; + +/** + * The arcTo() method creates an arc/curve between two tangents on the canvas. + * + * "borrowed" from https://code.google.com/p/fxcanvas/ - thanks google! + * + * @param x1 {number} The x-coordinate of the beginning of the arc + * @param y1 {number} The y-coordinate of the beginning of the arc + * @param x2 {number} The x-coordinate of the end of the arc + * @param y2 {number} The y-coordinate of the end of the arc + * @param radius {number} The radius of the arc + * @return {PIXI.Graphics} This Graphics object. Good for chaining method calls + */ +Graphics.prototype.arcTo = function (x1, y1, x2, y2, radius) +{ + if (this.currentPath) + { + if (this.currentPath.shape.points.length === 0) { - c = new core.Sprite(chars[i].texture); - this._glyphs.push(c); + this.currentPath.shape.points.push(x1, y1); } + } + else + { + this.moveTo(x1, y1); + } - c.position.x = (chars[i].position.x + lineAlignOffsets[chars[i].line]) * scale; - c.position.y = chars[i].position.y * scale; - c.scale.x = c.scale.y = scale; - c.tint = tint; + var points = this.currentPath.shape.points, + fromX = points[points.length-2], + fromY = points[points.length-1], + a1 = fromY - y1, + b1 = fromX - x1, + a2 = y2 - y1, + b2 = x2 - x1, + mm = Math.abs(a1 * b2 - b1 * a2); - if (!c.parent) + if (mm < 1.0e-8 || radius === 0) + { + if (points[points.length-2] !== x1 || points[points.length-1] !== y1) { - this.addChild(c); + points.push(x1, y1); } } - - // remove unnecessary children. - for (i = lenChars; i < this._glyphs.length; ++i) + else { - this.removeChild(this._glyphs[i]); + var dd = a1 * a1 + b1 * b1, + cc = a2 * a2 + b2 * b2, + tt = a1 * a2 + b1 * b2, + k1 = radius * Math.sqrt(dd) / mm, + k2 = radius * Math.sqrt(cc) / mm, + j1 = k1 * tt / dd, + j2 = k2 * tt / cc, + cx = k1 * b2 + k2 * b1, + cy = k1 * a2 + k2 * a1, + px = b1 * (k2 + j1), + py = a1 * (k2 + j1), + qx = b2 * (k1 + j2), + qy = a2 * (k1 + j2), + startAngle = Math.atan2(py - cy, px - cx), + endAngle = Math.atan2(qy - cy, qx - cx); + + this.arc(cx + x1, cy + y1, radius, startAngle, endAngle, b1 * a2 > b2 * a1); } - this.textWidth = maxLineWidth * scale; - this.textHeight = (pos.y + data.lineHeight) * scale; - this.maxLineHeight = maxLineHeight * scale; + this.dirty = this.boundsDirty = true; + + return this; }; /** - * Updates the transform of this object + * The arc method creates an arc/curve (used to create circles, or parts of circles). * - * @private + * @param cx {number} The x-coordinate of the center of the circle + * @param cy {number} The y-coordinate of the center of the circle + * @param radius {number} The radius of the circle + * @param startAngle {number} The starting angle, in radians (0 is at the 3 o'clock position of the arc's circle) + * @param endAngle {number} The ending angle, in radians + * @param [anticlockwise=false] {boolean} Specifies whether the drawing should be counterclockwise or clockwise. False is default, and indicates clockwise, while true indicates counter-clockwise. + * @return {PIXI.Graphics} This Graphics object. Good for chaining method calls */ -BitmapText.prototype.updateTransform = function () +Graphics.prototype.arc = function(cx, cy, radius, startAngle, endAngle, anticlockwise) { - this.validate(); - this.containerUpdateTransform(); -}; + anticlockwise = anticlockwise || false; -/** - * Validates text before calling parent's getLocalBounds - * - * @return {PIXI.Rectangle} The rectangular bounding area - */ + if (startAngle === endAngle) + { + return this; + } -BitmapText.prototype.getLocalBounds = function() -{ - this.validate(); - return core.Container.prototype.getLocalBounds.call(this); -}; + if( !anticlockwise && endAngle <= startAngle ) + { + endAngle += Math.PI * 2; + } + else if( anticlockwise && startAngle <= endAngle ) + { + startAngle += Math.PI * 2; + } -/** - * Updates text when needed - * - * @private - */ -BitmapText.prototype.validate = function() -{ - if (this.dirty) + var sweep = anticlockwise ? (startAngle - endAngle) * -1 : (endAngle - startAngle); + var segs = Math.ceil(Math.abs(sweep) / (Math.PI * 2)) * 40; + + if(sweep === 0) { - this.updateText(); - this.dirty = false; + return this; } -}; -BitmapText.fonts = {}; - -},{"../core":50}],105:[function(require,module,exports){ -var core = require('../core'); + var startX = cx + Math.cos(startAngle) * radius; + var startY = cy + Math.sin(startAngle) * radius; -/** - * A MovieClip is a simple way to display an animation depicted by a list of textures. - * - * ```js - * var alienImages = ["image_sequence_01.png","image_sequence_02.png","image_sequence_03.png","image_sequence_04.png"]; - * var textureArray = []; - * - * for (var i=0; i < 4; i++) - * { - * var texture = PIXI.Texture.fromImage(alienImages[i]); - * textureArray.push(texture); - * }; - * - * var mc = new PIXI.MovieClip(textureArray); - * ``` - * - * @class - * @extends PIXI.Sprite - * @memberof PIXI.extras - * @param textures {PIXI.Texture[]|Object[]} an array of {@link PIXI.Texture} or frame objects that make up the animation - * @param textures[].texture {PIXI.Texture} the {@link PIXI.Texture} of the frame - * @param textures[].time {number} the duration of the frame in ms - */ -function MovieClip(textures) -{ - core.Sprite.call(this, textures[0] instanceof core.Texture ? textures[0] : textures[0].texture); + if (this.currentPath) + { + this.currentPath.shape.points.push(startX, startY); + } + else + { + this.moveTo(startX, startY); + } - /** - * @private - */ - this._textures = null; + var points = this.currentPath.shape.points; - /** - * @private - */ - this._durations = null; + var theta = sweep/(segs*2); + var theta2 = theta*2; - this.textures = textures; + var cTheta = Math.cos(theta); + var sTheta = Math.sin(theta); - /** - * The speed that the MovieClip will play at. Higher is faster, lower is slower - * - * @member {number} - * @default 1 - */ - this.animationSpeed = 1; + var segMinus = segs - 1; - /** - * Whether or not the movie clip repeats after playing. - * - * @member {boolean} - * @default true - */ - this.loop = true; + var remainder = ( segMinus % 1 ) / segMinus; - /** - * Function to call when a MovieClip finishes playing - * - * @method - * @memberof PIXI.extras.MovieClip# - */ - this.onComplete = null; + for(var i=0; i<=segMinus; i++) + { + var real = i + remainder * i; - /** - * Elapsed time since animation has been started, used internally to display current texture - * - * @member {number} - * @private - */ - this._currentTime = 0; - /** - * Indicates if the MovieClip is currently playing - * - * @member {boolean} - * @readonly - */ - this.playing = false; -} + var angle = ((theta) + startAngle + (theta2 * real)); -// constructor -MovieClip.prototype = Object.create(core.Sprite.prototype); -MovieClip.prototype.constructor = MovieClip; -module.exports = MovieClip; + var c = Math.cos(angle); + var s = -Math.sin(angle); -Object.defineProperties(MovieClip.prototype, { - /** - * totalFrames is the total number of frames in the MovieClip. This is the same as number of textures - * assigned to the MovieClip. - * - * @member {number} - * @memberof PIXI.extras.MovieClip# - * @default 0 - * @readonly - */ - totalFrames: { - get: function() - { - return this._textures.length; - } - }, + points.push(( (cTheta * c) + (sTheta * s) ) * radius + cx, + ( (cTheta * -s) + (sTheta * c) ) * radius + cy); + } - /** - * The array of textures used for this MovieClip - * - * @member {PIXI.Texture[]} - * @memberof PIXI.extras.MovieClip# - * - */ - textures: { - get: function () - { - return this._textures; - }, - set: function (value) - { - if(value[0] instanceof core.Texture) - { - this._textures = value; - this._durations = null; - } - else - { - this._textures = []; - this._durations = []; - for(var i = 0; i < value.length; i++) - { - this._textures.push(value[i].texture); - this._durations.push(value[i].time); - } - } - } - }, + this.dirty = this.boundsDirty = true; - /** - * The MovieClips current frame index - * - * @member {number} - * @memberof PIXI.extras.MovieClip# - * @readonly - */ - currentFrame: { - get: function () + return this; +}; + +/** + * Specifies a simple one-color fill that subsequent calls to other Graphics methods + * (such as lineTo() or drawCircle()) use when drawing. + * + * @param color {number} the color of the fill + * @param alpha {number} the alpha of the fill + * @return {PIXI.Graphics} This Graphics object. Good for chaining method calls + */ +Graphics.prototype.beginFill = function (color, alpha) +{ + this.filling = true; + this.fillColor = color || 0; + this.fillAlpha = (alpha === undefined) ? 1 : alpha; + + if (this.currentPath) + { + if (this.currentPath.shape.points.length <= 2) { - var currentFrame = Math.floor(this._currentTime) % this._textures.length; - if (currentFrame < 0) - { - currentFrame += this._textures.length; - } - return currentFrame; + this.currentPath.fill = this.filling; + this.currentPath.fillColor = this.fillColor; + this.currentPath.fillAlpha = this.fillAlpha; } } + return this; +}; + +/** + * Applies a fill to the lines and shapes that were added since the last call to the beginFill() method. + * + * @return {PIXI.Graphics} This Graphics object. Good for chaining method calls + */ +Graphics.prototype.endFill = function () +{ + this.filling = false; + this.fillColor = null; + this.fillAlpha = 1; -}); + return this; +}; /** - * Stops the MovieClip * + * @param x {number} The X coord of the top-left of the rectangle + * @param y {number} The Y coord of the top-left of the rectangle + * @param width {number} The width of the rectangle + * @param height {number} The height of the rectangle + * @return {PIXI.Graphics} This Graphics object. Good for chaining method calls */ -MovieClip.prototype.stop = function () +Graphics.prototype.drawRect = function ( x, y, width, height ) { - if(!this.playing) - { - return; - } + this.drawShape(new math.Rectangle(x,y, width, height)); - this.playing = false; - core.ticker.shared.remove(this.update, this); + return this; }; /** - * Plays the MovieClip * + * @param x {number} The X coord of the top-left of the rectangle + * @param y {number} The Y coord of the top-left of the rectangle + * @param width {number} The width of the rectangle + * @param height {number} The height of the rectangle + * @param radius {number} Radius of the rectangle corners + * @return {PIXI.Graphics} This Graphics object. Good for chaining method calls */ -MovieClip.prototype.play = function () +Graphics.prototype.drawRoundedRect = function ( x, y, width, height, radius ) { - if(this.playing) - { - return; - } + this.drawShape(new math.RoundedRectangle(x, y, width, height, radius)); - this.playing = true; - core.ticker.shared.add(this.update, this); + return this; }; /** - * Stops the MovieClip and goes to a specific frame + * Draws a circle. * - * @param frameNumber {number} frame index to stop at + * @param x {number} The X coordinate of the center of the circle + * @param y {number} The Y coordinate of the center of the circle + * @param radius {number} The radius of the circle + * @return {PIXI.Graphics} This Graphics object. Good for chaining method calls */ -MovieClip.prototype.gotoAndStop = function (frameNumber) +Graphics.prototype.drawCircle = function (x, y, radius) { - this.stop(); - - this._currentTime = frameNumber; + this.drawShape(new math.Circle(x,y, radius)); - this._texture = this._textures[this.currentFrame]; + return this; }; /** - * Goes to a specific frame and begins playing the MovieClip + * Draws an ellipse. * - * @param frameNumber {number} frame index to start at + * @param x {number} The X coordinate of the center of the ellipse + * @param y {number} The Y coordinate of the center of the ellipse + * @param width {number} The half width of the ellipse + * @param height {number} The half height of the ellipse + * @return {PIXI.Graphics} This Graphics object. Good for chaining method calls */ -MovieClip.prototype.gotoAndPlay = function (frameNumber) +Graphics.prototype.drawEllipse = function (x, y, width, height) { - this._currentTime = frameNumber; + this.drawShape(new math.Ellipse(x, y, width, height)); - this.play(); + return this; }; -/* - * Updates the object transform for rendering - * @private +/** + * Draws a polygon using the given path. + * + * @param path {number[]|PIXI.Point[]} The path data used to construct the polygon. + * @return {PIXI.Graphics} This Graphics object. Good for chaining method calls */ -MovieClip.prototype.update = function (deltaTime) +Graphics.prototype.drawPolygon = function (path) { - var elapsed = this.animationSpeed * deltaTime; - - if (this._durations !== null) - { - var lag = this._currentTime % 1 * this._durations[this.currentFrame]; - - lag += elapsed / 60 * 1000; - - while (lag < 0) - { - this._currentTime--; - lag += this._durations[this.currentFrame]; - } - - var sign = Math.sign(this.animationSpeed * deltaTime); - this._currentTime = Math.floor(this._currentTime); + // prevents an argument assignment deopt + // see section 3.1: https://github.com/petkaantonov/bluebird/wiki/Optimization-killers#3-managing-arguments + var points = path; - while (lag >= this._durations[this.currentFrame]) - { - lag -= this._durations[this.currentFrame] * sign; - this._currentTime += sign; - } + var closed = true; - this._currentTime += lag / this._durations[this.currentFrame]; - } - else + if (points instanceof math.Polygon) { - this._currentTime += elapsed; + closed = points.closed; + points = points.points; } - if (this._currentTime < 0 && !this.loop) + if (!Array.isArray(points)) { - this.gotoAndStop(0); + // prevents an argument leak deopt + // see section 3.2: https://github.com/petkaantonov/bluebird/wiki/Optimization-killers#3-managing-arguments + points = new Array(arguments.length); - if (this.onComplete) + for (var i = 0; i < points.length; ++i) { - this.onComplete(); + points[i] = arguments[i]; } } - else if (this._currentTime >= this._textures.length && !this.loop) - { - this.gotoAndStop(this._textures.length - 1); - if (this.onComplete) - { - this.onComplete(); - } - } - else - { - this._texture = this._textures[this.currentFrame]; - } + var shape = new math.Polygon(points); + shape.closed = closed; -}; + this.drawShape(shape); -/* - * Stops the MovieClip and destroys it - * - */ -MovieClip.prototype.destroy = function ( ) -{ - this.stop(); - core.Sprite.prototype.destroy.call(this); + return this; }; /** - * A short hand way of creating a movieclip from an array of frame ids + * Clears the graphics that were drawn to this Graphics object, and resets fill and line style settings. * - * @static - * @param frames {string[]} the array of frames ids the movieclip will use as its texture frames + * @return {PIXI.Graphics} This Graphics object. Good for chaining method calls */ -MovieClip.fromFrames = function (frames) +Graphics.prototype.clear = function () { - var textures = []; + this.lineWidth = 0; + this.filling = false; - for (var i = 0; i < frames.length; ++i) - { - textures.push(new core.Texture.fromFrame(frames[i])); - } + this.dirty = true; + this.clearDirty = true; + this.graphicsData = []; - return new MovieClip(textures); + return this; }; /** - * A short hand way of creating a movieclip from an array of image ids + * True if graphics consists of one rectangle, and thus, can be drawn like a Sprite and masked with gl.scissor + * @returns {boolean} + */ +Graphics.prototype.isFastRect = function() { + return this.graphicsData.length === 1 && this.graphicsData[0].shape.type === CONST.SHAPES.RECT && !this.graphicsData[0].lineWidth; +}; + +/** + * Renders the object using the WebGL renderer * - * @static - * @param images {string[]} the array of image urls the movieclip will use as its texture frames + * @param renderer {PIXI.WebGLRenderer} + * @private */ -MovieClip.fromImages = function (images) +Graphics.prototype._renderWebGL = function (renderer) { - var textures = []; + // if the sprite is not visible or the alpha is 0 then no need to render this element - for (var i = 0; i < images.length; ++i) + if (this.glDirty) { - textures.push(new core.Texture.fromImage(images[i])); + this.dirty = true; + this.glDirty = false; } - return new MovieClip(textures); -}; -},{"../core":50}],106:[function(require,module,exports){ -var core = require('../core'), - // a sprite use dfor rendering textures.. - tempPoint = new core.Point(), - CanvasTinter = require('../core/sprites/canvas/CanvasTinter'), - TilingShader = require('./webgl/TilingShader') + if(this.dirty) + { + this._fastRect = this.isFastRect(); + } -/** - * A tiling sprite is a fast way of rendering a tiling image - * - * @class - * @extends PIXI.Sprite - * @memberof PIXI.extras - * @param texture {Texture} the texture of the tiling sprite - * @param width {number} the width of the tiling sprite - * @param height {number} the height of the tiling sprite - */ -function TilingSprite(texture, width, height) + //TODO this check can be moved to dirty? + if(this._fastRect) + { + this._renderSpriteRect(renderer); + } + else + { + renderer.setObjectRenderer(renderer.plugins.graphics); + renderer.plugins.graphics.render(this); + } + +}; + +Graphics.prototype._renderSpriteRect = function (renderer) { - core.Sprite.call(this, texture); + var rect = this.graphicsData[0].shape; + if(!this._spriteRect) + { + if(!Graphics._SPRITE_TEXTURE) + { + Graphics._SPRITE_TEXTURE = RenderTexture.create(10, 10); - /** - * The scaling of the image that is being tiled - * - * @member {PIXI.Point} - */ - this.tileScale = new core.Point(1,1); + var currentRenderTarget = renderer._activeRenderTarget; + renderer.bindRenderTexture(Graphics._SPRITE_TEXTURE); + renderer.clear([1,1,1,1]); + renderer.bindRenderTarget(currentRenderTarget); + } + + this._spriteRect = new Sprite(Graphics._SPRITE_TEXTURE); + this._spriteRect.tint = this.graphicsData[0].fillColor; + this._spriteRect.alpha = this.graphicsData[0].fillAlpha; + } + this._spriteRect.worldAlpha = this.worldAlpha * this._spriteRect.alpha; - /** - * The offset position of the image that is being tiled - * - * @member {PIXI.Point} - */ - this.tilePosition = new core.Point(0,0); + Graphics._SPRITE_TEXTURE._frame.width = rect.width; + Graphics._SPRITE_TEXTURE._frame.height = rect.height; - ///// private + this._spriteRect.transform.worldTransform = this.transform.worldTransform; - /** - * The with of the tiling sprite - * - * @member {number} - * @private - */ - this._width = width || 100; + this._spriteRect.anchor.set(-rect.x / rect.width, -rect.y / rect.height); + this._spriteRect.onAnchorUpdate(); + + this._spriteRect._renderWebGL(renderer); +}; + +/** + * Renders the object using the Canvas renderer + * + * @param renderer {PIXI.CanvasRenderer} + * @private + */ +Graphics.prototype._renderCanvas = function (renderer) +{ + if (this.isMask === true) + { + return; + } - /** - * The height of the tiling sprite - * - * @member {number} - * @private - */ - this._height = height || 100; + renderer.plugins.graphics.render(this); +}; - /** - * An internal WebGL UV cache. - * - * @member {PIXI.TextureUvs} - * @private - */ - this._uvs = new core.TextureUvs(); +/** + * Retrieves the bounds of the graphic shape as a rectangle object + * + * @param [matrix] {PIXI.Matrix} The world transform matrix to use, defaults to this + * object's worldTransform. + * @return {PIXI.Rectangle} the rectangular bounding area + */ +Graphics.prototype._calculateBounds = function () +{ + if (!this.renderable) + { + return; + } - this._canvasPattern = null; + if (this.boundsDirty) + { + this.updateLocalBounds(); - this._glDatas = []; -} + this.glDirty = true; + this.cachedSpriteDirty = true; + this.boundsDirty = false; + } -TilingSprite.prototype = Object.create(core.Sprite.prototype); -TilingSprite.prototype.constructor = TilingSprite; -module.exports = TilingSprite; + var lb = this._localBounds; + this._bounds.addFrame(this.transform, lb.minX, lb.minY, lb.maxX, lb.maxY); +}; +/** +* Tests if a point is inside this graphics object +* +* @param point {PIXI.Point} the point to test +* @return {boolean} the result of the test +*/ +Graphics.prototype.containsPoint = function( point ) +{ + this.worldTransform.applyInverse(point, tempPoint); -Object.defineProperties(TilingSprite.prototype, { - /** - * The width of the sprite, setting this will actually modify the scale to achieve the value set - * - * @member {number} - * @memberof PIXI.extras.TilingSprite# - */ - width: { - get: function () - { - return this._width; - }, - set: function (value) + var graphicsData = this.graphicsData; + + for (var i = 0; i < graphicsData.length; i++) + { + var data = graphicsData[i]; + + if (!data.fill) { - this._width = value; + continue; } - }, - /** - * The height of the TilingSprite, setting this will actually modify the scale to achieve the value set - * - * @member {number} - * @memberof PIXI.extras.TilingSprite# - */ - height: { - get: function () - { - return this._height; - }, - set: function (value) + // only deal with fills.. + if (data.shape) { - this._height = value; + if ( data.shape.contains( tempPoint.x, tempPoint.y ) ) + { + return true; + } } } -}); -TilingSprite.prototype._onTextureUpdate = function () -{ - return; + return false; }; - /** - * Renders the object using the WebGL renderer + * Update the bounds of the object * - * @param renderer {PIXI.WebGLRenderer} - * @private */ -TilingSprite.prototype._renderWebGL = function (renderer) +Graphics.prototype.updateLocalBounds = function () { - - // tweak our texture temporarily.. - var texture = this._texture; + var minX = Infinity; + var maxX = -Infinity; - if(!texture || !texture._uvs) + var minY = Infinity; + var maxY = -Infinity; + + if (this.graphicsData.length) { - return; - } + var shape, points, x, y, w, h; - // get rid of any thing that may be batching. - renderer.flush(); + for (var i = 0; i < this.graphicsData.length; i++) + { + var data = this.graphicsData[i]; + var type = data.type; + var lineWidth = data.lineWidth; + shape = data.shape; - var gl = renderer.gl; - var glData = this._glDatas[renderer.CONTEXT_UID]; + if (type === CONST.SHAPES.RECT || type === CONST.SHAPES.RREC) + { + x = shape.x - lineWidth/2; + y = shape.y - lineWidth/2; + w = shape.width + lineWidth; + h = shape.height + lineWidth; - if(!glData) - { - glData = { - shader:new TilingShader(gl), - quad:new core.Quad(gl) - } + minX = x < minX ? x : minX; + maxX = x + w > maxX ? x + w : maxX; - this._glDatas[renderer.CONTEXT_UID] = glData; - - glData.quad.initVao(glData.shader); - } + minY = y < minY ? y : minY; + maxY = y + h > maxY ? y + h : maxY; + } + else if (type === CONST.SHAPES.CIRC) + { + x = shape.x; + y = shape.y; + w = shape.radius + lineWidth/2; + h = shape.radius + lineWidth/2; - // if the sprite is trimmed and is not a tilingsprite then we need to add the extra space before transforming the sprite coords.. - var vertices = glData.quad.vertices; + minX = x - w < minX ? x - w : minX; + maxX = x + w > maxX ? x + w : maxX; - vertices[0] = vertices[6] = ( this._width ) * -this.anchor.x; - vertices[1] = vertices[3] = this._height * -this.anchor.y; + minY = y - h < minY ? y - h : minY; + maxY = y + h > maxY ? y + h : maxY; + } + else if (type === CONST.SHAPES.ELIP) + { + x = shape.x; + y = shape.y; + w = shape.width + lineWidth/2; + h = shape.height + lineWidth/2; - vertices[2] = vertices[4] = ( this._width ) * (1-this.anchor.x); - vertices[5] = vertices[7] = this._height * (1-this.anchor.y); + minX = x - w < minX ? x - w : minX; + maxX = x + w > maxX ? x + w : maxX; - glData.quad.upload(); - - renderer.bindShader(glData.shader); + minY = y - h < minY ? y - h : minY; + maxY = y + h > maxY ? y + h : maxY; + } + else + { + // POLY + points = shape.points; - var textureUvs = texture._uvs, - textureWidth = texture._frame.width, - textureHeight = texture._frame.height, - textureBaseWidth = texture.baseTexture.width, - textureBaseHeight = texture.baseTexture.height; + for (var j = 0; j < points.length; j += 2) + { + x = points[j]; + y = points[j+1]; - var uPixelSize = glData.shader.uniforms.uPixelSize; - uPixelSize[0] = 1.0/textureBaseWidth; - uPixelSize[1] = 1.0/textureBaseHeight; - glData.shader.uniforms.uPixelSize = uPixelSize; + minX = x-lineWidth < minX ? x-lineWidth : minX; + maxX = x+lineWidth > maxX ? x+lineWidth : maxX; - var uFrame = glData.shader.uniforms.uFrame; - uFrame[0] = textureUvs.x0; - uFrame[1] = textureUvs.y0; - uFrame[2] = textureUvs.x1 - textureUvs.x0; - uFrame[3] = textureUvs.y2 - textureUvs.y0; - glData.shader.uniforms.uFrame = uFrame; + minY = y-lineWidth < minY ? y-lineWidth : minY; + maxY = y+lineWidth > maxY ? y+lineWidth : maxY; + } + } + } + } + else + { + minX = 0; + maxX = 0; + minY = 0; + maxY = 0; + } - var uTransform = glData.shader.uniforms.uTransform; - uTransform[0] = (this.tilePosition.x % (textureWidth * this.tileScale.x)) / this._width; - uTransform[1] = (this.tilePosition.y % (textureHeight * this.tileScale.y)) / this._height; - uTransform[2] = ( textureBaseWidth / this._width ) * this.tileScale.x; - uTransform[3] = ( textureBaseHeight / this._height ) * this.tileScale.y; - glData.shader.uniforms.uTransform = uTransform; + var padding = this.boundsPadding; - glData.shader.uniforms.translationMatrix = this.worldTransform.toArray(true); - glData.shader.uniforms.alpha = this.worldAlpha; + this._localBounds.minX = minX - padding; + this._localBounds.maxX = maxX + padding * 2; - renderer.bindTexture(this._texture, 0); - glData.quad.draw(); + this._localBounds.minY = minY - padding; + this._localBounds.maxY = maxY + padding * 2; }; + /** - * Renders the object using the Canvas renderer + * Draws the given shape to this Graphics object. Can be any of Circle, Rectangle, Ellipse, Line or Polygon. * - * @param renderer {PIXI.CanvasRenderer} a reference to the canvas renderer - * @private + * @param shape {PIXI.Circle|PIXI.Ellipse|PIXI.Polygon|PIXI.Rectangle|PIXI.RoundedRectangle} The shape object to draw. + * @return {PIXI.GraphicsData} The generated GraphicsData object. */ -TilingSprite.prototype._renderCanvas = function (renderer) +Graphics.prototype.drawShape = function (shape) { - var texture = this._texture; + if (this.currentPath) + { + // check current path! + if (this.currentPath.shape.points.length <= 2) + { + this.graphicsData.pop(); + } + } - if (!texture.baseTexture.hasLoaded) + this.currentPath = null; + + var data = new GraphicsData(this.lineWidth, this.lineColor, this.lineAlpha, this.fillColor, this.fillAlpha, this.filling, shape); + + this.graphicsData.push(data); + + if (data.type === CONST.SHAPES.POLY) { - return; + data.shape.closed = data.shape.closed || this.filling; + this.currentPath = data; } - var context = renderer.context, - transform = this.worldTransform, - resolution = renderer.resolution, - baseTexture = texture.baseTexture, - modX = (this.tilePosition.x / this.tileScale.x) % texture._frame.width, - modY = (this.tilePosition.y / this.tileScale.y) % texture._frame.height; + this.dirty = this.boundsDirty = true; + + return data; +}; + +Graphics.prototype.generateCanvasTexture = function(scaleMode, resolution) +{ + resolution = resolution || 1; - // create a nice shiny pattern! - // TODO this needs to be refreshed if texture changes.. - if(!this._canvasPattern) - { - // cut an object from a spritesheet.. - var tempCanvas = new core.CanvasRenderTarget(texture._frame.width, texture._frame.height); + var bounds = this.getLocalBounds(); - // Tint the tiling sprite - if (this.tint !== 0xFFFFFF) - { - if (this.cachedTint !== this.tint) - { - this.cachedTint = this.tint; + var canvasBuffer = new RenderTexture.create(bounds.width * resolution, bounds.height * resolution); - this.tintedTexture = CanvasTinter.getTintedTexture(this, this.tint); - } - tempCanvas.context.drawImage(this.tintedTexture, 0, 0); - } - else - { - tempCanvas.context.drawImage(baseTexture.source, -texture._frame.x, -texture._frame.y); - } - this._canvasPattern = tempCanvas.context.createPattern( tempCanvas.canvas, 'repeat' ); + if(!canvasRenderer) + { + canvasRenderer = new CanvasRenderer(); } - // set context state.. - context.globalAlpha = this.worldAlpha; - context.setTransform(transform.a * resolution, - transform.b * resolution, - transform.c * resolution, - transform.d * resolution, - transform.tx * resolution, - transform.ty * resolution); + tempMatrix.tx = -bounds.x; + tempMatrix.ty = -bounds.y; - // TODO - this should be rolled into the setTransform above.. - context.scale(this.tileScale.x,this.tileScale.y); + canvasRenderer.render(this, canvasBuffer, false, tempMatrix); - context.translate(modX + (this.anchor.x * -this._width ), - modY + (this.anchor.y * -this._height)); + var texture = Texture.fromCanvas(canvasBuffer.baseTexture._canvasRenderTarget.canvas, scaleMode); + texture.baseTexture.resolution = resolution; - // check blend mode - var compositeOperation = renderer.blendModes[this.blendMode]; - if (compositeOperation !== renderer.context.globalCompositeOperation) + return texture; +}; + +Graphics.prototype.closePath = function () +{ + // ok so close path assumes next one is a hole! + var currentPath = this.currentPath; + if (currentPath && currentPath.shape) { - context.globalCompositeOperation = compositeOperation; + currentPath.shape.close(); } + return this; +}; - // fill the pattern! - context.fillStyle = this._canvasPattern; - context.fillRect(-modX, - -modY, - this._width / this.tileScale.x, - this._height / this.tileScale.y); +Graphics.prototype.addHole = function() +{ + // this is a hole! + var hole = this.graphicsData.pop(); + this.currentPath = this.graphicsData[this.graphicsData.length-1]; - //TODO - pretty sure this can be deleted... - //context.translate(-this.tilePosition.x + (this.anchor.x * this._width), -this.tilePosition.y + (this.anchor.y * this._height)); - //context.scale(1 / this.tileScale.x, 1 / this.tileScale.y); -}; + this.currentPath.addHole(hole.shape); + this.currentPath = null; + return this; +}; /** - * Returns the framing rectangle of the sprite as a Rectangle object -* - * @return {PIXI.Rectangle} the framing rectangle + * Destroys the Graphics object. */ -TilingSprite.prototype.getBounds = function () +Graphics.prototype.destroy = function () { - var width = this._width; - var height = this._height; - - var w0 = width * (1-this.anchor.x); - var w1 = width * -this.anchor.x; - - var h0 = height * (1-this.anchor.y); - var h1 = height * -this.anchor.y; + Container.prototype.destroy.apply(this, arguments); - var worldTransform = this.worldTransform; + // destroy each of the GraphicsData objects + for (var i = 0; i < this.graphicsData.length; ++i) { + this.graphicsData[i].destroy(); + } - var a = worldTransform.a; - var b = worldTransform.b; - var c = worldTransform.c; - var d = worldTransform.d; - var tx = worldTransform.tx; - var ty = worldTransform.ty; + // for each webgl data entry, destroy the WebGLGraphicsData + for (var id in this._webgl) { + for (var j = 0; j < this._webgl[id].data.length; ++j) { + this._webgl[id].data[j].destroy(); + } + } - var x1 = a * w1 + c * h1 + tx; - var y1 = d * h1 + b * w1 + ty; + if(this._spriteRect) + { + this._spriteRect.destroy(); + } + this.graphicsData = null; - var x2 = a * w0 + c * h1 + tx; - var y2 = d * h1 + b * w0 + ty; + this.currentPath = null; + this._webgl = null; + this._localBounds = null; +}; + +},{"../const":42,"../display/Bounds":43,"../display/Container":44,"../math":66,"../renderers/canvas/CanvasRenderer":73,"../sprites/Sprite":97,"../textures/RenderTexture":107,"../textures/Texture":108,"./GraphicsData":50,"./utils/bezierCurveTo":52}],50:[function(require,module,exports){ +/** + * A GraphicsData object. + * + * @class + * @memberof PIXI + * @param lineWidth {number} the width of the line to draw + * @param lineColor {number} the color of the line to draw + * @param lineAlpha {number} the alpha of the line to draw + * @param fillColor {number} the color of the fill + * @param fillAlpha {number} the alpha of the fill + * @param fill {boolean} whether or not the shape is filled with a colour + * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. + */ +function GraphicsData(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) +{ + /* + * @member {number} the width of the line to draw + */ + this.lineWidth = lineWidth; - var x3 = a * w0 + c * h0 + tx; - var y3 = d * h0 + b * w0 + ty; + /* + * @member {number} the color of the line to draw + */ + this.lineColor = lineColor; - var x4 = a * w1 + c * h0 + tx; - var y4 = d * h0 + b * w1 + ty; + /* + * @member {number} the alpha of the line to draw + */ + this.lineAlpha = lineAlpha; - var minX, - maxX, - minY, - maxY; + /* + * @member {number} cached tint of the line to draw + */ + this._lineTint = lineColor; - minX = x1; - minX = x2 < minX ? x2 : minX; - minX = x3 < minX ? x3 : minX; - minX = x4 < minX ? x4 : minX; + /* + * @member {number} the color of the fill + */ + this.fillColor = fillColor; - minY = y1; - minY = y2 < minY ? y2 : minY; - minY = y3 < minY ? y3 : minY; - minY = y4 < minY ? y4 : minY; + /* + * @member {number} the alpha of the fill + */ + this.fillAlpha = fillAlpha; - maxX = x1; - maxX = x2 > maxX ? x2 : maxX; - maxX = x3 > maxX ? x3 : maxX; - maxX = x4 > maxX ? x4 : maxX; + /* + * @member {number} cached tint of the fill + */ + this._fillTint = fillColor; - maxY = y1; - maxY = y2 > maxY ? y2 : maxY; - maxY = y3 > maxY ? y3 : maxY; - maxY = y4 > maxY ? y4 : maxY; + /* + * @member {boolean} whether or not the shape is filled with a colour + */ + this.fill = fill; - var bounds = this._bounds; + this.holes = []; - bounds.x = minX; - bounds.width = maxX - minX; + /* + * @member {PIXI.Circle|PIXI.Ellipse|PIXI.Polygon|PIXI.Rectangle|PIXI.RoundedRectangle} The shape object to draw. + */ + this.shape = shape; - bounds.y = minY; - bounds.height = maxY - minY; + /* + * @member {number} The type of the shape, see the Const.Shapes file for all the existing types, + */ + this.type = shape.type; +} - // store a reference so that if this function gets called again in the render cycle we do not have to recalculate - this._currentBounds = bounds; +GraphicsData.prototype.constructor = GraphicsData; +module.exports = GraphicsData; - return bounds; +/** + * Creates a new GraphicsData object with the same values as this one. + * + * @return {PIXI.GraphicsData} Cloned GraphicsData object + */ +GraphicsData.prototype.clone = function () +{ + return new GraphicsData( + this.lineWidth, + this.lineColor, + this.lineAlpha, + this.fillColor, + this.fillAlpha, + this.fill, + this.shape + ); }; /** - * Checks if a point is inside this tiling sprite - * @param point {PIXI.Point} the point to check + * + * */ -TilingSprite.prototype.containsPoint = function( point ) +GraphicsData.prototype.addHole = function (shape) { - this.worldTransform.applyInverse(point, tempPoint); - - var width = this._width; - var height = this._height; - var x1 = -width * this.anchor.x; - var y1; - - if ( tempPoint.x > x1 && tempPoint.x < x1 + width ) - { - y1 = -height * this.anchor.y; - - if ( tempPoint.y > y1 && tempPoint.y < y1 + height ) - { - return true; - } - } + this.holes.push(shape); +}; - return false; +/** + * Destroys the Graphics data. + */ +GraphicsData.prototype.destroy = function () { + this.shape = null; + this.holes = null; }; + +},{}],51:[function(require,module,exports){ +var CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), + CONST = require('../../const'); /** - * Destroys this tiling sprite + * @author Mat Groves + * + * Big thanks to the very clever Matt DesLauriers https://github.com/mattdesl/ + * for creating the original pixi version! + * Also a thanks to https://github.com/bchevalier for tweaking the tint and alpha so that they now share 4 bytes on the vertex buffer * + * Heavily inspired by LibGDX's CanvasGraphicsRenderer: + * https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/graphics/g2d/CanvasGraphicsRenderer.java */ -TilingSprite.prototype.destroy = function () { - core.Sprite.prototype.destroy.call(this); - - this.tileScale = null; - this._tileScaleOffset = null; - this.tilePosition = null; - - this._uvs = null; -}; /** - * Helper function that creates a tiling sprite that will use a texture from the TextureCache based on the frameId - * The frame ids are created when a Texture packer file has been loaded + * Renderer dedicated to drawing and batching graphics objects. * - * @static - * @param frameId {string} The frame Id of the texture in the cache - * @return {PIXI.extras.TilingSprite} A new TilingSprite using a texture from the texture cache matching the frameId - * @param width {number} the width of the tiling sprite - * @param height {number} the height of the tiling sprite + * @class + * @private + * @memberof PIXI + * @extends PIXI.ObjectRenderer + * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -TilingSprite.fromFrame = function (frameId,width,height) +function CanvasGraphicsRenderer(renderer) { - var texture = core.utils.TextureCache[frameId]; + this.renderer = renderer; +} - if (!texture) - { - throw new Error('The frameId "' + frameId + '" does not exist in the texture cache ' + this); - } - return new TilingSprite(texture,width,height); -}; +CanvasGraphicsRenderer.prototype.constructor = CanvasGraphicsRenderer; +module.exports = CanvasGraphicsRenderer; -/** - * Helper function that creates a sprite that will contain a texture based on an image url - * If the image is not in the texture cache it will be loaded +CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +/* + * Renders a Graphics object to a canvas. * - * @static - * @param imageId {string} The image url of the texture - * @param width {number} the width of the tiling sprite - * @param height {number} the height of the tiling sprite - * @param [crossorigin=(auto)] {boolean} if you want to specify the cross-origin parameter - * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} if you want to specify the scale mode, see {@link PIXI.SCALE_MODES} for possible values - * @return {PIXI.extras.TilingSprite} A new TilingSprite using a texture from the texture cache matching the image id + * @param graphics {PIXI.Graphics} the actual graphics object to render + * @param context {CanvasRenderingContext2D} the 2d drawing method of the canvas */ -TilingSprite.fromImage = function (imageId, width, height, crossorigin, scaleMode) +CanvasGraphicsRenderer.prototype.render = function (graphics) { - return new TilingSprite(core.Texture.fromImage(imageId, crossorigin, scaleMode),width,height); -}; - -},{"../core":50,"../core/sprites/canvas/CanvasTinter":85,"./webgl/TilingShader":111}],107:[function(require,module,exports){ -var core = require('../core'), - DisplayObject = core.DisplayObject, - _tempMatrix = new core.Matrix(); - -DisplayObject.prototype._cacheAsBitmap = false; -DisplayObject.prototype._originalRenderWebGL = null; -DisplayObject.prototype._originalRenderCanvas = null; + var renderer = this.renderer; + var context = renderer.context; + var worldAlpha = graphics.worldAlpha; + var transform = graphics.transform.worldTransform; + var resolution = renderer.resolution; -DisplayObject.prototype._originalUpdateTransform = null; -DisplayObject.prototype._originalHitTest = null; -DisplayObject.prototype._originalDestroy = null; -DisplayObject.prototype._cachedSprite = null; + // if the tint has changed, set the graphics object to dirty. + if (this._prevTint !== this.tint) { + this.dirty = true; + } -Object.defineProperties(DisplayObject.prototype, { + context.setTransform( + transform.a * resolution, + transform.b * resolution, + transform.c * resolution, + transform.d * resolution, + transform.tx * resolution, + transform.ty * resolution + ); - /** - * Set this to true if you want this display object to be cached as a bitmap. - * This basically takes a snap shot of the display object as it is at that moment. It can provide a performance benefit for complex static displayObjects. - * To remove simply set this property to 'false' - * - * @member {boolean} - * @memberof PIXI.DisplayObject# - */ - cacheAsBitmap: { - get: function () - { - return this._cacheAsBitmap; - }, - set: function (value) - { - if (this._cacheAsBitmap === value) - { - return; - } - this._cacheAsBitmap = value; + if (graphics.dirty) + { + this.updateGraphicsTint(graphics); + graphics.dirty = false; + } - if (value) - { - this._originalRenderWebGL = this.renderWebGL; - this._originalRenderCanvas = this.renderCanvas; + renderer.setBlendMode(graphics.blendMode); - this._originalUpdateTransform = this.updateTransform; - this._originalGetBounds = this.getBounds; + for (var i = 0; i < graphics.graphicsData.length; i++) + { + var data = graphics.graphicsData[i]; + var shape = data.shape; - this._originalDestroy = this.destroy; + var fillColor = data._fillTint; + var lineColor = data._lineTint; - this._originalContainsPoint = this.containsPoint; + context.lineWidth = data.lineWidth; - this.renderWebGL = this._renderCachedWebGL; - this.renderCanvas = this._renderCachedCanvas; + if (data.type === CONST.SHAPES.POLY) + { + context.beginPath(); - this.destroy = this._cacheAsBitmapDestroy; + this.renderPolygon(shape.points, shape.closed, context); - } - else + for (var j = 0; j < data.holes.length; j++) { - if (this._cachedSprite) - { - this._destroyCachedDisplayObject(); - } - - this.renderWebGL = this._originalRenderWebGL; - this.renderCanvas = this._originalRenderCanvas; - this.getBounds = this._originalGetBounds; + var hole = data.holes[j]; + this.renderPolygon(hole.points, true, context); + } - this.destroy = this._originalDestroy; - this.updateTransform = this._originalUpdateTransform; - this.containsPoint = this._originalContainsPoint; + if (data.fill) + { + context.globalAlpha = data.fillAlpha * worldAlpha; + context.fillStyle = '#' + ('00000' + ( fillColor | 0).toString(16)).substr(-6); + context.fill(); + } + if (data.lineWidth) + { + context.globalAlpha = data.lineAlpha * worldAlpha; + context.strokeStyle = '#' + ('00000' + ( lineColor | 0).toString(16)).substr(-6); + context.stroke(); } } - } -}); -/** -* Renders a cached version of the sprite with WebGL -* -* @param renderer {PIXI.WebGLRenderer} the WebGL renderer -* @private -*/ -DisplayObject.prototype._renderCachedWebGL = function (renderer) -{ - if (!this.visible || this.worldAlpha <= 0 || !this.renderable) - { - return; - } - - this._initCachedDisplayObject( renderer ); - - this._cachedSprite.transform.updated = true; - this._cachedSprite.worldAlpha = this.worldAlpha; - - this._cachedSprite._renderWebGL(renderer); -}; - -/** -* Prepares the WebGL renderer to cache the sprite -* -* @param renderer {PIXI.WebGLRenderer} the WebGL renderer -* @private -*/ -DisplayObject.prototype._initCachedDisplayObject = function (renderer) -{ - if(this._cachedSprite) - { - return; - } + else if (data.type === CONST.SHAPES.RECT) + { - // first we flush anything left in the renderer (otherwise it would get rendered to the cached texture) - renderer.currentRenderer.flush(); - //this.filters= []; - // next we find the dimensions of the untransformed object - // this function also calls updatetransform on all its children as part of the measuring. This means we don't need to update the transform again in this function - // TODO pass an object to clone too? saves having to create a new one each time! - var bounds = this.getLocalBounds().clone(); + if (data.fillColor || data.fillColor === 0) + { + context.globalAlpha = data.fillAlpha * worldAlpha; + context.fillStyle = '#' + ('00000' + ( fillColor | 0).toString(16)).substr(-6); + context.fillRect(shape.x, shape.y, shape.width, shape.height); - // add some padding! - if(this._filters) - { - var padding = this._filters[0].padding; - bounds.x -= padding; - bounds.y -= padding; + } + if (data.lineWidth) + { + context.globalAlpha = data.lineAlpha * worldAlpha; + context.strokeStyle = '#' + ('00000' + ( lineColor | 0).toString(16)).substr(-6); + context.strokeRect(shape.x, shape.y, shape.width, shape.height); + } + } + else if (data.type === CONST.SHAPES.CIRC) + { + // TODO - need to be Undefined! + context.beginPath(); + context.arc(shape.x, shape.y, shape.radius,0,2*Math.PI); + context.closePath(); - bounds.width += padding * 2; - bounds.height += padding * 2; - } + if (data.fill) + { + context.globalAlpha = data.fillAlpha * worldAlpha; + context.fillStyle = '#' + ('00000' + ( fillColor | 0).toString(16)).substr(-6); + context.fill(); + } + if (data.lineWidth) + { + context.globalAlpha = data.lineAlpha * worldAlpha; + context.strokeStyle = '#' + ('00000' + ( lineColor | 0).toString(16)).substr(-6); + context.stroke(); + } + } + else if (data.type === CONST.SHAPES.ELIP) + { + // ellipse code taken from: http://stackoverflow.com/questions/2172798/how-to-draw-an-oval-in-html5-canvas - // for now we cache the current renderTarget that the webGL renderer is currently using. - // this could be more elegent.. - var cachedRenderTarget = renderer._activeRenderTarget; - // We also store the filter stack - I will definitely look to change how this works a little later down the line. - var stack = renderer.filterManager.filterStack; + var w = shape.width * 2; + var h = shape.height * 2; - // this renderTexture will be used to store the cached DisplayObject - - var renderTexture = new core.RenderTexture.create(bounds.width | 0, bounds.height | 0); + var x = shape.x - w/2; + var y = shape.y - h/2; - // need to set // - var m = _tempMatrix; + context.beginPath(); - m.tx = -bounds.x; - m.ty = -bounds.y; + var kappa = 0.5522848, + ox = (w / 2) * kappa, // control point offset horizontal + oy = (h / 2) * kappa, // control point offset vertical + xe = x + w, // x-end + ye = y + h, // y-end + xm = x + w / 2, // x-middle + ym = y + h / 2; // y-middle - // set all properties to there original so we can render to a texture - this.renderWebGL = this._originalRenderWebGL; + context.moveTo(x, ym); + context.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y); + context.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym); + context.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye); + context.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym); - renderer.render(this, renderTexture, true, m, true); - // now restore the state be setting the new properties - - renderer.bindRenderTarget(cachedRenderTarget); - - renderer.filterManager.filterStack = stack; + context.closePath(); - this.renderWebGL = this._renderCachedWebGL; - this.updateTransform = this.displayObjectUpdateTransform; - this.getBounds = this._getCachedBounds; + if (data.fill) + { + context.globalAlpha = data.fillAlpha * worldAlpha; + context.fillStyle = '#' + ('00000' + ( fillColor | 0).toString(16)).substr(-6); + context.fill(); + } + if (data.lineWidth) + { + context.globalAlpha = data.lineAlpha * worldAlpha; + context.strokeStyle = '#' + ('00000' + ( lineColor | 0).toString(16)).substr(-6); + context.stroke(); + } + } + else if (data.type === CONST.SHAPES.RREC) + { + var rx = shape.x; + var ry = shape.y; + var width = shape.width; + var height = shape.height; + var radius = shape.radius; + var maxRadius = Math.min(width, height) / 2 | 0; + radius = radius > maxRadius ? maxRadius : radius; - // create our cached sprite - this._cachedSprite = new core.Sprite(renderTexture); - this._cachedSprite.transform.worldTransform = this.transform.worldTransform; - this._cachedSprite.anchor.x = -( bounds.x / bounds.width ); - this._cachedSprite.anchor.y = -( bounds.y / bounds.height ); + context.beginPath(); + context.moveTo(rx, ry + radius); + context.lineTo(rx, ry + height - radius); + context.quadraticCurveTo(rx, ry + height, rx + radius, ry + height); + context.lineTo(rx + width - radius, ry + height); + context.quadraticCurveTo(rx + width, ry + height, rx + width, ry + height - radius); + context.lineTo(rx + width, ry + radius); + context.quadraticCurveTo(rx + width, ry, rx + width - radius, ry); + context.lineTo(rx + radius, ry); + context.quadraticCurveTo(rx, ry, rx, ry + radius); + context.closePath(); - // restore the transform of the cached sprite to avoid the nasty flicker.. - this.updateTransform(); + if (data.fillColor || data.fillColor === 0) + { + context.globalAlpha = data.fillAlpha * worldAlpha; + context.fillStyle = '#' + ('00000' + ( fillColor | 0).toString(16)).substr(-6); + context.fill(); - // map the hit test.. - this.containsPoint = this._cachedSprite.containsPoint.bind(this._cachedSprite); + } + if (data.lineWidth) + { + context.globalAlpha = data.lineAlpha * worldAlpha; + context.strokeStyle = '#' + ('00000' + ( lineColor | 0).toString(16)).substr(-6); + context.stroke(); + } + } + } }; -/** -* Renders a cached version of the sprite with canvas -* -* @param renderer {PIXI.CanvasRenderer} the Canvas renderer -* @private -*/ -DisplayObject.prototype._renderCachedCanvas = function (renderer) +/* + * Updates the tint of a graphics object + * + * @private + * @param graphics {PIXI.Graphics} the graphics that will have its tint updated + * + */ +CanvasGraphicsRenderer.prototype.updateGraphicsTint = function (graphics) { - if (!this.visible || this.worldAlpha <= 0 || !this.renderable) - { - return; - } + graphics._prevTint = graphics.tint; - this._initCachedDisplayObjectCanvas( renderer ); + var tintR = (graphics.tint >> 16 & 0xFF) / 255; + var tintG = (graphics.tint >> 8 & 0xFF) / 255; + var tintB = (graphics.tint & 0xFF)/ 255; - this._cachedSprite.worldAlpha = this.worldAlpha; + for (var i = 0; i < graphics.graphicsData.length; i++) + { + var data = graphics.graphicsData[i]; + + var fillColor = data.fillColor | 0; + var lineColor = data.lineColor | 0; - this._cachedSprite.renderCanvas(renderer); + // super inline cos im an optimization NAZI :) + data._fillTint = (((fillColor >> 16 & 0xFF) / 255 * tintR*255 << 16) + ((fillColor >> 8 & 0xFF) / 255 * tintG*255 << 8) + (fillColor & 0xFF) / 255 * tintB*255); + data._lineTint = (((lineColor >> 16 & 0xFF) / 255 * tintR*255 << 16) + ((lineColor >> 8 & 0xFF) / 255 * tintG*255 << 8) + (lineColor & 0xFF) / 255 * tintB*255); + } }; -//TODO this can be the same as the webGL verison.. will need to do a little tweaking first though.. -/** -* Prepares the Canvas renderer to cache the sprite -* -* @param renderer {PIXI.CanvasRenderer} the Canvas renderer -* @private -*/ -DisplayObject.prototype._initCachedDisplayObjectCanvas = function (renderer) +CanvasGraphicsRenderer.prototype.renderPolygon = function (points, close, context) { - if(this._cachedSprite) + context.moveTo(points[0], points[1]); + + for (var j=1; j < points.length/2; j++) { - return; + context.lineTo(points[j * 2], points[j * 2 + 1]); } - //get bounds actually transforms the object for us already! - var bounds = this.getLocalBounds(); - - var cachedRenderTarget = renderer.context; - - var renderTexture = new core.RenderTexture.create(bounds.width | 0, bounds.height | 0); + if (close) + { + context.closePath(); + } +}; - // need to set // - var m = _tempMatrix; - this.transform.worldTransform.copy(m); - m.invert(); +/* + * destroy graphics object + * + */ +CanvasGraphicsRenderer.prototype.destroy = function () +{ + this.renderer = null; +}; + +},{"../../const":42,"../../renderers/canvas/CanvasRenderer":73}],52:[function(require,module,exports){ - m.tx -= bounds.x; - m.ty -= bounds.y; +/** + * Calculate the points for a bezier curve and then draws it. + * + * Ignored from docs since it is not directly exposed. + * + * @ignore + * @param fromX {number} Starting point x + * @param fromY {number} Starting point y + * @param cpX {number} Control point x + * @param cpY {number} Control point y + * @param cpX2 {number} Second Control point x + * @param cpY2 {number} Second Control point y + * @param toX {number} Destination point x + * @param toY {number} Destination point y + * @param [path=number[]] Path array to push points into + * @return {PIXI.Graphics} + */ +var bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +{ + path = path || []; - //m.append(this.transform.worldTransform.) - // set all properties to there original so we can render to a texture - this.renderCanvas = this._originalRenderCanvas; + var n = 20, + dt, + dt2, + dt3, + t2, + t3; - //renderTexture.render(this, m, true); - renderer.render(this, renderTexture, true, m, false); + path.push(fromX, fromY); - // now restore the state be setting the new properties - renderer.context = cachedRenderTarget; + var j = 0; - this.renderCanvas = this._renderCachedCanvas; - this.updateTransform = this.displayObjectUpdateTransform; - this.getBounds = this._getCachedBounds; + for (var i = 1; i <= n; ++i) + { + j = i / n; + dt = (1 - j); + dt2 = dt * dt; + dt3 = dt2 * dt; - // create our cached sprite - this._cachedSprite = new core.Sprite(renderTexture); - this._cachedSprite.transform.worldTransform = this.transform.worldTransform; - this._cachedSprite.anchor.x = -( bounds.x / bounds.width ); - this._cachedSprite.anchor.y = -( bounds.y / bounds.height ); + t2 = j * j; + t3 = t2 * j; - this.updateTransform(); + path.push( dt3 * fromX + 3 * dt2 * j * cpX + 3 * dt * t2 * cpX2 + t3 * toX, + dt3 * fromY + 3 * dt2 * j * cpY + 3 * dt * t2 * cpY2 + t3 * toY); + } - this.containsPoint = this._cachedSprite.containsPoint.bind(this._cachedSprite); + return path; }; -/** -* Calculates the bounds of the cached sprite -* -* @private -*/ -DisplayObject.prototype._getCachedBounds = function () -{ - this._cachedSprite._currentBounds = null; +module.exports = bezierCurveTo; + +},{}],53:[function(require,module,exports){ +var utils = require('../../utils'), + CONST = require('../../const'), + ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), + WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), + WebGLGraphicsData = require('./WebGLGraphicsData'), + PrimitiveShader = require('./shaders/PrimitiveShader'), - return this._cachedSprite.getBounds(); -}; + // some drawing functions.. + buildPoly = require('./utils/buildPoly'), + buildRectangle = require('./utils/buildRectangle'), + buildRoundedRectangle = require('./utils/buildRoundedRectangle'), + buildCircle = require('./utils/buildCircle'); -/** -* Destroys the cached sprite. -* -* @private -*/ -DisplayObject.prototype._destroyCachedDisplayObject = function () -{ - this._cachedSprite._texture.destroy(true); - this._cachedSprite = null; -}; -DisplayObject.prototype._cacheAsBitmapDestroy = function () -{ - this.cacheAsBitmap = false; - this._originalDestroy(); -}; - -},{"../core":50}],108:[function(require,module,exports){ -var core = require('../core'); /** - * The instance name of the object. + * Renders the graphics object. * - * @memberof PIXI.DisplayObject# - * @member {string} + * @class + * @memberof PIXI + * @extends PIXI.ObjectRenderer + * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -core.DisplayObject.prototype.name = null; - -/** -* Returns the display object in the container -* -* @memberof PIXI.Container# -* @param name {string} instance name -* @return {PIXI.DisplayObject} -*/ -core.Container.prototype.getChildByName = function (name) +function GraphicsRenderer(renderer) { - for (var i = 0; i < this.children.length; i++) - { - if (this.children[i].name === name) - { - return this.children[i]; - } - } - return null; -}; - -},{"../core":50}],109:[function(require,module,exports){ -var core = require('../core'); + ObjectRenderer.call(this, renderer); -/** -* Returns the global position of the displayObject -* -* @memberof PIXI.DisplayObject# -* @param point {Point} the point to write the global value to. If null a new point will be returned -* @return {Point} -*/ -core.DisplayObject.prototype.getGlobalPosition = function (point) -{ - point = point || new core.Point(); + this.graphicsDataPool = []; + + this.primitiveShader = null; - if(this.parent) - { - this.displayObjectUpdateTransform(); + this.gl = renderer.gl; - point.x = this.worldTransform.tx; - point.y = this.worldTransform.ty; - } - else - { - point.x = this.position.x; - point.y = this.position.y; - } + // easy access! + this.CONTEXT_UID = 0; +} - return point; -}; - -},{"../core":50}],110:[function(require,module,exports){ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +GraphicsRenderer.prototype = Object.create(ObjectRenderer.prototype); +GraphicsRenderer.prototype.constructor = GraphicsRenderer; +module.exports = GraphicsRenderer; -require('./cacheAsBitmap'); -require('./getChildByName'); -require('./getGlobalPosition'); +WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); /** - * @namespace PIXI.extras + * Called when there is a WebGL context change + * + * @private + * */ -module.exports = { - MovieClip: require('./MovieClip'), - TilingSprite: require('./TilingSprite'), - BitmapText: require('./BitmapText') +GraphicsRenderer.prototype.onContextChange = function() +{ + this.gl = this.renderer.gl; + this.CONTEXT_UID = this.renderer.CONTEXT_UID; + this.primitiveShader = new PrimitiveShader(this.gl); }; - -},{"./BitmapText":104,"./MovieClip":105,"./TilingSprite":106,"./cacheAsBitmap":107,"./getChildByName":108,"./getGlobalPosition":109}],111:[function(require,module,exports){ -var Shader = require('pixi-gl-core').GLShader; - /** - * @class - * @extends PIXI.Shader - * @memberof PIXI.mesh - * @param shaderManager {PIXI.ShaderManager} The WebGL shader manager this shader works for. + * Destroys this renderer. + * */ -function TilingShader(gl) +GraphicsRenderer.prototype.destroy = function () { - Shader.call(this, - gl, - "precision lowp float;\n#define GLSLIFY 1\n\nattribute vec2 aVertexPosition;\n\nattribute vec2 aTextureCoord;\n\nattribute vec4 aColor;\n\nuniform mat3 projectionMatrix;\n\nuniform mat3 translationMatrix;\n\nuniform vec4 uFrame;\n\nuniform vec4 uTransform;\n\nvarying vec2 vTextureCoord;\n\nvarying vec4 vColor;\n\nvoid main(void)\n\n{\n\n gl_Position = vec4((projectionMatrix * translationMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\n\n \n\n vec2 coord = aTextureCoord;\n\n coord -= uTransform.xy;\n\n coord /= uTransform.zw;\n\n vTextureCoord = coord;\n\n \n\n vColor = vec4(aColor.rgb * aColor.a, aColor.a);\n\n}", - "precision lowp float;\n#define GLSLIFY 1\n\nvarying vec2 vTextureCoord;\n\nvarying vec4 vColor;\n\nuniform sampler2D uSampler;\n\nuniform vec4 uFrame;\n\nuniform vec2 uPixelSize;\n\nvoid main(void)\n\n{\n\n vec2 coord = mod(vTextureCoord, uFrame.zw);\n\n coord = clamp(coord, uPixelSize, uFrame.zw - uPixelSize);\n\n coord += uFrame.xy;\n\n gl_FragColor = texture2D(uSampler, coord) ;\n\n}" - ); -} + ObjectRenderer.prototype.destroy.call(this); -TilingShader.prototype = Object.create(Shader.prototype); -TilingShader.prototype.constructor = TilingShader; -module.exports = TilingShader; + for (var i = 0; i < this.graphicsDataPool.length; ++i) { + this.graphicsDataPool[i].destroy(); + } - -},{"pixi-gl-core":15}],112:[function(require,module,exports){ -var core = require('../../core'), - BlurXFilter = require('./BlurXFilter'), - BlurYFilter = require('./BlurYFilter'); + this.graphicsDataPool = null; +}; /** - * The BlurFilter applies a Gaussian blur to an object. - * The strength of the blur can be set for x- and y-axis separately. + * Renders a graphics object. * - * @class - * @extends PIXI.Filter - * @memberof PIXI.filters + * @param graphics {PIXI.Graphics} The graphics object to render. */ -function BlurFilter() +GraphicsRenderer.prototype.render = function(graphics) { - core.Filter.call(this); + var renderer = this.renderer; + var gl = renderer.gl; - this.blurXFilter = new BlurXFilter(); - this.blurYFilter = new BlurYFilter(); - this.resolution = 0.25;//0.25;//0.25//1//01.26; - this.blurYFilter.passes = this.blurXFilter.passes = 1; - this.blurYFilter.strength = this.blurXFilter.strength = 4;//4// 4 + var webGLData; - this.padding = 20; + if (graphics.dirty || !graphics._webGL[this.CONTEXT_UID]) + { + this.updateGraphics(graphics); + } -} + var webGL = graphics._webGL[this.CONTEXT_UID]; -BlurFilter.prototype = Object.create(core.Filter.prototype); -BlurFilter.prototype.constructor = BlurFilter; -module.exports = BlurFilter; + // This could be speeded up for sure! + var shader = this.primitiveShader; + renderer.bindShader(shader); + renderer.state.setBlendMode( graphics.blendMode ); -BlurFilter.prototype.apply = function (filterManager, input, output) -{ - var renderTarget = filterManager.getRenderTarget(true); + for (var i = 0, n = webGL.data.length; i < n; i++) + { + webGLData = webGL.data[i]; + var shaderTemp = webGLData.shader; - this.blurXFilter.apply(filterManager, input, renderTarget, true); - this.blurYFilter.apply(filterManager, renderTarget, output); + renderer.bindShader(shaderTemp); + shaderTemp.uniforms.translationMatrix = graphics.transform.worldTransform.toArray(true); + shaderTemp.uniforms.tint = utils.hex2rgb(graphics.tint); + shaderTemp.uniforms.alpha = graphics.worldAlpha; - filterManager.returnRenderTarget(renderTarget); + webGLData.vao.bind() + .draw(gl.TRIANGLE_STRIP, webGLData.indices.length) + .unbind(); + } }; -Object.defineProperties(BlurFilter.prototype, { - /** - * Sets the strength of both the blurX and blurY properties simultaneously - * - * @member {number} - * @memberOf PIXI.filters.BlurFilter# - * @default 2 - */ - blur: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) +/** + * Updates the graphics object + * + * @private + * @param graphics {PIXI.Graphics} The graphics object to update + */ +GraphicsRenderer.prototype.updateGraphics = function(graphics) +{ + var gl = this.renderer.gl; + + // get the contexts graphics object + var webGL = graphics._webGL[this.CONTEXT_UID]; + + // if the graphics object does not exist in the webGL context time to create it! + if (!webGL) + { + webGL = graphics._webGL[this.CONTEXT_UID] = {lastIndex:0, data:[], gl:gl}; + + } + + // flag the graphics as not dirty as we are about to update it... + graphics.dirty = false; + + var i; + + // if the user cleared the graphics object we will need to clear every object + if (graphics.clearDirty) + { + graphics.clearDirty = false; + + // loop through and return all the webGLDatas to the object pool so than can be reused later on + for (i = 0; i < webGL.data.length; i++) { - this.padding = Math.abs(value) * 0.5; - this.blurXFilter.blur = this.blurYFilter.blur = value; + var graphicsData = webGL.data[i]; + this.graphicsDataPool.push( graphicsData ); } - }, - /** - * Sets the number of passes for blur. More passes means higher quaility bluring. - * - * @member {number} - * @memberof PIXI.filters.BlurYFilter# - * @default 1 - */ - passes: { - get: function () + // clear the array and reset the index.. + webGL.data = []; + webGL.lastIndex = 0; + } + + var webGLData; + + // loop through the graphics datas and construct each one.. + // if the object is a complex fill then the new stencil buffer technique will be used + // other wise graphics objects will be pushed into a batch.. + for (i = webGL.lastIndex; i < graphics.graphicsData.length; i++) + { + var data = graphics.graphicsData[i]; + + //TODO - this can be simplified + webGLData = this.getWebGLData(webGL, 0); + + if (data.type === CONST.SHAPES.POLY) { - return this.blurXFilter.passes; - }, - set: function (value) + buildPoly(data, webGLData); + } + if (data.type === CONST.SHAPES.RECT) { - this.blurXFilter.passes = this.blurYFilter.passes = value; + buildRectangle(data, webGLData); } - }, - - /** - * Sets the strength of the blurX property - * - * @member {number} - * @memberOf PIXI.filters.BlurFilter# - * @default 2 - */ - blurX: { - get: function () + else if (data.type === CONST.SHAPES.CIRC || data.type === CONST.SHAPES.ELIP) { - return this.blurXFilter.blur; - }, - set: function (value) + buildCircle(data, webGLData); + } + else if (data.type === CONST.SHAPES.RREC) { - this.blurXFilter.blur = value; + buildRoundedRectangle(data, webGLData); } - }, - /** - * Sets the strength of the blurY property - * - * @member {number} - * @memberOf PIXI.filters.BlurFilter# - * @default 2 - */ - blurY: { - get: function () - { - return this.blurYFilter.blur; - }, - set: function (value) + webGL.lastIndex++; + } + + // upload all the dirty data... + for (i = 0; i < webGL.data.length; i++) + { + webGLData = webGL.data[i]; + + if (webGLData.dirty) { - this.blurYFilter.blur = value; + webGLData.upload(); } } -}); +}; + +/** + * + * @private + * @param webGL {WebGLRenderingContext} the current WebGL drawing context + * @param type {number} TODO @Alvin + */ +GraphicsRenderer.prototype.getWebGLData = function (webGL, type) +{ + var webGLData = webGL.data[webGL.data.length-1]; + + if (!webGLData || webGLData.points.length > 320000) + { + webGLData = this.graphicsDataPool.pop() || new WebGLGraphicsData(this.renderer.gl, this.primitiveShader, this.renderer.state.attribsState); + webGLData.reset(type); + webGL.data.push(webGLData); + } + + webGLData.dirty = true; + + return webGLData; +}; -},{"../../core":50,"./BlurXFilter":113,"./BlurYFilter":114}],113:[function(require,module,exports){ -var core = require('../../core'); -var generateBlurVertSource = require('./generateBlurVertSource'); -var generateBlurFragSource = require('./generateBlurFragSource'); -var getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +},{"../../const":42,"../../renderers/webgl/WebGLRenderer":80,"../../renderers/webgl/utils/ObjectRenderer":90,"../../utils":115,"./WebGLGraphicsData":54,"./shaders/PrimitiveShader":55,"./utils/buildCircle":56,"./utils/buildPoly":58,"./utils/buildRectangle":59,"./utils/buildRoundedRectangle":60}],54:[function(require,module,exports){ +var glCore = require('pixi-gl-core'); + /** - * The BlurXFilter applies a horizontal Gaussian blur to an object. + * An object containing WebGL specific properties to be used by the WebGL renderer * * @class - * @extends PIXI.Filter - * @memberof PIXI.filters + * @private + * @memberof PIXI + * @param gl {WebGLRenderingContext} The current WebGL drawing context + * @param shader {PIXI.Shader} The shader + * @param attribsState {object} The state for the VAO */ -function BlurXFilter() +function WebGLGraphicsData(gl, shader, attribsState) { - var vertSrc = generateBlurVertSource(5, true); - var fragSrc = generateBlurFragSource(5); - - core.Filter.call(this, - // vertex shader - vertSrc, - // fragment shader - fragSrc - ); /** - * Sets the number of passes for blur. More passes means higher quaility bluring. + * The current WebGL drawing context * - * @member {number} - * @default 1 + * @member {WebGLRenderingContext} */ - this.passes = 1; - this.resolution = 1;//0.25;//0.5;//0.1//5; - this.strength = 4; + this.gl = gl; - this.firstRun = true; -} + //TODO does this need to be split before uploding?? + /** + * An array of color components (r,g,b) + * @member {number[]} + */ + this.color = [0,0,0]; // color split! -BlurXFilter.prototype = Object.create(core.Filter.prototype); -BlurXFilter.prototype.constructor = BlurXFilter; -module.exports = BlurXFilter; + /** + * An array of points to draw + * @member {PIXI.Point[]} + */ + this.points = []; -BlurXFilter.prototype.apply = function (filterManager, input, output, clear) -{ - if(this.firstRun) - { - var gl = filterManager.renderer.gl; - var kernelSize = getMaxBlurKernelSize(gl); + /** + * The indices of the vertices + * @member {number[]} + */ + this.indices = []; + /** + * The main buffer + * @member {WebGLBuffer} + */ + this.buffer = glCore.GLBuffer.createVertexBuffer(gl); - this.vertexSrc = generateBlurVertSource(kernelSize, true); - this.fragmentSrc = generateBlurFragSource(kernelSize); + /** + * The index buffer + * @member {WebGLBuffer} + */ + this.indexBuffer = glCore.GLBuffer.createIndexBuffer(gl); - this.firstRun = false; - } + /** + * Whether this graphics is dirty or not + * @member {boolean} + */ + this.dirty = true; - + this.glPoints = null; + this.glIndices = null; - this.uniforms.strength = (1/output.destinationFrame.width) * (output.size.width/input.size.width); /// // * 2 //4//this.strength / 4 / this.passes * (input.frame.width / input.size.width); + /** + * + * @member {PIXI.Shader} + */ + this.shader = shader; - // screen space! - this.uniforms.strength *= this.strength; - if(this.passes === 1) - { - filterManager.applyFilter(this, input, output, clear); - } - else - { - var renderTarget = filterManager.getRenderTarget(true); - var flip = input; - var flop = renderTarget; + this.vao = new glCore.VertexArrayObject(gl, attribsState) + .addIndex(this.indexBuffer) + .addAttribute(this.buffer, shader.attributes.aVertexPosition, gl.FLOAT, false, 4 * 6, 0) + .addAttribute(this.buffer, shader.attributes.aColor, gl.FLOAT, false, 4 * 6, 2 * 4); - for(var i = 0; i < this.passes-1; i++) - { - filterManager.applyFilter(this, flip, flop, true); - var temp = flop; - flop = flip; - flip = temp; - } +} - filterManager.applyFilter(this, flip, output, clear); +WebGLGraphicsData.prototype.constructor = WebGLGraphicsData; +module.exports = WebGLGraphicsData; - filterManager.returnRenderTarget(renderTarget); - } +/** + * Resets the vertices and the indices + */ +WebGLGraphicsData.prototype.reset = function () +{ + this.points.length = 0; + this.indices.length = 0; +}; + +/** + * Binds the buffers and uploads the data + */ +WebGLGraphicsData.prototype.upload = function () +{ + this.glPoints = new Float32Array(this.points); + this.buffer.upload( this.glPoints ); + + this.glIndices = new Uint16Array(this.indices); + this.indexBuffer.upload( this.glIndices ); + + this.dirty = false; }; -Object.defineProperties(BlurXFilter.prototype, { - /** - * Sets the strength of both the blur. - * - * @member {number} - * @memberof PIXI.filters.BlurXFilter# - * @default 2 - */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 0.5; - this.strength = value; - } - } -}); + +/** + * Empties all the data + */ +WebGLGraphicsData.prototype.destroy = function () +{ + this.color = null; + this.points = null; + this.indices = null; + + this.vao.destroy(); + this.buffer.destroy(); + this.indexBuffer.destroy(); + + this.gl = null; + + this.buffer = null; + this.indexBuffer = null; + + this.glPoints = null; + this.glIndices = null; +}; -},{"../../core":50,"./generateBlurFragSource":115,"./generateBlurVertSource":116,"./getMaxBlurKernelSize":117}],114:[function(require,module,exports){ -var core = require('../../core'); -var generateBlurVertSource = require('./generateBlurVertSource'); -var generateBlurFragSource = require('./generateBlurFragSource'); -var getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +},{"pixi-gl-core":14}],55:[function(require,module,exports){ +var Shader = require('../../../Shader'); /** - * The BlurYFilter applies a horizontal Gaussian blur to an object. + * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. * * @class - * @extends PIXI.Filter - * @memberof PIXI.filters + * @memberof PIXI + * @extends PIXI.Shader + * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -function BlurYFilter() +function PrimitiveShader(gl) { - var vertSrc = generateBlurVertSource(5, false); - var fragSrc = generateBlurFragSource(5); - - core.Filter.call(this, + Shader.call(this, + gl, // vertex shader - vertSrc, - // fragment shader - fragSrc - ); + [ + 'attribute vec2 aVertexPosition;', + 'attribute vec4 aColor;', - this.passes = 1; - this.resolution = 1;//0.25;//0.5;//0.1//5; - this.strength = 4; -} + 'uniform mat3 translationMatrix;', + 'uniform mat3 projectionMatrix;', -BlurYFilter.prototype = Object.create(core.Filter.prototype); -BlurYFilter.prototype.constructor = BlurYFilter; -module.exports = BlurYFilter; + 'uniform float alpha;', + 'uniform vec3 tint;', -BlurYFilter.prototype.apply = function (filterManager, input, output, clear) -{ - if(this.firstRun) - { - var gl = filterManager.renderer.gl; - var kernelSize = getMaxBlurKernelSize(gl); - - this.vertexSrc = generateBlurVertSource(kernelSize, false); - this.fragmentSrc = generateBlurFragSource(kernelSize); + 'varying vec4 vColor;', - this.firstRun = false; - } + 'void main(void){', + ' gl_Position = vec4((projectionMatrix * translationMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);', + ' vColor = aColor * vec4(tint * alpha, alpha);', + '}' + ].join('\n'), + // fragment shader + [ + 'varying vec4 vColor;', + + 'void main(void){', + ' gl_FragColor = vColor;', + '}' + ].join('\n') + ); +} - this.uniforms.strength = (1/output.destinationFrame.height) * (output.size.height/input.size.height); /// // * 2 //4//this.strength / 4 / this.passes * (input.frame.width / input.size.width); +PrimitiveShader.prototype = Object.create(Shader.prototype); +PrimitiveShader.prototype.constructor = PrimitiveShader; - this.uniforms.strength *= this.strength; +module.exports = PrimitiveShader; + +},{"../../../Shader":41}],56:[function(require,module,exports){ +var buildLine = require('./buildLine'), + CONST = require('../../../const'), + utils = require('../../../utils'); + +/** + * Builds a circle to draw + * + * Ignored from docs since it is not directly exposed. + * + * @ignore + * @private + * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw + * @param webGLData {object} an object containing all the webGL-specific information to create this shape + */ +var buildCircle = function (graphicsData, webGLData) +{ + // need to convert points to a nice regular data + var circleData = graphicsData.shape; + var x = circleData.x; + var y = circleData.y; + var width; + var height; - if(this.passes === 1) + // TODO - bit hacky?? + if (graphicsData.type === CONST.SHAPES.CIRC) { - filterManager.applyFilter(this, input, output, clear); + width = circleData.radius; + height = circleData.radius; } else { - var renderTarget = filterManager.getRenderTarget(true); - var flip = input; - var flop = renderTarget; - - for(var i = 0; i < this.passes-1; i++) - { - filterManager.applyFilter(this, flip, flop, true); - - var temp = flop; - flop = flip; - flip = temp; - } - - filterManager.applyFilter(this, flip, output, clear); - - filterManager.returnRenderTarget(renderTarget); + width = circleData.width; + height = circleData.height; } -}; + var totalSegs = Math.floor(30 * Math.sqrt(circleData.radius)) || Math.floor(15 * Math.sqrt(circleData.width + circleData.height)); + var seg = (Math.PI * 2) / totalSegs ; -Object.defineProperties(BlurYFilter.prototype, { - /** - * Sets the strength of both the blur. - * - * @member {number} - * @memberof PIXI.filters.BlurYFilter# - * @default 2 - */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 0.5; - this.strength = value; - } - } -}); - -},{"../../core":50,"./generateBlurFragSource":115,"./generateBlurVertSource":116,"./getMaxBlurKernelSize":117}],115:[function(require,module,exports){ -var GAUSSIAN_VALUES = { - 5:[0.153388, 0.221461, 0.250301], - 7:[0.071303, 0.131514, 0.189879, 0.214607], - 9:[0.028532, 0.067234, 0.124009, 0.179044, 0.20236], - 11:[0.0093, 0.028002, 0.065984, 0.121703, 0.175713, 0.198596], - 13:[0.002406, 0.009255, 0.027867, 0.065666, 0.121117, 0.174868, 0.197641], - 15:[0.000489, 0.002403, 0.009246, 0.02784, 0.065602, 0.120999, 0.174697, 0.197448] -}; + var i = 0; -var fragTemplate = [ + if (graphicsData.fill) + { + var color = utils.hex2rgb(graphicsData.fillColor); + var alpha = graphicsData.fillAlpha; - 'precision mediump float;', + var r = color[0] * alpha; + var g = color[1] * alpha; + var b = color[2] * alpha; - 'varying vec2 vBlurTexCoords[%size%];', - 'uniform sampler2D uSampler;', + var verts = webGLData.points; + var indices = webGLData.indices; - 'void main(void)', - '{', - ' gl_FragColor = vec4(0.0);', - ' %blur%', - '}' + var vecPos = verts.length/6; -].join('\n'); + indices.push(vecPos); -var generateFragBlurSource = function(kernelSize) -{ - var kernel = GAUSSIAN_VALUES[kernelSize]; - var halfLength = kernel.length; + for (i = 0; i < totalSegs + 1 ; i++) + { + verts.push(x,y, r, g, b, alpha); - var fragSource = fragTemplate; + verts.push(x + Math.sin(seg * i) * width, + y + Math.cos(seg * i) * height, + r, g, b, alpha); - var blurLoop = ''; - var template = 'gl_FragColor += texture2D(uSampler, vBlurTexCoords[%index%]) * %value%;'; - var value; + indices.push(vecPos++, vecPos++); + } - for (var i = 0; i < kernelSize; i++) - { - var blur = template.replace('%index%', i); + indices.push(vecPos-1); + } - value = i; + if (graphicsData.lineWidth) + { + var tempPoints = graphicsData.points; - if(i >= halfLength) - { - value = kernelSize - i - 1; - } + graphicsData.points = []; + for (i = 0; i < totalSegs + 1; i++) + { + graphicsData.points.push(x + Math.sin(seg * i) * width, + y + Math.cos(seg * i) * height); + } - blur = blur.replace('%value%', kernel[value]); + buildLine(graphicsData, webGLData); - blurLoop += blur; - blurLoop += '\n'; + graphicsData.points = tempPoints; } - - fragSource = fragSource.replace('%blur%', blurLoop); - fragSource = fragSource.replace('%size%', kernelSize); - - - return fragSource; }; - -module.exports = generateFragBlurSource; +module.exports = buildCircle; -},{}],116:[function(require,module,exports){ - -var vertTemplate = [ - 'attribute vec2 aVertexPosition;', - 'attribute vec2 aTextureCoord;', - - 'uniform float strength;', - 'uniform mat3 projectionMatrix;', - - 'varying vec2 vBlurTexCoords[%size%];', - - 'void main(void)', - '{', - 'gl_Position = vec4((projectionMatrix * vec3((aVertexPosition), 1.0)).xy, 0.0, 1.0);', - '%blur%', - '}' -].join('\n'); +},{"../../../const":42,"../../../utils":115,"./buildLine":57}],57:[function(require,module,exports){ +var math = require('../../../math'), + utils = require('../../../utils'); -var generateVertBlurSource = function(kernelSize, x) +/** + * Builds a line to draw + * + * Ignored from docs since it is not directly exposed. + * + * @ignore + * @private + * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties + * @param webGLData {object} an object containing all the webGL-specific information to create this shape + */ +var buildLine = function (graphicsData, webGLData) { - var halfLength = Math.ceil(kernelSize/2); - - var vertSource = vertTemplate; - - var blurLoop = ''; - var template; - var value; + // TODO OPTIMISE! + var i = 0; + var points = graphicsData.points; - if(x) - { - template = 'vBlurTexCoords[%index%] = aTextureCoord + vec2(%samlpeIndex% * strength, 0.0);'; - } - else + if (points.length === 0) { - template = 'vBlurTexCoords[%index%] = aTextureCoord + vec2(0.0, %samlpeIndex% * strength);'; - + return; } + // if the line width is an odd number add 0.5 to align to a whole pixel + // commenting this out fixes #711 and #1620 + // if (graphicsData.lineWidth%2) + // { + // for (i = 0; i < points.length; i++) + // { + // points[i] += 0.5; + // } + // } + // get first and last point.. figure out the middle! + var firstPoint = new math.Point(points[0], points[1]); + var lastPoint = new math.Point(points[points.length - 2], points[points.length - 1]); - for (var i = 0; i < kernelSize; i++) + // if the first point is the last point - gonna have issues :) + if (firstPoint.x === lastPoint.x && firstPoint.y === lastPoint.y) { - var blur = template.replace('%index%', i); + // need to clone as we are going to slightly modify the shape.. + points = points.slice(); - value = i; + points.pop(); + points.pop(); - if(i >= halfLength) - { - value = kernelSize - i - 1; - } + lastPoint = new math.Point(points[points.length - 2], points[points.length - 1]); - blur = blur.replace('%samlpeIndex%', (i - (halfLength-1)) + '.0'); + var midPointX = lastPoint.x + (firstPoint.x - lastPoint.x) *0.5; + var midPointY = lastPoint.y + (firstPoint.y - lastPoint.y) *0.5; - blurLoop += blur; - blurLoop += '\n'; + points.unshift(midPointX, midPointY); + points.push(midPointX, midPointY); } - vertSource = vertSource.replace('%blur%', blurLoop); - vertSource = vertSource.replace('%size%', kernelSize); - - return vertSource; -}; - + var verts = webGLData.points; + var indices = webGLData.indices; + var length = points.length / 2; + var indexCount = points.length; + var indexStart = verts.length/6; + // DRAW the Line + var width = graphicsData.lineWidth / 2; -module.exports = generateVertBlurSource; - -},{}],117:[function(require,module,exports){ + // sort color + var color = utils.hex2rgb(graphicsData.lineColor); + var alpha = graphicsData.lineAlpha; + var r = color[0] * alpha; + var g = color[1] * alpha; + var b = color[2] * alpha; + var px, py, p1x, p1y, p2x, p2y, p3x, p3y; + var perpx, perpy, perp2x, perp2y, perp3x, perp3y; + var a1, b1, c1, a2, b2, c2; + var denom, pdist, dist; -var getMaxKernelSize = function(gl) -{ - var maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) / 2 ) | 0; - var kernelSize = 15; + p1x = points[0]; + p1y = points[1]; - while(kernelSize > maxVaryings) - { - kernelSize -= 2; - } + p2x = points[2]; + p2y = points[3]; - return kernelSize; -}; + perpx = -(p1y - p2y); + perpy = p1x - p2x; -module.exports = getMaxKernelSize; - -},{}],118:[function(require,module,exports){ -var core = require('../../core'); -// @see https://github.com/substack/brfs/issues/25 + dist = Math.sqrt(perpx*perpx + perpy*perpy); + perpx /= dist; + perpy /= dist; + perpx *= width; + perpy *= width; -/** - * The ColorMatrixFilter class lets you apply a 5x4 matrix transformation on the RGBA - * color and alpha values of every pixel on your displayObject to produce a result - * with a new set of RGBA color and alpha values. It's pretty powerful! - * - * ```js - * var colorMatrix = new PIXI.ColorMatrixFilter(); - * container.filters = [colorMatrix]; - * colorMatrix.contrast(2); - * ``` - * @author Clément Chenebault - * @class - * @extends PIXI.AbstractFilter - * @memberof PIXI.filters - */ -function ColorMatrixFilter() -{ - core.Filter.call(this, - // vertex shader - "precision mediump float;\n#define GLSLIFY 1\n\nattribute vec2 aVertexPosition;\n\nattribute vec2 aTextureCoord;\n\nuniform mat3 projectionMatrix;\n\nvarying vec2 vTextureCoord;\n\nvoid main(void){\n\n gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\n\n vTextureCoord = aTextureCoord;\n\n}", - // fragment shader - "precision mediump float;\n#define GLSLIFY 1\n\nvarying vec2 vTextureCoord;\n\nuniform sampler2D uSampler;\n\nuniform float m[20];\n\nvoid main(void)\n\n{\n\n vec4 c = texture2D(uSampler, vTextureCoord);\n\n gl_FragColor.r = (m[0] * c.r);\n\n gl_FragColor.r += (m[1] * c.g);\n\n gl_FragColor.r += (m[2] * c.b);\n\n gl_FragColor.r += (m[3] * c.a);\n\n gl_FragColor.r += m[4];\n\n gl_FragColor.g = (m[5] * c.r);\n\n gl_FragColor.g += (m[6] * c.g);\n\n gl_FragColor.g += (m[7] * c.b);\n\n gl_FragColor.g += (m[8] * c.a);\n\n gl_FragColor.g += m[9];\n\n gl_FragColor.b = (m[10] * c.r);\n\n gl_FragColor.b += (m[11] * c.g);\n\n gl_FragColor.b += (m[12] * c.b);\n\n gl_FragColor.b += (m[13] * c.a);\n\n gl_FragColor.b += m[14];\n\n gl_FragColor.a = (m[15] * c.r);\n\n gl_FragColor.a += (m[16] * c.g);\n\n gl_FragColor.a += (m[17] * c.b);\n\n gl_FragColor.a += (m[18] * c.a);\n\n gl_FragColor.a += m[19];\n\n// gl_FragColor = vec4(m[0]);\r\n}\n\n" - ); + // start + verts.push(p1x - perpx , p1y - perpy, + r, g, b, alpha); - this.uniforms.m = [ - 1, 0, 0, 0, 0, - 0, 1, 0, 0, 0, - 0, 0, 1, 0, 0, - 0, 0, 0, 1, 0]; + verts.push(p1x + perpx , p1y + perpy, + r, g, b, alpha); + for (i = 1; i < length-1; i++) + { + p1x = points[(i-1)*2]; + p1y = points[(i-1)*2 + 1]; -} + p2x = points[(i)*2]; + p2y = points[(i)*2 + 1]; -ColorMatrixFilter.prototype = Object.create(core.Filter.prototype); -ColorMatrixFilter.prototype.constructor = ColorMatrixFilter; -module.exports = ColorMatrixFilter; + p3x = points[(i+1)*2]; + p3y = points[(i+1)*2 + 1]; + perpx = -(p1y - p2y); + perpy = p1x - p2x; -/** - * Transforms current matrix and set the new one - * - * @param matrix {number[]} (mat 5x4) - * @param multiply {boolean} if true, current matrix and matrix are multiplied. If false, just set the current matrix with @param matrix - */ -ColorMatrixFilter.prototype._loadMatrix = function (matrix, multiply) -{ - multiply = !!multiply; + dist = Math.sqrt(perpx*perpx + perpy*perpy); + perpx /= dist; + perpy /= dist; + perpx *= width; + perpy *= width; - var newMatrix = matrix; + perp2x = -(p2y - p3y); + perp2y = p2x - p3x; - if (multiply) { - this._multiply(newMatrix, this.uniforms.m, matrix); - newMatrix = this._colorMatrix(newMatrix); - } + dist = Math.sqrt(perp2x*perp2x + perp2y*perp2y); + perp2x /= dist; + perp2y /= dist; + perp2x *= width; + perp2y *= width; - // set the new matrix - this.uniforms.m = newMatrix; -}; + a1 = (-perpy + p1y) - (-perpy + p2y); + b1 = (-perpx + p2x) - (-perpx + p1x); + c1 = (-perpx + p1x) * (-perpy + p2y) - (-perpx + p2x) * (-perpy + p1y); + a2 = (-perp2y + p3y) - (-perp2y + p2y); + b2 = (-perp2x + p2x) - (-perp2x + p3x); + c2 = (-perp2x + p3x) * (-perp2y + p2y) - (-perp2x + p2x) * (-perp2y + p3y); -/** - * Multiplies two mat5's - * - * @param out {number[]} (mat 5x4) the receiving matrix - * @param a {number[]} (mat 5x4) the first operand - * @param b {number[]} (mat 5x4) the second operand - * @returns out {number[]} (mat 5x4) - */ -ColorMatrixFilter.prototype._multiply = function (out, a, b) -{ + denom = a1*b2 - a2*b1; - // Red Channel - out[0] = (a[0] * b[0]) + (a[1] * b[5]) + (a[2] * b[10]) + (a[3] * b[15]); - out[1] = (a[0] * b[1]) + (a[1] * b[6]) + (a[2] * b[11]) + (a[3] * b[16]); - out[2] = (a[0] * b[2]) + (a[1] * b[7]) + (a[2] * b[12]) + (a[3] * b[17]); - out[3] = (a[0] * b[3]) + (a[1] * b[8]) + (a[2] * b[13]) + (a[3] * b[18]); - out[4] = (a[0] * b[4]) + (a[1] * b[9]) + (a[2] * b[14]) + (a[3] * b[19]); + if (Math.abs(denom) < 0.1 ) + { - // Green Channel - out[5] = (a[5] * b[0]) + (a[6] * b[5]) + (a[7] * b[10]) + (a[8] * b[15]); - out[6] = (a[5] * b[1]) + (a[6] * b[6]) + (a[7] * b[11]) + (a[8] * b[16]); - out[7] = (a[5] * b[2]) + (a[6] * b[7]) + (a[7] * b[12]) + (a[8] * b[17]); - out[8] = (a[5] * b[3]) + (a[6] * b[8]) + (a[7] * b[13]) + (a[8] * b[18]); - out[9] = (a[5] * b[4]) + (a[6] * b[9]) + (a[7] * b[14]) + (a[8] * b[19]); + denom+=10.1; + verts.push(p2x - perpx , p2y - perpy, + r, g, b, alpha); - // Blue Channel - out[10] = (a[10] * b[0]) + (a[11] * b[5]) + (a[12] * b[10]) + (a[13] * b[15]); - out[11] = (a[10] * b[1]) + (a[11] * b[6]) + (a[12] * b[11]) + (a[13] * b[16]); - out[12] = (a[10] * b[2]) + (a[11] * b[7]) + (a[12] * b[12]) + (a[13] * b[17]); - out[13] = (a[10] * b[3]) + (a[11] * b[8]) + (a[12] * b[13]) + (a[13] * b[18]); - out[14] = (a[10] * b[4]) + (a[11] * b[9]) + (a[12] * b[14]) + (a[13] * b[19]); + verts.push(p2x + perpx , p2y + perpy, + r, g, b, alpha); - // Alpha Channel - out[15] = (a[15] * b[0]) + (a[16] * b[5]) + (a[17] * b[10]) + (a[18] * b[15]); - out[16] = (a[15] * b[1]) + (a[16] * b[6]) + (a[17] * b[11]) + (a[18] * b[16]); - out[17] = (a[15] * b[2]) + (a[16] * b[7]) + (a[17] * b[12]) + (a[18] * b[17]); - out[18] = (a[15] * b[3]) + (a[16] * b[8]) + (a[17] * b[13]) + (a[18] * b[18]); - out[19] = (a[15] * b[4]) + (a[16] * b[9]) + (a[17] * b[14]) + (a[18] * b[19]); + continue; + } - return out; -}; + px = (b1*c2 - b2*c1)/denom; + py = (a2*c1 - a1*c2)/denom; -/** - * Create a Float32 Array and normalize the offset component to 0-1 - * - * @param matrix {number[]} (mat 5x4) - * @return m {number[]} (mat 5x4) with all values between 0-1 - */ -ColorMatrixFilter.prototype._colorMatrix = function (matrix) -{ - // Create a Float32 Array and normalize the offset component to 0-1 - var m = new Float32Array(matrix); - m[4] /= 255; - m[9] /= 255; - m[14] /= 255; - m[19] /= 255; - return m; -}; + pdist = (px -p2x) * (px -p2x) + (py -p2y) * (py -p2y); -/** - * Adjusts brightness - * - * @param b {number} value of the brigthness (0 is black) - * @param multiply {boolean} refer to ._loadMatrix() method - */ -ColorMatrixFilter.prototype.brightness = function (b, multiply) -{ - var matrix = [ - b, 0, 0, 0, 0, - 0, b, 0, 0, 0, - 0, 0, b, 0, 0, - 0, 0, 0, 1, 0 - ]; - this._loadMatrix(matrix, multiply); -}; + if (pdist > 140 * 140) + { + perp3x = perpx - perp2x; + perp3y = perpy - perp2y; -/** - * Set the matrices in grey scales - * - * @param scale {number} value of the grey (0 is black) - * @param multiply {boolean} refer to ._loadMatrix() method - */ -ColorMatrixFilter.prototype.greyscale = function (scale, multiply) -{ - var matrix = [ - scale, scale, scale, 0, 0, - scale, scale, scale, 0, 0, - scale, scale, scale, 0, 0, - 0, 0, 0, 1, 0 - ]; + dist = Math.sqrt(perp3x*perp3x + perp3y*perp3y); + perp3x /= dist; + perp3y /= dist; + perp3x *= width; + perp3y *= width; - this._loadMatrix(matrix, multiply); -}; -//Americanized alias -ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; + verts.push(p2x - perp3x, p2y -perp3y); + verts.push(r, g, b, alpha); -/** - * Set the black and white matrice - * Multiply the current matrix - * - * @param multiply {boolean} refer to ._loadMatrix() method - */ -ColorMatrixFilter.prototype.blackAndWhite = function (multiply) -{ - var matrix = [ - 0.3, 0.6, 0.1, 0, 0, - 0.3, 0.6, 0.1, 0, 0, - 0.3, 0.6, 0.1, 0, 0, - 0, 0, 0, 1, 0 - ]; + verts.push(p2x + perp3x, p2y +perp3y); + verts.push(r, g, b, alpha); - this._loadMatrix(matrix, multiply); -}; + verts.push(p2x - perp3x, p2y -perp3y); + verts.push(r, g, b, alpha); -/** - * Set the hue property of the color - * - * @param rotation {number} in degrees - * @param multiply {boolean} refer to ._loadMatrix() method - */ -ColorMatrixFilter.prototype.hue = function (rotation, multiply) -{ - rotation = (rotation || 0) / 180 * Math.PI; - var cos = Math.cos(rotation), - sin = Math.sin(rotation); + indexCount++; + } + else + { - // luminanceRed, luminanceGreen, luminanceBlue - var lumR = 0.213, // or 0.3086 - lumG = 0.715, // or 0.6094 - lumB = 0.072; // or 0.0820 + verts.push(px , py); + verts.push(r, g, b, alpha); - var matrix = [ - lumR + cos * (1 - lumR) + sin * (-lumR), lumG + cos * (-lumG) + sin * (-lumG), lumB + cos * (-lumB) + sin * (1 - lumB), 0, 0, - lumR + cos * (-lumR) + sin * (0.143), lumG + cos * (1 - lumG) + sin * (0.140), lumB + cos * (-lumB) + sin * (-0.283), 0, 0, - lumR + cos * (-lumR) + sin * (-(1 - lumR)), lumG + cos * (-lumG) + sin * (lumG), lumB + cos * (1 - lumB) + sin * (lumB), 0, 0, - 0, 0, 0, 1, 0 - ]; + verts.push(p2x - (px-p2x), p2y - (py - p2y)); + verts.push(r, g, b, alpha); + } + } + p1x = points[(length-2)*2]; + p1y = points[(length-2)*2 + 1]; - this._loadMatrix(matrix, multiply); -}; + p2x = points[(length-1)*2]; + p2y = points[(length-1)*2 + 1]; + perpx = -(p1y - p2y); + perpy = p1x - p2x; -/** - * Set the contrast matrix, increase the separation between dark and bright - * Increase contrast : shadows darker and highlights brighter - * Decrease contrast : bring the shadows up and the highlights down - * - * @param amount {number} value of the contrast - * @param multiply {boolean} refer to ._loadMatrix() method - */ -ColorMatrixFilter.prototype.contrast = function (amount, multiply) -{ - var v = (amount || 0) + 1; - var o = -128 * (v - 1); + dist = Math.sqrt(perpx*perpx + perpy*perpy); + perpx /= dist; + perpy /= dist; + perpx *= width; + perpy *= width; - var matrix = [ - v, 0, 0, 0, o, - 0, v, 0, 0, o, - 0, 0, v, 0, o, - 0, 0, 0, 1, 0 - ]; + verts.push(p2x - perpx , p2y - perpy); + verts.push(r, g, b, alpha); - this._loadMatrix(matrix, multiply); -}; + verts.push(p2x + perpx , p2y + perpy); + verts.push(r, g, b, alpha); -/** - * Set the saturation matrix, increase the separation between colors - * Increase saturation : increase contrast, brightness, and sharpness - * - * @param amount {number} - * @param multiply {boolean} refer to ._loadMatrix() method - */ -ColorMatrixFilter.prototype.saturate = function (amount, multiply) -{ - var x = (amount || 0) * 2 / 3 + 1; - var y = ((x - 1) * -0.5); + indices.push(indexStart); - var matrix = [ - x, y, y, 0, 0, - y, x, y, 0, 0, - y, y, x, 0, 0, - 0, 0, 0, 1, 0 - ]; + for (i = 0; i < indexCount; i++) + { + indices.push(indexStart++); + } - this._loadMatrix(matrix, multiply); + indices.push(indexStart-1); }; +module.exports = buildLine; + +},{"../../../math":66,"../../../utils":115}],58:[function(require,module,exports){ +var buildLine = require('./buildLine'), + utils = require('../../../utils'), + earcut = require('earcut'); + /** - * Desaturate image (remove color) + * Builds a polygon to draw * - * Call the saturate function + * Ignored from docs since it is not directly exposed. * - * @param multiply {boolean} refer to ._loadMatrix() method + * @ignore + * @private + * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties + * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -ColorMatrixFilter.prototype.desaturate = function (multiply) // jshint unused:false +var buildPoly = function (graphicsData, webGLData) { - this.saturate(-1); -}; + graphicsData.points = graphicsData.shape.points.slice(); -/** - * Negative image (inverse of classic rgb matrix) - * - * @param multiply {boolean} refer to ._loadMatrix() method - */ -ColorMatrixFilter.prototype.negative = function (multiply) -{ - var matrix = [ - 0, 1, 1, 0, 0, - 1, 0, 1, 0, 0, - 1, 1, 0, 0, 0, - 0, 0, 0, 1, 0 - ]; + var points = graphicsData.points; - this._loadMatrix(matrix, multiply); -}; + if(graphicsData.fill && points.length > 6) + { -/** - * Sepia image - * - * @param multiply {boolean} refer to ._loadMatrix() method - */ -ColorMatrixFilter.prototype.sepia = function (multiply) -{ - var matrix = [ - 0.393, 0.7689999, 0.18899999, 0, 0, - 0.349, 0.6859999, 0.16799999, 0, 0, - 0.272, 0.5339999, 0.13099999, 0, 0, - 0, 0, 0, 1, 0 - ]; + var holeArray = []; + // Process holes.. + var holes = graphicsData.holes; - this._loadMatrix(matrix, multiply); -}; + for (var i = 0; i < holes.length; i++) { + var hole = holes[i]; -/** - * Color motion picture process invented in 1916 (thanks Dominic Szablewski) - * - * @param multiply {boolean} refer to ._loadMatrix() method - */ -ColorMatrixFilter.prototype.technicolor = function (multiply) -{ - var matrix = [ - 1.9125277891456083, -0.8545344976951645, -0.09155508482755585, 0, 11.793603434377337, - -0.3087833385928097, 1.7658908555458428, -0.10601743074722245, 0, -70.35205161461398, - -0.231103377548616, -0.7501899197440212, 1.847597816108189, 0, 30.950940869491138, - 0, 0, 0, 1, 0 - ]; + holeArray.push(points.length/2); - this._loadMatrix(matrix, multiply); -}; + points = points.concat(hole.points); + } -/** - * Polaroid filter - * - * @param multiply {boolean} refer to ._loadMatrix() method - */ -ColorMatrixFilter.prototype.polaroid = function (multiply) -{ - var matrix = [ - 1.438, -0.062, -0.062, 0, 0, - -0.122, 1.378, -0.122, 0, 0, - -0.016, -0.016, 1.483, 0, 0, - 0, 0, 0, 1, 0 - ]; + // get first and last point.. figure out the middle! + var verts = webGLData.points; + var indices = webGLData.indices; - this._loadMatrix(matrix, multiply); -}; + var length = points.length / 2; -/** - * Filter who transforms : Red -> Blue and Blue -> Red - * - * @param multiply {boolean} refer to ._loadMatrix() method - */ -ColorMatrixFilter.prototype.toBGR = function (multiply) -{ - var matrix = [ - 0, 0, 1, 0, 0, - 0, 1, 0, 0, 0, - 1, 0, 0, 0, 0, - 0, 0, 0, 1, 0 - ]; + // sort color + var color = utils.hex2rgb(graphicsData.fillColor); + var alpha = graphicsData.fillAlpha; + var r = color[0] * alpha; + var g = color[1] * alpha; + var b = color[2] * alpha; - this._loadMatrix(matrix, multiply); -}; + var triangles = earcut(points, holeArray, 2); -/** - * Color reversal film introduced by Eastman Kodak in 1935. (thanks Dominic Szablewski) - * - * @param multiply {boolean} refer to ._loadMatrix() method - */ -ColorMatrixFilter.prototype.kodachrome = function (multiply) -{ - var matrix = [ - 1.1285582396593525, -0.3967382283601348, -0.03992559172921793, 0, 63.72958762196502, - -0.16404339962244616, 1.0835251566291304, -0.05498805115633132, 0, 24.732407896706203, - -0.16786010706155763, -0.5603416277695248, 1.6014850761964943, 0, 35.62982807460946, - 0, 0, 0, 1, 0 - ]; + if (!triangles) { + return; + } - this._loadMatrix(matrix, multiply); -}; + var vertPos = verts.length / 6; -/** - * Brown delicious browni filter (thanks Dominic Szablewski) - * - * @param multiply {boolean} refer to ._loadMatrix() method - */ -ColorMatrixFilter.prototype.browni = function (multiply) -{ - var matrix = [ - 0.5997023498159715, 0.34553243048391263, -0.2708298674538042, 0, 47.43192855600873, - -0.037703249837783157, 0.8609577587992641, 0.15059552388459913, 0, -36.96841498319127, - 0.24113635128153335, -0.07441037908422492, 0.44972182064877153, 0, -7.562075277591283, - 0, 0, 0, 1, 0 - ]; + for (i = 0; i < triangles.length; i+=3) + { + indices.push(triangles[i] + vertPos); + indices.push(triangles[i] + vertPos); + indices.push(triangles[i+1] + vertPos); + indices.push(triangles[i+2] +vertPos); + indices.push(triangles[i+2] + vertPos); + } - this._loadMatrix(matrix, multiply); + for (i = 0; i < length; i++) + { + verts.push(points[i * 2], points[i * 2 + 1], + r, g, b, alpha); + } + } + + if (graphicsData.lineWidth > 0) + { + buildLine(graphicsData, webGLData); + } }; -/* - * Vintage filter (thanks Dominic Szablewski) - * - * @param multiply {boolean} refer to ._loadMatrix() method - */ -ColorMatrixFilter.prototype.vintage = function (multiply) -{ - var matrix = [ - 0.6279345635605994, 0.3202183420819367, -0.03965408211312453, 0, 9.651285835294123, - 0.02578397704808868, 0.6441188644374771, 0.03259127616149294, 0, 7.462829176470591, - 0.0466055556782719, -0.0851232987247891, 0.5241648018700465, 0, 5.159190588235296, - 0, 0, 0, 1, 0 - ]; - this._loadMatrix(matrix, multiply); -}; +module.exports = buildPoly; + +},{"../../../utils":115,"./buildLine":57,"earcut":3}],59:[function(require,module,exports){ +var buildLine = require('./buildLine'), + utils = require('../../../utils'); -/* - * We don't know exactly what it does, kind of gradient map, but funny to play with! +/** + * Builds a rectangle to draw * - * @param desaturation {number} - * @param toned {number} - * @param lightColor {string} (example : "0xFFE580") - * @param darkColor {string} (example : "0xFFE580") + * Ignored from docs since it is not directly exposed. * - * @param multiply {boolean} refer to ._loadMatrix() method + * @ignore + * @private + * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties + * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -ColorMatrixFilter.prototype.colorTone = function (desaturation, toned, lightColor, darkColor, multiply) +var buildRectangle = function (graphicsData, webGLData) { - desaturation = desaturation || 0.2; - toned = toned || 0.15; - lightColor = lightColor || 0xFFE580; - darkColor = darkColor || 0x338000; + // --- // + // need to convert points to a nice regular data + // + var rectData = graphicsData.shape; + var x = rectData.x; + var y = rectData.y; + var width = rectData.width; + var height = rectData.height; + + if (graphicsData.fill) + { + var color = utils.hex2rgb(graphicsData.fillColor); + var alpha = graphicsData.fillAlpha; + + var r = color[0] * alpha; + var g = color[1] * alpha; + var b = color[2] * alpha; + + var verts = webGLData.points; + var indices = webGLData.indices; + + var vertPos = verts.length/6; + + // start + verts.push(x, y); + verts.push(r, g, b, alpha); - var lR = ((lightColor >> 16) & 0xFF) / 255; - var lG = ((lightColor >> 8) & 0xFF) / 255; - var lB = (lightColor & 0xFF) / 255; + verts.push(x + width, y); + verts.push(r, g, b, alpha); - var dR = ((darkColor >> 16) & 0xFF) / 255; - var dG = ((darkColor >> 8) & 0xFF) / 255; - var dB = (darkColor & 0xFF) / 255; + verts.push(x , y + height); + verts.push(r, g, b, alpha); - var matrix = [ - 0.3, 0.59, 0.11, 0, 0, - lR, lG, lB, desaturation, 0, - dR, dG, dB, toned, 0, - lR - dR, lG - dG, lB - dB, 0, 0 - ]; + verts.push(x + width, y + height); + verts.push(r, g, b, alpha); - this._loadMatrix(matrix, multiply); -}; + // insert 2 dead triangles.. + indices.push(vertPos, vertPos, vertPos+1, vertPos+2, vertPos+3, vertPos+3); + } -/* - * Night effect - * - * @param intensity {number} - * @param multiply {boolean} refer to ._loadMatrix() method - */ -ColorMatrixFilter.prototype.night = function (intensity, multiply) -{ - intensity = intensity || 0.1; - var matrix = [ - intensity * ( -2.0), -intensity, 0, 0, 0, - -intensity, 0, intensity, 0, 0, - 0, intensity, intensity * 2.0, 0, 0, - 0, 0, 0, 1, 0 - ]; + if (graphicsData.lineWidth) + { + var tempPoints = graphicsData.points; - this._loadMatrix(matrix, multiply); -}; + graphicsData.points = [x, y, + x + width, y, + x + width, y + height, + x, y + height, + x, y]; -/* - * Predator effect - * - * Erase the current matrix by setting a new indepent one - * - * @param amount {number} how much the predator feels his future victim - * @param multiply {boolean} refer to ._loadMatrix() method - */ -ColorMatrixFilter.prototype.predator = function (amount, multiply) -{ - var matrix = [ - 11.224130630493164 * amount, -4.794486999511719 * amount, -2.8746118545532227 * amount, 0 * amount, 0.40342438220977783 * amount, - -3.6330697536468506 * amount, 9.193157196044922 * amount, -2.951810836791992 * amount, 0 * amount, -1.316135048866272 * amount, - -3.2184197902679443 * amount, -4.2375030517578125 * amount, 7.476448059082031 * amount, 0 * amount, 0.8044459223747253 * amount, - 0, 0, 0, 1, 0 - ]; + buildLine(graphicsData, webGLData); - this._loadMatrix(matrix, multiply); + graphicsData.points = tempPoints; + } }; -/* - * LSD effect +module.exports = buildRectangle; + +},{"../../../utils":115,"./buildLine":57}],60:[function(require,module,exports){ +var earcut = require('earcut'), + buildLine = require('./buildLine'), + utils = require('../../../utils'); + +/** + * Builds a rounded rectangle to draw * - * Multiply the current matrix + * Ignored from docs since it is not directly exposed. * - * @param amount {number} How crazy is your effect - * @param multiply {boolean} refer to ._loadMatrix() method + * @ignore + * @private + * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties + * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -ColorMatrixFilter.prototype.lsd = function (multiply) +var buildRoundedRectangle = function (graphicsData, webGLData) { - var matrix = [ - 2, -0.4, 0.5, 0, 0, - -0.5, 2, -0.4, 0, 0, - -0.4, -0.5, 3, 0, 0, - 0, 0, 0, 1, 0 - ]; + var rrectData = graphicsData.shape; + var x = rrectData.x; + var y = rrectData.y; + var width = rrectData.width; + var height = rrectData.height; - this._loadMatrix(matrix, multiply); -}; + var radius = rrectData.radius; -/* - * Erase the current matrix by setting the default one - * - */ -ColorMatrixFilter.prototype.reset = function () -{ - var matrix = [ - 1, 0, 0, 0, 0, - 0, 1, 0, 0, 0, - 0, 0, 1, 0, 0, - 0, 0, 0, 1, 0 - ]; + var recPoints = []; + recPoints.push(x, y + radius); + quadraticBezierCurve(x, y + height - radius, x, y + height, x + radius, y + height, recPoints); + quadraticBezierCurve(x + width - radius, y + height, x + width, y + height, x + width, y + height - radius, recPoints); + quadraticBezierCurve(x + width, y + radius, x + width, y, x + width - radius, y, recPoints); + quadraticBezierCurve(x + radius, y, x, y, x, y + radius + 0.0000000001, recPoints); - this._loadMatrix(matrix, false); -}; + // this tiny number deals with the issue that occurs when points overlap and earcut fails to triangulate the item. + // TODO - fix this properly, this is not very elegant.. but it works for now. + if (graphicsData.fill) + { + var color = utils.hex2rgb(graphicsData.fillColor); + var alpha = graphicsData.fillAlpha; -Object.defineProperties(ColorMatrixFilter.prototype, { - /** - * Sets the matrix of the color matrix filter - * - * @member {number[]} - * @memberof PIXI.filters.ColorMatrixFilter# - * @default [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0] - */ - matrix: { - get: function () + var r = color[0] * alpha; + var g = color[1] * alpha; + var b = color[2] * alpha; + + var verts = webGLData.points; + var indices = webGLData.indices; + + var vecPos = verts.length/6; + + var triangles = earcut(recPoints, null, 2); + + var i = 0; + for (i = 0; i < triangles.length; i+=3) { - return this.uniforms.m; - }, - set: function (value) + indices.push(triangles[i] + vecPos); + indices.push(triangles[i] + vecPos); + indices.push(triangles[i+1] + vecPos); + indices.push(triangles[i+2] + vecPos); + indices.push(triangles[i+2] + vecPos); + } + + for (i = 0; i < recPoints.length; i++) { - this.uniforms.m = value; + verts.push(recPoints[i], recPoints[++i], r, g, b, alpha); } } -}); - -},{"../../core":50}],119:[function(require,module,exports){ -var core = require('../../core'); + if (graphicsData.lineWidth) + { + var tempPoints = graphicsData.points; + + graphicsData.points = recPoints; + + buildLine(graphicsData, webGLData); + + graphicsData.points = tempPoints; + } +}; /** - * The DisplacementFilter class uses the pixel values from the specified texture (called the displacement map) to perform a displacement of an object. - * You can use this filter to apply all manor of crazy warping effects - * Currently the r property of the texture is used to offset the x and the g property of the texture is used to offset the y. + * Calculate the points for a quadratic bezier curve. (helper function..) + * Based on: https://stackoverflow.com/questions/785097/how-do-i-implement-a-bezier-curve-in-c * - * @class - * @extends PIXI.Filter - * @memberof PIXI.filters - * @param sprite {PIXI.Sprite} the sprite used for the displacement map. (make sure its added to the scene!) + * Ignored from docs since it is not directly exposed. + * + * @ignore + * @private + * @param fromX {number} Origin point x + * @param fromY {number} Origin point x + * @param cpX {number} Control point x + * @param cpY {number} Control point y + * @param toX {number} Destination point x + * @param toY {number} Destination point y + * @param [out] {number[]} The output array to add points into. If not passed, a new array is created. + * @return {number[]} an array of points */ -function DisplacementFilter(sprite, scale) +var quadraticBezierCurve = function (fromX, fromY, cpX, cpY, toX, toY, out)// jshint ignore:line { - var maskMatrix = new core.Matrix(); - sprite.renderable = false; + var xa, + ya, + xb, + yb, + x, + y, + n = 20, + points = out || []; - core.Filter.call(this, - // vertex shader - "#define GLSLIFY 1\nattribute vec2 aVertexPosition;\n\nattribute vec2 aTextureCoord;\n\nattribute vec4 aColor;\n\nuniform mat3 projectionMatrix;\n\nuniform mat3 otherMatrix;\n\nvarying vec2 vMapCoord;\n\nvarying vec2 vTextureCoord;\n\nvarying vec4 vColor;\n\nvoid main(void)\n\n{\n\n gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\n\n vTextureCoord = aTextureCoord;\n\n vMapCoord = ( otherMatrix * vec3( aTextureCoord, 1.0) ).xy;\n\n vColor = vec4(aColor.rgb * aColor.a, aColor.a);\n\n}\n\n", - // fragment shader - "precision mediump float;\n#define GLSLIFY 1\n\nvarying vec2 vMapCoord;\n\nvarying vec2 vTextureCoord;\n\nvarying vec4 vColor;\n\nuniform vec2 scale;\n\nuniform sampler2D uSampler;\n\nuniform sampler2D mapSampler;\n\nvoid main(void)\n\n{\n\n vec4 map = texture2D(mapSampler, vMapCoord);\n\n map -= 0.5;\n\n map.xy *= scale;\n\n gl_FragColor = texture2D(uSampler, vec2(vTextureCoord.x + map.x, vTextureCoord.y + map.y));\n\n}\n\n" + function getPt(n1 , n2, perc) { + var diff = n2 - n1; - ); + return n1 + ( diff * perc ); + } - this.maskSprite = sprite; - this.maskMatrix = maskMatrix; + var j = 0; + for (var i = 0; i <= n; i++ ) { + j = i / n; - this.uniforms.mapSampler = sprite.texture; - this.uniforms.otherMatrix = maskMatrix.toArray(true); - this.uniforms.scale = { x: 1, y: 1 }; + // The Green Line + xa = getPt( fromX , cpX , j ); + ya = getPt( fromY , cpY , j ); + xb = getPt( cpX , toX , j ); + yb = getPt( cpY , toY , j ); + + // The Black Dot + x = getPt( xa , xb , j ); + y = getPt( ya , yb , j ); + + points.push(x, y); + } + + return points; +}; + + +module.exports = buildRoundedRectangle; + +},{"../../../utils":115,"./buildLine":57,"earcut":3}],61:[function(require,module,exports){ +/** + * @file Main export of the PIXI core library + * @author Mat Groves + * @copyright 2013-2015 GoodBoyDigital + * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} + */ + +/** + * @namespace PIXI + */ +// export core and const. We assign core to const so that the non-reference types in const remain in-tact +var core = module.exports = Object.assign(require('./const'), require('./math'), { + // utils + utils: require('./utils'), + ticker: require('./ticker'), + + // display + DisplayObject: require('./display/DisplayObject'), + Container: require('./display/Container'), + Transform: require('./display/Transform'), + TransformStatic: require('./display/TransformStatic'), + TransformBase: require('./display/TransformBase'), - if (scale === null || scale === undefined) - { - scale = 20; - } + // sprites + Sprite: require('./sprites/Sprite'), + CanvasSpriteRender: require('./sprites/canvas/CanvasSpriteRenderer'), + CanvasTinter: require('./sprites/canvas/CanvasTinter'), + SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), - this.scale = new core.Point(scale, scale); -} + // text + Text: require('./text/Text'), + TextStyle: require('./text/TextStyle'), + // primitives + Graphics: require('./graphics/Graphics'), + GraphicsData: require('./graphics/GraphicsData'), + GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), + CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), -DisplacementFilter.prototype = Object.create(core.Filter.prototype); -DisplacementFilter.prototype.constructor = DisplacementFilter; -module.exports = DisplacementFilter; + // textures + Texture: require('./textures/Texture'), + BaseTexture: require('./textures/BaseTexture'), + RenderTexture: require('./textures/RenderTexture'), + BaseRenderTexture: require('./textures/BaseRenderTexture'), + VideoBaseTexture: require('./textures/VideoBaseTexture'), + TextureUvs: require('./textures/TextureUvs'), -DisplacementFilter.prototype.apply = function (filterManager, input, output) -{ - var ratio = (1/output.destinationFrame.width) * (output.size.width/input.size.width); /// // * 2 //4//this.strength / 4 / this.passes * (input.frame.width / input.size.width); + // renderers - canvas + CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), + CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), - this.uniforms.otherMatrix = filterManager.calculateSpriteMatrix(this.maskMatrix, this.maskSprite); - this.uniforms.scale.x = this.scale.x * ratio; - this.uniforms.scale.y = this.scale.y * ratio; + // renderers - webgl + Shader: require('./Shader'), + WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), + WebGLManager: require('./renderers/webgl/managers/WebGLManager'), + ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), + RenderTarget: require('./renderers/webgl/utils/RenderTarget'), + Quad: require('./renderers/webgl/utils/Quad'), - // draw the filter... - filterManager.applyFilter(this, input, output); -}; + // filters - webgl + SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), + Filter: require('./renderers/webgl/filters/Filter'), + glCore: require('pixi-gl-core'), -Object.defineProperties(DisplacementFilter.prototype, { /** - * The texture used for the displacement map. Must be power of 2 sized texture. + * This helper function will automatically detect which renderer you should be using. + * WebGL is the preferred renderer as it is a lot faster. If webGL is not supported by + * the browser then this function will return a canvas renderer * - * @member {PIXI.Texture} - * @memberof PIXI.filters.DisplacementFilter# + * @memberof PIXI + * @param width=800 {number} the width of the renderers view + * @param height=600 {number} the height of the renderers view + * @param [options] {object} The optional renderer parameters + * @param [options.view] {HTMLCanvasElement} the canvas to use as a view, optional + * @param [options.transparent=false] {boolean} If the render view is transparent, default false + * @param [options.antialias=false] {boolean} sets antialias (only applicable in chrome at the moment) + * @param [options.preserveDrawingBuffer=false] {boolean} enables drawing buffer preservation, enable this if you + * need to call toDataUrl on the webgl context + * @param [options.resolution=1] {number} The resolution / device pixel ratio of the renderer, retina would be 2 + * @param [noWebGL=false] {boolean} prevents selection of WebGL renderer, even if such is present + * + * @return {WebGLRenderer|CanvasRenderer} Returns WebGL renderer if available, otherwise CanvasRenderer */ - map: { - get: function () - { - return this.uniforms.mapSampler; - }, - set: function (value) - { - this.uniforms.mapSampler = value; + autoDetectRenderer: function (width, height, options, noWebGL) + { + width = width || 800; + height = height || 600; + if (!noWebGL && core.utils.isWebGLSupported()) + { + return new core.WebGLRenderer(width, height, options); } + + return new core.CanvasRenderer(width, height, options); } }); -},{"../../core":50}],120:[function(require,module,exports){ -var core = require('../../core'); +},{"./Shader":41,"./const":42,"./display/Container":44,"./display/DisplayObject":45,"./display/Transform":46,"./display/TransformBase":47,"./display/TransformStatic":48,"./graphics/Graphics":49,"./graphics/GraphicsData":50,"./graphics/canvas/CanvasGraphicsRenderer":51,"./graphics/webgl/GraphicsRenderer":53,"./math":66,"./renderers/canvas/CanvasRenderer":73,"./renderers/canvas/utils/CanvasRenderTarget":75,"./renderers/webgl/WebGLRenderer":80,"./renderers/webgl/filters/Filter":82,"./renderers/webgl/filters/spriteMask/SpriteMaskFilter":85,"./renderers/webgl/managers/WebGLManager":89,"./renderers/webgl/utils/ObjectRenderer":90,"./renderers/webgl/utils/Quad":91,"./renderers/webgl/utils/RenderTarget":92,"./sprites/Sprite":97,"./sprites/canvas/CanvasSpriteRenderer":98,"./sprites/canvas/CanvasTinter":99,"./sprites/webgl/SpriteRenderer":101,"./text/Text":103,"./text/TextStyle":104,"./textures/BaseRenderTexture":105,"./textures/BaseTexture":106,"./textures/RenderTexture":107,"./textures/Texture":108,"./textures/TextureUvs":109,"./textures/VideoBaseTexture":110,"./ticker":112,"./utils":115,"pixi-gl-core":14}],62:[function(require,module,exports){ +// Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +var ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; +var uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; +var vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; +var vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; +var tempMatrices = []; +var Matrix = require('./Matrix'); -/** - * This filter applies a twist effect making display objects appear twisted in the given direction. - * - * @class - * @extends PIXI.Filter - * @memberof PIXI.filters - */ -function GodrayFilter() -{ - core.Filter.call(this, - // vertex shader +var mul = []; - "#define GLSLIFY 1\nattribute vec2 aVertexPosition;\n\nattribute vec2 aTextureCoord;\n\nuniform mat3 projectionMatrix;\n\nvarying vec2 vTextureCoord;\n\nvoid main(void)\n\n{\n\n gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\n\n vTextureCoord = aTextureCoord;\n\n}\n\n", - // fragment shader - "precision mediump float;\n#define GLSLIFY 1\n\nvarying vec2 vTextureCoord;\n\nuniform float exposure;\n\nuniform float decay;\n\nuniform float density;\n\nuniform float weight;\n\nuniform vec2 lightPositionOnScreen;\n\nuniform sampler2D uSampler;\n\nconst int NUM_SAMPLES = 100;\n\nvoid main()\n\n{\n\n vec2 deltaTextCoord = vec2( vTextureCoord - lightPositionOnScreen.xy );\n\n vec2 textCoo = vTextureCoord;\n\n deltaTextCoord *= 1.0 / float(NUM_SAMPLES) * density;\n\n float illuminationDecay = 1.0;\n\n \n\n for(int i=0; i < NUM_SAMPLES ; i++)\n\n {\n\n textCoo -= deltaTextCoord;\n\n vec4 sample = texture2D(uSampler, textCoo );\n\n sample *= illuminationDecay * weight;\n\n gl_FragColor += sample;\n\n illuminationDecay *= decay;\n\n }\n\n \n\n gl_FragColor *= exposure;\n\n}" - ); +function signum(x) { + if (x < 0) { + return -1; + } + if (x > 0) { + return 1; + } + return 0; +} - this.uniforms.exposure = 0.0034; - this.uniforms.decay = 1.0; - this.uniforms.density = 0.84; - this.uniforms.weight = 5.65; +function init() { + for (var i = 0; i < 16; i++) { + var row = []; + mul.push(row); + for (var j = 0; j < 16; j++) { + var _ux = signum(ux[i] * ux[j] + vx[i] * uy[j]); + var _uy = signum(uy[i] * ux[j] + vy[i] * uy[j]); + var _vx = signum(ux[i] * vx[j] + vx[i] * vy[j]); + var _vy = signum(uy[i] * vx[j] + vy[i] * vy[j]); + for (var k = 0; k < 16; k++) { + if (ux[k] === _ux && uy[k] === _uy && vx[k] === _vx && vy[k] === _vy) { + row.push(k); + break; + } + } + } + } - this.uniforms.lightPositionOnScreen[0] = 0.5;///0.5; - this.uniforms.lightPositionOnScreen[1] = 0.5;//; + for (i=0;i<16;i++) { + var mat = new Matrix(); + mat.set(ux[i], uy[i], vx[i], vy[i], 0, 0); + tempMatrices.push(mat); + } } -GodrayFilter.prototype = Object.create(core.Filter.prototype); -GodrayFilter.prototype.constructor = GodrayFilter; -module.exports = GodrayFilter; +init(); + +/** + * Implements Dihedral Group D_8, see [group D4]{@link http://mathworld.wolfram.com/DihedralGroupD4.html}, D8 is the same but with diagonals + * Used for texture rotations + * Vector xX(i), xY(i) is U-axis of sprite with rotation i + * Vector yY(i), yY(i) is V-axis of sprite with rotation i + * Rotations: 0 grad (0), 90 grad (2), 180 grad (4), 270 grad (6) + * Mirrors: vertical (8), main diagonal (10), horizontal (12), reverse diagonal (14) + * This is the small part of gameofbombs.com portal system. It works. + * @author Ivan @ivanpopelyshev + * + * @namespace PIXI.GroupD8 + */ +var GroupD8 = { + E: 0, + SE: 1, + S: 2, + SW: 3, + W: 4, + NW: 5, + N: 6, + NE: 7, + MIRROR_VERTICAL: 8, + MIRROR_HORIZONTAL: 12, + uX: function (ind) { + return ux[ind]; + }, + uY: function (ind) { + return uy[ind]; + }, + vX: function (ind) { + return vx[ind]; + }, + vY: function (ind) { + return vy[ind]; + }, + inv: function (rotation) { + if (rotation & 8) { + return rotation & 15; + } + return (-rotation) & 7; + }, + add: function (rotationSecond, rotationFirst) { + return mul[rotationSecond][rotationFirst]; + }, + sub: function (rotationSecond, rotationFirst) { + return mul[rotationSecond][GroupD8.inv(rotationFirst)]; + }, + /** + * Adds 180 degrees to rotation. Commutative operation + * @param rotation + * @returns {number} + */ + rotate180: function (rotation) { + return rotation ^ 4; + }, + /** + * I dont know why sometimes width and heights needs to be swapped. We'll fix it later. + * @param rotation + * @returns {boolean} + */ + isSwapWidthHeight: function(rotation) { + return (rotation & 3) === 2; + }, + byDirection: function (dx, dy) { + if (Math.abs(dx) * 2 <= Math.abs(dy)) { + if (dy >= 0) { + return GroupD8.S; + } + else { + return GroupD8.N; + } + } else if (Math.abs(dy) * 2 <= Math.abs(dx)) { + if (dx > 0) { + return GroupD8.E; + } + else { + return GroupD8.W; + } + } else { + if (dy > 0) { + if (dx > 0) { + return GroupD8.SE; + } + else { + return GroupD8.SW; + } + } + else if (dx > 0) { + return GroupD8.NE; + } + else { + return GroupD8.NW; + } + } + }, + /** + * Helps sprite to compensate texture packer rotation. + * @param matrix {PIXI.Matrix} sprite world matrix + * @param rotation {number} + * @param tx {number|*} sprite anchoring + * @param ty {number|*} sprite anchoring + */ + matrixAppendRotationInv: function (matrix, rotation, tx, ty) { + //Packer used "rotation", we use "inv(rotation)" + var mat = tempMatrices[GroupD8.inv(rotation)]; + tx = tx || 0; + ty = ty || 0; + mat.tx = tx; + mat.ty = ty; + matrix.append(mat); + } +}; + +module.exports = GroupD8; + +},{"./Matrix":63}],63:[function(require,module,exports){ +// @todo - ignore the too many parameters warning for now +// should either fix it or change the jshint config +// jshint -W072 + +var Point = require('./Point'); -GodrayFilter.prototype.apply = function (filterManager, input, output, clear) +/** + * The pixi Matrix class as an object, which makes it a lot faster, + * here is a representation of it : + * | a | b | tx| + * | c | d | ty| + * | 0 | 0 | 1 | + * + * @class + * @memberof PIXI + */ +function Matrix() { + /** + * @member {number} + * @default 1 + */ + this.a = 1; - filterManager.applyFilter(this, input, output, clear); -}; + /** + * @member {number} + * @default 0 + */ + this.b = 0; -Object.defineProperties(GodrayFilter.prototype, { /** - * This point describes the the offset of the twist. - * - * @member {PIXI.Point} - * @memberof PIXI.filters.GodrayFilter# + * @member {number} + * @default 0 */ - offset: { - get: function () - { - return this.uniforms.offset; - }, - set: function (value) - { - this.uniforms.offset = value; - } - }, + this.c = 0; /** - * This radius of the twist. - * * @member {number} - * @memberof PIXI.filters.GodrayFilter# + * @default 1 */ - radius: { - get: function () - { - return this.uniforms.radius; - }, - set: function (value) - { - this.uniforms.radius = value; - } - }, + this.d = 1; /** - * This angle of the twist. - * * @member {number} - * @memberof PIXI.filters.GodrayFilter# + * @default 0 */ - angle: { - get: function () - { - return this.uniforms.angle; - }, - set: function (value) - { - this.uniforms.angle = value; - } - } -}); - -},{"../../core":50}],121:[function(require,module,exports){ -var core = require('../../core'); -// @see https://github.com/substack/brfs/issues/25 + this.tx = 0; + + /** + * @member {number} + * @default 0 + */ + this.ty = 0; + + this.array = null; +} +Matrix.prototype.constructor = Matrix; +module.exports = Matrix; /** - * This greyscales the palette of your Display Objects. + * Creates a Matrix object based on the given array. The Element to Matrix mapping order is as follows: * - * @class - * @extends PIXI.AbstractFilter - * @memberof PIXI.filters + * a = array[0] + * b = array[1] + * c = array[3] + * d = array[4] + * tx = array[2] + * ty = array[5] + * + * @param array {number[]} The array that the matrix will be populated from. */ -function GrayFilter() +Matrix.prototype.fromArray = function (array) { - core.Filter.call(this, - // vertex shader - "precision lowp float;\n#define GLSLIFY 1\n\nattribute vec2 aVertexPosition;\n\nattribute vec2 aTextureCoord;\n\nuniform mat3 projectionMatrix;\n\nvarying vec2 vTextureCoord;\n\nvoid main(void){\n\n gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\n\n vTextureCoord = aTextureCoord;\n\n}", - // fragment shader - "precision mediump float;\n#define GLSLIFY 1\n\nvarying vec2 vTextureCoord;\n\nuniform sampler2D uSampler;\n\nuniform float gray;\n\nvoid main(void)\n\n{\n\n gl_FragColor = texture2D(uSampler, vTextureCoord);\n\n gl_FragColor.rgb = mix(gl_FragColor.rgb, vec3(0.2126*gl_FragColor.r + 0.7152*gl_FragColor.g + 0.0722*gl_FragColor.b), gray);\n\n}\n\n" - ); - - this.uniforms.gray = 1; - - this.glShaderKey = 'gray'; -} + this.a = array[0]; + this.b = array[1]; + this.c = array[3]; + this.d = array[4]; + this.tx = array[2]; + this.ty = array[5]; +}; -GrayFilter.prototype = Object.create(core.Filter.prototype); -GrayFilter.prototype.constructor = GrayFilter; -module.exports = GrayFilter; -Object.defineProperties(GrayFilter.prototype, { - /** - * The strength of the gray. 1 will make the object black and white, 0 will make the object its normal color. - * - * @member {number} - * @memberof PIXI.filters.GrayFilter# - */ - gray: { - get: function () - { - return this.uniforms.gray; - }, - set: function (value) - { - this.uniforms.gray = value; - } - } -}); - -},{"../../core":50}],122:[function(require,module,exports){ /** - * @file Main export of the PIXI filters library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} + * sets the matrix properties + * + * @param {number} a + * @param {number} b + * @param {number} c + * @param {number} d + * @param {number} tx + * @param {number} ty + * + * @return {PIXI.Matrix} This matrix. Good for chaining method calls. */ +Matrix.prototype.set = function (a, b, c, d, tx, ty) +{ + this.a = a; + this.b = b; + this.c = c; + this.d = d; + this.tx = tx; + this.ty = ty; -/** - * @namespace PIXI.filters - */ -module.exports = { - // AsciiFilter: require('./ascii/AsciiFilter'), - // BloomFilter: require('./bloom/BloomFilter'), - // BlurDirFilter: require('./blur/BlurDirFilter'), - // ColorStepFilter: require('./color/ColorStepFilter'), - // ConvolutionFilter: require('./convolution/ConvolutionFilter'), - // CrossHatchFilter: require('./crosshatch/CrossHatchFilter'), - // DotScreenFilter: require('./dot/DotScreenFilter'), - // DropShadowFilter: require('./dropshadow/DropShadowFilter'), - // InvertFilter: require('./invert/InvertFilter'), - // NoiseFilter: require('./noise/NoiseFilter'), - // PixelateFilter: require('./pixelate/PixelateFilter'), - // RGBSplitFilter: require('./rgb/RGBSplitFilter'), - // ShockwaveFilter: require('./shockwave/ShockwaveFilter'), - // SepiaFilter: require('./sepia/SepiaFilter'), - // SmartBlurFilter: require('./blur/SmartBlurFilter'), - // TiltShiftFilter: require('./tiltshift/TiltShiftFilter'), - // TiltShiftXFilter: require('./tiltshift/TiltShiftXFilter'), - //TiltShiftYFilter: require('./tiltshift/TiltShiftYFilter'), - DisplacementFilter: require('./displacement/DisplacementFilter'), - BlurFilter: require('./blur/BlurFilter'), - BlurXFilter: require('./blur/BlurXFilter'), - BlurYFilter: require('./blur/BlurYFilter'), - - ColorMatrixFilter: require('./colormatrix/ColorMatrixFilter'), - TwistFilter: require('./twist/TwistFilter'), - GrayFilter: require('./gray/GrayFilter'), - GodrayFilter: require('./godray/GodrayFilter') + return this; }; - -},{"./blur/BlurFilter":112,"./blur/BlurXFilter":113,"./blur/BlurYFilter":114,"./colormatrix/ColorMatrixFilter":118,"./displacement/DisplacementFilter":119,"./godray/GodrayFilter":120,"./gray/GrayFilter":121,"./twist/TwistFilter":123}],123:[function(require,module,exports){ -var core = require('../../core'); /** - * This filter applies a twist effect making display objects appear twisted in the given direction. + * Creates an array from the current Matrix object. * - * @class - * @extends PIXI.Filter - * @memberof PIXI.filters + * @param transpose {boolean} Whether we need to transpose the matrix or not + * @param [out=new Float32Array(9)] {Float32Array} If provided the array will be assigned to out + * @return {number[]} the newly created array which contains the matrix */ -function TwistFilter() +Matrix.prototype.toArray = function (transpose, out) { - core.Filter.call(this, - // vertex shader - - "#define GLSLIFY 1\nattribute vec2 aVertexPosition;\n\nattribute vec2 aTextureCoord;\n\nuniform mat3 projectionMatrix;\n\nvarying vec2 vTextureCoord;\n\nvoid main(void)\n\n{\n\n gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\n\n vTextureCoord = aTextureCoord;\n\n}\n\n", - // fragment shader - "precision mediump float;\n#define GLSLIFY 1\n\nvarying vec2 vTextureCoord;\n\nuniform sampler2D uSampler;\n\nuniform float radius;\n\nuniform float angle;\n\nuniform vec2 offset;\n\nuniform vec4 filterArea;\n\nvec2 mapCoord( vec2 coord )\n\n{\n\n coord *= filterArea.xy;\n\n coord += filterArea.zw;\n\n return coord;\n\n}\n\nvec2 unmapCoord( vec2 coord )\n\n{\n\n coord -= filterArea.zw;\n\n coord /= filterArea.xy;\n\n return coord;\n\n}\n\nvec2 twist(vec2 coord)\n\n{\n\n coord -= offset;\n\n float dist = length(coord);\n\n if (dist < radius)\n\n {\n\n float ratioDist = (radius - dist) / radius;\n\n float angleMod = ratioDist * ratioDist * angle;\n\n float s = sin(angleMod);\n\n float c = cos(angleMod);\n\n coord = vec2(coord.x * c - coord.y * s, coord.x * s + coord.y * c);\n\n }\n\n coord += offset;\n\n return coord;\n\n}\n\nvoid main(void)\n\n{\n\n vec2 coord = mapCoord(vTextureCoord);\n\n coord = twist(coord);\n\n coord = unmapCoord(coord);\n\n gl_FragColor = texture2D(uSampler, coord );\n\n}\n\n" - ); - - this.uniforms.radius = 400; - this.uniforms.angle = 3; - this.uniforms.offset = [400,300]; - //this.uniforms.dimensions = [100, 100, 100, 100]; - this.transform = new core.math.Matrix(); - this.padding = 200; -} + if (!this.array) + { + this.array = new Float32Array(9); + } -TwistFilter.prototype = Object.create(core.Filter.prototype); -TwistFilter.prototype.constructor = TwistFilter; -module.exports = TwistFilter; + var array = out || this.array; -TwistFilter.prototype.apply = function (filterManager, input, output, clear) -{ - /* - this.uniforms.filterArea[0] = input.size.width; - this.uniforms.filterArea[1] = input.size.height; - this.uniforms.filterArea[2] = currentState.sourceFrame.x; - this.uniforms.filterArea[3] = currentState.sourceFrame.y; - */ + if (transpose) + { + array[0] = this.a; + array[1] = this.b; + array[2] = 0; + array[3] = this.c; + array[4] = this.d; + array[5] = 0; + array[6] = this.tx; + array[7] = this.ty; + array[8] = 1; + } + else + { + array[0] = this.a; + array[1] = this.c; + array[2] = this.tx; + array[3] = this.b; + array[4] = this.d; + array[5] = this.ty; + array[6] = 0; + array[7] = 0; + array[8] = 1; + } - filterManager.applyFilter(this, input, output, clear); + return array; }; -Object.defineProperties(TwistFilter.prototype, { - /** - * This point describes the the offset of the twist. - * - * @member {PIXI.Point} - * @memberof PIXI.filters.TwistFilter# - */ - offset: { - get: function () - { - return this.uniforms.offset; - }, - set: function (value) - { - this.uniforms.offset = value; - } - }, - - /** - * This radius of the twist. - * - * @member {number} - * @memberof PIXI.filters.TwistFilter# - */ - radius: { - get: function () - { - return this.uniforms.radius; - }, - set: function (value) - { - this.uniforms.radius = value; - } - }, +/** + * Get a new position with the current transformation applied. + * Can be used to go from a child's coordinate space to the world coordinate space. (e.g. rendering) + * + * @param pos {PIXI.Point} The origin + * @param [newPos] {PIXI.Point} The point that the new position is assigned to (allowed to be same as input) + * @return {PIXI.Point} The new point, transformed through this matrix + */ +Matrix.prototype.apply = function (pos, newPos) +{ + newPos = newPos || new Point(); - /** - * This angle of the twist. - * - * @member {number} - * @memberof PIXI.filters.TwistFilter# - */ - angle: { - get: function () - { - return this.uniforms.angle; - }, - set: function (value) - { - this.uniforms.angle = value; - } - } -}); - -},{"../../core":50}],124:[function(require,module,exports){ -(function (global){ -// run the polyfills -require('./polyfill'); + var x = pos.x; + var y = pos.y; -var core = module.exports = require('./core'); + newPos.x = this.a * x + this.c * y + this.tx; + newPos.y = this.b * x + this.d * y + this.ty; -// add core plugins. -core.extras = require('./extras'); -core.filters = require('./filters'); -core.interaction = require('./interaction'); -core.loaders = require('./loaders'); -core.mesh = require('./mesh'); -core.particles = require('./particles'); -core.accessibility = require('./accessibility'); + return newPos; +}; -// export a premade loader instance /** - * A premade instance of the loader that can be used to loader resources. + * Get a new position with the inverse of the current transformation applied. + * Can be used to go from the world coordinate space to a child's coordinate space. (e.g. input) * - * @name loader - * @memberof PIXI - * @property {PIXI.loaders.Loader} + * @param pos {PIXI.Point} The origin + * @param [newPos] {PIXI.Point} The point that the new position is assigned to (allowed to be same as input) + * @return {PIXI.Point} The new point, inverse-transformed through this matrix */ -core.loader = new core.loaders.Loader(); +Matrix.prototype.applyInverse = function (pos, newPos) +{ + newPos = newPos || new Point(); -// mixin the deprecation features. -Object.assign(core, require('./deprecation')); + var id = 1 / (this.a * this.d + this.c * -this.b); -// Always export pixi globally. -global.PIXI = core; - -}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"./accessibility":32,"./core":50,"./deprecation":103,"./extras":110,"./filters":122,"./interaction":127,"./loaders":130,"./mesh":137,"./particles":140,"./polyfill":146}],125:[function(require,module,exports){ -var core = require('../core'); + var x = pos.x; + var y = pos.y; + + newPos.x = this.d * id * x + -this.c * id * y + (this.ty * this.c - this.tx * this.d) * id; + newPos.y = this.a * id * y + -this.b * id * x + (-this.ty * this.a + this.tx * this.b) * id; + + return newPos; +}; /** - * Holds all information related to an Interaction event + * Translates the matrix on the x and y. * - * @class - * @memberof PIXI.interaction + * @param {number} x How much to translate x by + * @param {number} y How much to translate y by + * @return {PIXI.Matrix} This matrix. Good for chaining method calls. */ -function InteractionData() +Matrix.prototype.translate = function (x, y) { - /** - * This point stores the global coords of where the touch/mouse event happened - * - * @member {PIXI.Point} - */ - this.global = new core.Point(); - - /** - * The target Sprite that was interacted with - * - * @member {PIXI.Sprite} - */ - this.target = null; - - /** - * When passed to an event handler, this will be the original DOM Event that was captured - * - * @member {Event} - */ - this.originalEvent = null; -} + this.tx += x; + this.ty += y; -InteractionData.prototype.constructor = InteractionData; -module.exports = InteractionData; + return this; +}; /** - * This will return the local coordinates of the specified displayObject for this InteractionData + * Applies a scale transformation to the matrix. * - * @param displayObject {PIXI.DisplayObject} The DisplayObject that you would like the local coords off - * @param [point] {PIXI.Point} A Point object in which to store the value, optional (otherwise will create a new point) - * @param [globalPos] {PIXI.Point} A Point object containing your custom global coords, optional (otherwise will use the current global coords) - * @return {PIXI.Point} A point containing the coordinates of the InteractionData position relative to the DisplayObject + * @param {number} x The amount to scale horizontally + * @param {number} y The amount to scale vertically + * @return {PIXI.Matrix} This matrix. Good for chaining method calls. */ -InteractionData.prototype.getLocalPosition = function (displayObject, point, globalPos) +Matrix.prototype.scale = function (x, y) { - return displayObject.worldTransform.applyInverse(globalPos || this.global, point); + this.a *= x; + this.d *= y; + this.c *= x; + this.b *= y; + this.tx *= x; + this.ty *= y; + + return this; }; - -},{"../core":50}],126:[function(require,module,exports){ -var core = require('../core'), - InteractionData = require('./InteractionData'); -// Mix interactiveTarget into core.DisplayObject.prototype -Object.assign( - core.DisplayObject.prototype, - require('./interactiveTarget') -); /** - * The interaction manager deals with mouse and touch events. Any DisplayObject can be interactive - * if its interactive parameter is set to true - * This manager also supports multitouch. + * Applies a rotation transformation to the matrix. * - * @class - * @memberof PIXI.interaction - * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer - * @param [options] {object} - * @param [options.autoPreventDefault=true] {boolean} Should the manager automatically prevent default browser actions. - * @param [options.interactionFrequency=10] {number} Frequency increases the interaction events will be checked. + * @param {number} angle - The angle in radians. + * @return {PIXI.Matrix} This matrix. Good for chaining method calls. */ -function InteractionManager(renderer, options) +Matrix.prototype.rotate = function (angle) { - options = options || {}; + var cos = Math.cos( angle ); + var sin = Math.sin( angle ); - /** - * The renderer this interaction manager works for. - * - * @member {PIXI.SystemRenderer} - */ - this.renderer = renderer; + var a1 = this.a; + var c1 = this.c; + var tx1 = this.tx; - /** - * Should default browser actions automatically be prevented. - * - * @member {boolean} - * @default true - */ - this.autoPreventDefault = options.autoPreventDefault !== undefined ? options.autoPreventDefault : true; + this.a = a1 * cos-this.b * sin; + this.b = a1 * sin+this.b * cos; + this.c = c1 * cos-this.d * sin; + this.d = c1 * sin+this.d * cos; + this.tx = tx1 * cos - this.ty * sin; + this.ty = tx1 * sin + this.ty * cos; - /** - * As this frequency increases the interaction events will be checked more often. - * - * @member {number} - * @default 10 - */ - this.interactionFrequency = options.interactionFrequency || 10; + return this; +}; - /** - * The mouse data - * - * @member {PIXI.interaction.InteractionData} - */ - this.mouse = new InteractionData(); +/** + * Appends the given Matrix to this Matrix. + * + * @param {PIXI.Matrix} matrix + * @return {PIXI.Matrix} This matrix. Good for chaining method calls. + */ +Matrix.prototype.append = function (matrix) +{ + var a1 = this.a; + var b1 = this.b; + var c1 = this.c; + var d1 = this.d; - /** - * An event data object to handle all the event tracking/dispatching - * - * @member {object} - */ - this.eventData = { - stopped: false, - target: null, - type: null, - data: this.mouse, - stopPropagation:function(){ - this.stopped = true; - } - }; + this.a = matrix.a * a1 + matrix.b * c1; + this.b = matrix.a * b1 + matrix.b * d1; + this.c = matrix.c * a1 + matrix.d * c1; + this.d = matrix.c * b1 + matrix.d * d1; - /** - * Tiny little interactiveData pool ! - * - * @member {PIXI.interaction.InteractionData[]} - */ - this.interactiveDataPool = []; + this.tx = matrix.tx * a1 + matrix.ty * c1 + this.tx; + this.ty = matrix.tx * b1 + matrix.ty * d1 + this.ty; - /** - * The DOM element to bind to. - * - * @member {HTMLElement} - * @private - */ - this.interactionDOMElement = null; + return this; +}; - /** - * This property determins if mousemove and touchmove events are fired only when the cursror is over the object - * Setting to true will make things work more in line with how the DOM verison works. - * Setting to false can make things easier for things like dragging - * @member {HTMLElement} - * @private - */ - this.moveWhenInside = false; +/** + * Sets the matrix based on all the available properties + * + * @param {number} x Position on the x axis + * @param {number} y Position on the y axis + * @param {number} pivotX Pivot on the x axis + * @param {number} pivotY Pivot on the y axis + * @param {number} scaleX Scale on the x axis + * @param {number} scaleY Scale on the y axis + * @param {number} rotation Rotation in radians + * @param {number} skewX Skew on the x axis + * @param {number} skewY Skew on the y axis + * + * @return {PIXI.Matrix} This matrix. Good for chaining method calls. + */ +Matrix.prototype.setTransform = function (x, y, pivotX, pivotY, scaleX, scaleY, rotation, skewX, skewY) +{ + var a, b, c, d, sr, cr, cy, sy, nsx, cx; - /** - * Have events been attached to the dom element? - * - * @member {boolean} - * @private - */ - this.eventsAdded = false; + sr = Math.sin(rotation); + cr = Math.cos(rotation); + cy = Math.cos(skewY); + sy = Math.sin(skewY); + nsx = -Math.sin(skewX); + cx = Math.cos(skewX); - //this will make it so that you don't have to call bind all the time + a = cr * scaleX; + b = sr * scaleX; + c = -sr * scaleY; + d = cr * scaleY; - /** - * @member {Function} - */ - this.onMouseUp = this.onMouseUp.bind(this); - this.processMouseUp = this.processMouseUp.bind( this ); + this.a = cy * a + sy * c; + this.b = cy * b + sy * d; + this.c = nsx * a + cx * c; + this.d = nsx * b + cx * d; + this.tx = x + ( pivotX * a + pivotY * c ); + this.ty = y + ( pivotX * b + pivotY * d ); - /** - * @member {Function} - */ - this.onMouseDown = this.onMouseDown.bind(this); - this.processMouseDown = this.processMouseDown.bind( this ); + return this; +}; - /** - * @member {Function} - */ - this.onMouseMove = this.onMouseMove.bind( this ); - this.processMouseMove = this.processMouseMove.bind( this ); +/** + * Prepends the given Matrix to this Matrix. + * + * @param {PIXI.Matrix} matrix + * @return {PIXI.Matrix} This matrix. Good for chaining method calls. + */ +Matrix.prototype.prepend = function(matrix) +{ + var tx1 = this.tx; - /** - * @member {Function} - */ - this.onMouseOut = this.onMouseOut.bind(this); - this.processMouseOverOut = this.processMouseOverOut.bind( this ); + if (matrix.a !== 1 || matrix.b !== 0 || matrix.c !== 0 || matrix.d !== 1) + { + var a1 = this.a; + var c1 = this.c; + this.a = a1*matrix.a+this.b*matrix.c; + this.b = a1*matrix.b+this.b*matrix.d; + this.c = c1*matrix.a+this.d*matrix.c; + this.d = c1*matrix.b+this.d*matrix.d; + } + this.tx = tx1*matrix.a+this.ty*matrix.c+matrix.tx; + this.ty = tx1*matrix.b+this.ty*matrix.d+matrix.ty; - /** - * @member {Function} - */ - this.onTouchStart = this.onTouchStart.bind(this); - this.processTouchStart = this.processTouchStart.bind(this); + return this; +}; - /** - * @member {Function} - */ - this.onTouchEnd = this.onTouchEnd.bind(this); - this.processTouchEnd = this.processTouchEnd.bind(this); +/** + * Decomposes the matrix (x, y, scaleX, scaleY, and rotation) and sets the properties on to a transform. + * @param transform {PIXI.Transform|PIXI.TransformStatic} the transform to apply the properties to. + * @return {PIXI.Transform|PIXI.TransformStatic} The transform with the newly applied properies +*/ +Matrix.prototype.decompose = function(transform) +{ + // sort out rotation / skew.. + var a = this.a, + b = this.b, + c = this.c, + d = this.d; - /** - * @member {Function} - */ - this.onTouchMove = this.onTouchMove.bind(this); - this.processTouchMove = this.processTouchMove.bind(this); + var skewX = Math.atan2(-c, d); + var skewY = Math.atan2(b, a); - /** - * @member {number} - */ - this.last = 0; + var delta = Math.abs(1-skewX/skewY); - /** - * Every update cursor will be reset to this value, if some element wont override it in its hitTest - * @member {string} - * @default 'inherit' - */ - this.defaultCursorStyle = 'inherit'; + if (delta < 0.00001) + { + transform.rotation = skewY; - /** - * The css style of the cursor that is being used - * @member {string} - */ - this.currentCursorStyle = 'inherit'; + if (a < 0 && d >= 0) + { + transform.rotation += (transform.rotation <= 0) ? Math.PI : -Math.PI; + } - /** - * Internal cached var - * @member {PIXI.Point} - * @private - */ - this._tempPoint = new core.Point(); + transform.skew.x = transform.skew.y = 0; + + } + else + { + transform.skew.x = skewX; + transform.skew.y = skewY; + } + // next set scale + transform.scale.x = Math.sqrt(a * a + b * b); + transform.scale.y = Math.sqrt(c * c + d * d); - /** - * The current resolution - * @member {number} - */ - this.resolution = 1; + // next set position + transform.position.x = this.tx; + transform.position.y = this.ty; - this.setTargetElement(this.renderer.view, this.renderer.resolution); -} + return transform; +}; -InteractionManager.prototype.constructor = InteractionManager; -module.exports = InteractionManager; /** - * Sets the DOM element which will receive mouse/touch events. This is useful for when you have - * other DOM elements on top of the renderers Canvas element. With this you'll be bale to deletegate - * another DOM element to receive those events. + * Inverts this matrix * - * @param element {HTMLElement} the DOM element which will receive mouse and touch events. - * @param [resolution=1] {number} THe resolution of the new element (relative to the canvas). - * @private + * @return {PIXI.Matrix} This matrix. Good for chaining method calls. */ -InteractionManager.prototype.setTargetElement = function (element, resolution) +Matrix.prototype.invert = function() { - this.removeEvents(); - - this.interactionDOMElement = element; + var a1 = this.a; + var b1 = this.b; + var c1 = this.c; + var d1 = this.d; + var tx1 = this.tx; + var n = a1*d1-b1*c1; - this.resolution = resolution || 1; + this.a = d1/n; + this.b = -b1/n; + this.c = -c1/n; + this.d = a1/n; + this.tx = (c1*this.ty-d1*tx1)/n; + this.ty = -(a1*this.ty-b1*tx1)/n; - this.addEvents(); + return this; }; + /** - * Registers all the DOM events + * Resets this Matix to an identity (default) matrix. * - * @private + * @return {PIXI.Matrix} This matrix. Good for chaining method calls. */ -InteractionManager.prototype.addEvents = function () +Matrix.prototype.identity = function () { - if (!this.interactionDOMElement) - { - return; - } - - core.ticker.shared.add(this.update, this); - - if (window.navigator.msPointerEnabled) - { - this.interactionDOMElement.style['-ms-content-zooming'] = 'none'; - this.interactionDOMElement.style['-ms-touch-action'] = 'none'; - } - - window.document.addEventListener('mousemove', this.onMouseMove, true); - this.interactionDOMElement.addEventListener('mousedown', this.onMouseDown, true); - this.interactionDOMElement.addEventListener('mouseout', this.onMouseOut, true); + this.a = 1; + this.b = 0; + this.c = 0; + this.d = 1; + this.tx = 0; + this.ty = 0; - this.interactionDOMElement.addEventListener('touchstart', this.onTouchStart, true); - this.interactionDOMElement.addEventListener('touchend', this.onTouchEnd, true); - this.interactionDOMElement.addEventListener('touchmove', this.onTouchMove, true); + return this; +}; - window.addEventListener('mouseup', this.onMouseUp, true); +/** + * Creates a new Matrix object with the same values as this one. + * + * @return {PIXI.Matrix} A copy of this matrix. Good for chaining method calls. + */ +Matrix.prototype.clone = function () +{ + var matrix = new Matrix(); + matrix.a = this.a; + matrix.b = this.b; + matrix.c = this.c; + matrix.d = this.d; + matrix.tx = this.tx; + matrix.ty = this.ty; - this.eventsAdded = true; + return matrix; }; /** - * Removes all the DOM events that were previously registered + * Changes the values of the given matrix to be the same as the ones in this matrix * - * @private + * @return {PIXI.Matrix} The matrix given in parameter with its values updated. */ -InteractionManager.prototype.removeEvents = function () +Matrix.prototype.copy = function (matrix) { - if (!this.interactionDOMElement) - { - return; - } + matrix.a = this.a; + matrix.b = this.b; + matrix.c = this.c; + matrix.d = this.d; + matrix.tx = this.tx; + matrix.ty = this.ty; - core.ticker.shared.remove(this.update); + return matrix; +}; - if (window.navigator.msPointerEnabled) - { - this.interactionDOMElement.style['-ms-content-zooming'] = ''; - this.interactionDOMElement.style['-ms-touch-action'] = ''; - } +/** + * A default (identity) matrix + * + * @static + * @const + */ +Matrix.IDENTITY = new Matrix(); - window.document.removeEventListener('mousemove', this.onMouseMove, true); - this.interactionDOMElement.removeEventListener('mousedown', this.onMouseDown, true); - this.interactionDOMElement.removeEventListener('mouseout', this.onMouseOut, true); +/** + * A temp matrix + * + * @static + * @const + */ +Matrix.TEMP_MATRIX = new Matrix(); + +},{"./Point":65}],64:[function(require,module,exports){ +/** + * The Point object represents a location in a two-dimensional coordinate system, where x represents + * the horizontal axis and y represents the vertical axis. + * An observable point is a point that triggers a callback when the point's position is changed. + * + * @class + * @memberof PIXI + * @param cb {Function} callback when changed + * @param scope {Object} owner of callback + * @param [x=0] {number} position of the point on the x axis + * @param [y=0] {number} position of the point on the y axis + */ +function ObservablePoint(cb, scope, x, y) +{ + this._x = x || 0; + this._y = y || 0; - this.interactionDOMElement.removeEventListener('touchstart', this.onTouchStart, true); - this.interactionDOMElement.removeEventListener('touchend', this.onTouchEnd, true); - this.interactionDOMElement.removeEventListener('touchmove', this.onTouchMove, true); + this.cb = cb; + this.scope = scope; +} - this.interactionDOMElement = null; +ObservablePoint.prototype.constructor = ObservablePoint; +module.exports = ObservablePoint; - window.removeEventListener('mouseup', this.onMouseUp, true); - this.eventsAdded = false; -}; + +Object.defineProperties(ObservablePoint.prototype, { + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + x: { + get: function () + { + return this._x; + }, + set: function (value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); + } + } + }, + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + y: { + get: function () + { + return this._y; + }, + set: function (value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } + } +}); /** - * Updates the state of interactive objects. - * Invoked by a throttled ticker update from - * {@link PIXI.ticker.shared}. + * Sets the point to a new x and y position. + * If y is omitted, both x and y will be set to x. * - * @param deltaTime {number} + * @param [x=0] {number} position of the point on the x axis + * @param [y=0] {number} position of the point on the y axis */ -InteractionManager.prototype.update = function (deltaTime) +ObservablePoint.prototype.set = function (x, y) { - this._deltaTime += deltaTime; - - if (this._deltaTime < this.interactionFrequency) - { - return; - } - - this._deltaTime = 0; - - if (!this.interactionDOMElement) + var _x = x || 0; + var _y = y || ( (y !== 0) ? _x : 0 ); + if (this._x !== _x || this._y !== _y) { - return; + this._x = _x; + this._y = _y; + this.cb.call(this.scope); } +}; - // if the user move the mouse this check has already been dfone using the mouse move! - if(this.didMove) +/** + * Copies the data from another point + * + * @param point {PIXI.Point|PIXI.ObservablePoint} point to copy from + */ +ObservablePoint.prototype.copy = function (point) +{ + if (this._x !== point.x || this._y !== point.y) { - this.didMove = false; - return; + this._x = point.x; + this._y = point.y; + this.cb.call(this.scope); } +}; + +},{}],65:[function(require,module,exports){ +/** + * The Point object represents a location in a two-dimensional coordinate system, where x represents + * the horizontal axis and y represents the vertical axis. + * + * @class + * @memberof PIXI + * @param [x=0] {number} position of the point on the x axis + * @param [y=0] {number} position of the point on the y axis + */ +function Point(x, y) +{ + /** + * @member {number} + * @default 0 + */ + this.x = x || 0; - this.cursor = this.defaultCursorStyle; - - this.processInteractive(this.mouse.global, this.renderer._lastObjectRendered, this.processMouseOverOut, true ); - - if (this.currentCursorStyle !== this.cursor) - { - this.currentCursorStyle = this.cursor; - this.interactionDOMElement.style.cursor = this.cursor; - } + /** + * @member {number} + * @default 0 + */ + this.y = y || 0; +} - //TODO -}; +Point.prototype.constructor = Point; +module.exports = Point; /** - * Dispatches an event on the display object that was interacted with + * Creates a clone of this point * - * @param displayObject {PIXI.Container|PIXI.Sprite|PIXI.extras.TilingSprite} the display object in question - * @param eventString {string} the name of the event (e.g, mousedown) - * @param eventData {object} the event data object - * @private + * @return {PIXI.Point} a copy of the point */ -InteractionManager.prototype.dispatchEvent = function ( displayObject, eventString, eventData ) +Point.prototype.clone = function () { - if(!eventData.stopped) - { - eventData.target = displayObject; - eventData.type = eventString; - - displayObject.emit( eventString, eventData ); + return new Point(this.x, this.y); +}; - if( displayObject[eventString] ) - { - displayObject[eventString]( eventData ); - } - } +/** + * Copies x and y from the given point + * + * @param p {PIXI.Point} + */ +Point.prototype.copy = function (p) { + this.set(p.x, p.y); }; /** - * Maps x and y coords from a DOM object and maps them correctly to the pixi view. The resulting value is stored in the point. - * This takes into account the fact that the DOM element could be scaled and positioned anywhere on the screen. + * Returns true if the given point is equal to this point * - * @param {PIXI.Point} point the point that the result will be stored in - * @param {number} x the x coord of the position to map - * @param {number} y the y coord of the position to map + * @param p {PIXI.Point} + * @returns {boolean} Whether the given point equal to this point */ -InteractionManager.prototype.mapPositionToPoint = function ( point, x, y ) -{ - var rect = this.interactionDOMElement.getBoundingClientRect(); - point.x = ( ( x - rect.left ) * (this.interactionDOMElement.width / rect.width ) ) / this.resolution; - point.y = ( ( y - rect.top ) * (this.interactionDOMElement.height / rect.height ) ) / this.resolution; +Point.prototype.equals = function (p) { + return (p.x === this.x) && (p.y === this.y); }; /** - * This function is provides a neat way of crawling through the scene graph and running a specified function on all interactive objects it finds. - * It will also take care of hit testing the interactive objects and passes the hit across in the function. + * Sets the point to a new x and y position. + * If y is omitted, both x and y will be set to x. * - * @param {PIXI.Point} point the point that is tested for collision - * @param {PIXI.Container|PIXI.Sprite|PIXI.extras.TilingSprite} displayObject the displayObject that will be hit test (recurcsivly crawls its children) - * @param {Function} func the function that will be called on each interactive object. The displayObject and hit will be passed to the function - * @param {boolean} hitTest this indicates if the objects inside should be hit test against the point - * @return {boolean} returns true if the displayObject hit the point + * @param [x=0] {number} position of the point on the x axis + * @param [y=0] {number} position of the point on the y axis */ -InteractionManager.prototype.processInteractive = function (point, displayObject, func, hitTest, interactive) +Point.prototype.set = function (x, y) { - if(!displayObject || !displayObject.visible) - { - return false; - } + this.x = x || 0; + this.y = y || ( (y !== 0) ? this.x : 0 ) ; +}; + +},{}],66:[function(require,module,exports){ +/** + * Math classes and utilities mixed into PIXI namespace. + * + * @lends PIXI + */ +module.exports = { + // These will be mixed to be made publicly available, + // while this module is used internally in core + // to avoid circular dependencies and cut down on + // internal module requires. - // Took a little while to rework this function correctly! But now it is done and nice and optimised. ^_^ - // - // This function will now loop through all objects and then only hit test the objects it HAS to, not all of them. MUCH faster.. - // An object will be hit test if the following is true: - // - // 1: It is interactive. - // 2: It belongs to a parent that is interactive AND one of the parents children have not already been hit. - // - // As another little optimisation once an interactive object has been hit we can carry on through the scenegraph, but we know that there will be no more hits! So we can avoid extra hit tests - // A final optimisation is that an object is not hit test directly if a child has already been hit. + Point: require('./Point'), + ObservablePoint: require('./ObservablePoint'), + Matrix: require('./Matrix'), + GroupD8: require('./GroupD8'), - var hit = false, - interactiveParent = interactive = displayObject.interactive || interactive; + Circle: require('./shapes/Circle'), + Ellipse: require('./shapes/Ellipse'), + Polygon: require('./shapes/Polygon'), + Rectangle: require('./shapes/Rectangle'), + RoundedRectangle: require('./shapes/RoundedRectangle') +}; + +},{"./GroupD8":62,"./Matrix":63,"./ObservablePoint":64,"./Point":65,"./shapes/Circle":67,"./shapes/Ellipse":68,"./shapes/Polygon":69,"./shapes/Rectangle":70,"./shapes/RoundedRectangle":71}],67:[function(require,module,exports){ +var Rectangle = require('./Rectangle'), + CONST = require('../../const'); +/** + * The Circle object can be used to specify a hit area for displayObjects + * + * @class + * @memberof PIXI + * @param x {number} The X coordinate of the center of this circle + * @param y {number} The Y coordinate of the center of this circle + * @param radius {number} The radius of the circle + */ +function Circle(x, y, radius) +{ + /** + * @member {number} + * @default 0 + */ + this.x = x || 0; + /** + * @member {number} + * @default 0 + */ + this.y = y || 0; + /** + * @member {number} + * @default 0 + */ + this.radius = radius || 0; - // if the displayobject has a hitArea, then it does not need to hitTest children. - if(displayObject.hitArea) - { - interactiveParent = false; - } + /** + * The type of the object, mainly used to avoid `instanceof` checks + * + * @member {number} + * @readOnly + * @default CONST.SHAPES.CIRC + * @see PIXI.SHAPES + */ + this.type = CONST.SHAPES.CIRC; +} - // it has a mask! Then lets hit test that before continuing.. - if(hitTest && displayObject._mask) - { - if(!displayObject._mask.containsPoint(point)) - { - hitTest = false; - } - } +Circle.prototype.constructor = Circle; +module.exports = Circle; - // it has a filterArea! Same as mask but easier, its a rectangle - if(hitTest && displayObject.filterArea) - { - if(!displayObject.filterArea.containsPoint(point)) - { - hitTest = false; - } - } +/** + * Creates a clone of this Circle instance + * + * @return {PIXI.Circle} a copy of the Circle + */ +Circle.prototype.clone = function () +{ + return new Circle(this.x, this.y, this.radius); +}; - // ** FREE TIP **! If an object is not interactive or has no buttons in it (such as a game scene!) set interactiveChildren to false for that displayObject. - // This will allow pixi to completly ignore and bypass checking the displayObjects children. - if(displayObject.interactiveChildren) +/** + * Checks whether the x and y coordinates given are contained within this circle + * + * @param x {number} The X coordinate of the point to test + * @param y {number} The Y coordinate of the point to test + * @return {boolean} Whether the x/y coordinates are within this Circle + */ +Circle.prototype.contains = function (x, y) +{ + if (this.radius <= 0) { - var children = displayObject.children; - - for (var i = children.length-1; i >= 0; i--) - { - - var child = children[i]; - - // time to get recursive.. if this function will return if somthing is hit.. - if(this.processInteractive(point, child, func, hitTest, interactiveParent)) - { - // its a good idea to check if a child has lost its parent. - // this means it has been removed whilst looping so its best - if(!child.parent) - { - continue; - } - - hit = true; - - // we no longer need to hit test any more objects in this container as we we now know the parent has been hit - interactiveParent = false; - - // If the child is interactive , that means that the object hit was actually interactive and not just the child of an interactive object. - // This means we no longer need to hit test anything else. We still need to run through all objects, but we don't need to perform any hit tests. - // if(child.interactive) - //{ - hitTest = false; - //} + return false; + } - // we can break now as we have hit an object. + var dx = (this.x - x), + dy = (this.y - y), + r2 = this.radius * this.radius; - } - } - } + dx *= dx; + dy *= dy; + return (dx + dy <= r2); +}; +/** +* Returns the framing rectangle of the circle as a Rectangle object +* +* @return {PIXI.Rectangle} the framing rectangle +*/ +Circle.prototype.getBounds = function () +{ + return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); +}; + +},{"../../const":42,"./Rectangle":70}],68:[function(require,module,exports){ +var Rectangle = require('./Rectangle'), + CONST = require('../../const'); - // no point running this if the item is not interactive or does not have an interactive parent. - if(interactive) - { - // if we are hit testing (as in we have no hit any objects yet) - // We also don't need to worry about hit testing if once of the displayObjects children has already been hit! - if(hitTest && !hit) - { +/** + * The Ellipse object can be used to specify a hit area for displayObjects + * + * @class + * @memberof PIXI + * @param x {number} The X coordinate of the center of the ellipse + * @param y {number} The Y coordinate of the center of the ellipse + * @param width {number} The half width of this ellipse + * @param height {number} The half height of this ellipse + */ +function Ellipse(x, y, width, height) +{ + /** + * @member {number} + * @default 0 + */ + this.x = x || 0; - if(displayObject.hitArea) - { - displayObject.worldTransform.applyInverse(point, this._tempPoint); - hit = displayObject.hitArea.contains( this._tempPoint.x, this._tempPoint.y ); - } - else if(displayObject.containsPoint) - { - hit = displayObject.containsPoint(point); - } + /** + * @member {number} + * @default 0 + */ + this.y = y || 0; + /** + * @member {number} + * @default 0 + */ + this.width = width || 0; - } + /** + * @member {number} + * @default 0 + */ + this.height = height || 0; - if(displayObject.interactive) - { - func(displayObject, hit); - } - } + /** + * The type of the object, mainly used to avoid `instanceof` checks + * + * @member {number} + * @readOnly + * @default CONST.SHAPES.ELIP + * @see PIXI.SHAPES + */ + this.type = CONST.SHAPES.ELIP; +} - return hit; +Ellipse.prototype.constructor = Ellipse; +module.exports = Ellipse; +/** + * Creates a clone of this Ellipse instance + * + * @return {PIXI.Ellipse} a copy of the ellipse + */ +Ellipse.prototype.clone = function () +{ + return new Ellipse(this.x, this.y, this.width, this.height); }; - /** - * Is called when the mouse button is pressed down on the renderer element + * Checks whether the x and y coordinates given are contained within this ellipse * - * @param event {Event} The DOM event of a mouse button being pressed down - * @private + * @param x {number} The X coordinate of the point to test + * @param y {number} The Y coordinate of the point to test + * @return {boolean} Whether the x/y coords are within this ellipse */ -InteractionManager.prototype.onMouseDown = function (event) +Ellipse.prototype.contains = function (x, y) { - this.mouse.originalEvent = event; - this.eventData.data = this.mouse; - this.eventData.stopped = false; - - // Update internal mouse reference - this.mapPositionToPoint( this.mouse.global, event.clientX, event.clientY); - - if (this.autoPreventDefault) + if (this.width <= 0 || this.height <= 0) { - this.mouse.originalEvent.preventDefault(); + return false; } - this.processInteractive(this.mouse.global, this.renderer._lastObjectRendered, this.processMouseDown, true ); + //normalize the coords to an ellipse with center 0,0 + var normx = ((x - this.x) / this.width), + normy = ((y - this.y) / this.height); + + normx *= normx; + normy *= normy; + + return (normx + normy <= 1); }; /** - * Processes the result of the mouse down check and dispatches the event if need be + * Returns the framing rectangle of the ellipse as a Rectangle object * - * @param displayObject {PIXI.Container|PIXI.Sprite|PIXI.extras.TilingSprite} The display object that was tested - * @param hit {boolean} the result of the hit test on the dispay object - * @private + * @return {PIXI.Rectangle} the framing rectangle */ -InteractionManager.prototype.processMouseDown = function ( displayObject, hit ) +Ellipse.prototype.getBounds = function () { - var e = this.mouse.originalEvent; + return new Rectangle(this.x - this.width, this.y - this.height, this.width, this.height); +}; + +},{"../../const":42,"./Rectangle":70}],69:[function(require,module,exports){ +var Point = require('../Point'), + CONST = require('../../const'); - var isRightButton = e.button === 2 || e.which === 3; +/** + * @class + * @memberof PIXI + * @param points_ {PIXI.Point[]|number[]|...PIXI.Point|...number} This can be an array of Points that form the polygon, + * a flat array of numbers that will be interpreted as [x,y, x,y, ...], or the arguments passed can be + * all the points of the polygon e.g. `new PIXI.Polygon(new PIXI.Point(), new PIXI.Point(), ...)`, or the + * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are + * Numbers. + */ +function Polygon(points_) +{ + // prevents an argument assignment deopt + // see section 3.1: https://github.com/petkaantonov/bluebird/wiki/Optimization-killers#3-managing-arguments + var points = points_; - if(hit) + //if points isn't an array, use arguments as the array + if (!Array.isArray(points)) { - displayObject[ isRightButton ? '_isRightDown' : '_isLeftDown' ] = true; - this.dispatchEvent( displayObject, isRightButton ? 'rightdown' : 'mousedown', this.eventData ); + // prevents an argument leak deopt + // see section 3.2: https://github.com/petkaantonov/bluebird/wiki/Optimization-killers#3-managing-arguments + points = new Array(arguments.length); + + for (var a = 0; a < points.length; ++a) { + points[a] = arguments[a]; + } + } + + // if this is an array of points, convert it to a flat array of numbers + if (points[0] instanceof Point) + { + var p = []; + for (var i = 0, il = points.length; i < il; i++) + { + p.push(points[i].x, points[i].y); + } + + points = p; } -}; + this.closed = true; + + /** + * An array of the points of this polygon + * + * @member {number[]} + */ + this.points = points; + /** + * The type of the object, mainly used to avoid `instanceof` checks + * + * @member {number} + * @readOnly + * @default CONST.SHAPES.POLY + * @see PIXI.SHAPES + */ + this.type = CONST.SHAPES.POLY; +} +Polygon.prototype.constructor = Polygon; +module.exports = Polygon; /** - * Is called when the mouse button is released on the renderer element + * Creates a clone of this polygon * - * @param event {Event} The DOM event of a mouse button being released - * @private + * @return {PIXI.Polygon} a copy of the polygon */ -InteractionManager.prototype.onMouseUp = function (event) +Polygon.prototype.clone = function () { - this.mouse.originalEvent = event; - this.eventData.data = this.mouse; - this.eventData.stopped = false; + return new Polygon(this.points.slice()); +}; - // Update internal mouse reference - this.mapPositionToPoint( this.mouse.global, event.clientX, event.clientY); - this.processInteractive(this.mouse.global, this.renderer._lastObjectRendered, this.processMouseUp, true ); +Polygon.prototype.close = function () +{ + var points = this.points; + + // close the poly if the value is true! + if (points[0] !== points[points.length-2] || points[1] !== points[points.length-1]) + { + points.push(points[0], points[1]); + } }; /** - * Processes the result of the mouse up check and dispatches the event if need be + * Checks whether the x and y coordinates passed to this function are contained within this polygon * - * @param displayObject {PIXI.Container|PIXI.Sprite|PIXI.extras.TilingSprite} The display object that was tested - * @param hit {boolean} the result of the hit test on the display object - * @private + * @param x {number} The X coordinate of the point to test + * @param y {number} The Y coordinate of the point to test + * @return {boolean} Whether the x/y coordinates are within this polygon */ -InteractionManager.prototype.processMouseUp = function ( displayObject, hit ) +Polygon.prototype.contains = function (x, y) { - var e = this.mouse.originalEvent; + var inside = false; - var isRightButton = e.button === 2 || e.which === 3; - var isDown = isRightButton ? '_isRightDown' : '_isLeftDown'; + // use some raycasting to test hits + // https://github.com/substack/point-in-polygon/blob/master/index.js + var length = this.points.length / 2; - if(hit) + for (var i = 0, j = length - 1; i < length; j = i++) { - this.dispatchEvent( displayObject, isRightButton ? 'rightup' : 'mouseup', this.eventData ); + var xi = this.points[i * 2], yi = this.points[i * 2 + 1], + xj = this.points[j * 2], yj = this.points[j * 2 + 1], + intersect = ((yi > y) !== (yj > y)) && (x < (xj - xi) * (y - yi) / (yj - yi) + xi); - if( displayObject[ isDown ] ) - { - displayObject[ isDown ] = false; - this.dispatchEvent( displayObject, isRightButton ? 'rightclick' : 'click', this.eventData ); - } - } - else - { - if( displayObject[ isDown ] ) + if (intersect) { - displayObject[ isDown ] = false; - this.dispatchEvent( displayObject, isRightButton ? 'rightupoutside' : 'mouseupoutside', this.eventData ); + inside = !inside; } } -}; + return inside; +}; + +},{"../../const":42,"../Point":65}],70:[function(require,module,exports){ +var CONST = require('../../const'); /** - * Is called when the mouse moves across the renderer element + * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. * - * @param event {Event} The DOM event of the mouse moving - * @private + * @class + * @memberof PIXI + * @param x {number} The X coordinate of the upper-left corner of the rectangle + * @param y {number} The Y coordinate of the upper-left corner of the rectangle + * @param width {number} The overall width of this rectangle + * @param height {number} The overall height of this rectangle */ -InteractionManager.prototype.onMouseMove = function (event) +function Rectangle(x, y, width, height) { - this.mouse.originalEvent = event; - this.eventData.data = this.mouse; - this.eventData.stopped = false; - - this.mapPositionToPoint( this.mouse.global, event.clientX, event.clientY); + /** + * @member {number} + * @default 0 + */ + this.x = x || 0; - this.didMove = true; + /** + * @member {number} + * @default 0 + */ + this.y = y || 0; - this.cursor = this.defaultCursorStyle; + /** + * @member {number} + * @default 0 + */ + this.width = width || 0; - this.processInteractive(this.mouse.global, this.renderer._lastObjectRendered, this.processMouseMove, true ); + /** + * @member {number} + * @default 0 + */ + this.height = height || 0; - if (this.currentCursorStyle !== this.cursor) - { - this.currentCursorStyle = this.cursor; - this.interactionDOMElement.style.cursor = this.cursor; - } + /** + * The type of the object, mainly used to avoid `instanceof` checks + * + * @member {number} + * @readOnly + * @default CONST.SHAPES.RECT + * @see PIXI.SHAPES + */ + this.type = CONST.SHAPES.RECT; +} - //TODO BUG for parents ineractive object (border order issue) -}; +Rectangle.prototype.constructor = Rectangle; +module.exports = Rectangle; /** - * Processes the result of the mouse move check and dispatches the event if need be + * A constant empty rectangle. * - * @param displayObject {PIXI.Container|PIXI.Sprite|PIXI.extras.TilingSprite} The display object that was tested - * @param hit {boolean} the result of the hit test on the display object - * @private + * @static + * @constant */ -InteractionManager.prototype.processMouseMove = function ( displayObject, hit ) -{ - this.processMouseOverOut(displayObject, hit); - - // only display on mouse over - if(!this.moveWhenInside || hit) - { - this.dispatchEvent( displayObject, 'mousemove', this.eventData); - } -}; +Rectangle.EMPTY = new Rectangle(0, 0, 0, 0); /** - * Is called when the mouse is moved out of the renderer element + * Creates a clone of this Rectangle * - * @param event {Event} The DOM event of a mouse being moved out - * @private + * @return {PIXI.Rectangle} a copy of the rectangle */ -InteractionManager.prototype.onMouseOut = function (event) +Rectangle.prototype.clone = function () { - this.mouse.originalEvent = event; - this.eventData.stopped = false; - - // Update internal mouse reference - this.mapPositionToPoint( this.mouse.global, event.clientX, event.clientY); - - this.interactionDOMElement.style.cursor = this.defaultCursorStyle; + return new Rectangle(this.x, this.y, this.width, this.height); +}; - // TODO optimize by not check EVERY TIME! maybe half as often? // - this.mapPositionToPoint( this.mouse.global, event.clientX, event.clientY ); +Rectangle.prototype.copy = function (rectangle) +{ + this.x = rectangle.x; + this.y = rectangle.y; + this.width = rectangle.width; + this.height = rectangle.height; - this.processInteractive( this.mouse.global, this.renderer._lastObjectRendered, this.processMouseOverOut, false ); + return this; }; /** - * Processes the result of the mouse over/out check and dispatches the event if need be + * Checks whether the x and y coordinates given are contained within this Rectangle * - * @param displayObject {PIXI.Container|PIXI.Sprite|PIXI.extras.TilingSprite} The display object that was tested - * @param hit {boolean} the result of the hit test on the display object - * @private + * @param x {number} The X coordinate of the point to test + * @param y {number} The Y coordinate of the point to test + * @return {boolean} Whether the x/y coordinates are within this Rectangle */ -InteractionManager.prototype.processMouseOverOut = function ( displayObject, hit ) +Rectangle.prototype.contains = function (x, y) { - if(hit) + if (this.width <= 0 || this.height <= 0) { - if(!displayObject._over) - { - displayObject._over = true; - this.dispatchEvent( displayObject, 'mouseover', this.eventData ); - } - - if (displayObject.buttonMode) - { - this.cursor = displayObject.defaultCursor; - } + return false; } - else + + if (x >= this.x && x < this.x + this.width) { - if(displayObject._over) + if (y >= this.y && y < this.y + this.height) { - displayObject._over = false; - this.dispatchEvent( displayObject, 'mouseout', this.eventData); + return true; } } -}; + return false; +}; -/** - * Is called when a touch is started on the renderer element - * - * @param event {Event} The DOM event of a touch starting on the renderer view - * @private - */ -InteractionManager.prototype.onTouchStart = function (event) +Rectangle.prototype.pad = function (paddingX, paddingY) { - if (this.autoPreventDefault) - { - event.preventDefault(); - } + paddingX = paddingX || 0; + paddingY = paddingY || ( (paddingY !== 0) ? paddingX : 0 ); - var changedTouches = event.changedTouches; - var cLength = changedTouches.length; + this.x -= paddingX; + this.y -= paddingY; - for (var i=0; i < cLength; i++) + this.width += paddingX * 2; + this.height += paddingY * 2; +}; + +Rectangle.prototype.fit = function (rectangle) +{ + if (this.x < rectangle.x) { - var touchEvent = changedTouches[i]; - //TODO POOL - var touchData = this.getTouchData( touchEvent ); + this.width += this.x; + if(this.width < 0) { + this.width = 0; + } - touchData.originalEvent = event; + this.x = rectangle.x; + } - this.eventData.data = touchData; - this.eventData.stopped = false; + if (this.y < rectangle.y) + { + this.height += this.y; + if(this.height < 0) { + this.height = 0; + } + this.y = rectangle.y; + } - this.processInteractive( touchData.global, this.renderer._lastObjectRendered, this.processTouchStart, true ); + if ( this.x + this.width > rectangle.x + rectangle.width ) + { + this.width = rectangle.width - this.x; + if(this.width < 0) { + this.width = 0; + } + } - this.returnTouchData( touchData ); + if ( this.y + this.height > rectangle.y + rectangle.height ) + { + this.height = rectangle.height - this.y; + if(this.height < 0) { + this.height = 0; + } } }; -/** - * Processes the result of a touch check and dispatches the event if need be - * - * @param displayObject {PIXI.Container|PIXI.Sprite|PIXI.extras.TilingSprite} The display object that was tested - * @param hit {boolean} the result of the hit test on the display object - * @private - */ -InteractionManager.prototype.processTouchStart = function ( displayObject, hit ) +Rectangle.prototype.enlarge = function (rect) { - if(hit) + + if (rect === Rectangle.EMPTY) { - displayObject._touchDown = true; - this.dispatchEvent( displayObject, 'touchstart', this.eventData ); + return; } -}; + var x1 = Math.min(this.x, rect.x); + var x2 = Math.max(this.x + this.width, rect.x + rect.width); + var y1 = Math.min(this.y, rect.y); + var y2 = Math.max(this.y + this.height, rect.y + rect.height); + this.x = x1; + this.width = x2 - x1; + this.y = y1; + this.height = y2 - y1; +}; + +},{"../../const":42}],71:[function(require,module,exports){ +var CONST = require('../../const'); /** - * Is called when a touch ends on the renderer element + * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. * - * @param event {Event} The DOM event of a touch ending on the renderer view + * @class + * @memberof PIXI + * @param x {number} The X coordinate of the upper-left corner of the rounded rectangle + * @param y {number} The Y coordinate of the upper-left corner of the rounded rectangle + * @param width {number} The overall width of this rounded rectangle + * @param height {number} The overall height of this rounded rectangle + * @param radius {number} Controls the radius of the rounded corners */ -InteractionManager.prototype.onTouchEnd = function (event) +function RoundedRectangle(x, y, width, height, radius) { - if (this.autoPreventDefault) - { - event.preventDefault(); - } - - var changedTouches = event.changedTouches; - var cLength = changedTouches.length; + /** + * @member {number} + * @default 0 + */ + this.x = x || 0; - for (var i=0; i < cLength; i++) - { - var touchEvent = changedTouches[i]; + /** + * @member {number} + * @default 0 + */ + this.y = y || 0; - var touchData = this.getTouchData( touchEvent ); + /** + * @member {number} + * @default 0 + */ + this.width = width || 0; - touchData.originalEvent = event; + /** + * @member {number} + * @default 0 + */ + this.height = height || 0; - //TODO this should be passed along.. no set - this.eventData.data = touchData; - this.eventData.stopped = false; + /** + * @member {number} + * @default 20 + */ + this.radius = radius || 20; + /** + * The type of the object, mainly used to avoid `instanceof` checks + * + * @member {number} + * @readonly + * @default CONST.SHAPES.RREC + * @see PIXI.SHAPES + */ + this.type = CONST.SHAPES.RREC; +} - this.processInteractive( touchData.global, this.renderer._lastObjectRendered, this.processTouchEnd, true ); +RoundedRectangle.prototype.constructor = RoundedRectangle; +module.exports = RoundedRectangle; - this.returnTouchData( touchData ); - } +/** + * Creates a clone of this Rounded Rectangle + * + * @return {PIXI.RoundedRectangle} a copy of the rounded rectangle + */ +RoundedRectangle.prototype.clone = function () +{ + return new RoundedRectangle(this.x, this.y, this.width, this.height, this.radius); }; /** - * Processes the result of the end of a touch and dispatches the event if need be + * Checks whether the x and y coordinates given are contained within this Rounded Rectangle * - * @param displayObject {PIXI.Container|PIXI.Sprite|PIXI.extras.TilingSprite} The display object that was tested - * @param hit {boolean} the result of the hit test on the display object - * @private + * @param x {number} The X coordinate of the point to test + * @param y {number} The Y coordinate of the point to test + * @return {boolean} Whether the x/y coordinates are within this Rounded Rectangle */ -InteractionManager.prototype.processTouchEnd = function ( displayObject, hit ) +RoundedRectangle.prototype.contains = function (x, y) { - if(hit) + if (this.width <= 0 || this.height <= 0) { - this.dispatchEvent( displayObject, 'touchend', this.eventData ); - - if( displayObject._touchDown ) - { - displayObject._touchDown = false; - this.dispatchEvent( displayObject, 'tap', this.eventData ); - } + return false; } - else + + if (x >= this.x && x <= this.x + this.width) { - if( displayObject._touchDown ) + if (y >= this.y && y <= this.y + this.height) { - displayObject._touchDown = false; - this.dispatchEvent( displayObject, 'touchendoutside', this.eventData ); + return true; } } -}; + return false; +}; + +},{"../../const":42}],72:[function(require,module,exports){ +var utils = require('../utils'), + math = require('../math'), + CONST = require('../const'), + Container = require('../display/Container'), + RenderTexture = require('../textures/RenderTexture'), + EventEmitter = require('eventemitter3'), + tempMatrix = new math.Matrix(); /** - * Is called when a touch is moved across the renderer element + * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. + * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) * - * @param event {Event} The DOM event of a touch moving across the renderer view - * @private + * @class + * @memberof PIXI + * @param system {string} The name of the system this renderer is for. + * @param [width=800] {number} the width of the canvas view + * @param [height=600] {number} the height of the canvas view + * @param [options] {object} The optional renderer parameters + * @param [options.view] {HTMLCanvasElement} the canvas to use as a view, optional + * @param [options.transparent=false] {boolean} If the render view is transparent, default false + * @param [options.autoResize=false] {boolean} If the render view is automatically resized, default false + * @param [options.antialias=false] {boolean} sets antialias (only applicable in chrome at the moment) + * @param [options.resolution=1] {number} The resolution / device pixel ratio of the renderer. The resolution of the renderer retina would be 2. + * @param [options.clearBeforeRender=true] {boolean} This sets if the CanvasRenderer will clear the canvas or + * not before the new render pass. + * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). + * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -InteractionManager.prototype.onTouchMove = function (event) +function SystemRenderer(system, width, height, options) { - if (this.autoPreventDefault) + EventEmitter.call(this); + + utils.sayHello(system); + + // prepare options + if (options) { - event.preventDefault(); + for (var i in CONST.DEFAULT_RENDER_OPTIONS) + { + if (typeof options[i] === 'undefined') + { + options[i] = CONST.DEFAULT_RENDER_OPTIONS[i]; + } + } + } + else + { + options = CONST.DEFAULT_RENDER_OPTIONS; } - var changedTouches = event.changedTouches; - var cLength = changedTouches.length; + /** + * The type of the renderer. + * + * @member {number} + * @default PIXI.RENDERER_TYPE.UNKNOWN + * @see PIXI.RENDERER_TYPE + */ + this.type = CONST.RENDERER_TYPE.UNKNOWN; - for (var i=0; i < cLength; i++) - { - var touchEvent = changedTouches[i]; + /** + * The width of the canvas view + * + * @member {number} + * @default 800 + */ + this.width = width || 800; - var touchData = this.getTouchData( touchEvent ); + /** + * The height of the canvas view + * + * @member {number} + * @default 600 + */ + this.height = height || 600; - touchData.originalEvent = event; + /** + * The canvas element that everything is drawn to + * + * @member {HTMLCanvasElement} + */ + this.view = options.view || document.createElement('canvas'); - this.eventData.data = touchData; - this.eventData.stopped = false; + /** + * The resolution / device pixel ratio of the renderer + * + * @member {number} + * @default 1 + */ + this.resolution = options.resolution; - this.processInteractive( touchData.global, this.renderer._lastObjectRendered, this.processTouchMove, this.moveWhenInside ); + /** + * Whether the render view is transparent + * + * @member {boolean} + */ + this.transparent = options.transparent; - this.returnTouchData( touchData ); + /** + * Whether the render view should be resized automatically + * + * @member {boolean} + */ + this.autoResize = options.autoResize || false; + + /** + * Tracks the blend modes useful for this renderer. + * + * @member {object} + */ + this.blendModes = null; + + /** + * The value of the preserveDrawingBuffer flag affects whether or not the contents of the stencil buffer is retained after rendering. + * + * @member {boolean} + */ + this.preserveDrawingBuffer = options.preserveDrawingBuffer; + + /** + * This sets if the CanvasRenderer will clear the canvas or not before the new render pass. + * If the scene is NOT transparent Pixi will use a canvas sized fillRect operation every frame to set the canvas background color. + * If the scene is transparent Pixi will use clearRect to clear the canvas every frame. + * Disable this by setting this to false. For example if your game has a canvas filling background image you often don't need this set. + * + * @member {boolean} + * @default + */ + this.clearBeforeRender = options.clearBeforeRender; + + /** + * If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. + * Handy for crisp pixel art and speed on legacy devices. + * + * @member {boolean} + */ + this.roundPixels = options.roundPixels; + + /** + * The background color as a number. + * + * @member {number} + * @private + */ + this._backgroundColor = 0x000000; + + /** + * The background color as an [R, G, B] array. + * + * @member {number[]} + * @private + */ + this._backgroundColorRgba = [0, 0, 0, 0]; + + /** + * The background color as a string. + * + * @member {string} + * @private + */ + this._backgroundColorString = '#000000'; + + this.backgroundColor = options.backgroundColor || this._backgroundColor; // run bg color setter + + /** + * This temporary display object used as the parent of the currently being rendered item + * + * @member {PIXI.DisplayObject} + * @private + */ + this._tempDisplayObjectParent = new Container(); + + /** + * The last root object that the renderer tried to render. + * + * @member {PIXI.DisplayObject} + * @private + */ + this._lastObjectRendered = this._tempDisplayObjectParent; +} + +// constructor +SystemRenderer.prototype = Object.create(EventEmitter.prototype); +SystemRenderer.prototype.constructor = SystemRenderer; +module.exports = SystemRenderer; + +Object.defineProperties(SystemRenderer.prototype, { + /** + * The background color to fill if not transparent + * + * @member {number} + * @memberof PIXI.SystemRenderer# + */ + backgroundColor: + { + get: function () + { + return this._backgroundColor; + }, + set: function (val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } } -}; +}); /** - * Processes the result of a touch move check and dispatches the event if need be + * Resizes the canvas view to the specified width and height * - * @param displayObject {PIXI.Container|PIXI.Sprite|PIXI.extras.TilingSprite} The display object that was tested - * @param hit {boolean} the result of the hit test on the display object - * @private + * @param width {number} the new width of the canvas view + * @param height {number} the new height of the canvas view */ -InteractionManager.prototype.processTouchMove = function ( displayObject, hit ) -{ - if(!this.moveWhenInside || hit) +SystemRenderer.prototype.resize = function (width, height) { + this.width = width * this.resolution; + this.height = height * this.resolution; + + this.view.width = this.width; + this.view.height = this.height; + + if (this.autoResize) { - this.dispatchEvent( displayObject, 'touchmove', this.eventData); + this.view.style.width = this.width / this.resolution + 'px'; + this.view.style.height = this.height / this.resolution + 'px'; } }; /** - * Grabs an interaction data object from the internal pool - * - * @param touchEvent {EventData} The touch event we need to pair with an interactionData object + * Useful function that returns a texture of the display object that can then be used to create sprites + * This can be quite useful if your displayObject is complicated and needs to be reused multiple times. * - * @private + * @param displayObject {PIXI.DisplayObject} The displayObject the object will be generated from + * @param scaleMode {number} Should be one of the scaleMode consts + * @param resolution {number} The resolution / device pixel ratio of the texture being generated + * @return {PIXI.Texture} a texture of the graphics object */ -InteractionManager.prototype.getTouchData = function (touchEvent) -{ - var touchData = this.interactiveDataPool.pop(); - - if(!touchData) - { - touchData = new InteractionData(); - } +SystemRenderer.prototype.generateTexture = function (displayObject, scaleMode, resolution) { - touchData.identifier = touchEvent.identifier; - this.mapPositionToPoint( touchData.global, touchEvent.clientX, touchEvent.clientY ); + var bounds = displayObject.getLocalBounds(); - if(navigator.isCocoonJS) - { - touchData.global.x = touchData.global.x / this.resolution; - touchData.global.y = touchData.global.y / this.resolution; - } + var renderTexture = RenderTexture.create(bounds.width | 0, bounds.height | 0, scaleMode, resolution); - touchEvent.globalX = touchData.global.x; - touchEvent.globalY = touchData.global.y; + tempMatrix.tx = -bounds.x; + tempMatrix.ty = -bounds.y; - return touchData; -}; + this.render(displayObject, renderTexture, false, tempMatrix, true); -/** - * Returns an interaction data object to the internal pool - * - * @param touchData {PIXI.interaction.InteractionData} The touch data object we want to return to the pool - * - * @private - */ -InteractionManager.prototype.returnTouchData = function ( touchData ) -{ - this.interactiveDataPool.push( touchData ); + return renderTexture; }; /** - * Destroys the interaction manager + * Removes everything from the renderer and optionally removes the Canvas DOM element. * + * @param [removeView=false] {boolean} Removes the Canvas element from the DOM. */ -InteractionManager.prototype.destroy = function () { - this.removeEvents(); - - this.renderer = null; - - this.mouse = null; - - this.eventData = null; - - this.interactiveDataPool = null; +SystemRenderer.prototype.destroy = function (removeView) { + if (removeView && this.view.parentNode) + { + this.view.parentNode.removeChild(this.view); + } - this.interactionDOMElement = null; + this.type = CONST.RENDERER_TYPE.UNKNOWN; - this.onMouseUp = null; - this.processMouseUp = null; + this.width = 0; + this.height = 0; + this.view = null; - this.onMouseDown = null; - this.processMouseDown = null; + this.resolution = 0; - this.onMouseMove = null; - this.processMouseMove = null; + this.transparent = false; - this.onMouseOut = null; - this.processMouseOverOut = null; + this.autoResize = false; + this.blendModes = null; - this.onTouchStart = null; - this.processTouchStart = null; + this.preserveDrawingBuffer = false; + this.clearBeforeRender = false; - this.onTouchEnd = null; - this.processTouchEnd = null; + this.roundPixels = false; - this.onTouchMove = null; - this.processTouchMove = null; + this._backgroundColor = 0; + this._backgroundColorRgba = null; + this._backgroundColorString = null; - this._tempPoint = null; + this.backgroundColor = 0; + this._tempDisplayObjectParent = null; + this._lastObjectRendered = null; }; - -core.WebGLRenderer.registerPlugin('interaction', InteractionManager); -core.CanvasRenderer.registerPlugin('interaction', InteractionManager); -},{"../core":50,"./InteractionData":125,"./interactiveTarget":128}],127:[function(require,module,exports){ -/** - * @file Main export of the PIXI interactions library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +},{"../const":42,"../display/Container":44,"../math":66,"../textures/RenderTexture":107,"../utils":115,"eventemitter3":4}],73:[function(require,module,exports){ +var SystemRenderer = require('../SystemRenderer'), + CanvasMaskManager = require('./utils/CanvasMaskManager'), + CanvasRenderTarget = require('./utils/CanvasRenderTarget'), + mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), + utils = require('../../utils'), + CONST = require('../../const'); /** - * @namespace PIXI.interaction - */ -module.exports = { - InteractionData: require('./InteractionData'), - InteractionManager: require('./InteractionManager'), - interactiveTarget: require('./interactiveTarget') -}; - -},{"./InteractionData":125,"./InteractionManager":126,"./interactiveTarget":128}],128:[function(require,module,exports){ -/** - * Default property values of interactive objects - * used by {@link PIXI.interaction.InteractionManager}. - * - * @mixin - * @memberof PIXI.interaction - * @example - * function MyObject() {} + * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. + * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) * - * Object.assign( - * MyObject.prototype, - * PIXI.interaction.interactiveTarget - * ); + * @class + * @memberof PIXI + * @extends PIXI.SystemRenderer + * @param [width=800] {number} the width of the canvas view + * @param [height=600] {number} the height of the canvas view + * @param [options] {object} The optional renderer parameters + * @param [options.view] {HTMLCanvasElement} the canvas to use as a view, optional + * @param [options.transparent=false] {boolean} If the render view is transparent, default false + * @param [options.autoResize=false] {boolean} If the render view is automatically resized, default false + * @param [options.antialias=false] {boolean} sets antialias (only applicable in chrome at the moment) + * @param [options.resolution=1] {number} The resolution / device pixel ratio of the renderer. The resolution of the renderer retina would be 2. + * @param [options.clearBeforeRender=true] {boolean} This sets if the CanvasRenderer will clear the canvas or + * not before the new render pass. + * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -var interactiveTarget = { - /** - * @todo Needs docs. - */ - interactive: false, - /** - * @todo Needs docs. - */ - buttonMode: false, - /** - * @todo Needs docs. - */ - interactiveChildren: true, - /** - * @todo Needs docs. - */ - defaultCursor: 'pointer', - - // some internal checks.. - - /** - * @todo Needs docs. - * @private - */ - _over: false, - /** - * @todo Needs docs. - * @private - */ - _touchDown: false -}; - -module.exports = interactiveTarget; - -},{}],129:[function(require,module,exports){ -var Resource = require('resource-loader').Resource, - core = require('../core'), - extras = require('../extras'), - path = require('path'); - - -function parse(resource, texture) { - var data = {}; - var info = resource.data.getElementsByTagName('info')[0]; - var common = resource.data.getElementsByTagName('common')[0]; - - data.font = info.getAttribute('face'); - data.size = parseInt(info.getAttribute('size'), 10); - data.lineHeight = parseInt(common.getAttribute('lineHeight'), 10); - data.chars = {}; - - //parse letters - var letters = resource.data.getElementsByTagName('char'); - - for (var i = 0; i < letters.length; i++) - { - var charCode = parseInt(letters[i].getAttribute('id'), 10); - - var textureRect = new core.Rectangle( - parseInt(letters[i].getAttribute('x'), 10) + texture.frame.x, - parseInt(letters[i].getAttribute('y'), 10) + texture.frame.y, - parseInt(letters[i].getAttribute('width'), 10), - parseInt(letters[i].getAttribute('height'), 10) - ); - - data.chars[charCode] = { - xOffset: parseInt(letters[i].getAttribute('xoffset'), 10), - yOffset: parseInt(letters[i].getAttribute('yoffset'), 10), - xAdvance: parseInt(letters[i].getAttribute('xadvance'), 10), - kerning: {}, - texture: new core.Texture(texture.baseTexture, textureRect) - - }; - } +function CanvasRenderer(width, height, options) +{ + options = options || {}; - //parse kernings - var kernings = resource.data.getElementsByTagName('kerning'); - for (i = 0; i < kernings.length; i++) - { - var first = parseInt(kernings[i].getAttribute('first'), 10); - var second = parseInt(kernings[i].getAttribute('second'), 10); - var amount = parseInt(kernings[i].getAttribute('amount'), 10); + SystemRenderer.call(this, 'Canvas', width, height, options); - if(data.chars[second]) - { - data.chars[second].kerning[first] = amount; - } - } + this.type = CONST.RENDERER_TYPE.CANVAS; - resource.bitmapFont = data; + /** + * The canvas 2d context that everything is drawn with. + * + * @member {CanvasRenderingContext2D} + */ + this.rootContext = this.view.getContext('2d', { alpha: this.transparent }); + this.rootResolution = this.resolution; - // I'm leaving this as a temporary fix so we can test the bitmap fonts in v3 - // but it's very likely to change - extras.BitmapText.fonts[data.font] = data; -} + /** + * Boolean flag controlling canvas refresh. + * + * @member {boolean} + */ + this.refresh = true; + /** + * Instance of a CanvasMaskManager, handles masking when using the canvas renderer. + * + * @member {PIXI.CanvasMaskManager} + */ + this.maskManager = new CanvasMaskManager(this); -module.exports = function () -{ - return function (resource, next) + /** + * The canvas property used to set the canvas smoothing property. + * + * @member {string} + */ + this.smoothProperty = 'imageSmoothingEnabled'; + + if (!this.rootContext.imageSmoothingEnabled) { - // skip if no data or not xml data - if (!resource.data || !resource.isXml) + if (this.rootContext.webkitImageSmoothingEnabled) { - return next(); + this.smoothProperty = 'webkitImageSmoothingEnabled'; } - - // skip if not bitmap font data, using some silly duck-typing - if ( - resource.data.getElementsByTagName('page').length === 0 || - resource.data.getElementsByTagName('info').length === 0 || - resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) + else if (this.rootContext.mozImageSmoothingEnabled) { - return next(); + this.smoothProperty = 'mozImageSmoothingEnabled'; } - - var xmlUrl = path.dirname(resource.url); - - if (xmlUrl === '.') { - xmlUrl = ''; + else if (this.rootContext.oImageSmoothingEnabled) + { + this.smoothProperty = 'oImageSmoothingEnabled'; } + else if (this.rootContext.msImageSmoothingEnabled) + { + this.smoothProperty = 'msImageSmoothingEnabled'; + } + } - if (this.baseUrl && xmlUrl) { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') { - xmlUrl += '/'; - } + this.initPlugins(); - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - } + this.blendModes = mapCanvasBlendModesToPixi(); + this._activeBlendMode = null; - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') { - xmlUrl += '/'; - } - var textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - if (core.utils.TextureCache[textureUrl]) { - //reuse existing texture - parse(resource, core.utils.TextureCache[textureUrl]); - next(); - } - else { - var loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata - }; - // load the texture for the font - this.add(resource.name + '_image', textureUrl, loadOptions, function (res) { - parse(resource, res.texture); - next(); - }); - } - }; -}; - -},{"../core":50,"../extras":110,"path":4,"resource-loader":151}],130:[function(require,module,exports){ -/** - * @file Main export of the PIXI loaders library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ + this.context = null; + this.renderingToScreen = false; -/** - * @namespace PIXI.loaders - */ -module.exports = { - Loader: require('./loader'), + this.resize(width, height); +} + +// constructor +CanvasRenderer.prototype = Object.create(SystemRenderer.prototype); +CanvasRenderer.prototype.constructor = CanvasRenderer; +module.exports = CanvasRenderer; +utils.pluginTarget.mixin(CanvasRenderer); - // parsers - bitmapFontParser: require('./bitmapFontParser'), - spritesheetParser: require('./spritesheetParser'), - textureParser: require('./textureParser'), - Resource: require('resource-loader').Resource -}; - -},{"./bitmapFontParser":129,"./loader":131,"./spritesheetParser":132,"./textureParser":133,"resource-loader":151}],131:[function(require,module,exports){ -var ResourceLoader = require('resource-loader'), - textureParser = require('./textureParser'), - spritesheetParser = require('./spritesheetParser'), - bitmapFontParser = require('./bitmapFontParser'); /** + * Renders the object to this canvas view * - * The new loader, extends Resource Loader by Chad Engler : https://github.com/englercj/resource-loader - * - * ```js - * var loader = PIXI.loader; // pixi exposes a premade instance for you to use. - * //or - * var loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * loader.add('bunny',"data/bunny.png"); - * - * loader.once('complete',onAssetsLoaded); - * - * loader.load(); - * ``` - * - * @class - * @extends PIXI.ResourceLoader - * @memberof PIXI.loaders - * @param [baseUrl=''] {string} The base url for all resources loaded by this loader. - * @param [concurrency=10] {number} The number of resources to load concurrently. + * @param displayObject {PIXI.DisplayObject} The object to be rendered + * @param [renderTexture] {PIXI.RenderTexture} A render texture to be rendered to. If unset, it will render to the root context. + * @param [clear=false] {boolean} Whether to clear the canvas before drawing + * @param [transform] {PIXI.Transform} A transformation to be applied + * @param [skipUpdateTransform=false] {boolean} Whether to skip the update transform */ -function Loader(baseUrl, concurrency) +CanvasRenderer.prototype.render = function (displayObject, renderTexture, clear, transform, skipUpdateTransform) { - ResourceLoader.call(this, baseUrl, concurrency); - for (var i = 0; i < Loader._pixiMiddleware.length; ++i) { - this.use(Loader._pixiMiddleware[i]()); + if (!this.view){ + return; } -} -Loader.prototype = Object.create(ResourceLoader.prototype); -Loader.prototype.constructor = Loader; + // can be handy to know! + this.renderingToScreen = !renderTexture; -module.exports = Loader; + this.emit('prerender'); -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - ResourceLoader.middleware.parsing.blob, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse any spritesheet data into multiple textures - bitmapFontParser -]; + if(renderTexture) + { + renderTexture = renderTexture.baseTexture || renderTexture; -Loader.addPixiMiddleware = function (fn) { - Loader._pixiMiddleware.push(fn); -}; + if(!renderTexture._canvasRenderTarget) + { -// Add custom extentions -var Resource = ResourceLoader.Resource; + renderTexture._canvasRenderTarget = new CanvasRenderTarget(renderTexture.width, renderTexture.height, renderTexture.resolution); + renderTexture.source = renderTexture._canvasRenderTarget.canvas; + renderTexture.valid = true; + } -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); - -},{"./bitmapFontParser":129,"./spritesheetParser":132,"./textureParser":133,"resource-loader":151}],132:[function(require,module,exports){ -var Resource = require('resource-loader').Resource, - path = require('path'), - core = require('../core'); + this.context = renderTexture._canvasRenderTarget.context; + this.resolution = renderTexture._canvasRenderTarget.resolution; + } + else + { -module.exports = function () -{ - return function (resource, next) + this.context = this.rootContext; + this.resolution = this.rootResolution; + } + + var context = this.context; + + if(!renderTexture) { - // skip if no data, its not json, or it isn't spritesheet data - if (!resource.data || !resource.isJson || !resource.data.frames) - { - return next(); - } + this._lastObjectRendered = displayObject; + } - var loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata - }; - var route = path.dirname(resource.url.replace(this.baseUrl, '')); - var resolution = core.utils.getResolutionOfUrl( resource.url ); - // load the image for this sheet - this.add(resource.name + '_image', route + '/' + resource.data.meta.image, loadOptions, function (res) + if(!skipUpdateTransform) + { + // update the scene graph + var cacheParent = displayObject.parent; + var tempWt = this._tempDisplayObjectParent.transform.worldTransform; + + if(transform) { - resource.textures = {}; + transform.copy(tempWt); + } + else + { + tempWt.identity(); + } - var frames = resource.data.frames; + displayObject.parent = this._tempDisplayObjectParent; + displayObject.updateTransform(); + displayObject.parent = cacheParent; + // displayObject.hitArea = //TODO add a temp hit area + } - for (var i in frames) - { - var rect = frames[i].frame; - if (rect) - { - var frame = null; - var trim = null; - var crop = new core.Rectangle(0, 0, frames[i].sourceSize.w / resolution, frames[i].sourceSize.h / resolution); + context.setTransform(1, 0, 0, 1, 0, 0); + context.globalAlpha = 1; + context.globalCompositeOperation = this.blendModes[CONST.BLEND_MODES.NORMAL]; - if (frames[i].rotated) { - frame = new core.Rectangle(rect.x / resolution, rect.y / resolution, rect.h / resolution, rect.w / resolution); - } - else { - frame = new core.Rectangle(rect.x / resolution, rect.y / resolution, rect.w / resolution, rect.h / resolution); - } + if (navigator.isCocoonJS && this.view.screencanvas) + { + context.fillStyle = 'black'; + context.clear(); + } - // Check to see if the sprite is trimmed - if (frames[i].trimmed) - { - trim = new core.Rectangle( - frames[i].spriteSourceSize.x / resolution, - frames[i].spriteSourceSize.y / resolution, - frames[i].spriteSourceSize.w / resolution, - frames[i].spriteSourceSize.h / resolution - ); - } + if(clear !== undefined ? clear : this.clearBeforeRender) + { + if (this.renderingToScreen) { + if (this.transparent) { + context.clearRect(0, 0, this.width, this.height); + } + else { + context.fillStyle = this._backgroundColorString; + context.fillRect(0, 0, this.width, this.height); + } + } //else { + //TODO: implement background for CanvasRenderTarget or RenderTexture? + //} + } - resource.textures[i] = new core.Texture(res.texture.baseTexture, frame, crop, trim, frames[i].rotated ? 2 : 0); + // TODO RENDER TARGET STUFF HERE.. + var tempContext = this.context; - // lets also add the frame to pixi's global cache for fromFrame and fromImage functions - core.utils.TextureCache[i] = resource.textures[i]; - } - } + this.context = context; + displayObject.renderCanvas(this); + this.context = tempContext; - next(); - }); - }; + this.emit('postrender'); }; - -},{"../core":50,"path":4,"resource-loader":151}],133:[function(require,module,exports){ -var core = require('../core'); -module.exports = function () + +CanvasRenderer.prototype.setBlendMode = function (blendMode) { - return function (resource, next) - { - // create a new texture if the data is an Image object - if (resource.data && resource.isImage) - { - var baseTexture = new core.BaseTexture(resource.data, null, core.utils.getResolutionOfUrl(resource.url)); - baseTexture.imageUrl = resource.url; - resource.texture = new core.Texture(baseTexture); - // lets also add the frame to pixi's global cache for fromFrame and fromImage fucntions - core.utils.BaseTextureCache[resource.url] = baseTexture; - core.utils.TextureCache[resource.url] = resource.texture; - } + if(this._activeBlendMode === blendMode) { + return; + } - next(); - }; + this.context.globalCompositeOperation = this.blendModes[blendMode]; }; - -},{"../core":50}],134:[function(require,module,exports){ -var core = require('../core'), - glCore = require('pixi-gl-core'), - Shader = require('./webgl/MeshShader'), - tempPoint = new core.Point(), - tempPolygon = new core.Polygon(); /** - * Base mesh class - * @class - * @extends PIXI.Container - * @memberof PIXI.mesh - * @param texture {PIXI.Texture} The texture to use - * @param [vertices] {Float32Array} if you want to specify the vertices - * @param [uvs] {Float32Array} if you want to specify the uvs - * @param [indices] {Uint16Array} if you want to specify the indices - * @param [drawMode] {number} the drawMode, can be any of the Mesh.DRAW_MODES consts + * Removes everything from the renderer and optionally removes the Canvas DOM element. + * + * @param [removeView=false] {boolean} Removes the Canvas element from the DOM. */ -function Mesh(texture, vertices, uvs, indices, drawMode) +CanvasRenderer.prototype.destroy = function (removeView) { - core.Container.call(this); - - /** - * The texture of the Mesh - * - * @member {PIXI.Texture} - * @private - */ - this._texture = null; + this.destroyPlugins(); - /** - * The Uvs of the Mesh - * - * @member {Float32Array} - */ - this.uvs = uvs || new Float32Array([0, 0, - 1, 0, - 1, 1, - 0, 1]); + // call the base destroy + SystemRenderer.prototype.destroy.call(this, removeView); - /** - * An array of vertices - * - * @member {Float32Array} - */ - this.vertices = vertices || new Float32Array([0, 0, - 100, 0, - 100, 100, - 0, 100]); + this.context = null; - /* - * @member {Uint16Array} An array containing the indices of the vertices - */ - // TODO auto generate this based on draw mode! - this.indices = indices || new Uint16Array([0, 1, 3, 2]); + this.refresh = true; - /** - * Whether the Mesh is dirty or not - * - * @member {boolean} - */ - this.dirty = true; - this.indexDirty = true; + this.maskManager.destroy(); + this.maskManager = null; - /** - * The blend mode to be applied to the sprite. Set to `PIXI.BLEND_MODES.NORMAL` to remove any blend mode. - * - * @member {number} - * @default PIXI.BLEND_MODES.NORMAL - * @see PIXI.BLEND_MODES - */ - this.blendMode = core.BLEND_MODES.NORMAL; + this.smoothProperty = null; +}; - /** - * Triangles in canvas mode are automatically antialiased, use this value to force triangles to overlap a bit with each other. - * - * @member {number} - */ - this.canvasPadding = 0; +/** + * Resizes the canvas view to the specified width and height. + * + * @extends PIXI.SystemRenderer#resize + * + * @param width {number} The new width of the canvas view + * @param height {number} The new height of the canvas view + */ +CanvasRenderer.prototype.resize = function (width, height) +{ + SystemRenderer.prototype.resize.call(this, width, height); - /** - * The way the Mesh should be drawn, can be any of the {@link PIXI.mesh.Mesh.DRAW_MODES} consts - * - * @member {number} - * @see PIXI.mesh.Mesh.DRAW_MODES - */ - this.drawMode = drawMode || Mesh.DRAW_MODES.TRIANGLE_MESH; + //reset the scale mode.. oddly this seems to be reset when the canvas is resized. + //surely a browser bug?? Let pixi fix that for you.. + if(this.smoothProperty) + { + this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); + } - // run texture setter; - this.texture = texture; +}; + +},{"../../const":42,"../../utils":115,"../SystemRenderer":72,"./utils/CanvasMaskManager":74,"./utils/CanvasRenderTarget":75,"./utils/mapCanvasBlendModesToPixi":77}],74:[function(require,module,exports){ +var CONST = require('../../../const'); +/** + * A set of functions used to handle masking. + * + * @class + * @memberof PIXI + */ +function CanvasMaskManager(renderer) +{ + this.renderer = renderer; +} - /** - * The default shader that is used if a mesh doesn't have a more specific one. - * - * @member {PIXI.Shader} - */ - this.shader = null; +CanvasMaskManager.prototype.constructor = CanvasMaskManager; +module.exports = CanvasMaskManager; - this._glDatas = []; -} +/** + * This method adds it to the current stack of masks. + * + * @param maskData {object} the maskData that will be pushed + */ +CanvasMaskManager.prototype.pushMask = function (maskData) +{ + var renderer = this.renderer; -// constructor -Mesh.prototype = Object.create(core.Container.prototype); -Mesh.prototype.constructor = Mesh; -module.exports = Mesh; + renderer.context.save(); -Object.defineProperties(Mesh.prototype, { - /** - * The texture that the sprite is using - * - * @member {PIXI.Texture} - * @memberof PIXI.mesh.Mesh# - */ - texture: { - get: function () - { - return this._texture; - }, - set: function (value) - { - if (this._texture === value) - { - return; - } + var cacheAlpha = maskData.alpha; + var transform = maskData.transform.worldTransform; + var resolution = renderer.resolution; - this._texture = value; + renderer.context.setTransform( + transform.a * resolution, + transform.b * resolution, + transform.c * resolution, + transform.d * resolution, + transform.tx * resolution, + transform.ty * resolution + ); - if (value) - { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } - } - } + //TODO suport sprite alpha masks?? + //lots of effort required. If demand is great enough.. + if(!maskData._texture) + { + this.renderGraphicsShape(maskData); + renderer.context.clip(); } -}); -/** - * Renders the object using the WebGL renderer - * - * @param renderer {PIXI.WebGLRenderer} a reference to the WebGL renderer - * @private - */ -Mesh.prototype._renderWebGL = function (renderer) + maskData.worldAlpha = cacheAlpha; +}; + +CanvasMaskManager.prototype.renderGraphicsShape = function (graphics) { - // get rid of any thing that may be batching. - renderer.flush(); + var context = this.renderer.context; + var len = graphics.graphicsData.length; - // renderer.plugins.mesh.render(this); - var gl = renderer.gl; - var glData = this._glDatas[renderer.CONTEXT_UID]; + if (len === 0) + { + return; + } - if(!glData) + context.beginPath(); + + for (var i = 0; i < len; i++) { - glData = { - shader:new Shader(gl), - vertexBuffer:glCore.GLBuffer.createVertexBuffer(gl, this.vertices, gl.STREAM_DRAW), - uvBuffer:glCore.GLBuffer.createVertexBuffer(gl, this.uvs, gl.STREAM_DRAW), - indexBuffer:glCore.GLBuffer.createIndexBuffer(gl, this.indices, gl.STATIC_DRAW), - // build the vao object that will render.. - vao:new glCore.VertexArrayObject(gl) - }; + var data = graphics.graphicsData[i]; + var shape = data.shape; - // build the vao object that will render.. - glData.vao = new glCore.VertexArrayObject(gl) - .addIndex(glData.indexBuffer) - .addAttribute(glData.vertexBuffer, glData.shader.attributes.aVertexPosition, gl.FLOAT, false, 2 * 4, 0) - .addAttribute(glData.uvBuffer, glData.shader.attributes.aTextureCoord, gl.FLOAT, false, 2 * 4, 0); + if (data.type === CONST.SHAPES.POLY) + { - this._glDatas[renderer.CONTEXT_UID] = glData; + var points = shape.points; + context.moveTo(points[0], points[1]); - this.indexDirty = false; - } + for (var j=1; j < points.length/2; j++) + { + context.lineTo(points[j * 2], points[j * 2 + 1]); + } - if(this.dirty) - { - this.dirty = false; - glData.uvBuffer.upload(); + // if the first and last point are the same close the path - much neater :) + if (points[0] === points[points.length-2] && points[1] === points[points.length-1]) + { + context.closePath(); + } - } + } + else if (data.type === CONST.SHAPES.RECT) + { + context.rect(shape.x, shape.y, shape.width, shape.height); + context.closePath(); + } + else if (data.type === CONST.SHAPES.CIRC) + { + // TODO - need to be Undefined! + context.arc(shape.x, shape.y, shape.radius, 0, 2 * Math.PI); + context.closePath(); + } + else if (data.type === CONST.SHAPES.ELIP) + { - if(this.indexDirty) - { - this.indexDirty = false; - glData.indexBuffer.upload(); - } + // ellipse code taken from: http://stackoverflow.com/questions/2172798/how-to-draw-an-oval-in-html5-canvas - glData.vertexBuffer.upload(); + var w = shape.width * 2; + var h = shape.height * 2; - renderer.bindShader(glData.shader); - renderer.bindTexture(this._texture, 0); + var x = shape.x - w/2; + var y = shape.y - h/2; - glData.shader.uniforms.translationMatrix = this.worldTransform.toArray(true); - glData.shader.uniforms.alpha = this.worldAlpha; + var kappa = 0.5522848, + ox = (w / 2) * kappa, // control point offset horizontal + oy = (h / 2) * kappa, // control point offset vertical + xe = x + w, // x-end + ye = y + h, // y-end + xm = x + w / 2, // x-middle + ym = y + h / 2; // y-middle - var drawMode = this.drawMode === Mesh.DRAW_MODES.TRIANGLE_MESH ? gl.TRIANGLE_STRIP : gl.TRIANGLES; + context.moveTo(x, ym); + context.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y); + context.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym); + context.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye); + context.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym); + context.closePath(); + } + else if (data.type === CONST.SHAPES.RREC) + { + var rx = shape.x; + var ry = shape.y; + var width = shape.width; + var height = shape.height; + var radius = shape.radius; - glData.vao.bind() - .draw(drawMode, this.indices.length) - .unbind(); + var maxRadius = Math.min(width, height) / 2 | 0; + radius = radius > maxRadius ? maxRadius : radius; + + context.moveTo(rx, ry + radius); + context.lineTo(rx, ry + height - radius); + context.quadraticCurveTo(rx, ry + height, rx + radius, ry + height); + context.lineTo(rx + width - radius, ry + height); + context.quadraticCurveTo(rx + width, ry + height, rx + width, ry + height - radius); + context.lineTo(rx + width, ry + radius); + context.quadraticCurveTo(rx + width, ry, rx + width - radius, ry); + context.lineTo(rx + radius, ry); + context.quadraticCurveTo(rx, ry, rx, ry + radius); + context.closePath(); + } + } }; /** - * Renders the object using the Canvas renderer + * Restores the current drawing context to the state it was before the mask was applied. * - * @param renderer {PIXI.CanvasRenderer} - * @private + * @param renderer {PIXI.WebGLRenderer|PIXI.CanvasRenderer} The renderer context to use. */ -Mesh.prototype._renderCanvas = function (renderer) +CanvasMaskManager.prototype.popMask = function (renderer) { - var context = renderer.context; - - var transform = this.worldTransform; - - if (renderer.roundPixels) - { - context.setTransform(transform.a, transform.b, transform.c, transform.d, transform.tx | 0, transform.ty | 0); - } - else - { - context.setTransform(transform.a, transform.b, transform.c, transform.d, transform.tx, transform.ty); - } - - if (this.drawMode === Mesh.DRAW_MODES.TRIANGLE_MESH) - { - this._renderCanvasTriangleMesh(context); - } - else - { - this._renderCanvasTriangles(context); - } + renderer.context.restore(); }; +CanvasMaskManager.prototype.destroy = function () {}; + +},{"../../../const":42}],75:[function(require,module,exports){ +var CONST = require('../../../const'); + /** - * Draws the object in Triangle Mesh mode using canvas + * Creates a Canvas element of the given size. * - * @param context {CanvasRenderingContext2D} the current drawing context - * @private + * @class + * @memberof PIXI + * @param width {number} the width for the newly created canvas + * @param height {number} the height for the newly created canvas + * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -Mesh.prototype._renderCanvasTriangleMesh = function (context) +function CanvasRenderTarget(width, height, resolution) { - // draw triangles!! - var vertices = this.vertices; - var uvs = this.uvs; + /** + * The Canvas object that belongs to this CanvasRenderTarget. + * + * @member {HTMLCanvasElement} + */ + this.canvas = document.createElement('canvas'); - var length = vertices.length / 2; - // this.count++; + /** + * A CanvasRenderingContext2D object representing a two-dimensional rendering context. + * + * @member {CanvasRenderingContext2D} + */ + this.context = this.canvas.getContext('2d'); - for (var i = 0; i < length - 2; i++) - { - // draw some triangles! - var index = i * 2; - this._renderCanvasDrawTriangle(context, vertices, uvs, index, (index + 2), (index + 4)); + this.resolution = resolution || CONST.RESOLUTION; + + this.resize(width, height); +} + +CanvasRenderTarget.prototype.constructor = CanvasRenderTarget; +module.exports = CanvasRenderTarget; + +Object.defineProperties(CanvasRenderTarget.prototype, { + /** + * The width of the canvas buffer in pixels. + * + * @member {number} + * @memberof PIXI.CanvasRenderTarget# + */ + width: { + get: function () + { + return this.canvas.width; + }, + set: function (val) + { + this.canvas.width = val; + } + }, + /** + * The height of the canvas buffer in pixels. + * + * @member {number} + * @memberof PIXI.CanvasRenderTarget# + */ + height: { + get: function () + { + return this.canvas.height; + }, + set: function (val) + { + this.canvas.height = val; + } } -}; +}); /** - * Draws the object in triangle mode using canvas + * Clears the canvas that was created by the CanvasRenderTarget class. * - * @param context {CanvasRenderingContext2D} the current drawing context * @private */ -Mesh.prototype._renderCanvasTriangles = function (context) +CanvasRenderTarget.prototype.clear = function () { - // draw triangles!! - var vertices = this.vertices; - var uvs = this.uvs; - var indices = this.indices; - - var length = indices.length; - // this.count++; - - for (var i = 0; i < length; i += 3) - { - // draw some triangles! - var index0 = indices[i] * 2, index1 = indices[i + 1] * 2, index2 = indices[i + 2] * 2; - this._renderCanvasDrawTriangle(context, vertices, uvs, index0, index1, index2); - } + this.context.setTransform(1, 0, 0, 1, 0, 0); + this.context.clearRect(0,0, this.canvas.width, this.canvas.height); }; /** - * Draws one of the triangles that form this Mesh + * Resizes the canvas to the specified width and height. * - * @param context {CanvasRenderingContext2D} the current drawing context - * @param vertices {Float32Array} a reference to the vertices of the Mesh - * @param uvs {Float32Array} a reference to the uvs of the Mesh - * @param index0 {number} the index of the first vertex - * @param index1 {number} the index of the second vertex - * @param index2 {number} the index of the third vertex - * @private + * @param width {number} the new width of the canvas + * @param height {number} the new height of the canvas */ -Mesh.prototype._renderCanvasDrawTriangle = function (context, vertices, uvs, index0, index1, index2) -{ - var textureSource = this._texture.baseTexture.source; - var textureWidth = this._texture.baseTexture.width; - var textureHeight = this._texture.baseTexture.height; - - var x0 = vertices[index0], x1 = vertices[index1], x2 = vertices[index2]; - var y0 = vertices[index0 + 1], y1 = vertices[index1 + 1], y2 = vertices[index2 + 1]; - - var u0 = uvs[index0] * textureWidth, u1 = uvs[index1] * textureWidth, u2 = uvs[index2] * textureWidth; - var v0 = uvs[index0 + 1] * textureHeight, v1 = uvs[index1 + 1] * textureHeight, v2 = uvs[index2 + 1] * textureHeight; - - if (this.canvasPadding > 0) - { - var paddingX = this.canvasPadding / this.worldTransform.a; - var paddingY = this.canvasPadding / this.worldTransform.d; - var centerX = (x0 + x1 + x2) / 3; - var centerY = (y0 + y1 + y2) / 3; - - var normX = x0 - centerX; - var normY = y0 - centerY; - - var dist = Math.sqrt(normX * normX + normY * normY); - x0 = centerX + (normX / dist) * (dist + paddingX); - y0 = centerY + (normY / dist) * (dist + paddingY); - - // - - normX = x1 - centerX; - normY = y1 - centerY; - - dist = Math.sqrt(normX * normX + normY * normY); - x1 = centerX + (normX / dist) * (dist + paddingX); - y1 = centerY + (normY / dist) * (dist + paddingY); +CanvasRenderTarget.prototype.resize = function (width, height) +{ - normX = x2 - centerX; - normY = y2 - centerY; + this.canvas.width = width * this.resolution; + this.canvas.height = height * this.resolution; +}; - dist = Math.sqrt(normX * normX + normY * normY); - x2 = centerX + (normX / dist) * (dist + paddingX); - y2 = centerY + (normY / dist) * (dist + paddingY); - } +/** + * Destroys this canvas. + * + */ +CanvasRenderTarget.prototype.destroy = function () +{ + this.context = null; + this.canvas = null; +}; + +},{"../../../const":42}],76:[function(require,module,exports){ - context.save(); - context.beginPath(); +/** + * Checks whether the Canvas BlendModes are supported by the current browser + * + * @return {boolean} whether they are supported + */ +var canUseNewCanvasBlendModes = function () +{ + if (typeof document === 'undefined') + { + return false; + } + var pngHead = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAABAQMAAADD8p2OAAAAA1BMVEX/'; + var pngEnd = 'AAAACklEQVQI12NgAAAAAgAB4iG8MwAAAABJRU5ErkJggg=='; - context.moveTo(x0, y0); - context.lineTo(x1, y1); - context.lineTo(x2, y2); + var magenta = new Image(); + magenta.src = pngHead + 'AP804Oa6' + pngEnd; - context.closePath(); + var yellow = new Image(); + yellow.src = pngHead + '/wCKxvRF' + pngEnd; - context.clip(); + var canvas = document.createElement('canvas'); + canvas.width = 6; + canvas.height = 1; - // Compute matrix transform - var delta = (u0 * v1) + (v0 * u2) + (u1 * v2) - (v1 * u2) - (v0 * u1) - (u0 * v2); - var deltaA = (x0 * v1) + (v0 * x2) + (x1 * v2) - (v1 * x2) - (v0 * x1) - (x0 * v2); - var deltaB = (u0 * x1) + (x0 * u2) + (u1 * x2) - (x1 * u2) - (x0 * u1) - (u0 * x2); - var deltaC = (u0 * v1 * x2) + (v0 * x1 * u2) + (x0 * u1 * v2) - (x0 * v1 * u2) - (v0 * u1 * x2) - (u0 * x1 * v2); - var deltaD = (y0 * v1) + (v0 * y2) + (y1 * v2) - (v1 * y2) - (v0 * y1) - (y0 * v2); - var deltaE = (u0 * y1) + (y0 * u2) + (u1 * y2) - (y1 * u2) - (y0 * u1) - (u0 * y2); - var deltaF = (u0 * v1 * y2) + (v0 * y1 * u2) + (y0 * u1 * v2) - (y0 * v1 * u2) - (v0 * u1 * y2) - (u0 * y1 * v2); + var context = canvas.getContext('2d'); + context.globalCompositeOperation = 'multiply'; + context.drawImage(magenta, 0, 0); + context.drawImage(yellow, 2, 0); - context.transform(deltaA / delta, deltaD / delta, - deltaB / delta, deltaE / delta, - deltaC / delta, deltaF / delta); + var data = context.getImageData(2,0,1,1).data; - context.drawImage(textureSource, 0, 0); - context.restore(); + return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - +module.exports = canUseNewCanvasBlendModes; + +},{}],77:[function(require,module,exports){ +var CONST = require('../../../const'), +canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); /** - * Renders a flat Mesh - * - * @param Mesh {PIXI.mesh.Mesh} The Mesh to render - * @private + * Maps blend combinations to Canvas + * @class + * @memberof PIXI + * @param array */ -Mesh.prototype.renderMeshFlat = function (Mesh) +function mapCanvasBlendModesToPixi(array) { - var context = this.context; - var vertices = Mesh.vertices; - - var length = vertices.length/2; - // this.count++; + array = array || []; - context.beginPath(); - for (var i=1; i < length-2; i++) + if (canUseNewCanvasBlendModes()) { - // draw some triangles! - var index = i*2; - - var x0 = vertices[index], x1 = vertices[index+2], x2 = vertices[index+4]; - var y0 = vertices[index+1], y1 = vertices[index+3], y2 = vertices[index+5]; - - context.moveTo(x0, y0); - context.lineTo(x1, y1); - context.lineTo(x2, y2); + array[CONST.BLEND_MODES.NORMAL] = 'source-over'; + array[CONST.BLEND_MODES.ADD] = 'lighter'; //IS THIS OK??? + array[CONST.BLEND_MODES.MULTIPLY] = 'multiply'; + array[CONST.BLEND_MODES.SCREEN] = 'screen'; + array[CONST.BLEND_MODES.OVERLAY] = 'overlay'; + array[CONST.BLEND_MODES.DARKEN] = 'darken'; + array[CONST.BLEND_MODES.LIGHTEN] = 'lighten'; + array[CONST.BLEND_MODES.COLOR_DODGE] = 'color-dodge'; + array[CONST.BLEND_MODES.COLOR_BURN] = 'color-burn'; + array[CONST.BLEND_MODES.HARD_LIGHT] = 'hard-light'; + array[CONST.BLEND_MODES.SOFT_LIGHT] = 'soft-light'; + array[CONST.BLEND_MODES.DIFFERENCE] = 'difference'; + array[CONST.BLEND_MODES.EXCLUSION] = 'exclusion'; + array[CONST.BLEND_MODES.HUE] = 'hue'; + array[CONST.BLEND_MODES.SATURATION] = 'saturate'; + array[CONST.BLEND_MODES.COLOR] = 'color'; + array[CONST.BLEND_MODES.LUMINOSITY] = 'luminosity'; + } + else + { + // this means that the browser does not support the cool new blend modes in canvas 'cough' ie 'cough' + array[CONST.BLEND_MODES.NORMAL] = 'source-over'; + array[CONST.BLEND_MODES.ADD] = 'lighter'; //IS THIS OK??? + array[CONST.BLEND_MODES.MULTIPLY] = 'source-over'; + array[CONST.BLEND_MODES.SCREEN] = 'source-over'; + array[CONST.BLEND_MODES.OVERLAY] = 'source-over'; + array[CONST.BLEND_MODES.DARKEN] = 'source-over'; + array[CONST.BLEND_MODES.LIGHTEN] = 'source-over'; + array[CONST.BLEND_MODES.COLOR_DODGE] = 'source-over'; + array[CONST.BLEND_MODES.COLOR_BURN] = 'source-over'; + array[CONST.BLEND_MODES.HARD_LIGHT] = 'source-over'; + array[CONST.BLEND_MODES.SOFT_LIGHT] = 'source-over'; + array[CONST.BLEND_MODES.DIFFERENCE] = 'source-over'; + array[CONST.BLEND_MODES.EXCLUSION] = 'source-over'; + array[CONST.BLEND_MODES.HUE] = 'source-over'; + array[CONST.BLEND_MODES.SATURATION] = 'source-over'; + array[CONST.BLEND_MODES.COLOR] = 'source-over'; + array[CONST.BLEND_MODES.LUMINOSITY] = 'source-over'; } - context.fillStyle = '#FF0000'; - context.fill(); - context.closePath(); -}; + return array; +} -/** - * When the texture is updated, this event will fire to update the scale and frame - * - * @param event - * @private - */ -Mesh.prototype._onTextureUpdate = function () -{ - this.updateFrame = true; -}; +module.exports = mapCanvasBlendModesToPixi; + +},{"../../../const":42,"./canUseNewCanvasBlendModes":76}],78:[function(require,module,exports){ + +var CONST = require('../../const'); /** - * Returns the bounds of the mesh as a rectangle. The bounds calculation takes the worldTransform into account. + * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. * - * @param matrix {PIXI.Matrix} the transformation matrix of the sprite - * @return {PIXI.Rectangle} the framing rectangle + * @class + * @memberof PIXI + * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -Mesh.prototype.getBounds = function (matrix) +function TextureGarbageCollector(renderer) { - if (!this._currentBounds) { - var worldTransform = matrix || this.worldTransform; - - var a = worldTransform.a; - var b = worldTransform.b; - var c = worldTransform.c; - var d = worldTransform.d; - var tx = worldTransform.tx; - var ty = worldTransform.ty; - - var maxX = -Infinity; - var maxY = -Infinity; + this.renderer = renderer; - var minX = Infinity; - var minY = Infinity; + this.count = 0; + this.checkCount = 0; + this.maxIdle = 60 * 60; + this.checkCountMax = 60 * 10; - var vertices = this.vertices; - for (var i = 0, n = vertices.length; i < n; i += 2) { - var rawX = vertices[i], rawY = vertices[i + 1]; - var x = (a * rawX) + (c * rawY) + tx; - var y = (d * rawY) + (b * rawX) + ty; + this.mode = CONST.GC_MODES.DEFAULT; +} - minX = x < minX ? x : minX; - minY = y < minY ? y : minY; +TextureGarbageCollector.prototype.constructor = TextureGarbageCollector; +module.exports = TextureGarbageCollector; - maxX = x > maxX ? x : maxX; - maxY = y > maxY ? y : maxY; - } +/** + * Checks to see when the last time a texture was used + * if the texture has not been used for a specified amount of time it will be removed from the GPU + */ +TextureGarbageCollector.prototype.update = function() +{ + this.count++; - if (minX === -Infinity || maxY === Infinity) { - return core.Rectangle.EMPTY; - } + if(this.mode === CONST.GC_MODES.MANUAL) + { + return; + } - var bounds = this._bounds; + this.checkCount++; - bounds.x = minX; - bounds.width = maxX - minX; - bounds.y = minY; - bounds.height = maxY - minY; + if(this.checkCount > this.checkCountMax) + { + this.checkCount = 0; - // store a reference so that if this function gets called again in the render cycle we do not have to recalculate - this._currentBounds = bounds; + this.run(); } - - return this._currentBounds; }; /** - * Tests if a point is inside this mesh. Works only for TRIANGLE_MESH - * - * @param point {PIXI.Point} the point to test - * @return {boolean} the result of the test + * Checks to see when the last time a texture was used + * if the texture has not been used for a specified amount of time it will be removed from the GPU */ -Mesh.prototype.containsPoint = function( point ) { - if (!this.getBounds().contains(point.x, point.y)) { - return false; - } - this.worldTransform.applyInverse(point, tempPoint); +TextureGarbageCollector.prototype.run = function() +{ + var tm = this.renderer.textureManager; + var managedTextures = tm._managedTextures; + var wasRemoved = false; + var i,j; - var vertices = this.vertices; - var points = tempPolygon.points; - var i, len; + for (i = 0; i < managedTextures.length; i++) + { + var texture = managedTextures[i]; - if (this.drawMode === Mesh.DRAW_MODES.TRIANGLES) { - var indices = this.indices; - len = this.indices.length; - //TODO: inline this. - for (i=0;i this.maxIdle) + { + tm.destroyTexture(texture, true); + managedTextures[i] = null; + wasRemoved = true; } - } else { - len = vertices.length; - for (i=0;i= 0; i--) { + + this.unload(displayObject.children[i]); + + } }; -},{"../core":50,"./webgl/MeshShader":138,"pixi-gl-core":15}],135:[function(require,module,exports){ -var Mesh = require('./Mesh'); - -/** - * The Plane allows you to draw a texture across several points and them manipulate these points - * - *```js - * for (var i = 0; i < 20; i++) { - * points.push(new PIXI.Point(i * 50, 0)); - * }; - * var Plane = new PIXI.Plane(PIXI.Texture.fromImage("snake.png"), points); - * ``` +},{"../../const":42}],79:[function(require,module,exports){ +var GLTexture = require('pixi-gl-core').GLTexture, + CONST = require('../../const'), + RenderTarget = require('./utils/RenderTarget'), + utils = require('../../utils'); + +/** + * Helper class to create a webGL Texture * * @class - * @extends PIXI.mesh.Mesh - * @memberof PIXI.mesh - * @param {PIXI.Texture} texture - The texture to use on the Plane. - * @param {int} segmentsX - The number ox x segments - * @param {int} segmentsY - The number of y segments - * + * @memberof PIXI + * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -function Plane(texture, segmentsX, segmentsY) +var TextureManager = function(renderer) { - Mesh.call(this, texture); - /** - * Tracker for if the Plane is ready to be drawn. Needed because Mesh ctor can - * call _onTextureUpdated which could call refresh too early. + * A reference to the current renderer * - * @member {boolean} - * @private + * @member {PIXI.WebGLRenderer} */ - this._ready = true; + this.renderer = renderer; - this.segmentsX = segmentsX || 10; - this.segmentsY = segmentsY || 10; + /** + * The current WebGL rendering context + * + * @member {WebGLRenderingContext} + */ + this.gl = renderer.gl; - this.drawMode = Mesh.DRAW_MODES.TRIANGLES; - this.refresh(); + /** + * Track textures in the renderer so we can no longer listen to them on destruction. + * + * @member {Array<*>} + * @private + */ + this._managedTextures = []; +}; -} +TextureManager.prototype.bindTexture = function() +{ +}; -// constructor -Plane.prototype = Object.create( Mesh.prototype ); -Plane.prototype.constructor = Plane; -module.exports = Plane; +TextureManager.prototype.getTexture = function() +{ +}; /** - * Refreshes + * Updates and/or Creates a WebGL texture for the renderer's context. * + * @param texture {PIXI.BaseTexture|PIXI.Texture} the texture to update */ -Plane.prototype.refresh = function() +TextureManager.prototype.updateTexture = function(texture) { - var total = this.segmentsX * this.segmentsY; - var verts = []; - var colors = []; - var uvs = []; - var indices = []; - var texture = this.texture; - - var segmentsXSub = this.segmentsX - 1; - var segmentsYSub = this.segmentsY - 1; - var i = 0; + texture = texture.baseTexture || texture; - var sizeX = texture.width / segmentsXSub; - var sizeY = texture.height / segmentsYSub; + var isRenderTexture = !!texture._glRenderTargets; - for (i = 0; i < total; i++) { + if (!texture.hasLoaded) + { + return; + } - var x = (i % this.segmentsX); - var y = ( (i / this.segmentsX ) | 0 ); + var glTexture = texture._glTextures[this.renderer.CONTEXT_UID]; + if (!glTexture) + { + if(isRenderTexture) + { + var renderTarget = new RenderTarget(this.gl, texture.width, texture.height, texture.scaleMode, texture.resolution); + renderTarget.resize(texture.width, texture.height); + texture._glRenderTargets[this.renderer.CONTEXT_UID] = renderTarget; + glTexture = renderTarget.texture; + } + else + { + glTexture = new GLTexture(this.gl); + glTexture.premultiplyAlpha = true; + glTexture.upload(texture.source); + } - verts.push((x * sizeX), - (y * sizeY)); + texture._glTextures[this.renderer.CONTEXT_UID] = glTexture; - // this works for rectangular textures. - uvs.push(texture._uvs.x0 + (texture._uvs.x1 - texture._uvs.x0) * (x / (this.segmentsX-1)), texture._uvs.y0 + (texture._uvs.y3-texture._uvs.y0) * (y/ (this.segmentsY-1))); - } + texture.on('update', this.updateTexture, this); + texture.on('dispose', this.destroyTexture, this); - // cons + this._managedTextures.push(texture); - var totalSub = segmentsXSub * segmentsYSub; + if(texture.isPowerOfTwo) + { + if(texture.mipmap) + { + glTexture.enableMipmap(); + } - for (i = 0; i < totalSub; i++) { + if(texture.wrapMode === CONST.WRAP_MODES.CLAMP) + { + glTexture.enableWrapClamp(); + } + else if(texture.wrapMode === CONST.WRAP_MODES.REPEAT) + { + glTexture.enableWrapRepeat(); + } + else + { + glTexture.enableWrapMirrorRepeat(); + } + } + else + { + glTexture.enableWrapClamp(); + } - var xpos = i % segmentsXSub; - var ypos = (i / segmentsXSub ) | 0; + if(texture.scaleMode === CONST.SCALE_MODES.NEAREST) + { + glTexture.enableNearestScaling(); + } + else + { + glTexture.enableLinearScaling(); + } + } + else + { + // the textur ealrady exists so we only need to update it.. + if(isRenderTexture) + { + texture._glRenderTargets[this.renderer.CONTEXT_UID].resize(texture.width, texture.height); + } + else + { + glTexture.upload(texture.source); + } + } + return glTexture; +}; - var value = (ypos * this.segmentsX) + xpos; - var value2 = (ypos * this.segmentsX) + xpos + 1; - var value3 = ((ypos+1) * this.segmentsX) + xpos; - var value4 = ((ypos+1) * this.segmentsX) + xpos + 1; +/** + * Deletes the texture from WebGL + * + * @param texture {PIXI.BaseTexture|PIXI.Texture} the texture to destroy + * @param [skipRemove=false] {boolean} Whether to skip removing the texture from the TextureManager. + */ +TextureManager.prototype.destroyTexture = function(texture, skipRemove) +{ + texture = texture.baseTexture || texture; - indices.push(value, value2, value3); - indices.push(value2, value4, value3); + if (!texture.hasLoaded) + { + return; } + if (texture._glTextures[this.renderer.CONTEXT_UID]) + { + texture._glTextures[this.renderer.CONTEXT_UID].destroy(); + texture.off('update', this.updateTexture, this); + texture.off('dispose', this.destroyTexture, this); - //console.log(indices) - this.vertices = new Float32Array(verts); - this.uvs = new Float32Array(uvs); - this.colors = new Float32Array(colors); - this.indices = new Uint16Array(indices); - this.indexDirty = true; + delete texture._glTextures[this.renderer.CONTEXT_UID]; + + if (!skipRemove) + { + var i = this._managedTextures.indexOf(texture); + if (i !== -1) { + utils.removeItems(this._managedTextures, i, 1); + } + } + } }; /** - * Clear texture UVs when new texture is set - * - * @private + * Deletes all the textures from WebGL */ -Plane.prototype._onTextureUpdate = function () +TextureManager.prototype.removeAll = function() { - Mesh.prototype._onTextureUpdate.call(this); + // empty all the old gl textures as they are useless now + for (var i = 0; i < this._managedTextures.length; ++i) + { + var texture = this._managedTextures[i]; + if (texture._glTextures[this.renderer.CONTEXT_UID]) + { + delete texture._glTextures[this.renderer.CONTEXT_UID]; + } + } +}; - // wait for the Plane ctor to finish before calling refresh - if (this._ready) { - this.refresh(); +/** + * Destroys this manager and removes all its textures + */ +TextureManager.prototype.destroy = function() +{ + // destroy managed textures + for (var i = 0; i < this._managedTextures.length; ++i) + { + var texture = this._managedTextures[i]; + this.destroyTexture(texture, true); + texture.off('update', this.updateTexture, this); + texture.off('dispose', this.destroyTexture, this); } + + this._managedTextures = null; }; + +module.exports = TextureManager; -},{"./Mesh":134}],136:[function(require,module,exports){ -var Mesh = require('./Mesh'); -var core = require('../core'); +},{"../../const":42,"../../utils":115,"./utils/RenderTarget":92,"pixi-gl-core":14}],80:[function(require,module,exports){ +var SystemRenderer = require('../SystemRenderer'), + MaskManager = require('./managers/MaskManager'), + StencilManager = require('./managers/StencilManager'), + FilterManager = require('./managers/FilterManager'), + RenderTarget = require('./utils/RenderTarget'), + ObjectRenderer = require('./utils/ObjectRenderer'), + TextureManager = require('./TextureManager'), + TextureGarbageCollector = require('./TextureGarbageCollector'), + WebGLState = require('./WebGLState'), + createContext = require('pixi-gl-core').createContext, + mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), + validateContext = require('./utils/validateContext'), + utils = require('../../utils'), + glCore = require('pixi-gl-core'), + CONST = require('../../const'); + +var CONTEXT_UID = 0; /** - * The rope allows you to draw a texture across several points and them manipulate these points - * - *```js - * for (var i = 0; i < 20; i++) { - * points.push(new PIXI.Point(i * 50, 0)); - * }; - * var rope = new PIXI.Rope(PIXI.Texture.fromImage("snake.png"), points); - * ``` + * The WebGLRenderer draws the scene and all its content onto a webGL enabled canvas. This renderer + * should be used for browsers that support webGL. This Render works by automatically managing webGLBatchs. + * So no need for Sprite Batches or Sprite Clouds. + * Don't forget to add the view to your DOM or you will not see anything :) * * @class - * @extends PIXI.mesh.Mesh - * @memberof PIXI.mesh - * @param {PIXI.Texture} texture - The texture to use on the rope. - * @param {PIXI.Point[]} points - An array of {@link PIXI.Point} objects to construct this rope. - * + * @memberof PIXI + * @extends PIXI.SystemRenderer + * @param [width=0] {number} the width of the canvas view + * @param [height=0] {number} the height of the canvas view + * @param [options] {object} The optional renderer parameters + * @param [options.view] {HTMLCanvasElement} the canvas to use as a view, optional + * @param [options.transparent=false] {boolean} If the render view is transparent, default false + * @param [options.autoResize=false] {boolean} If the render view is automatically resized, default false + * @param [options.antialias=false] {boolean} sets antialias. If not available natively then FXAA antialiasing is used + * @param [options.forceFXAA=false] {boolean} forces FXAA antialiasing to be used over native. FXAA is faster, but may not always look as great + * @param [options.resolution=1] {number} The resolution / device pixel ratio of the renderer. The resolution of the renderer retina would be 2. + * @param [options.clearBeforeRender=true] {boolean} This sets if the CanvasRenderer will clear the canvas or + * not before the new render pass. If you wish to set this to false, you *must* set preserveDrawingBuffer to `true`. + * @param [options.preserveDrawingBuffer=false] {boolean} enables drawing buffer preservation, enable this if + * you need to call toDataUrl on the webgl context. + * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -function Rope(texture, points) +function WebGLRenderer(width, height, options) { - Mesh.call(this, texture); + options = options || {}; - /* - * @member {PIXI.Point[]} An array of points that determine the rope + SystemRenderer.call(this, 'WebGL', width, height, options); + /** + * The type of this renderer as a standardised const + * + * @member {number} + * @see PIXI.RENDERER_TYPE */ - this.points = points; + this.type = CONST.RENDERER_TYPE.WEBGL; - /* - * @member {Float32Array} An array of vertices used to construct this rope. - */ - this.vertices = new Float32Array(points.length * 4); + this.handleContextLost = this.handleContextLost.bind(this); + this.handleContextRestored = this.handleContextRestored.bind(this); - /* - * @member {Float32Array} The WebGL Uvs of the rope. - */ - this.uvs = new Float32Array(points.length * 4); + this.view.addEventListener('webglcontextlost', this.handleContextLost, false); + this.view.addEventListener('webglcontextrestored', this.handleContextRestored, false); - /* - * @member {Float32Array} An array containing the color components + /** + * The options passed in to create a new webgl context. + * + * @member {object} + * @private */ - this.colors = new Float32Array(points.length * 2); + this._contextOptions = { + alpha: this.transparent, + antialias: options.antialias, + premultipliedAlpha: this.transparent && this.transparent !== 'notMultiplied', + stencil: true, + preserveDrawingBuffer: options.preserveDrawingBuffer + }; - /* - * @member {Uint16Array} An array containing the indices of the vertices - */ - this.indices = new Uint16Array(points.length * 2); + this._backgroundColorRgba[3] = this.transparent ? 0 : 1; /** - * Tracker for if the rope is ready to be drawn. Needed because Mesh ctor can - * call _onTextureUpdated which could call refresh too early. + * Manages the masks using the stencil buffer. * - * @member {boolean} - * @private + * @member {PIXI.MaskManager} */ - this._ready = true; + this.maskManager = new MaskManager(this); - this.refresh(); -} + /** + * Manages the stencil buffer. + * + * @member {PIXI.StencilManager} + */ + this.stencilManager = new StencilManager(this); + /** + * An empty renderer. + * + * @member {PIXI.ObjectRenderer} + */ + this.emptyRenderer = new ObjectRenderer(this); -// constructor -Rope.prototype = Object.create(Mesh.prototype); -Rope.prototype.constructor = Rope; -module.exports = Rope; + /** + * The currently active ObjectRenderer. + * + * @member {PIXI.ObjectRenderer} + */ + this.currentRenderer = this.emptyRenderer; -/** - * Refreshes - * - */ -Rope.prototype.refresh = function () -{ - var points = this.points; + this.initPlugins(); - // if too little points, or texture hasn't got UVs set yet just move on. - if (points.length < 1 || !this._texture._uvs) + /** + * The current WebGL rendering context, it is created here + * + * @member {WebGLRenderingContext} + */ + // initialize the context so it is ready for the managers. + if(options.context) { - return; + // checks to see if a context is valid.. + validateContext(options.context); } - var uvs = this.uvs; - - var indices = this.indices; - var colors = this.colors; + this.gl = options.context || createContext(this.view, this._contextOptions); - var textureUvs = this._texture._uvs; - var offset = new core.Point(textureUvs.x0, textureUvs.y0); - var factor = new core.Point(textureUvs.x2 - textureUvs.x0, textureUvs.y2 - textureUvs.y0); + this.CONTEXT_UID = CONTEXT_UID++; - uvs[0] = 0 + offset.x; - uvs[1] = 0 + offset.y; - uvs[2] = 0 + offset.x; - uvs[3] = 1 * factor.y + offset.y; + /** + * The currently active ObjectRenderer. + * + * @member {PIXI.WebGLState} + */ + this.state = new WebGLState(this.gl); - colors[0] = 1; - colors[1] = 1; + this.renderingToScreen = true; - indices[0] = 0; - indices[1] = 1; - var total = points.length, - point, index, amount; - for (var i = 1; i < total; i++) - { - point = points[i]; - index = i * 4; - // time to do some smart drawing! - amount = i / (total-1); + this._initContext(); - uvs[index] = amount * factor.x + offset.x; - uvs[index+1] = 0 + offset.y; + /** + * Manages the filters. + * + * @member {PIXI.FilterManager} + */ + this.filterManager = new FilterManager(this); + // map some webGL blend and drawmodes.. + this.drawModes = mapWebGLDrawModesToPixi(this.gl); - uvs[index+2] = amount * factor.x + offset.x; - uvs[index+3] = 1 * factor.y + offset.y; - index = i * 2; - colors[index] = 1; - colors[index+1] = 1; + /** + * Holds the current shader + * + * @member {PIXI.Shader} + */ + this._activeShader = null; - index = i * 2; - indices[index] = index; - indices[index + 1] = index + 1; - } + /** + * Holds the current render target + * + * @member {PIXI.RenderTarget} + */ + this._activeRenderTarget = null; + this._activeTextureLocation = 999; + this._activeTexture = null; - this.dirty = true; - this.indexDirty = true; -}; + this.setBlendMode(0); -/** - * Clear texture UVs when new texture is set - * - * @private - */ -Rope.prototype._onTextureUpdate = function () -{ - Mesh.prototype._onTextureUpdate.call(this); +} - // wait for the Rope ctor to finish before calling refresh - if (this._ready) { - this.refresh(); - } -}; +// constructor +WebGLRenderer.prototype = Object.create(SystemRenderer.prototype); +WebGLRenderer.prototype.constructor = WebGLRenderer; +module.exports = WebGLRenderer; +utils.pluginTarget.mixin(WebGLRenderer); /** - * Updates the object transform for rendering + * Creates the WebGL context * * @private */ -Rope.prototype.updateTransform = function () +WebGLRenderer.prototype._initContext = function () { - var points = this.points; - - if (points.length < 1) - { - return; - } - - var lastPoint = points[0]; - var nextPoint; - var perpX = 0; - var perpY = 0; - - // this.count -= 0.2; - - var vertices = this.vertices; - var total = points.length, - point, index, ratio, perpLength, num; - - for (var i = 0; i < total; i++) - { - point = points[i]; - index = i * 4; - - if (i < points.length-1) - { - nextPoint = points[i+1]; - } - else - { - nextPoint = point; - } - - perpY = -(nextPoint.x - lastPoint.x); - perpX = nextPoint.y - lastPoint.y; - - ratio = (1 - (i / (total-1))) * 10; + var gl = this.gl; - if (ratio > 1) - { - ratio = 1; - } + // create a texture manager... + this.textureManager = new TextureManager(this); + this.textureGC = new TextureGarbageCollector(this); - perpLength = Math.sqrt(perpX * perpX + perpY * perpY); - num = this._texture.height / 2; //(20 + Math.abs(Math.sin((i + this.count) * 0.3) * 50) )* ratio; - perpX /= perpLength; - perpY /= perpLength; + this.state.resetToDefault(); - perpX *= num; - perpY *= num; + this.rootRenderTarget = new RenderTarget(gl, this.width, this.height, null, this.resolution, true); + this.rootRenderTarget.clearColor = this._backgroundColorRgba; - vertices[index] = point.x + perpX; - vertices[index+1] = point.y + perpY; - vertices[index+2] = point.x - perpX; - vertices[index+3] = point.y - perpY; - lastPoint = point; - } + this.bindRenderTarget(this.rootRenderTarget); - this.containerUpdateTransform(); -}; - -},{"../core":50,"./Mesh":134}],137:[function(require,module,exports){ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ + this.emit('context', gl); -/** - * @namespace PIXI.mesh - */ -module.exports = { - Mesh: require('./Mesh'), - Plane: require('./Plane'), - Rope: require('./Rope'), - MeshShader: require('./webgl/MeshShader') + // setup the width/height properties and gl viewport + this.resize(this.width, this.height); }; - -},{"./Mesh":134,"./Plane":135,"./Rope":136,"./webgl/MeshShader":138}],138:[function(require,module,exports){ -var Shader = require('pixi-gl-core').GLShader; /** - * @class - * @extends PIXI.Shader - * @memberof PIXI.mesh - * @param shaderManager {PIXI.ShaderManager} The WebGL shader manager this shader works for. + * Renders the object to its webGL view + * + * @param displayObject {PIXI.DisplayObject} the object to be rendered + * @param renderTexture {PIXI.RenderTexture} + * @param [clear] {boolean} Should the canvas be cleared before the new render + * @param [transform] {PIXI.Transform} + * @param [skipUpdateTransform] {boolean} */ -function MeshShader(gl) +WebGLRenderer.prototype.render = function (displayObject, renderTexture, clear, transform, skipUpdateTransform) { - Shader.call(this, - gl, - // vertex shader - [ - 'precision lowp float;', - 'attribute vec2 aVertexPosition;', - 'attribute vec2 aTextureCoord;', - 'uniform mat3 translationMatrix;', - 'uniform mat3 projectionMatrix;', + // can be handy to know! + this.renderingToScreen = !renderTexture; - 'varying vec2 vTextureCoord;', + this.emit('prerender'); - 'void main(void){', - ' gl_Position = vec4((projectionMatrix * translationMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);', - ' vTextureCoord = aTextureCoord;', - '}' - ].join('\n'), - [ - 'precision lowp float;', - 'varying vec2 vTextureCoord;', - 'uniform float alpha;', + // no point rendering if our context has been blown up! + if (!this.gl || this.gl.isContextLost()) + { + return; + } - 'uniform sampler2D uSampler;', + if(!renderTexture) + { + this._lastObjectRendered = displayObject; + } - 'void main(void){', - ' gl_FragColor = texture2D(uSampler, vTextureCoord) * alpha ;', - // ' gl_FragColor = vec4(1.0);', - '}' - ].join('\n') - ); -} + if(!skipUpdateTransform) + { + // update the scene graph + var cacheParent = displayObject.parent; + displayObject.parent = this._tempDisplayObjectParent; + displayObject.updateTransform(); + displayObject.parent = cacheParent; + // displayObject.hitArea = //TODO add a temp hit area + } -MeshShader.prototype = Object.create(Shader.prototype); -MeshShader.prototype.constructor = MeshShader; -module.exports = MeshShader; + this.bindRenderTexture(renderTexture, transform); - -},{"pixi-gl-core":15}],139:[function(require,module,exports){ -var core = require('../core'); - -/** - * The ParticleContainer class is a really fast version of the Container built solely for speed, - * so use when you need a lot of sprites or particles. The tradeoff of the ParticleContainer is that advanced - * functionality will not work. ParticleContainer implements only the basic object transform (position, scale, rotation). - * Any other functionality like tinting, masking, etc will not work on sprites in this batch. - * - * It's extremely easy to use : - * - * ```js - * var container = new ParticleContainer(); - * - * for (var i = 0; i < 100; ++i) - * { - * var sprite = new PIXI.Sprite.fromImage("myImage.png"); - * container.addChild(sprite); - * } - * ``` - * - * And here you have a hundred sprites that will be renderer at the speed of light. - * - * @class - * @extends PIXI.Container - * @memberof PIXI.particles - * @param [maxSize=15000] {number} The maximum number of particles that can be renderer by the container. - * @param [properties] {object} The properties of children that should be uploaded to the gpu and applied. - * @param [properties.scale=false] {boolean} When true, scale be uploaded and applied. - * @param [properties.position=true] {boolean} When true, position be uploaded and applied. - * @param [properties.rotation=false] {boolean} When true, rotation be uploaded and applied. - * @param [properties.uvs=false] {boolean} When true, uvs be uploaded and applied. - * @param [properties.alpha=false] {boolean} When true, alpha be uploaded and applied. - * @param [batchSize=15000] {number} Number of particles per batch. - */ -function ParticleContainer(maxSize, properties, batchSize) -{ - core.Container.call(this); - - batchSize = batchSize || 15000; //CONST.SPRITE_BATCH_SIZE; // 2000 is a nice balance between mobile / desktop - maxSize = maxSize || 15000; - - // Making sure the batch size is valid - // 65535 is max vertex index in the index buffer (see ParticleRenderer) - // so max number of particles is 65536 / 4 = 16384 - var maxBatchSize = 16384; - if (batchSize > maxBatchSize) { - batchSize = maxBatchSize; - } - - if (batchSize > maxSize) { - batchSize = maxSize; - } - - /** - * Set properties to be dynamic (true) / static (false) - * - * @member {boolean[]} - * @private - */ - this._properties = [false, true, false, false, false]; - - /** - * @member {number} - * @private - */ - this._maxSize = maxSize; - - /** - * @member {number} - * @private - */ - this._batchSize = batchSize; - - /** - * @member {WebGLBuffer} - * @private - */ - this._glBuffers = []; - - /** - * @member {number} - * @private - */ - this._bufferToUpdate = 0; - - /** - * @member {boolean} - * - */ - this.interactiveChildren = false; - - /** - * The blend mode to be applied to the sprite. Apply a value of `PIXI.BLEND_MODES.NORMAL` to reset the blend mode. - * - * @member {number} - * @default PIXI.BLEND_MODES.NORMAL - * @see PIXI.BLEND_MODES - */ - this.blendMode = core.BLEND_MODES.NORMAL; - - /** - * Used for canvas renderering. If true then the elements will be positioned at the nearest pixel. This provides a nice speed boost. - * - * @member {boolean} - * @default true; - */ - this.roundPixels = true; - - this.baseTexture = null; - - this.setProperties(properties); -} - -ParticleContainer.prototype = Object.create(core.Container.prototype); -ParticleContainer.prototype.constructor = ParticleContainer; -module.exports = ParticleContainer; - -/** - * Sets the private properties array to dynamic / static based on the passed properties object - * - * @param properties {object} The properties to be uploaded - */ -ParticleContainer.prototype.setProperties = function(properties) -{ - if ( properties ) { - this._properties[0] = 'scale' in properties ? !!properties.scale : this._properties[0]; - this._properties[1] = 'position' in properties ? !!properties.position : this._properties[1]; - this._properties[2] = 'rotation' in properties ? !!properties.rotation : this._properties[2]; - this._properties[3] = 'uvs' in properties ? !!properties.uvs : this._properties[3]; - this._properties[4] = 'alpha' in properties ? !!properties.alpha : this._properties[4]; - } -}; - -/** - * Updates the object transform for rendering - * - * @private - */ -ParticleContainer.prototype.updateTransform = function () -{ - - // TODO don't need to! - this.displayObjectUpdateTransform(); - // PIXI.Container.prototype.updateTransform.call( this ); -}; - -/** - * Renders the container using the WebGL renderer - * - * @param renderer {PIXI.WebGLRenderer} The webgl renderer - * @private - */ -ParticleContainer.prototype.renderWebGL = function (renderer) -{ - if (!this.visible || this.worldAlpha <= 0 || !this.children.length || !this.renderable) - { - return; - } - - - if(!this.baseTexture) - { - this.baseTexture = this.children[0]._texture.baseTexture; - if(!this.baseTexture.hasLoaded) - { - this.baseTexture.once('update', function(){ - this.onChildrenChange(0); - }, this); - } - } - - - renderer.setObjectRenderer( renderer.plugins.particle ); - renderer.plugins.particle.render( this ); -}; - -/** - * Set the flag that static data should be updated to true - * - * @private - */ -ParticleContainer.prototype.onChildrenChange = function (smallestChildIndex) -{ - var bufferIndex = Math.floor(smallestChildIndex / this._batchSize); - if (bufferIndex < this._bufferToUpdate) { - this._bufferToUpdate = bufferIndex; - } -}; - -/** - * Renders the object using the Canvas renderer - * - * @param renderer {PIXI.CanvasRenderer} The canvas renderer - * @private - */ -ParticleContainer.prototype.renderCanvas = function (renderer) -{ - if (!this.visible || this.worldAlpha <= 0 || !this.children.length || !this.renderable) - { - return; - } - - var context = renderer.context; - var transform = this.worldTransform; - var isRotated = true; - - var positionX = 0; - var positionY = 0; - - var finalWidth = 0; - var finalHeight = 0; - - var compositeOperation = renderer.blendModes[this.blendMode]; - if (compositeOperation !== context.globalCompositeOperation) - { - context.globalCompositeOperation = compositeOperation; - } - - context.globalAlpha = this.worldAlpha; - - this.displayObjectUpdateTransform(); - - for (var i = 0; i < this.children.length; ++i) - { - var child = this.children[i]; - - if (!child.visible) - { - continue; - } - - var frame = child.texture.frame; - - context.globalAlpha = this.worldAlpha * child.alpha; - - if (child.rotation % (Math.PI * 2) === 0) - { - // this is the fastest way to optimise! - if rotation is 0 then we can avoid any kind of setTransform call - if (isRotated) - { - context.setTransform( - transform.a, - transform.b, - transform.c, - transform.d, - transform.tx, - transform.ty - ); - - isRotated = false; - } - - positionX = ((child.anchor.x) * (-frame.width * child.scale.x) + child.position.x + 0.5); - positionY = ((child.anchor.y) * (-frame.height * child.scale.y) + child.position.y + 0.5); - - finalWidth = frame.width * child.scale.x; - finalHeight = frame.height * child.scale.y; - - } - else - { - if (!isRotated) - { - isRotated = true; - } - - child.displayObjectUpdateTransform(); - - var childTransform = child.worldTransform; - - if (renderer.roundPixels) - { - context.setTransform( - childTransform.a, - childTransform.b, - childTransform.c, - childTransform.d, - childTransform.tx | 0, - childTransform.ty | 0 - ); - } - else - { - context.setTransform( - childTransform.a, - childTransform.b, - childTransform.c, - childTransform.d, - childTransform.tx, - childTransform.ty - ); - } - - positionX = ((child.anchor.x) * (-frame.width) + 0.5); - positionY = ((child.anchor.y) * (-frame.height) + 0.5); - - finalWidth = frame.width; - finalHeight = frame.height; - } - - context.drawImage( - child.texture.baseTexture.source, - frame.x, - frame.y, - frame.width, - frame.height, - positionX, - positionY, - finalWidth, - finalHeight - ); - } -}; - -/** - * Destroys the container - * - * @param [destroyChildren=false] {boolean} if set to true, all the children will have their destroy method called as well - */ -ParticleContainer.prototype.destroy = function () { - core.Container.prototype.destroy.apply(this, arguments); - - if (this._buffers) { - for (var i = 0; i < this._buffers.length; ++i) { - this._buffers[i].destroy(); - } - } - - this._properties = null; - this._buffers = null; -}; - -},{"../core":50}],140:[function(require,module,exports){ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ + this.currentRenderer.start(); + + if(clear !== undefined ? clear : this.clearBeforeRender) + { + this._activeRenderTarget.clear(); + } + + displayObject.renderWebGL(this); + + // apply transform.. + this.currentRenderer.flush(); + + //this.setObjectRenderer(this.emptyRenderer); + + this.textureGC.update(); + + this.emit('postrender'); +}; /** - * @namespace PIXI.mesh + * Changes the current renderer to the one given in parameter + * + * @param objectRenderer {PIXI.ObjectRenderer} The object renderer to use. */ -module.exports = { - ParticleContainer: require('./ParticleContainer'), - ParticleRenderer: require('./webgl/ParticleRenderer') +WebGLRenderer.prototype.setObjectRenderer = function (objectRenderer) +{ + if (this.currentRenderer === objectRenderer) + { + return; + } + + this.currentRenderer.stop(); + this.currentRenderer = objectRenderer; + this.currentRenderer.start(); }; - -},{"./ParticleContainer":139,"./webgl/ParticleRenderer":142}],141:[function(require,module,exports){ -var glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../core/utils/createIndicesForQuads'); /** - * @author Mat Groves - * - * Big thanks to the very clever Matt DesLauriers https://github.com/mattdesl/ - * for creating the original pixi version! - * Also a thanks to https://github.com/bchevalier for tweaking the tint and alpha so that they now share 4 bytes on the vertex buffer + * This shoudl be called if you wish to do some custom rendering + * It will basically render anything that may be batched up such as sprites * - * Heavily inspired by LibGDX's ParticleBuffer: - * https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/graphics/g2d/ParticleBuffer.java */ +WebGLRenderer.prototype.flush = function () +{ + this.setObjectRenderer(this.emptyRenderer); +}; /** - * The particle buffer manages the static and dynamic buffers for a particle container. + * Resizes the webGL view to the specified width and height. * - * @class - * @private - * @memberof PIXI + * @param width {number} the new width of the webGL view + * @param height {number} the new height of the webGL view */ -function ParticleBuffer(gl, properties, dynamicPropertyFlags, size) +WebGLRenderer.prototype.resize = function (width, height) { - /** - * The current WebGL drawing context. - * - * @member {WebGLRenderingContext} - */ - this.gl = gl; - - /** - * Size of a single vertex. - * - * @member {number} - */ - this.vertSize = 2; - - /** - * Size of a single vertex in bytes. - * - * @member {number} - */ - this.vertByteSize = this.vertSize * 4; - - /** - * The number of particles the buffer can hold - * - * @member {number} - */ - this.size = size; + // if(width * this.resolution === this.width && height * this.resolution === this.height)return; - /** - * A list of the properties that are dynamic. - * - * @member {object[]} - */ - this.dynamicProperties = []; + SystemRenderer.prototype.resize.call(this, width, height); - /** - * A list of the properties that are static. - * - * @member {object[]} - */ - this.staticProperties = []; + this.rootRenderTarget.resize(width, height); - for (var i = 0; i < properties.length; i++) + if(this._activeRenderTarget === this.rootRenderTarget) { - var property = properties[i]; + this.rootRenderTarget.activate(); - if(dynamicPropertyFlags[i]) - { - this.dynamicProperties.push(property); - } - else + if(this._activeShader) { - this.staticProperties.push(property); + this._activeShader.uniforms.projectionMatrix = this.rootRenderTarget.projectionMatrix.toArray(true); } } +}; - this.staticStride = 0; - this.staticBuffer = null; - this.staticData = null; - - this.dynamicStride = 0; - this.dynamicBuffer = null; - this.dynamicData = null; +/** + * Resizes the webGL view to the specified width and height. + * + * @param blendMode {number} the desired blend mode + */ +WebGLRenderer.prototype.setBlendMode = function (blendMode) +{ + this.state.setBlendMode(blendMode); +}; - this.initBuffers(); +/** + * Erases the active render target and fills the drawing area with a colour + * + * @param [clearColor] {number} The colour + */ +WebGLRenderer.prototype.clear = function (clearColor) +{ + this._activeRenderTarget.clear(clearColor); +}; -} +/** + * Sets the transform of the active render target to the given matrix + * + * @param matrix {PIXI.Matrix} The transformation matrix + */ +WebGLRenderer.prototype.setTransform = function (matrix) +{ + this._activeRenderTarget.transform = matrix; +}; -ParticleBuffer.prototype.constructor = ParticleBuffer; -module.exports = ParticleBuffer; /** - * Sets up the renderer context and necessary buffers. + * Binds a render texture for rendering * - * @private + * @param renderTexture {PIXI.RenderTexture} The render texture to render + * @param transform {PIXI.Transform} The transform to be applied to the render texture */ -ParticleBuffer.prototype.initBuffers = function () +WebGLRenderer.prototype.bindRenderTexture = function (renderTexture, transform) { - var gl = this.gl; - var i; - var property; - - var dynamicOffset = 0; + var renderTarget; + if(renderTexture) + { + var baseTexture = renderTexture.baseTexture; + var gl = this.gl; - /** - * Holds the indices of the geometry (quads) to draw - * - * @member {Uint16Array} - */ - this.indices = createIndicesForQuads(this.size); - this.indexBuffer = glCore.GLBuffer.createIndexBuffer(gl, this.indices, gl.STATIC_DRAW); + if(!baseTexture._glRenderTargets[this.CONTEXT_UID]) + { + this.textureManager.updateTexture(baseTexture); + gl.bindTexture(gl.TEXTURE_2D, null); + } + else + { + // the texture needs to be unbound if its being rendererd too.. + this._activeTextureLocation = baseTexture._id; + gl.activeTexture(gl.TEXTURE0 + baseTexture._id); + gl.bindTexture(gl.TEXTURE_2D, null); + } - this.dynamicStride = 0; - for (i = 0; i < this.dynamicProperties.length; i++) + renderTarget = baseTexture._glRenderTargets[this.CONTEXT_UID]; + renderTarget.setFrame(renderTexture.frame); + } + else { - property = this.dynamicProperties[i]; - - property.offset = dynamicOffset; - dynamicOffset += property.size; - this.dynamicStride += property.size; + renderTarget = this.rootRenderTarget; } - this.dynamicData = new Float32Array( this.size * this.dynamicStride * 4); - this.dynamicBuffer = glCore.GLBuffer.createVertexBuffer(gl, this.dynamicData, gl.STREAM_DRAW); + renderTarget.transform = transform; + this.bindRenderTarget(renderTarget); - // static // - var staticOffset = 0; - this.staticStride = 0; + return this; +}; - for (i = 0; i < this.staticProperties.length; i++) +/** + * Changes the current render target to the one given in parameter + * + * @param renderTarget {PIXI.RenderTarget} the new render target + */ +WebGLRenderer.prototype.bindRenderTarget = function (renderTarget) +{ + if(renderTarget !== this._activeRenderTarget) { - property = this.staticProperties[i]; + this._activeRenderTarget = renderTarget; + renderTarget.activate(); - property.offset = staticOffset; - staticOffset += property.size; - this.staticStride += property.size; + if(this._activeShader) + { + this._activeShader.uniforms.projectionMatrix = renderTarget.projectionMatrix.toArray(true); + } + this.stencilManager.setMaskStack( renderTarget.stencilMaskStack ); } - this.staticData = new Float32Array( this.size * this.staticStride * 4); - this.staticBuffer = glCore.GLBuffer.createVertexBuffer(gl, this.staticData, gl.STATIC_DRAW); + return this; +}; + +/** + * Changes the current shader to the one given in parameter + * + * @param shader {PIXI.Shader} the new shader + */ +WebGLRenderer.prototype.bindShader = function (shader) +{ + //TODO cache + if(this._activeShader !== shader) + { + this._activeShader = shader; + shader.bind(); + + // automatically set the projection matrix + shader.uniforms.projectionMatrix = this._activeRenderTarget.projectionMatrix.toArray(true); + } + + return this; +}; + +/** + * Binds the texture ... @mat + * + * @param texture {PIXI.Texture} the new texture + * @param location {number} the texture location + */ +WebGLRenderer.prototype.bindTexture = function (texture, location) +{ + texture = texture.baseTexture || texture; + var gl = this.gl; - this.vao = new glCore.VertexArrayObject(gl) - .addIndex(this.indexBuffer); + //TODO test perf of cache? + location = location || 0; - for (i = 0; i < this.dynamicProperties.length; i++) + if(this._activeTextureLocation !== location)// { - property = this.dynamicProperties[i]; - this.vao.addAttribute(this.dynamicBuffer, property.attribute, gl.FLOAT, false, this.dynamicStride * 4, property.offset * 4); + this._activeTextureLocation = location; + gl.activeTexture(gl.TEXTURE0 + location ); } - for (i = 0; i < this.staticProperties.length; i++) + //TODO - can we cache this texture too? + this._activeTexture = texture; + + if (!texture._glTextures[this.CONTEXT_UID]) { - property = this.staticProperties[i]; - this.vao.addAttribute(this.staticBuffer, property.attribute, gl.FLOAT, false, this.staticStride * 4, property.offset * 4); + // this will also bind the texture.. + this.textureManager.updateTexture(texture); + + } + else + { + texture.touched = this.textureGC.count; + // bind the current texture + texture._glTextures[this.CONTEXT_UID].bind(); } + + return this; +}; + +WebGLRenderer.prototype.createVao = function () +{ + return new glCore.VertexArrayObject(this.gl, this.state.attribState); }; /** - * Uploads the dynamic properties. - * + * Resets the WebGL state so you can render things however you fancy! */ -ParticleBuffer.prototype.uploadDynamic = function(children, startIndex, amount) +WebGLRenderer.prototype.reset = function () { - for (var i = 0; i < this.dynamicProperties.length; i++) - { - var property = this.dynamicProperties[i]; - property.uploadFunction(children, startIndex, amount, this.dynamicData, this.dynamicStride, property.offset); - } + this.setObjectRenderer(this.emptyRenderer); - this.dynamicBuffer.upload(); + this._activeShader = null; + this._activeRenderTarget = this.rootRenderTarget; + this._activeTextureLocation = 999; + this._activeTexture = null; + + // bind the main frame buffer (the screen); + this.rootRenderTarget.activate(); + + this.state.resetToDefault(); + + return this; }; /** - * Uploads the static properties. + * Handles a lost webgl context * + * @private */ -ParticleBuffer.prototype.uploadStatic = function(children, startIndex, amount) +WebGLRenderer.prototype.handleContextLost = function (event) { - for (var i = 0; i < this.staticProperties.length; i++) - { - var property = this.staticProperties[i]; - property.uploadFunction(children, startIndex, amount, this.staticData, this.staticStride, property.offset); - } - - this.staticBuffer.upload(); + event.preventDefault(); }; /** - * Binds the buffers to the GPU + * Handles a restored webgl context * + * @private */ -ParticleBuffer.prototype.bind = function () +WebGLRenderer.prototype.handleContextRestored = function () { - this.vao.bind(); + this._initContext(); + this.textureManager.removeAll(); }; /** - * Destroys the ParticleBuffer. + * Removes everything from the renderer (event listeners, spritebatch, etc...) * + * @param [removeView=false] {boolean} Removes the Canvas element from the DOM. https://github.com/pixijs/pixi.js/issues/2233 */ -ParticleBuffer.prototype.destroy = function () +WebGLRenderer.prototype.destroy = function (removeView) { - this.dynamicProperties = null; - this.dynamicData = null; - this.dynamicBuffer.destroy(); + this.destroyPlugins(); - this.staticProperties = null; - this.staticData = null; - this.staticBuffer.destroy(); + // remove listeners + this.view.removeEventListener('webglcontextlost', this.handleContextLost); + this.view.removeEventListener('webglcontextrestored', this.handleContextRestored); + + this.textureManager.destroy(); + + // call base destroy + SystemRenderer.prototype.destroy.call(this, removeView); + + this.uid = 0; + + // destroy the managers + this.maskManager.destroy(); + this.stencilManager.destroy(); + this.filterManager.destroy(); + + this.maskManager = null; + this.filterManager = null; + this.textureManager = null; + this.currentRenderer = null; + + this.handleContextLost = null; + this.handleContextRestored = null; + + this._contextOptions = null; + this.gl.useProgram(null); + + if(this.gl.getExtension('WEBGL_lose_context')) + { + this.gl.getExtension('WEBGL_lose_context').loseContext(); + } + + this.gl = null; + + // this = null; }; -},{"../../core/utils/createIndicesForQuads":98,"pixi-gl-core":15}],142:[function(require,module,exports){ -var core = require('../../core'), - ParticleShader = require('./ParticleShader'), - ParticleBuffer = require('./ParticleBuffer'); - -/** - * @author Mat Groves - * - * Big thanks to the very clever Matt DesLauriers https://github.com/mattdesl/ - * for creating the original pixi version! - * Also a thanks to https://github.com/bchevalier for tweaking the tint and alpha so that they now share 4 bytes on the vertex buffer - * - * Heavily inspired by LibGDX's ParticleRenderer: - * https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/graphics/g2d/ParticleRenderer.java - */ +},{"../../const":42,"../../utils":115,"../SystemRenderer":72,"./TextureGarbageCollector":78,"./TextureManager":79,"./WebGLState":81,"./managers/FilterManager":86,"./managers/MaskManager":87,"./managers/StencilManager":88,"./utils/ObjectRenderer":90,"./utils/RenderTarget":92,"./utils/mapWebGLDrawModesToPixi":95,"./utils/validateContext":96,"pixi-gl-core":14}],81:[function(require,module,exports){ +var mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); /** + * A WebGL state machines * - * @class - * @private * @memberof PIXI - * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. + * @class + * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -function ParticleRenderer(renderer) +function WebGLState(gl) { - core.ObjectRenderer.call(this, renderer); + /** + * The current active state + * + * @member {Uint8Array} + */ + this.activeState = new Uint8Array(16); - // 65535 is max vertex index in the index buffer (see ParticleRenderer) - // so max number of particles is 65536 / 4 = 16384 - // and max number of element in the index buffer is 16384 * 6 = 98304 - // Creating a full index buffer, overhead is 98304 * 2 = 196Ko - // var numIndices = 98304; + /** + * The default state + * + * @member {Uint8Array} + */ + this.defaultState = new Uint8Array(16); + + // default blend mode.. + this.defaultState[0] = 1; /** - * The default shader that is used if a sprite doesn't have a more specific one. + * The current state index in the stack * - * @member {PIXI.Shader} + * @member {number} + * @private */ - this.shader = null; + this.stackIndex = 0; - this.indexBuffer = null; + /** + * The stack holding all the different states + * + * @member {Array<*>} + * @private + */ + this.stack = []; - this.properties = null; + /** + * The current WebGL rendering context + * + * @member {WebGLRenderingContext} + */ + this.gl = gl; - this.tempMatrix = new core.Matrix(); + this.maxAttribs = gl.getParameter(gl.MAX_VERTEX_ATTRIBS); - this.CONTEXT_UID = 0; -} + this.attribState = {tempAttribState:new Array(this.maxAttribs), + attribState:new Array(this.maxAttribs)}; -ParticleRenderer.prototype = Object.create(core.ObjectRenderer.prototype); -ParticleRenderer.prototype.constructor = ParticleRenderer; -module.exports = ParticleRenderer; + this.blendModes = mapWebGLBlendModesToPixi(gl); -core.WebGLRenderer.registerPlugin('particle', ParticleRenderer); + // check we have vao.. + this.nativeVaoExtension = ( + gl.getExtension('OES_vertex_array_object') || + gl.getExtension('MOZ_OES_vertex_array_object') || + gl.getExtension('WEBKIT_OES_vertex_array_object') + ); +} /** - * When there is a WebGL context change - * - * @private + * Pushes a new active state */ -ParticleRenderer.prototype.onContextChange = function () +WebGLState.prototype.push = function() { - var gl = this.renderer.gl; + // next state.. + var state = this.state[++this.stackIndex]; - this.CONTEXT_UID = this.renderer.CONTEXT_UID; + if(!state) + { + state = this.state[this.stackIndex] = new Uint8Array(16); + } - // setup default shader - this.shader = new ParticleShader(gl); + // copy state.. + // set active state so we can force overrides of gl state + for (var i = 0; i < this.activeState.length; i++) + { + this.activeState[i] = state[i]; + } +}; - this.properties = [ - // verticesData - { - attribute:this.shader.attributes.aVertexPosition, - size:2, - uploadFunction:this.uploadVertices, - offset:0 - }, - // positionData - { - attribute:this.shader.attributes.aPositionCoord, - size:2, - uploadFunction:this.uploadPosition, - offset:0 - }, - // rotationData - { - attribute:this.shader.attributes.aRotation, - size:1, - uploadFunction:this.uploadRotation, - offset:0 - }, - // uvsData - { - attribute:this.shader.attributes.aTextureCoord, - size:2, - uploadFunction:this.uploadUvs, - offset:0 - }, - // alphaData - { - attribute:this.shader.attributes.aColor, - size:1, - uploadFunction:this.uploadAlpha, - offset:0 - } - ]; +var BLEND = 0, + DEPTH_TEST = 1, + FRONT_FACE = 2, + CULL_FACE = 3, + BLEND_FUNC = 4; + +/** + * Pops a state out + */ +WebGLState.prototype.pop = function() +{ + var state = this.state[--this.stackIndex]; + this.setState(state); +}; +/** + * Sets the current state + * @param state {number} + */ +WebGLState.prototype.setState = function(state) +{ + this.setBlend(state[BLEND]); + this.setDepthTest(state[DEPTH_TEST]); + this.setFrontFace(state[FRONT_FACE]); + this.setCullFace(state[CULL_FACE]); + this.setBlendMode(state[BLEND_FUNC]); }; /** - * Starts a new particle batch. - * + * Sets the blend mode ? @mat + * @param value {number} */ -ParticleRenderer.prototype.start = function () +WebGLState.prototype.setBlend = function(value) { - this.renderer.bindShader(this.shader); + if(this.activeState[BLEND] === value|0) { + return; + } + + this.activeState[BLEND] = value|0; + + var gl = this.gl; + + if(value) + { + gl.enable(gl.BLEND); + } + else + { + gl.disable(gl.BLEND); + } }; +/** + * Sets the blend mode ? @mat + * @param value {number} + */ +WebGLState.prototype.setBlendMode = function(value) +{ + if(value === this.activeState[BLEND_FUNC]) { + return; + } + + this.activeState[BLEND_FUNC] = value; + + this.gl.blendFunc(this.blendModes[value][0], this.blendModes[value][1]); +}; /** - * Renders the particle container object. - * - * @param container {PIXI.ParticleContainer} The container to render using this ParticleRenderer + * Sets the depth test @mat + * @param value {number} */ -ParticleRenderer.prototype.render = function (container) +WebGLState.prototype.setDepthTest = function(value) { - var children = container.children, - totalChildren = children.length, - maxSize = container._maxSize, - batchSize = container._batchSize; + if(this.activeState[DEPTH_TEST] === value|0) { + return; + } - if(totalChildren === 0) + this.activeState[DEPTH_TEST] = value|0; + + var gl = this.gl; + + if(value) { - return; + gl.enable(gl.DEPTH_TEST); } - else if(totalChildren > maxSize) + else { - totalChildren = maxSize; + gl.disable(gl.DEPTH_TEST); } +}; - var buffers = container._glBuffers[this.renderer.CONTEXT_UID]; - - if(!buffers) - { - buffers = container._glBuffers[this.renderer.CONTEXT_UID] = this.generateBuffers( container ); +/** + * Sets the depth test @mat + * @param value {number} + */ +WebGLState.prototype.setCullFace = function(value) +{ + if(this.activeState[CULL_FACE] === value|0) { + return; } - // if the uvs have not updated then no point rendering just yet! - this.renderer.setBlendMode(container.blendMode); + this.activeState[CULL_FACE] = value|0; - var gl = this.renderer.gl; + var gl = this.gl; - // var m = container.worldTransform.copy( this.tempMatrix ); -// m.prepend( this.renderer.currentRenderTarget.projectionMatrix ); - this.shader.uniforms.uAlpha = container.worldAlpha; + if(value) + { + gl.enable(gl.CULL_FACE); + } + else + { + gl.disable(gl.CULL_FACE); + } +}; +/** + * Sets the depth test @mat + * @param value {number} + */ +WebGLState.prototype.setFrontFace = function(value) +{ + if(this.activeState[FRONT_FACE] === value|0) { + return; + } - // make sure the texture is bound.. - var baseTexture = children[0]._texture.baseTexture; + this.activeState[FRONT_FACE] = value|0; - this.renderer.bindTexture(baseTexture); + var gl = this.gl; - // now lets upload and render the buffers.. - for (var i = 0, j = 0; i < totalChildren; i += batchSize, j += 1) + if(value) { - var amount = ( totalChildren - i); - if(amount > batchSize) - { - amount = batchSize; - } + gl.frontFace(gl.CW); + } + else + { + gl.frontFace(gl.CCW); + } +}; - var buffer = buffers[j]; +/** + * Disables all the vaos in use + */ +WebGLState.prototype.resetAttributes = function() +{ + var i; - // we always upload the dynamic - buffer.uploadDynamic(children, i, amount); + for ( i = 0; i < this.attribState.tempAttribState.length; i++) { + this.attribState.tempAttribState[i] = 0; + } - // we only upload the static content when we have to! - if(container._bufferToUpdate === j) - { - buffer.uploadStatic(children, i, amount); - container._bufferToUpdate = j + 1; - } + for ( i = 0; i < this.attribState.attribState.length; i++) { + this.attribState.attribState[i] = 0; + } - // bind the buffer - buffer.vao.bind() - .draw(gl.TRIANGLES, amount * 6) - .unbind(); + var gl = this.gl; - // now draw those suckas! - // gl.drawElements(gl.TRIANGLES, amount * 6, gl.UNSIGNED_SHORT, 0); - // this.renderer.drawCount++; + // im going to assume one is always active for performance reasons. + for (i = 1; i < this.maxAttribs; i++) + { + gl.disableVertexAttribArray(i); } }; +//used /** - * Creates one particle buffer for each child in the container we want to render and updates internal properties - * - * @param container {PIXI.ParticleContainer} The container to render using this ParticleRenderer + * Resets all the logic and disables the vaos */ -ParticleRenderer.prototype.generateBuffers = function (container) +WebGLState.prototype.resetToDefault = function() { - var gl = this.renderer.gl, - buffers = [], - size = container._maxSize, - batchSize = container._batchSize, - dynamicPropertyFlags = container._properties, - i; - for (i = 0; i < size; i += batchSize) + // unbind any VAO if they exist.. + if(this.nativeVaoExtension) { - buffers.push(new ParticleBuffer(gl, this.properties, dynamicPropertyFlags, batchSize)); + this.nativeVaoExtension.bindVertexArrayOES(null); } - return buffers; -}; -/** - * Uploads the verticies. - * - * @param children {PIXI.DisplayObject[]} the array of display objects to render - * @param startIndex {number} the index to start from in the children array - * @param amount {number} the amount of children that will have their vertices uploaded - * @param array {number[]} - * @param stride {number} - * @param offset {number} - */ -ParticleRenderer.prototype.uploadVertices = function (children, startIndex, amount, array, stride, offset) -{ - var sprite, - texture, - trim, - crop, - sx, - sy, - w0, w1, h0, h1; + // reset all attributs.. + this.resetAttributes(); - for (var i = 0; i < amount; i++) { + // set active state so we can force overrides of gl state + for (var i = 0; i < this.activeState.length; i++) + { + this.activeState[i] = 2; + } - sprite = children[startIndex + i]; - texture = sprite._texture; - sx = sprite.scale.x; - sy = sprite.scale.y; - trim = texture.trim; - crop = texture.crop; + var gl = this.gl; + gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false); - if (trim) - { - // if the sprite is trimmed and is not a tilingsprite then we need to add the extra space before transforming the sprite coords.. - w1 = trim.x - sprite.anchor.x * crop.width; - w0 = w1 + trim.width; - h1 = trim.y - sprite.anchor.y * crop.height; - h0 = h1 + trim.height; + this.setState(this.defaultState); +}; - } - else - { - w0 = (crop.width ) * (1-sprite.anchor.x); - w1 = (crop.width ) * -sprite.anchor.x; +module.exports = WebGLState; + +},{"./utils/mapWebGLBlendModesToPixi":94}],82:[function(require,module,exports){ +var extractUniformsFromSrc = require('./extractUniformsFromSrc'), + utils = require('../../../utils'), + CONST = require('../../../const'), + SOURCE_KEY_MAP = {}; - h0 = crop.height * (1-sprite.anchor.y); - h1 = crop.height * -sprite.anchor.y; - } +// var math = require('../../../math'); +/** + * @class + * @memberof PIXI + * @extends PIXI.Shader + * @param [vertexSrc] {string} The source of the vertex shader. + * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. + * @param [fragmentSrc] {string} The source of the fragment shader. + */ +function Filter(vertexSrc, fragmentSrc, uniforms) +{ - array[offset] = w1 * sx; - array[offset + 1] = h1 * sy; + /** + * The vertex shader. + * + * @member {string} + */ + this.vertexSrc = vertexSrc || Filter.defaultVertexSrc; - array[offset + stride] = w0 * sx; - array[offset + stride + 1] = h1 * sy; + /** + * The fragment shader. + * + * @member {string} + */ + this.fragmentSrc = fragmentSrc || Filter.defaultFragmentSrc; - array[offset + stride * 2] = w0 * sx; - array[offset + stride * 2 + 1] = h0 * sy; + this.blendMode = CONST.BLEND_MODES.NORMAL; - array[offset + stride * 3] = w1 * sx; - array[offset + stride * 3 + 1] = h0 * sy; + // pull out the vertex and shader uniforms if they are not specified.. + // currently this does not extract structs only default types + this.uniformData = uniforms || extractUniformsFromSrc( this.vertexSrc, this.fragmentSrc, 'projectionMatrix|uSampler'); - offset += stride * 4; + this.uniforms = {}; + + for (var i in this.uniformData) + { + this.uniforms[i] = this.uniformData[i].value; } -}; + // this is where we store shader references.. + // TODO we could cache this! + this.glShaders = []; -/** - * - * @param children {PIXI.DisplayObject[]} the array of display objects to render - * @param startIndex {number} the index to start from in the children array - * @param amount {number} the amount of children that will have their positions uploaded - * @param array {number[]} - * @param stride {number} - * @param offset {number} - */ -ParticleRenderer.prototype.uploadPosition = function (children,startIndex, amount, array, stride, offset) -{ - for (var i = 0; i < amount; i++) + // used for cacheing.. sure there is a better way! + if(!SOURCE_KEY_MAP[this.vertexSrc + this.fragmentSrc]) { - var spritePosition = children[startIndex + i].position; + SOURCE_KEY_MAP[this.vertexSrc + this.fragmentSrc] = utils.uid(); + } - array[offset] = spritePosition.x; - array[offset + 1] = spritePosition.y; + this.glShaderKey = SOURCE_KEY_MAP[this.vertexSrc + this.fragmentSrc]; - array[offset + stride] = spritePosition.x; - array[offset + stride + 1] = spritePosition.y; + this.padding = 4; + this.resolution = 1; +} - array[offset + stride * 2] = spritePosition.x; - array[offset + stride * 2 + 1] = spritePosition.y; +// constructor +//Filter.prototype.constructor = Filter; +module.exports = Filter; + +// var tempMatrix = new math.Matrix(); + +Filter.prototype.apply = function(filterManager, input, output, clear) +{ + // --- // + // this.uniforms.filterMatrix = filterManager.calculateSpriteMatrix(tempMatrix, window.panda ); - array[offset + stride * 3] = spritePosition.x; - array[offset + stride * 3 + 1] = spritePosition.y; + // do as you please! - offset += stride * 4; - } + filterManager.applyFilter(this, input, output, clear); + // or just do a regular render.. }; /** + * The default vertex shader source * - * @param children {PIXI.DisplayObject[]} the array of display objects to render - * @param startIndex {number} the index to start from in the children array - * @param amount {number} the amount of children that will have their rotation uploaded - * @param array {number[]} - * @param stride {number} - * @param offset {number} + * @static + * @constant */ -ParticleRenderer.prototype.uploadRotation = function (children,startIndex, amount, array, stride, offset) -{ - for (var i = 0; i < amount; i++) - { - var spriteRotation = children[startIndex + i].rotation; +Filter.defaultVertexSrc = [ + 'attribute vec2 aVertexPosition;', + 'attribute vec2 aTextureCoord;', + 'uniform mat3 projectionMatrix;', + 'uniform mat3 filterMatrix;', - array[offset] = spriteRotation; - array[offset + stride] = spriteRotation; - array[offset + stride * 2] = spriteRotation; - array[offset + stride * 3] = spriteRotation; + 'varying vec2 vTextureCoord;', + 'varying vec2 vFilterCoord;', - offset += stride * 4; - } -}; + 'void main(void){', + ' gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);', + ' vFilterCoord = ( filterMatrix * vec3( aTextureCoord, 1.0) ).xy;', + ' vTextureCoord = aTextureCoord ;', + '}' +].join('\n'); /** + * The default fragment shader source * - * @param children {PIXI.DisplayObject[]} the array of display objects to render - * @param startIndex {number} the index to start from in the children array - * @param amount {number} the amount of children that will have their Uvs uploaded - * @param array {number[]} - * @param stride {number} - * @param offset {number} + * @static + * @constant */ -ParticleRenderer.prototype.uploadUvs = function (children,startIndex, amount, array, stride, offset) +Filter.defaultFragmentSrc = [ + 'varying vec2 vTextureCoord;', + 'varying vec2 vFilterCoord;', + + 'uniform sampler2D uSampler;', + 'uniform sampler2D filterSampler;', + + 'void main(void){', + ' vec4 masky = texture2D(filterSampler, vFilterCoord);', + ' vec4 sample = texture2D(uSampler, vTextureCoord);', + ' vec4 color;', + ' if(mod(vFilterCoord.x, 1.0) > 0.5)', + ' {', + ' color = vec4(1.0, 0.0, 0.0, 1.0);', + ' }', + ' else', + ' {', + ' color = vec4(0.0, 1.0, 0.0, 1.0);', + ' }', + // ' gl_FragColor = vec4(mod(vFilterCoord.x, 1.5), vFilterCoord.y,0.0,1.0);', + ' gl_FragColor = mix(sample, masky, 0.5);', + ' gl_FragColor *= sample.a;', + '}' +].join('\n'); + +},{"../../../const":42,"../../../utils":115,"./extractUniformsFromSrc":83}],83:[function(require,module,exports){ +var defaultValue = require('pixi-gl-core').shader.defaultValue; + +function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { - for (var i = 0; i < amount; i++) - { - var textureUvs = children[startIndex + i]._texture._uvs; + var vertUniforms = extractUniformsFromString(vertexSrc, mask); + var fragUniforms = extractUniformsFromString(fragmentSrc, mask); - if (textureUvs) - { - array[offset] = textureUvs.x0; - array[offset + 1] = textureUvs.y0; + return Object.assign(vertUniforms, fragUniforms); +} - array[offset + stride] = textureUvs.x1; - array[offset + stride + 1] = textureUvs.y1; - array[offset + stride * 2] = textureUvs.x2; - array[offset + stride * 2 + 1] = textureUvs.y2; +function extractUniformsFromString(string) +{ + var maskRegex = new RegExp('^(projectionMatrix|uSampler|filterArea)$'); - array[offset + stride * 3] = textureUvs.x3; - array[offset + stride * 3 + 1] = textureUvs.y3; + var uniforms = {}; + var nameSplit; - offset += stride * 4; - } - else - { - //TODO you know this can be easier! - array[offset] = 0; - array[offset + 1] = 0; - array[offset + stride] = 0; - array[offset + stride + 1] = 0; + // clean the lines a little - remove extra spaces / teabs etc + // then split along ';' + var lines = string.replace(/\s+/g,' ') + .split(/\s*;\s*/); - array[offset + stride * 2] = 0; - array[offset + stride * 2 + 1] = 0; + // loop through.. + for (var i = 0; i < lines.length; i++) + { + var line = lines[i].trim(); - array[offset + stride * 3] = 0; - array[offset + stride * 3 + 1] = 0; + if(line.indexOf('uniform') > -1) + { + var splitLine = line.split(' '); + var type = splitLine[1]; - offset += stride * 4; + var name = splitLine[2]; + var size = 1; + + if(name.indexOf('[') > -1) + { + // array! + nameSplit = name.split(/\[|\]/); + name = nameSplit[0]; + size *= Number(nameSplit[1]); + } + + if(!name.match(maskRegex)) + { + uniforms[name] = { + value:defaultValue(type, size), + name:name, + type:type + }; + } } } -}; -/** - * - * @param children {PIXI.DisplayObject[]} the array of display objects to render - * @param startIndex {number} the index to start from in the children array - * @param amount {number} the amount of children that will have their alpha uploaded - * @param array {number[]} - * @param stride {number} - * @param offset {number} + return uniforms; +} + +module.exports = extractUniformsFromSrc; + +},{"pixi-gl-core":14}],84:[function(require,module,exports){ +var math = require('../../../math'); + +/* + * Calculates the mapped matrix + * @param filterArea {Rectangle} The filter area + * @param sprite {Sprite} the target sprite + * @param outputMatrix {Matrix} @alvin */ -ParticleRenderer.prototype.uploadAlpha = function (children,startIndex, amount, array, stride, offset) +// TODO playing around here.. this is temporary - (will end up in the shader) +// thia returns a matrix that will normalise map filter cords in the filter to screen space +var calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { - for (var i = 0; i < amount; i++) - { - var spriteAlpha = children[startIndex + i].alpha; + //var worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), + // var texture = {width:1136, height:700};//sprite._texture.baseTexture; - array[offset] = spriteAlpha; - array[offset + stride] = spriteAlpha; - array[offset + stride * 2] = spriteAlpha; - array[offset + stride * 3] = spriteAlpha; + // TODO unwrap? + var mappedMatrix = outputMatrix.identity(); - offset += stride * 4; - } -}; + mappedMatrix.translate(filterArea.x / textureSize.width, filterArea.y / textureSize.height ); + mappedMatrix.scale( textureSize.width , textureSize.height ); -/** - * Destroys the ParticleRenderer. - * - */ -ParticleRenderer.prototype.destroy = function () + return mappedMatrix; + +}; + +var calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { - if (this.renderer.gl) { - this.renderer.gl.deleteBuffer(this.indexBuffer); - } - core.ObjectRenderer.prototype.destroy.apply(this, arguments); + var mappedMatrix = outputMatrix.identity(); - this.shader.destroy(); + mappedMatrix.translate(filterArea.x / textureSize.width, filterArea.y / textureSize.height ); - this.indices = null; - this.tempMatrix = null; + var translateScaleX = (textureSize.width / filterArea.width); + var translateScaleY = (textureSize.height / filterArea.height); + + mappedMatrix.scale( translateScaleX , translateScaleY ); + + return mappedMatrix; }; - -},{"../../core":50,"./ParticleBuffer":141,"./ParticleShader":143}],143:[function(require,module,exports){ -var Shader = require('pixi-gl-core').GLShader; -/** - * @class - * @extends PIXI.TextureShader - * @memberof PIXI - * @param shaderManager {ShaderManager} The webgl shader manager this shader works for. - */ -function ParticleShader(gl) +// this will map the filter coord so that a texture can be used based on the transform of a sprite +var calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { - Shader.call(this, - gl, - // vertex shader - [ - 'attribute vec2 aVertexPosition;', - 'attribute vec2 aTextureCoord;', - 'attribute float aColor;', + var worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), + texture = sprite._texture.baseTexture; - 'attribute vec2 aPositionCoord;', - 'attribute vec2 aScale;', - 'attribute float aRotation;', + // TODO unwrap? + var mappedMatrix = outputMatrix.identity(); - 'uniform mat3 projectionMatrix;', + // scale.. + var ratio = textureSize.height / textureSize.width; - 'varying vec2 vTextureCoord;', - 'varying float vColor;', + mappedMatrix.translate(filterArea.x / textureSize.width, filterArea.y / textureSize.height ); - 'void main(void){', - ' vec2 v = aVertexPosition;', + mappedMatrix.scale(1 , ratio); + + var translateScaleX = (textureSize.width / texture.width); + var translateScaleY = (textureSize.height / texture.height); + + worldTransform.tx /= texture.width * translateScaleX; + + //this...? free beer for anyone who can explain why this makes sense! + worldTransform.ty /= texture.width * translateScaleX; + // worldTransform.ty /= texture.height * translateScaleY; + + worldTransform.invert(); + mappedMatrix.prepend(worldTransform); + + // apply inverse scale.. + mappedMatrix.scale(1 , 1/ratio); - ' v.x = (aVertexPosition.x) * cos(aRotation) - (aVertexPosition.y) * sin(aRotation);', - ' v.y = (aVertexPosition.x) * sin(aRotation) + (aVertexPosition.y) * cos(aRotation);', - ' v = v + aPositionCoord;', + mappedMatrix.scale( translateScaleX , translateScaleY ); - ' gl_Position = vec4((projectionMatrix * vec3(v, 1.0)).xy, 0.0, 1.0);', + mappedMatrix.translate(sprite.anchor.x, sprite.anchor.y); - ' vTextureCoord = aTextureCoord;', - ' vColor = aColor;', - '}' - ].join('\n'), - // hello - [ - 'precision lowp float;', + return mappedMatrix; +}; - 'varying vec2 vTextureCoord;', - 'varying float vColor;', +module.exports = { + calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix:calculateSpriteMatrix +}; + +},{"../../../math":66}],85:[function(require,module,exports){ +var Filter = require('../Filter'), + math = require('../../../../math'); - 'uniform sampler2D uSampler;', - 'uniform float uAlpha;', +// @see https://github.com/substack/brfs/issues/25 - 'void main(void){', - ' vec4 color = texture2D(uSampler, vTextureCoord) * vColor * uAlpha;', - ' if (color.a == 0.0) discard;', - ' gl_FragColor = color;', - '}' - ].join('\n') +/** + * The SpriteMaskFilter class + * + * @class + * @extends PIXI.Filter + * @memberof PIXI + * @param sprite {PIXI.Sprite} the target sprite + */ +function SpriteMaskFilter(sprite) +{ + var maskMatrix = new math.Matrix(); + + Filter.call(this, + "#define GLSLIFY 1\nattribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\n\nuniform mat3 projectionMatrix;\nuniform mat3 otherMatrix;\n\nvarying vec2 vMaskCoord;\nvarying vec2 vTextureCoord;\n\nvoid main(void)\n{\n gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n vMaskCoord = ( otherMatrix * vec3( aTextureCoord, 1.0) ).xy;\n}\n", + "#define GLSLIFY 1\nvarying vec2 vMaskCoord;\nvarying vec2 vTextureCoord;\n\nuniform sampler2D uSampler;\nuniform float alpha;\nuniform sampler2D mask;\n\nvoid main(void)\n{\n // check clip! this will stop the mask bleeding out from the edges\n vec2 text = abs( vMaskCoord - 0.5 );\n text = step(0.5, text);\n float clip = 1.0 - max(text.y, text.x);\n vec4 original = texture2D(uSampler, vTextureCoord);\n vec4 masky = texture2D(mask, vMaskCoord);\n original *= (masky.r * masky.a * alpha * clip);\n gl_FragColor = original;\n}\n" ); - // TEMP HACK + sprite.renderable = false; + this.maskSprite = sprite; + this.maskMatrix = maskMatrix; } -ParticleShader.prototype = Object.create(Shader.prototype); -ParticleShader.prototype.constructor = ParticleShader; - -module.exports = ParticleShader; - -},{"pixi-gl-core":15}],144:[function(require,module,exports){ -// References: -// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign +SpriteMaskFilter.prototype = Object.create(Filter.prototype); +SpriteMaskFilter.prototype.constructor = SpriteMaskFilter; +module.exports = SpriteMaskFilter; -if (!Math.sign) +/** + * Applies the filter + * + * @param filterManager {PIXI.FilterManager} The renderer to retrieve the filter from + * @param input {PIXI.RenderTarget} + * @param output {PIXI.RenderTarget} + */ +SpriteMaskFilter.prototype.apply = function (filterManager, input, output) { - Math.sign = function (x) { - x = +x; - if (x === 0 || isNaN(x)) - { - return x; - } - return x > 0 ? 1 : -1; - }; -} - -},{}],145:[function(require,module,exports){ -// References: -// https://github.com/sindresorhus/object-assign -// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign + var maskSprite = this.maskSprite; -if (!Object.assign) -{ - Object.assign = require('object-assign'); -} - -},{"object-assign":14}],146:[function(require,module,exports){ -require('./Object.assign'); -require('./requestAnimationFrame'); -require('./Math.sign'); + this.uniforms.mask = maskSprite._texture; + this.uniforms.otherMatrix = filterManager.calculateSpriteMatrix(this.maskMatrix, maskSprite ); + this.uniforms.alpha = maskSprite.worldAlpha; -if(!window.ArrayBuffer){ - window.ArrayBuffer = Array; -} -if(!window.Float32Array) { - window.Float32Array = Array; -} -if(!window.Uint32Array){ - window.Uint32Array = Array; -} -if(!window.Uint16Array){ - window.Uint16Array = Array; -} + filterManager.applyFilter(this, input, output); +}; -},{"./Math.sign":144,"./Object.assign":145,"./requestAnimationFrame":147}],147:[function(require,module,exports){ -(function (global){ -// References: -// http://paulirish.com/2011/requestanimationframe-for-smart-animating/ -// https://gist.github.com/1579671 -// http://updates.html5rocks.com/2012/05/requestAnimationFrame-API-now-with-sub-millisecond-precision -// https://gist.github.com/timhall/4078614 -// https://github.com/Financial-Times/polyfill-service/tree/master/polyfills/requestAnimationFrame +},{"../../../../math":66,"../Filter":82}],86:[function(require,module,exports){ -// Expected to be used with Browserfiy -// Browserify automatically detects the use of `global` and passes the -// correct reference of `global`, `self`, and finally `window` +var WebGLManager = require('./WebGLManager'), + RenderTarget = require('../utils/RenderTarget'), + Quad = require('../utils/Quad'), + math = require('../../../math'), + Shader = require('../../../Shader'), + filterTransforms = require('../filters/filterTransforms'), + bitTwiddle = require('bit-twiddle'); -// Date.now -if (!(Date.now && Date.prototype.getTime)) { - Date.now = function now() { - return new Date().getTime(); - }; -} +var FilterState = function() +{ + this.renderTarget = null; + this.sourceFrame = new math.Rectangle(); + this.destinationFrame = new math.Rectangle(); + this.filters = []; + this.target = null; + this.resolution = 1; +}; -// performance.now -if (!(global.performance && global.performance.now)) { - var startTime = Date.now(); - if (!global.performance) { - global.performance = {}; - } - global.performance.now = function () { - return Date.now() - startTime; - }; -} -// requestAnimationFrame -var lastTime = Date.now(); -var vendors = ['ms', 'moz', 'webkit', 'o']; +/** + * @class + * @memberof PIXI + * @extends PIXI.WebGLManager + * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. + */ +function FilterManager(renderer) +{ + WebGLManager.call(this, renderer); -for(var x = 0; x < vendors.length && !global.requestAnimationFrame; ++x) { - global.requestAnimationFrame = global[vendors[x] + 'RequestAnimationFrame']; - global.cancelAnimationFrame = global[vendors[x] + 'CancelAnimationFrame'] || - global[vendors[x] + 'CancelRequestAnimationFrame']; -} + this.gl = this.renderer.gl; + // know about sprites! + this.quad = new Quad(this.gl, renderer.state.attribState); -if (!global.requestAnimationFrame) { - global.requestAnimationFrame = function (callback) { - if (typeof callback !== 'function') { - throw new TypeError(callback + 'is not a function'); - } + this.shaderCache = {}; + // todo add default! + this.pool = {}; +} - var currentTime = Date.now(), - delay = 16 + lastTime - currentTime; +FilterManager.prototype = Object.create(WebGLManager.prototype); +FilterManager.prototype.constructor = FilterManager; +module.exports = FilterManager; - if (delay < 0) { - delay = 0; - } +FilterManager.prototype.pushFilter = function(target, filters) +{ + var renderer = this.renderer; - lastTime = currentTime; + var filterData = this.filterData; - return setTimeout(function () { - lastTime = Date.now(); - callback(performance.now()); - }, delay); - }; -} + if(!filterData) + { + filterData = this.renderer._activeRenderTarget.filterStack; -if (!global.cancelAnimationFrame) { - global.cancelAnimationFrame = function(id) { - clearTimeout(id); - }; -} - -}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{}],148:[function(require,module,exports){ -var async = require('async'), - urlParser = require('url'), - Resource = require('./Resource'), - EventEmitter = require('eventemitter3'); + // add new stack + var filterState = new FilterState(); + filterState.sourceFrame = filterState.destinationFrame = this.renderer._activeRenderTarget.size; + filterState.renderTarget = renderer._activeRenderTarget; -/** - * Manages the state and loading of multiple resources to load. - * - * @class - * @param [baseUrl=''] {string} The base url for all resources loaded by this loader. - * @param [concurrency=10] {number} The number of resources to load concurrently. - */ -function Loader(baseUrl, concurrency) { - EventEmitter.call(this); + this.renderer._activeRenderTarget.filterData = filterData = { + index:0, + stack:[filterState] + }; - concurrency = concurrency || 10; + this.filterData = filterData; + } - /** - * The base url for all resources loaded by this loader. - * - * @member {string} - */ - this.baseUrl = baseUrl || ''; + // get the current filter state.. + var currentState = filterData.stack[++filterData.index]; + if(!currentState) + { + currentState = filterData.stack[filterData.index] = new FilterState(); + } - /** - * The progress percent of the loader going through the queue. - * - * @member {number} - */ - this.progress = 0; + // for now we go off the filter of the first resolution.. + var resolution = filters[0].resolution; + var padding = filters[0].padding; + var targetBounds = target.filterArea || target.getBounds(true); + var sourceFrame = currentState.sourceFrame; + var destinationFrame = currentState.destinationFrame; - /** - * Loading state of the loader, true if it is currently loading resources. - * - * @member {boolean} - */ - this.loading = false; + sourceFrame.x = (((targetBounds.x - padding) * resolution) | 0) / resolution; + sourceFrame.y = (((targetBounds.y - padding) * resolution) | 0) / resolution; + sourceFrame.width = (((targetBounds.width + padding*2) * resolution) | 0) / resolution; + sourceFrame.height = (((targetBounds.height + padding*2)* resolution) | 0) / resolution; - /** - * The percentage of total progress that a single resource represents. - * - * @member {number} - */ - this._progressChunk = 0; + if(filterData.stack[0].renderTarget.transform) + {//jshint ignore:line - /** - * The middleware to run before loading each resource. - * - * @member {function[]} - */ - this._beforeMiddleware = []; + // TODO we should fit the rect around the transform.. - /** - * The middleware to run after loading each resource. - * - * @member {function[]} - */ - this._afterMiddleware = []; + } + else + { + sourceFrame.fit(filterData.stack[0].destinationFrame); + } - /** - * The `_loadResource` function bound with this object context. - * - * @private - * @member {function} - */ - this._boundLoadResource = this._loadResource.bind(this); + destinationFrame.width = sourceFrame.width; + destinationFrame.height = sourceFrame.height; - /** - * The `_onLoad` function bound with this object context. - * - * @private - * @member {function} - */ - this._boundOnLoad = this._onLoad.bind(this); + var renderTarget = this.getPotRenderTarget(renderer.gl, sourceFrame.width, sourceFrame.height, resolution); - /** - * The resource buffer that fills until `load` is called to start loading resources. - * - * @private - * @member {Resource[]} - */ - this._buffer = []; + currentState.target = target; + currentState.filters = filters; + currentState.resolution = resolution; + currentState.renderTarget = renderTarget; - /** - * Used to track load completion. - * - * @private - * @member {number} - */ - this._numToLoad = 0; + // bind the render taget to draw the shape in the top corner.. - /** - * The resources waiting to be loaded. - * - * @private - * @member {Resource[]} - */ - this._queue = async.queue(this._boundLoadResource, concurrency); + renderTarget.setFrame(destinationFrame, sourceFrame); + // bind the render target + renderer.bindRenderTarget(renderTarget); - /** - * All the resources for this loader keyed by name. - * - * @member {object} - */ - this.resources = {}; + // clear the renderTarget + renderer.clear();//[0.5,0.5,0.5, 1.0]); +}; - /** - * Emitted once per loaded or errored resource. - * - * @event progress - * @memberof Loader# - */ +FilterManager.prototype.popFilter = function() +{ + var filterData = this.filterData; - /** - * Emitted once per errored resource. - * - * @event error - * @memberof Loader# - */ + var lastState = filterData.stack[filterData.index-1]; + var currentState = filterData.stack[filterData.index]; - /** - * Emitted once per loaded resource. - * - * @event load - * @memberof Loader# - */ + this.quad.map(currentState.renderTarget.size, currentState.sourceFrame).upload(); - /** - * Emitted when the loader begins to process the queue. - * - * @event start - * @memberof Loader# - */ + var filters = currentState.filters; - /** - * Emitted when the queued resources all load. - * - * @event complete - * @memberof Loader# - */ -} + if(filters.length === 1) + { + filters[0].apply(this, currentState.renderTarget, lastState.renderTarget, false); + this.freePotRenderTarget(currentState.renderTarget); + } + else + { + var flip = currentState.renderTarget; + var flop = this.getPotRenderTarget(this.renderer.gl, currentState.sourceFrame.width, currentState.sourceFrame.height, 1); + flop.setFrame(currentState.destinationFrame, currentState.sourceFrame); -Loader.prototype = Object.create(EventEmitter.prototype); -Loader.prototype.constructor = Loader; -module.exports = Loader; + for (var i = 0; i < filters.length-1; i++) + { + filters[i].apply(this, flip, flop, true); -/** - * Adds a resource (or multiple resources) to the loader queue. - * - * This function can take a wide variety of different parameters. The only thing that is always - * required the url to load. All the following will work: - * - * ```js - * loader - * // normal param syntax - * .add('key', 'http://...', function () {}) - * .add('http://...', function () {}) - * .add('http://...') - * - * // object syntax - * .add({ - * name: 'key2', - * url: 'http://...' - * }, function () {}) - * .add({ - * url: 'http://...' - * }, function () {}) - * .add({ - * name: 'key3', - * url: 'http://...' - * onComplete: function () {} - * }) - * .add({ - * url: 'https://...', - * onComplete: function () {}, - * crossOrigin: true - * }) - * - * // you can also pass an array of objects or urls or both - * .add([ - * { name: 'key4', url: 'http://...', onComplete: function () {} }, - * { url: 'http://...', onComplete: function () {} }, - * 'http://...' - * ]); - * ``` - * - * @alias enqueue - * @param [name] {string} The name of the resource to load, if not passed the url is used. - * @param url {string} The url for this resource, relative to the baseUrl of this loader. - * @param [options] {object} The options for the load. - * @param [options.crossOrigin] {boolean} Is this request cross-origin? Default is to determine automatically. - * @param [options.loadType=Resource.LOAD_TYPE.XHR] {Resource.XHR_LOAD_TYPE} How should this resource be loaded? - * @param [options.xhrType=Resource.XHR_RESPONSE_TYPE.DEFAULT] {Resource.XHR_RESPONSE_TYPE} How should the data being - * loaded be interpreted when using XHR? - * @param [callback] {function} Function to call when this specific resource completes loading. - * @return {Loader} - */ -Loader.prototype.add = Loader.prototype.enqueue = function (name, url, options, cb) { - // special case of an array of objects or urls - if (Array.isArray(name)) { - for (var i = 0; i < name.length; ++i) { - this.add(name[i]); + var t = flip; + flip = flop; + flop = t; } - return this; - } + filters[i].apply(this, flip, lastState.renderTarget, false); - // if an object is passed instead of params - if (typeof name === 'object') { - cb = url || name.callback || name.onComplete; - options = name; - url = name.url; - name = name.name || name.key || name.url; + this.freePotRenderTarget(flip); + this.freePotRenderTarget(flop); } - // case where no name is passed shift all args over by one. - if (typeof url !== 'string') { - cb = options; - options = url; - url = name; - } + filterData.index--; - // now that we shifted make sure we have a proper url. - if (typeof url !== 'string') { - throw new Error('No url passed to add resource to loader.'); + if(filterData.index === 0) + { + this.filterData = null; } +}; - // options are optional so people might pass a function and no options - if (typeof options === 'function') { - cb = options; - options = null; - } +FilterManager.prototype.applyFilter = function (filter, input, output, clear) +{ + var renderer = this.renderer; + var shader = filter.glShaders[renderer.CONTEXT_UID]; + + // cacheing.. + if(!shader) + { + if(filter.glShaderKey) + { + shader = this.shaderCache[filter.glShaderKey]; - // check if resource already exists. - if (this.resources[name]) { - throw new Error('Resource with name "' + name + '" already exists.'); + if(!shader) + { + shader = filter.glShaders[renderer.CONTEXT_UID] = this.shaderCache[filter.glShaderKey] = new Shader(this.gl, filter.vertexSrc, filter.fragmentSrc); + } + } + else + { + shader = filter.glShaders[renderer.CONTEXT_UID] = new Shader(this.gl, filter.vertexSrc, filter.fragmentSrc); + } + + //TODO - this only needs to be done once? + this.quad.initVao(shader); } - // add base url if this isn't an absolute url - url = this._handleBaseUrl(url); + renderer.bindRenderTarget(output); - // create the store the resource - this.resources[name] = new Resource(name, url, options); - if (typeof cb === 'function') { - this.resources[name].once('afterMiddleware', cb); - } - this._numToLoad++; + if(clear) + { + var gl = renderer.gl; - // if already loading add it to the worker queue - if (this._queue.started) { - this._queue.push(this.resources[name]); - this._progressChunk = (100 - this.progress) / (this._queue.length() + this._queue.running()); + gl.disable(gl.SCISSOR_TEST); + renderer.clear();//[1, 1, 1, 1]); + gl.enable(gl.SCISSOR_TEST); } - // otherwise buffer it to be added to the queue later - else { - this._buffer.push(this.resources[name]); - this._progressChunk = 100 / this._buffer.length; + + // in case the render target is being masked using a scissor rect + if(output === renderer.maskManager.scissorRenderTarget) + { + renderer.maskManager.pushScissorMask(null, renderer.maskManager.scissorData); } - return this; + renderer.bindShader(shader); + + // this syncs the pixi filters uniforms with glsl uniforms + this.syncUniforms(shader, filter); + + // bind the input texture.. + input.texture.bind(0); + // when you manually bind a texture, please switch active texture location to it + renderer._activeTextureLocation = 0; + + renderer.state.setBlendMode( filter.blendMode ); + + this.quad.draw(); }; -Loader.prototype._handleBaseUrl = function (url) { - var parsedUrl = urlParser.parse(url); +// this returns a matrix that will normalise map filter cords in the filter to screen space +FilterManager.prototype.syncUniforms = function (shader, filter) +{ + var uniformData = filter.uniformData; + var uniforms = filter.uniforms; + + // 0 is reserverd for the pixi texture so we start at 1! + var textureCount = 1; + var currentState; + + if(shader.uniforms.data.filterArea) + { + currentState = this.filterData.stack[this.filterData.index]; + var filterArea = shader.uniforms.filterArea; + + filterArea[0] = currentState.renderTarget.size.width; + filterArea[1] = currentState.renderTarget.size.height; + filterArea[2] = currentState.sourceFrame.x; + filterArea[3] = currentState.sourceFrame.y; - // absolute url, just use it as is. - if (parsedUrl.protocol || parsedUrl.pathname.indexOf('//') === 0) { - return url; + shader.uniforms.filterArea = filterArea; } - // if baseUrl doesn't end in slash and url doesn't start with slash, then add a slash inbetween - if ( - this.baseUrl.length && - this.baseUrl.lastIndexOf('/') !== this.baseUrl.length - 1 && - url.charAt(0) !== '/' - ) { - return this.baseUrl + '/' + url; + // use this to clamp displaced texture coords so they belong to filterArea + // see displacementFilter fragment shader for an example + if(shader.uniforms.data.filterClamp) + { + currentState = this.filterData.stack[this.filterData.index]; + var filterClamp = shader.uniforms.filterClamp; + + filterClamp[0] = 0.5 / currentState.renderTarget.size.width; + filterClamp[1] = 0.5 / currentState.renderTarget.size.height; + filterClamp[2] = (currentState.sourceFrame.width - 0.5) / currentState.renderTarget.size.width; + filterClamp[3] = (currentState.sourceFrame.height - 0.5) / currentState.renderTarget.size.height; + + shader.uniforms.filterClamp = filterClamp; } - else { - return this.baseUrl + url; + + var val; + //TODO Cacheing layer.. + for(var i in uniformData) + { + if(uniformData[i].type === 'sampler2D') + { + shader.uniforms[i] = textureCount; + this.renderer.bindTexture(uniforms[i].baseTexture, textureCount); + + textureCount++; + } + else if(uniformData[i].type === 'mat3') + { + // check if its pixi matrix.. + if(uniforms[i].a !== undefined) + { + shader.uniforms[i] = uniforms[i].toArray(true); + } + else + { + shader.uniforms[i] = uniforms[i]; + } + } + else if(uniformData[i].type === 'vec2') + { + //check if its a point.. + if(uniforms[i].x !== undefined) + { + val = shader.uniforms[i] || new Float32Array(2); + val[0] = uniforms[i].x; + val[1] = uniforms[i].y; + shader.uniforms[i] = val; + } + else + { + shader.uniforms[i] = uniforms[i]; + } + } + else if(uniformData[i].type === 'float') + { + if(shader.uniforms.data[i].value !== uniformData[i]) + { + shader.uniforms[i] = uniforms[i]; + } + } + else + { + shader.uniforms[i] = uniforms[i]; + } } }; -/** - * Sets up a middleware function that will run *before* the - * resource is loaded. - * - * @alias pre - * @param middleware {function} The middleware function to register. - * @return {Loader} - */ -Loader.prototype.before = Loader.prototype.pre = function (fn) { - this._beforeMiddleware.push(fn); +FilterManager.prototype.getRenderTarget = function() +{ + var currentState = this.filterData.stack[this.filterData.index]; + var renderTarget = this.getPotRenderTarget(this.renderer.gl, currentState.sourceFrame.width, currentState.sourceFrame.height, currentState.resolution); + renderTarget.setFrame(currentState.destinationFrame, currentState.sourceFrame); - return this; + return renderTarget; +}; + +FilterManager.prototype.returnRenderTarget = function(renderTarget) +{ + return this.freePotRenderTarget(renderTarget); +}; + +/* + * Calculates the mapped matrix + * @param filterArea {Rectangle} The filter area + * @param sprite {Sprite} the target sprite + * @param outputMatrix {Matrix} @alvin + */ +// TODO playing around here.. this is temporary - (will end up in the shader) +// thia returns a matrix that will normalise map filter cords in the filter to screen space +FilterManager.prototype.calculateScreenSpaceMatrix = function (outputMatrix) +{ + var currentState = this.filterData.stack[this.filterData.index]; + return filterTransforms.calculateScreenSpaceMatrix(outputMatrix, currentState.sourceFrame, currentState.renderTarget.size); }; /** - * Sets up a middleware function that will run *after* the - * resource is loaded. + * Multiply vTextureCoord to this matrix to achieve (0,0,1,1) for filterArea * - * @alias use - * @param middleware {function} The middleware function to register. - * @return {Loader} + * @param outputMatrix {PIXI.Matrix} */ -Loader.prototype.after = Loader.prototype.use = function (fn) { - this._afterMiddleware.push(fn); +FilterManager.prototype.calculateNormalizedScreenSpaceMatrix = function (outputMatrix) +{ + var currentState = this.filterData.stack[this.filterData.index]; - return this; + return filterTransforms.calculateNormalizedScreenSpaceMatrix(outputMatrix, currentState.sourceFrame, currentState.renderTarget.size, currentState.destinationFrame); +}; + +// this will map the filter coord so that a texture can be used based on the transform of a sprite +FilterManager.prototype.calculateSpriteMatrix = function (outputMatrix, sprite) +{ + var currentState = this.filterData.stack[this.filterData.index]; + return filterTransforms.calculateSpriteMatrix(outputMatrix, currentState.sourceFrame, currentState.renderTarget.size, sprite); +}; + +FilterManager.prototype.destroy = function() +{ + this.shaderCache = []; + this.emptyPool(); +}; + + + +//TODO move to a seperate class could be on renderer? +//also - could cause issue with multiple contexts? +FilterManager.prototype.getPotRenderTarget = function(gl, minWidth, minHeight, resolution) +{ + //TODO you coud return a bigger texture if there is not one in the pool? + minWidth = bitTwiddle.nextPow2(minWidth * resolution); + minHeight = bitTwiddle.nextPow2(minHeight * resolution); + + var key = ((minWidth & 0xFFFF) << 16) | ( minHeight & 0xFFFF); + + // console.log(minWidth + " " + minHeight) + if(!this.pool[key]) { + this.pool[key] = []; + } + + var renderTarget = this.pool[key].pop() || new RenderTarget(gl, minWidth, minHeight, null, 1); + + //manually tweak the resolution... + //this will not modify the size of the frame buffer, just its resolution. + renderTarget.resolution = resolution; + renderTarget.defaultFrame.width = renderTarget.size.width = minWidth / resolution; + renderTarget.defaultFrame.height = renderTarget.size.height = minHeight / resolution; + return renderTarget; +}; + +FilterManager.prototype.emptyPool = function() +{ + for (var i in this.pool) + { + var textures = this.pool[i]; + if(textures) + { + for (var j = 0; j < textures.length; j++) + { + textures[j].destroy(true); + } + } + } + + this.pool = {}; +}; + +FilterManager.prototype.freePotRenderTarget = function(renderTarget) +{ + var minWidth = renderTarget.size.width * renderTarget.resolution; + var minHeight = renderTarget.size.height * renderTarget.resolution; + + var key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); + this.pool[key].push(renderTarget); }; + +},{"../../../Shader":41,"../../../math":66,"../filters/filterTransforms":84,"../utils/Quad":91,"../utils/RenderTarget":92,"./WebGLManager":89,"bit-twiddle":2}],87:[function(require,module,exports){ +var WebGLManager = require('./WebGLManager'), + AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); /** - * Resets the queue of the loader to prepare for a new load. - * - * @return {Loader} + * @class + * @memberof PIXI + * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -Loader.prototype.reset = function () { - // this.baseUrl = baseUrl || ''; +function MaskManager(renderer) +{ + WebGLManager.call(this, renderer); - this.progress = 0; + //TODO - we don't need both! + this.scissor = false; + this.scissorData = null; + this.scissorRenderTarget = null; - this.loading = false; + this.enableScissor = true; - this._progressChunk = 0; + this.alphaMaskPool = []; + this.alphaMaskIndex = 0; +} - // this._beforeMiddleware.length = 0; - // this._afterMiddleware.length = 0; +MaskManager.prototype = Object.create(WebGLManager.prototype); +MaskManager.prototype.constructor = MaskManager; +module.exports = MaskManager; - this._buffer.length = 0; +/** + * Applies the Mask and adds it to the current filter stack. + * + * @param target {PIXI.DisplayObject} Display Object to push the mask to + * @param maskData {PIXI.Sprite|PIXI.Graphics} + */ +MaskManager.prototype.pushMask = function (target, maskData) +{ + if (maskData.texture) + { + this.pushSpriteMask(target, maskData); + } + else + { + if(this.enableScissor && !this.scissor && !this.renderer.stencilManager.stencilMaskStack.length && maskData.isFastRect()) + { + var matrix = maskData.worldTransform; - this._numToLoad = 0; + var rot = Math.atan2(matrix.b, matrix.a); - this._queue.kill(); - this._queue.started = false; + // use the nearest degree! + rot = Math.round(rot * (180/Math.PI)); - this.resources = {}; + if(rot % 90) + { + this.pushStencilMask(maskData); + } + else + { + this.pushScissorMask(target, maskData); + } + } + else + { + this.pushStencilMask(maskData); + } + } }; /** - * Starts loading the queued resources. + * Removes the last mask from the mask stack and doesn't return it. * - * @fires start - * @param [callback] {function} Optional callback that will be bound to the `complete` event. - * @return {Loader} + * @param target {PIXI.DisplayObject} Display Object to pop the mask from + * @param maskData {Array<*>} */ -Loader.prototype.load = function (cb) { - // register complete callback if they pass one - if (typeof cb === 'function') { - this.once('complete', cb); +MaskManager.prototype.popMask = function (target, maskData) +{ + if (maskData.texture) + { + this.popSpriteMask(target, maskData); } + else + { + if(this.enableScissor && !this.renderer.stencilManager.stencilMaskStack.length) + { + this.popScissorMask(target, maskData); + } + else + { + this.popStencilMask(target, maskData); + } - // if the queue has already started we are done here - if (this._queue.started) { - return this; } +}; - // notify of start - this.emit('start', this); +/** + * Applies the Mask and adds it to the current filter stack. + * + * @param target {PIXI.RenderTarget} Display Object to push the sprite mask to + * @param maskData {PIXI.Sprite} Sprite to be used as the mask + */ +MaskManager.prototype.pushSpriteMask = function (target, maskData) +{ + var alphaMaskFilter = this.alphaMaskPool[this.alphaMaskIndex]; - // start the internal queue - for (var i = 0; i < this._buffer.length; ++i) { - this._queue.push(this._buffer[i]); + if (!alphaMaskFilter) + { + alphaMaskFilter = this.alphaMaskPool[this.alphaMaskIndex] = [new AlphaMaskFilter(maskData)]; } - // empty the buffer - this._buffer.length = 0; + alphaMaskFilter[0].resolution = this.renderer.resolution; + alphaMaskFilter[0].maskSprite = maskData; + + //TODO - may cause issues! + target.filterArea = maskData.getBounds(true); - return this; + this.renderer.filterManager.pushFilter(target, alphaMaskFilter); + + this.alphaMaskIndex++; }; /** - * Loads a single resource. + * Removes the last filter from the filter stack and doesn't return it. * - * @fires progress - * @private */ -Loader.prototype._loadResource = function (resource, dequeue) { - var self = this; - - resource._dequeue = dequeue; +MaskManager.prototype.popSpriteMask = function () +{ + this.renderer.filterManager.popFilter(); + this.alphaMaskIndex--; +}; - this._runMiddleware(resource, this._beforeMiddleware, function () { - // resource.on('progress', self.emit.bind(self, 'progress')); - resource.load(self._boundOnLoad); - }); +/** + * Applies the Mask and adds it to the current filter stack. + * + * @param maskData {Array<*>} + */ +MaskManager.prototype.pushStencilMask = function (maskData) +{ + this.renderer.currentRenderer.stop(); + this.renderer.stencilManager.pushStencil(maskData); }; /** - * Called once each resource has loaded. + * Removes the last filter from the filter stack and doesn't return it. * - * @fires complete - * @private */ -Loader.prototype._onComplete = function () { - this.emit('complete', this, this.resources); +MaskManager.prototype.popStencilMask = function () +{ + this.renderer.currentRenderer.stop(); + this.renderer.stencilManager.popStencil(); }; /** - * Called each time a resources is loaded. * - * @fires progress - * @fires error - * @fires load - * @private + * @param target {PIXI.RenderTarget} Display Object to push the scissor mask to + * @param maskData */ -Loader.prototype._onLoad = function (resource) { - this.progress += this._progressChunk; +MaskManager.prototype.pushScissorMask = function (target, maskData) +{ + maskData.renderable = true; - this.emit('progress', this, resource); + var renderTarget = this.renderer._activeRenderTarget; - // run middleware, this *must* happen before dequeue so sub-assets get added properly - this._runMiddleware(resource, this._afterMiddleware, function () { - resource.emit('afterMiddleware', resource); + var bounds = maskData.getBounds(); - this._numToLoad--; + bounds.fit(renderTarget.size); + maskData.renderable = false; - // do completion check - if (this._numToLoad === 0) { - this.progress = 100; - this._onComplete(); - } - - if (resource.error) { - this.emit('error', resource.error, this, resource); - } - else { - this.emit('load', this, resource); - } - }); - + this.renderer.gl.enable(this.renderer.gl.SCISSOR_TEST); + var resolution = this.renderer.resolution; + this.renderer.gl.scissor(bounds.x * resolution, + (renderTarget.root ? renderTarget.size.height - bounds.y - bounds.height : bounds.y) * resolution, + bounds.width * resolution, + bounds.height * resolution); - // remove this resource from the async queue - resource._dequeue(); + this.scissorRenderTarget = renderTarget; + this.scissorData = maskData; + this.scissor = true; }; /** - * Run middleware functions on a resource. * - * @private + * */ -Loader.prototype._runMiddleware = function (resource, fns, cb) { - var self = this; +MaskManager.prototype.popScissorMask = function () +{ + this.scissorRenderTarget = null; + this.scissorData = null; + this.scissor = false; - async.eachSeries(fns, function (fn, next) { - fn.call(self, resource, next); - }, cb.bind(this, resource)); + // must be scissor! + var gl = this.renderer.gl; + gl.disable(gl.SCISSOR_TEST); }; - -Loader.LOAD_TYPE = Resource.LOAD_TYPE; -Loader.XHR_READY_STATE = Resource.XHR_READY_STATE; -Loader.XHR_RESPONSE_TYPE = Resource.XHR_RESPONSE_TYPE; - -},{"./Resource":149,"async":1,"eventemitter3":2,"url":10}],149:[function(require,module,exports){ -var EventEmitter = require('eventemitter3'), - _url = require('url'), - // tests is CORS is supported in XHR, if not we need to use XDR - useXdr = !!(window.XDomainRequest && !('withCredentials' in (new XMLHttpRequest()))), - tempAnchor = null; - -/** - * Manages the state and loading of a single resource represented by - * a single URL. - * - * @class - * @param name {string} The name of the resource to load. - * @param url {string|string[]} The url for this resource, for audio/video loads you can pass an array of sources. - * @param [options] {object} The options for the load. - * @param [options.crossOrigin] {string|boolean} Is this request cross-origin? Default is to determine automatically. - * @param [options.loadType=Resource.LOAD_TYPE.XHR] {Resource.LOAD_TYPE} How should this resource be loaded? - * @param [options.xhrType=Resource.XHR_RESPONSE_TYPE.DEFAULT] {Resource.XHR_RESPONSE_TYPE} How should the data being - * loaded be interpreted when using XHR? - * @param [options.metadata] {object} Extra info for middleware. - */ -function Resource(name, url, options) { - EventEmitter.call(this); - - options = options || {}; - - if (typeof name !== 'string' || typeof url !== 'string') { - throw new Error('Both name and url are required for constructing a resource.'); - } - - /** - * The name of this resource. - * - * @member {string} - * @readonly - */ - this.name = name; - - /** - * The url used to load this resource. - * - * @member {string} - * @readonly - */ - this.url = url; - - /** - * Stores whether or not this url is a data url. - * - * @member {boolean} - * @readonly - */ - this.isDataUrl = this.url.indexOf('data:') === 0; - - /** - * The data that was loaded by the resource. - * - * @member {any} - */ - this.data = null; - - /** - * Is this request cross-origin? If unset, determined automatically. - * - * @member {string} - */ - this.crossOrigin = options.crossOrigin === true ? 'anonymous' : options.crossOrigin; - - /** - * The method of loading to use for this resource. - * - * @member {Resource.LOAD_TYPE} - */ - this.loadType = options.loadType || this._determineLoadType(); - - /** - * The type used to load the resource via XHR. If unset, determined automatically. - * - * @member {string} - */ - this.xhrType = options.xhrType; - - /** - * Extra info for middleware - * - * @member {object} - */ - this.metadata = options.metadata || {}; - - /** - * The error that occurred while loading (if any). - * - * @member {Error} - * @readonly - */ - this.error = null; - - /** - * The XHR object that was used to load this resource. This is only set - * when `loadType` is `Resource.LOAD_TYPE.XHR`. - * - * @member {XMLHttpRequest} - */ - this.xhr = null; - - /** - * Describes if this resource was loaded as json. Only valid after the resource - * has completely loaded. - * - * @member {boolean} - */ - this.isJson = false; - - /** - * Describes if this resource was loaded as xml. Only valid after the resource - * has completely loaded. - * - * @member {boolean} - */ - this.isXml = false; - - /** - * Describes if this resource was loaded as an image tag. Only valid after the resource - * has completely loaded. - * - * @member {boolean} - */ - this.isImage = false; - - /** - * Describes if this resource was loaded as an audio tag. Only valid after the resource - * has completely loaded. - * - * @member {boolean} - */ - this.isAudio = false; - - /** - * Describes if this resource was loaded as a video tag. Only valid after the resource - * has completely loaded. - * - * @member {boolean} - */ - this.isVideo = false; - - /** - * The `dequeue` method that will be used a storage place for the async queue dequeue method - * used privately by the loader. - * - * @member {function} - * @private - */ - this._dequeue = null; - - /** - * The `complete` function bound to this resource's context. - * - * @member {function} - * @private - */ - this._boundComplete = this.complete.bind(this); - - /** - * The `_onError` function bound to this resource's context. - * - * @member {function} - * @private - */ - this._boundOnError = this._onError.bind(this); - - /** - * The `_onProgress` function bound to this resource's context. - * - * @member {function} - * @private - */ - this._boundOnProgress = this._onProgress.bind(this); - - // xhr callbacks - this._boundXhrOnError = this._xhrOnError.bind(this); - this._boundXhrOnAbort = this._xhrOnAbort.bind(this); - this._boundXhrOnLoad = this._xhrOnLoad.bind(this); - this._boundXdrOnTimeout = this._xdrOnTimeout.bind(this); - - /** - * Emitted when the resource beings to load. - * - * @event start - * @memberof Resource# - */ - - /** - * Emitted each time progress of this resource load updates. - * Not all resources types and loader systems can support this event - * so sometimes it may not be available. If the resource - * is being loaded on a modern browser, using XHR, and the remote server - * properly sets Content-Length headers, then this will be available. - * - * @event progress - * @memberof Resource# - */ - - /** - * Emitted once this resource has loaded, if there was an error it will - * be in the `error` property. - * - * @event complete - * @memberof Resource# - */ -} - -Resource.prototype = Object.create(EventEmitter.prototype); -Resource.prototype.constructor = Resource; -module.exports = Resource; - -/** - * Marks the resource as complete. - * - * @fires complete - */ -Resource.prototype.complete = function () { - // TODO: Clean this up in a wrapper or something...gross.... - if (this.data && this.data.removeEventListener) { - this.data.removeEventListener('error', this._boundOnError); - this.data.removeEventListener('load', this._boundComplete); - this.data.removeEventListener('progress', this._boundOnProgress); - this.data.removeEventListener('canplaythrough', this._boundComplete); - } - if (this.xhr) { - if (this.xhr.removeEventListener) { - this.xhr.removeEventListener('error', this._boundXhrOnError); - this.xhr.removeEventListener('abort', this._boundXhrOnAbort); - this.xhr.removeEventListener('progress', this._boundOnProgress); - this.xhr.removeEventListener('load', this._boundXhrOnLoad); - } - else { - this.xhr.onerror = null; - this.xhr.ontimeout = null; - this.xhr.onprogress = null; - this.xhr.onload = null; - } - } - - this.emit('complete', this); -}; +},{"../filters/spriteMask/SpriteMaskFilter":85,"./WebGLManager":89}],88:[function(require,module,exports){ +var WebGLManager = require('./WebGLManager'); + +/** + * @class + * @memberof PIXI + * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. + */ +function StencilManager(renderer) +{ + WebGLManager.call(this, renderer); + this.stencilMaskStack = null; +} + +StencilManager.prototype = Object.create(WebGLManager.prototype); +StencilManager.prototype.constructor = StencilManager; +module.exports = StencilManager; + +/** + * Changes the mask stack that is used by this manager. + * + * @param stencilMaskStack {PIXI.Graphics[]} The mask stack + */ +StencilManager.prototype.setMaskStack = function ( stencilMaskStack ) +{ + this.stencilMaskStack = stencilMaskStack; + + var gl = this.renderer.gl; + + if (stencilMaskStack.length === 0) + { + gl.disable(gl.STENCIL_TEST); + } + else + { + gl.enable(gl.STENCIL_TEST); + } +}; + +/** + * Applies the Mask and adds it to the current filter stack. @alvin + * + * @param graphics {PIXI.Graphics} + */ +StencilManager.prototype.pushStencil = function (graphics) +{ + this.renderer.setObjectRenderer(this.renderer.plugins.graphics); + + this.renderer._activeRenderTarget.attachStencilBuffer(); + + var gl = this.renderer.gl, + sms = this.stencilMaskStack; + + if (sms.length === 0) + { + gl.enable(gl.STENCIL_TEST); + gl.clear(gl.STENCIL_BUFFER_BIT); + gl.stencilFunc(gl.ALWAYS,1,1); + } + + sms.push(graphics); + + gl.colorMask(false, false, false, false); + gl.stencilOp(gl.KEEP,gl.KEEP,gl.INCR); + + this.renderer.plugins.graphics.render(graphics); + + gl.colorMask(true, true, true, true); + gl.stencilFunc(gl.NOTEQUAL,0, sms.length); + gl.stencilOp(gl.KEEP,gl.KEEP,gl.KEEP); +}; + +/** + * TODO @alvin + */ +StencilManager.prototype.popStencil = function () +{ + this.renderer.setObjectRenderer(this.renderer.plugins.graphics); + + var gl = this.renderer.gl, + sms = this.stencilMaskStack; + + var graphics = sms.pop(); + + if (sms.length === 0) + { + // the stack is empty! + gl.disable(gl.STENCIL_TEST); + } + else + { + gl.colorMask(false, false, false, false); + gl.stencilOp(gl.KEEP,gl.KEEP,gl.DECR); + + this.renderer.plugins.graphics.render(graphics); + + gl.colorMask(true, true, true, true); + gl.stencilFunc(gl.NOTEQUAL, 0, sms.length); + gl.stencilOp(gl.KEEP,gl.KEEP,gl.KEEP); + } +}; + +/** + * Destroys the mask stack. + * + */ +StencilManager.prototype.destroy = function () +{ + WebGLManager.prototype.destroy.call(this); + + this.stencilMaskStack.stencilStack = null; +}; -/** - * Kicks off loading of this resource. - * - * @fires start - * @param [callback] {function} Optional callback to call once the resource is loaded. - */ -Resource.prototype.load = function (cb) { - this.emit('start', this); +},{"./WebGLManager":89}],89:[function(require,module,exports){ +/** + * @class + * @memberof PIXI + * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. + */ +function WebGLManager(renderer) +{ + /** + * The renderer this manager works for. + * + * @member {PIXI.WebGLRenderer} + */ + this.renderer = renderer; + + this.renderer.on('context', this.onContextChange, this); +} + +WebGLManager.prototype.constructor = WebGLManager; +module.exports = WebGLManager; + +/** + * Generic method called when there is a WebGL context change. + * + */ +WebGLManager.prototype.onContextChange = function () +{ + // do some codes init! +}; + +/** + * Generic destroy methods to be overridden by the subclass + * + */ +WebGLManager.prototype.destroy = function () +{ + this.renderer.off('context', this.onContextChange, this); + + this.renderer = null; +}; - // if a callback is set, listen for complete event - if (cb) { - this.once('complete', cb); - } +},{}],90:[function(require,module,exports){ +var WebGLManager = require('../managers/WebGLManager'); + +/** + * Base for a common object renderer that can be used as a system renderer plugin. + * + * @class + * @extends PIXI.WebGLManager + * @memberof PIXI + * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. + */ +function ObjectRenderer(renderer) +{ + WebGLManager.call(this, renderer); +} + + +ObjectRenderer.prototype = Object.create(WebGLManager.prototype); +ObjectRenderer.prototype.constructor = ObjectRenderer; +module.exports = ObjectRenderer; + +/** + * Starts the renderer and sets the shader + * + */ +ObjectRenderer.prototype.start = function () +{ + // set the shader.. +}; + +/** + * Stops the renderer + * + */ +ObjectRenderer.prototype.stop = function () +{ + this.flush(); +}; + +/** + * Stub method for rendering content and emptying the current batch. + * + */ +ObjectRenderer.prototype.flush = function () +{ + // flush! +}; + +/** + * Renders an object + * + * @param object {PIXI.DisplayObject} The object to render. + */ +ObjectRenderer.prototype.render = function (object) // jshint unused:false +{ + // render the object +}; - // if unset, determine the value - if (this.crossOrigin === false || typeof this.crossOrigin !== 'string') { - this.crossOrigin = this._determineCrossOrigin(this.url); - } +},{"../managers/WebGLManager":89}],91:[function(require,module,exports){ +var glCore = require('pixi-gl-core'), + createIndicesForQuads = require('../../../utils/createIndicesForQuads'); + +/** + * Helper class to create a quad + * + * @class + * @memberof PIXI + * @param gl {WebGLRenderingContext} The gl context for this quad to use. + * @param state {object} TODO: Description + */ +function Quad(gl, state) +{ + /* + * the current WebGL drawing context + * + * @member {WebGLRenderingContext} + */ + this.gl = gl; + + /** + * An array of vertices + * + * @member {Float32Array} + */ + this.vertices = new Float32Array([ + -1,-1, + 1,-1, + 1,1, + -1,1 + ]); + + /** + * The Uvs of the quad + * + * @member {Float32Array} + */ + this.uvs = new Float32Array([ + 0,0, + 1,0, + 1,1, + 0,1 + ]); + + this.interleaved = new Float32Array(8 * 2); + + for (var i = 0; i < 4; i++) { + this.interleaved[i*4] = this.vertices[(i*2)]; + this.interleaved[(i*4)+1] = this.vertices[(i*2)+1]; + this.interleaved[(i*4)+2] = this.uvs[i*2]; + this.interleaved[(i*4)+3] = this.uvs[(i*2)+1]; + } + + /* + * @member {Uint16Array} An array containing the indices of the vertices + */ + this.indices = createIndicesForQuads(1); + + /* + * @member {glCore.GLBuffer} The vertex buffer + */ + this.vertexBuffer = glCore.GLBuffer.createVertexBuffer(gl, this.interleaved, gl.STATIC_DRAW); + + /* + * @member {glCore.GLBuffer} The index buffer + */ + this.indexBuffer = glCore.GLBuffer.createIndexBuffer(gl, this.indices, gl.STATIC_DRAW); + + /* + * @member {glCore.VertexArrayObject} The index buffer + */ + this.vao = new glCore.VertexArrayObject(gl, state); + +} + +Quad.prototype.constructor = Quad; + +/** + * Initialises the vaos and uses the shader + * @param shader {PIXI.Shader} the shader to use + */ +Quad.prototype.initVao = function(shader) +{ + this.vao.clear() + .addIndex(this.indexBuffer) + .addAttribute(this.vertexBuffer, shader.attributes.aVertexPosition, this.gl.FLOAT, false, 4 * 4, 0) + .addAttribute(this.vertexBuffer, shader.attributes.aTextureCoord, this.gl.FLOAT, false, 4 * 4, 2 * 4); +}; + +/** + * Maps two Rectangle to the quad + * @param targetTextureFrame {PIXI.Rectangle} the first rectangle + * @param destinationFrame {PIXI.Rectangle} the second rectangle + */ +Quad.prototype.map = function(targetTextureFrame, destinationFrame) +{ + var x = 0; //destinationFrame.x / targetTextureFrame.width; + var y = 0; //destinationFrame.y / targetTextureFrame.height; + + this.uvs[0] = x; + this.uvs[1] = y; + + this.uvs[2] = x + destinationFrame.width / targetTextureFrame.width; + this.uvs[3] = y; + + this.uvs[4] = x + destinationFrame.width / targetTextureFrame.width; + this.uvs[5] = y + destinationFrame.height / targetTextureFrame.height; + + this.uvs[6] = x; + this.uvs[7] = y + destinationFrame.height / targetTextureFrame.height; + + /// ----- + x = destinationFrame.x; + y = destinationFrame.y; + + this.vertices[0] = x; + this.vertices[1] = y; + + this.vertices[2] = x + destinationFrame.width; + this.vertices[3] = y; + + this.vertices[4] = x + destinationFrame.width; + this.vertices[5] = y + destinationFrame.height; + + this.vertices[6] = x; + this.vertices[7] = y + destinationFrame.height; + + return this; +}; + +/** + * Draws the quad + */ +Quad.prototype.draw = function() +{ + this.vao.bind() + .draw(this.gl.TRIANGLES, 6, 0) + .unbind(); + + return this; +}; + +/** + * Binds the buffer and uploads the data + */ +Quad.prototype.upload = function() +{ + for (var i = 0; i < 4; i++) { + this.interleaved[i*4] = this.vertices[(i*2)]; + this.interleaved[(i*4)+1] = this.vertices[(i*2)+1]; + this.interleaved[(i*4)+2] = this.uvs[i*2]; + this.interleaved[(i*4)+3] = this.uvs[(i*2)+1]; + } + + this.vertexBuffer.upload(this.interleaved); + + return this; +}; + +/** + * Removes this quad from WebGL + */ +Quad.prototype.destroy = function() +{ + var gl = this.gl; + + gl.deleteBuffer(this.vertexBuffer); + gl.deleteBuffer(this.indexBuffer); +}; + +module.exports = Quad; - switch(this.loadType) { - case Resource.LOAD_TYPE.IMAGE: - this._loadImage(); - break; +},{"../../../utils/createIndicesForQuads":113,"pixi-gl-core":14}],92:[function(require,module,exports){ +var math = require('../../../math'), + CONST = require('../../../const'), + GLFramebuffer = require('pixi-gl-core').GLFramebuffer; + +/** + * @author Mat Groves http://matgroves.com/ @Doormat23 + */ + +/** + * @class + * @memberof PIXI + * @param gl {WebGLRenderingContext} the current WebGL drawing context + * @param [width=0] {number} the horizontal range of the filter + * @param [height=0] {number} the vertical range of the filter + * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values + * @param [resolution=1] {number} The current resolution / device pixel ratio + * @param [root=false] {boolean} Whether this object is the root element or not + */ +var RenderTarget = function(gl, width, height, scaleMode, resolution, root) +{ + //TODO Resolution could go here ( eg low res blurs ) + + /** + * The current WebGL drawing context. + * + * @member {WebGLRenderingContext} + */ + this.gl = gl; + + // next time to create a frame buffer and texture + + /** + * A frame buffer + * + * @member {glCore.GLFramebuffer} + */ + this.frameBuffer = null; + + /** + * The texture + * + * @member {PIXI.Texture} + */ + this.texture = null; + + /** + * The background colour of this render target, as an array of [r,g,b,a] values + * + * @member {number[]} + */ + this.clearColor = [0, 0, 0, 0]; + + /** + * The size of the object as a rectangle + * + * @member {PIXI.Rectangle} + */ + this.size = new math.Rectangle(0, 0, 1, 1); + + /** + * The current resolution / device pixel ratio + * + * @member {number} + * @default 1 + */ + this.resolution = resolution || CONST.RESOLUTION; + + /** + * The projection matrix + * + * @member {PIXI.Matrix} + */ + this.projectionMatrix = new math.Matrix(); + + /** + * The object's transform + * + * @member {PIXI.Matrix} + */ + this.transform = null; + + /** + * The frame. + * + * @member {PIXI.Rectangle} + */ + this.frame = null; + + /** + * The stencil buffer stores masking data for the render target + * + * @member {glCore.GLBuffer} + */ + this.defaultFrame = new math.Rectangle(); + this.destinationFrame = null; + this.sourceFrame = null; + + /** + * The stencil buffer stores masking data for the render target + * + * @member {glCore.GLBuffer} + */ + this.stencilBuffer = null; + + /** + * The data structure for the stencil masks + * + * @member {PIXI.Graphics[]} + */ + this.stencilMaskStack = []; + + /** + * Stores filter data for the render target + * + * @member {object[]} + */ + this.filterData = null; + + /** + * The scale mode. + * + * @member {number} + * @default PIXI.SCALE_MODES.DEFAULT + * @see PIXI.SCALE_MODES + */ + this.scaleMode = scaleMode || CONST.SCALE_MODES.DEFAULT; + + /** + * Whether this object is the root element or not + * + * @member {boolean} + */ + this.root = root; + + + if (!this.root) + { + this.frameBuffer = GLFramebuffer.createRGBA(gl, 100, 100); + + if( this.scaleMode === CONST.SCALE_MODES.NEAREST) + { + this.frameBuffer.texture.enableNearestScaling(); + } + else + { + this.frameBuffer.texture.enableLinearScaling(); + + } + /* + A frame buffer needs a target to render to.. + create a texture and bind it attach it to the framebuffer.. + */ + + // this is used by the base texture + this.texture = this.frameBuffer.texture; + } + else + { + // make it a null framebuffer.. + this.frameBuffer = new GLFramebuffer(gl, 100, 100); + this.frameBuffer.framebuffer = null; + + } + + this.setFrame(); + + this.resize(width, height); +}; + +RenderTarget.prototype.constructor = RenderTarget; +module.exports = RenderTarget; + +/** + * Clears the filter texture. + * + * @param [clearColor=this.clearColor] {number[]} Array of [r,g,b,a] to clear the framebuffer + */ +RenderTarget.prototype.clear = function(clearColor) +{ + var cc = clearColor || this.clearColor; + this.frameBuffer.clear(cc[0],cc[1],cc[2],cc[3]);//r,g,b,a); +}; + +/** + * Binds the stencil buffer. + * + */ +RenderTarget.prototype.attachStencilBuffer = function() +{ + //TODO check if stencil is done? + /** + * The stencil buffer is used for masking in pixi + * lets create one and then add attach it to the framebuffer.. + */ + if (!this.root) + { + this.frameBuffer.enableStencil(); + } +}; + +RenderTarget.prototype.setFrame = function(destinationFrame, sourceFrame) +{ + this.destinationFrame = destinationFrame || this.destinationFrame || this.defaultFrame; + this.sourceFrame = sourceFrame || this.sourceFrame || destinationFrame; +}; + +/** + * Binds the buffers and initialises the viewport. + * + */ +RenderTarget.prototype.activate = function() +{ + //TOOD refactor usage of frame.. + var gl = this.gl; + + // make surethe texture is unbound! + this.frameBuffer.bind(); + + this.calculateProjection( this.destinationFrame, this.sourceFrame ); + + if(this.transform) + { + this.projectionMatrix.append(this.transform); + } + + //TODO add a check as them may be the same! + if(this.destinationFrame !== this.sourceFrame) + { + + gl.enable(gl.SCISSOR_TEST); + gl.scissor(this.destinationFrame.x | 0,this.destinationFrame.y | 0, (this.destinationFrame.width * this.resolution) | 0, (this.destinationFrame.height* this.resolution) | 0); + } + else + { + gl.disable(gl.SCISSOR_TEST); + } + + + // TODO - does not need to be updated all the time?? + gl.viewport(this.destinationFrame.x | 0,this.destinationFrame.y | 0, (this.destinationFrame.width * this.resolution) | 0, (this.destinationFrame.height * this.resolution)|0); + + +}; + + +/** + * Updates the projection matrix based on a projection frame (which is a rectangle) + * + */ +RenderTarget.prototype.calculateProjection = function (destinationFrame, sourceFrame) +{ + var pm = this.projectionMatrix; + + sourceFrame = sourceFrame || destinationFrame; + + pm.identity(); + + // TODO: make dest scale source + if (!this.root) + { + pm.a = 1 / destinationFrame.width*2; + pm.d = 1 / destinationFrame.height*2; + + pm.tx = -1 - sourceFrame.x * pm.a; + pm.ty = -1 - sourceFrame.y * pm.d; + } + else + { + pm.a = 1 / destinationFrame.width*2; + pm.d = -1 / destinationFrame.height*2; + + pm.tx = -1 - sourceFrame.x * pm.a; + pm.ty = 1 - sourceFrame.y * pm.d; + } +}; + + +/** + * Resizes the texture to the specified width and height + * + * @param width {Number} the new width of the texture + * @param height {Number} the new height of the texture + */ +RenderTarget.prototype.resize = function (width, height) +{ + width = width | 0; + height = height | 0; + + if (this.size.width === width && this.size.height === height) + { + return; + } + + this.size.width = width; + this.size.height = height; + + this.defaultFrame.width = width; + this.defaultFrame.height = height; + + + this.frameBuffer.resize(width * this.resolution, height * this.resolution); + + var projectionFrame = this.frame || this.size; + + this.calculateProjection( projectionFrame ); +}; + +/** + * Destroys the render target. + * + */ +RenderTarget.prototype.destroy = function () +{ + this.frameBuffer.destroy(); + + this.frameBuffer = null; + this.texture = null; +}; - case Resource.LOAD_TYPE.AUDIO: - this._loadElement('audio'); - break; +},{"../../../const":42,"../../../math":66,"pixi-gl-core":14}],93:[function(require,module,exports){ +var glCore = require('pixi-gl-core'); + +var fragTemplate = [ + 'precision mediump float;', + 'void main(void){', + 'float test = 0.1;', + '%forloop%', + 'gl_FragColor = vec4(0.0);', + '}' +].join('\n'); + +var checkMaxIfStatmentsInShader = function(maxIfs, gl) +{ + var createTempContext = !gl; + + if(createTempContext) + { + var tinyCanvas = document.createElement('canvas'); + tinyCanvas.width = 1; + tinyCanvas.height = 1; + + gl = glCore.createContext(tinyCanvas); + } + + var shader = gl.createShader(gl.FRAGMENT_SHADER); + + while(true) + { + var fragmentSrc = fragTemplate.replace(/%forloop%/gi, generateIfTestSrc(maxIfs)); + + gl.shaderSource(shader, fragmentSrc); + gl.compileShader(shader); + + if(!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) + { + maxIfs = (maxIfs/2)|0; + } + else + { + // valid! + break; + } + } + + if(createTempContext) + { + // get rid of context + if(gl.getExtension('WEBGL_lose_context')) + { + gl.getExtension('WEBGL_lose_context').loseContext(); + } + } + + return maxIfs; +}; + + + +function generateIfTestSrc(maxIfs) +{ + var src = ''; + + for (var i = 0; i < maxIfs; i++) + { + if(i > 0) + { + src += '\nelse '; + } + + if(i < maxIfs-1) + { + src += 'if(test == ' + i + '.0){}'; + } + } + + return src; +} + +module.exports = checkMaxIfStatmentsInShader; - case Resource.LOAD_TYPE.VIDEO: - this._loadElement('video'); - break; +},{"pixi-gl-core":14}],94:[function(require,module,exports){ +var CONST = require('../../../const'); + +/** + * Maps gl blend combinations to WebGL + * @class + * @memberof PIXI + * @param gl {WebGLRenderingContext} The current WebGL drawing context + * @param array + */ +function mapWebGLBlendModesToPixi(gl, array) +{ + array = array || []; + + //TODO - premultiply alpha would be different. + //add a boolean for that! + array[CONST.BLEND_MODES.NORMAL] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; + array[CONST.BLEND_MODES.ADD] = [gl.ONE, gl.DST_ALPHA]; + array[CONST.BLEND_MODES.MULTIPLY] = [gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA]; + array[CONST.BLEND_MODES.SCREEN] = [gl.ONE, gl.ONE_MINUS_SRC_COLOR]; + array[CONST.BLEND_MODES.OVERLAY] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; + array[CONST.BLEND_MODES.DARKEN] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; + array[CONST.BLEND_MODES.LIGHTEN] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; + array[CONST.BLEND_MODES.COLOR_DODGE] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; + array[CONST.BLEND_MODES.COLOR_BURN] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; + array[CONST.BLEND_MODES.HARD_LIGHT] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; + array[CONST.BLEND_MODES.SOFT_LIGHT] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; + array[CONST.BLEND_MODES.DIFFERENCE] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; + array[CONST.BLEND_MODES.EXCLUSION] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; + array[CONST.BLEND_MODES.HUE] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; + array[CONST.BLEND_MODES.SATURATION] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; + array[CONST.BLEND_MODES.COLOR] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; + array[CONST.BLEND_MODES.LUMINOSITY] = [gl.ONE, gl.ONE_MINUS_SRC_ALPHA]; + + return array; +} + +module.exports = mapWebGLBlendModesToPixi; - case Resource.LOAD_TYPE.XHR: - /* falls through */ - default: - if (useXdr && this.crossOrigin) { - this._loadXdr(); - } - else { - this._loadXhr(); - } - break; - } -}; +},{"../../../const":42}],95:[function(require,module,exports){ +var CONST = require('../../../const'); + +/** + * Generic Mask Stack data structure + * @class + * @memberof PIXI + * @param gl {WebGLRenderingContext} The current WebGL drawing context + * @param object + */ +function mapWebGLDrawModesToPixi(gl, object) +{ + object= object || {}; + + object[CONST.DRAW_MODES.POINTS] = gl.POINTS; + object[CONST.DRAW_MODES.LINES] = gl.LINES; + object[CONST.DRAW_MODES.LINE_LOOP] = gl.LINE_LOOP; + object[CONST.DRAW_MODES.LINE_STRIP] = gl.LINE_STRIP; + object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; + object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; + object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; + +} + +module.exports = mapWebGLDrawModesToPixi; -/** - * Loads this resources using an Image object. - * - * @private - */ -Resource.prototype._loadImage = function () { - if (!this.data) { - this.prepareImage(); - } - this.data.src = this.url; -}; +},{"../../../const":42}],96:[function(require,module,exports){ + + +function validateContext(gl) +{ + var attributes = gl.getContextAttributes(); + + // this is going to be fairly simple for now.. but at least we have rom to grow! + if(!attributes.stencil) + { + console.warn('Provided WebGL context does not have a stencil buffer, masks may not render correctly'); // jshint ignore:line + } +} + +module.exports = validateContext; -/** - * Prepares image for loading, but does not set src yet - */ -Resource.prototype.prepareImage = function () { - this.data = new Image(); +},{}],97:[function(require,module,exports){ +var math = require('../math'), + Texture = require('../textures/Texture'), + Container = require('../display/Container'), + utils = require('../utils'), + CONST = require('../const'), + tempPoint = new math.Point(); + +/** + * The Sprite object is the base for all textured objects that are rendered to the screen + * + * A sprite can be created directly from an image like this: + * + * ```js + * var sprite = new PIXI.Sprite.fromImage('assets/image.png'); + * ``` + * + * @class + * @extends PIXI.Container + * @memberof PIXI + * @param texture {PIXI.Texture} The texture for this sprite + */ +function Sprite(texture) +{ + Container.call(this); + + /** + * The anchor sets the origin point of the texture. + * The default is 0,0 this means the texture's origin is the top left + * Setting the anchor to 0.5,0.5 means the texture's origin is centered + * Setting the anchor to 1,1 would mean the texture's origin point will be the bottom right corner + * + * @member {PIXI.ObservablePoint} + */ + this.anchor = new math.ObservablePoint(this.onAnchorUpdate, this); + + /** + * The texture that the sprite is using + * + * @member {PIXI.Texture} + * @private + */ + this._texture = null; + + /** + * The width of the sprite (this is initially set by the texture) + * + * @member {number} + * @private + */ + this._width = 0; + + /** + * The height of the sprite (this is initially set by the texture) + * + * @member {number} + * @private + */ + this._height = 0; + + /** + * The tint applied to the sprite. This is a hex value. A value of 0xFFFFFF will remove any tint effect. + * + * @member {number} + * @default 0xFFFFFF + */ + this.tint = 0xFFFFFF; + + /** + * The blend mode to be applied to the sprite. Apply a value of `PIXI.BLEND_MODES.NORMAL` to reset the blend mode. + * + * @member {number} + * @default PIXI.BLEND_MODES.NORMAL + * @see PIXI.BLEND_MODES + */ + this.blendMode = CONST.BLEND_MODES.NORMAL; + + /** + * The shader that will be used to render the sprite. Set to null to remove a current shader. + * + * @member {PIXI.AbstractFilter|PIXI.Shader} + */ + this.shader = null; + + /** + * An internal cached value of the tint. + * + * @member {number} + * @default 0xFFFFFF + * @private + */ + this.cachedTint = 0xFFFFFF; + + // call texture setter + this.texture = texture || Texture.EMPTY; + this.vertexData = new Float32Array(16); + this._transformID = -1; + this._textureID = -1; +} + +// constructor +Sprite.prototype = Object.create(Container.prototype); +Sprite.prototype.constructor = Sprite; +module.exports = Sprite; + +Object.defineProperties(Sprite.prototype, { + /** + * The width of the sprite, setting this will actually modify the scale to achieve the value set + * + * @member {number} + * @memberof PIXI.Sprite# + */ + width: { + get: function () + { + return Math.abs(this.scale.x) * this.texture.orig.width; + }, + set: function (value) + { + var sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } + }, + + /** + * The height of the sprite, setting this will actually modify the scale to achieve the value set + * + * @member {number} + * @memberof PIXI.Sprite# + */ + height: { + get: function () + { + return Math.abs(this.scale.y) * this.texture.orig.height; + }, + set: function (value) + { + var sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } + }, + + /** + * The texture that the sprite is using + * + * @member {PIXI.Texture} + * @memberof PIXI.Sprite# + */ + texture: { + get: function () + { + return this._texture; + }, + set: function (value) + { + if (this._texture === value) + { + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) + { + // wait for the texture to load + if (value.baseTexture.hasLoaded) + { + this._onTextureUpdate(); + } + else + { + value.once('update', this._onTextureUpdate, this); + } + } + } + } +}); + +/** + * When the texture is updated, this event will fire to update the scale and frame + * + * @private + */ +Sprite.prototype._onTextureUpdate = function () +{ + this._textureID = -1; + + // so if _width is 0 then width was not set.. + if (this._width) + { + this.scale.x = utils.sign(this.scale.x) * this._width / this.texture.orig.width; + } + + if (this._height) + { + this.scale.y = utils.sign(this.scale.y) * this._height / this.texture.orig.height; + } +}; + +Sprite.prototype.onAnchorUpdate = function() +{ + this._transformID = -1; +}; + +/** + * calculates worldTransform * vertices, store it in vertexData + */ +Sprite.prototype.calculateVertices = function () +{ + if(this._transformID === this.transform._worldID && this._textureID === this._texture._updateID) + { + return; + } + + this._transformID = this.transform._worldID; + this._textureID = this._texture._updateID; + + // set the vertex data + + var texture = this._texture, + wt = this.transform.worldTransform, + a = wt.a, b = wt.b, c = wt.c, d = wt.d, tx = wt.tx, ty = wt.ty, + vertexData = this.vertexData, + w0, w1, h0, h1, + trim = texture.trim, + orig = texture.orig; + + if (trim) + { + // if the sprite is trimmed and is not a tilingsprite then we need to add the extra space before transforming the sprite coords.. + w1 = trim.x - this.anchor.x * orig.width; + w0 = w1 + trim.width; + + h1 = trim.y - this.anchor.y * orig.height; + h0 = h1 + trim.height; + + } + else + { + w0 = (orig.width ) * (1-this.anchor.x); + w1 = (orig.width ) * -this.anchor.x; + + h0 = orig.height * (1-this.anchor.y); + h1 = orig.height * -this.anchor.y; + } + + // xy + vertexData[0] = a * w1 + c * h1 + tx; + vertexData[1] = d * h1 + b * w1 + ty; + + // xy + vertexData[2] = a * w0 + c * h1 + tx; + vertexData[3] = d * h1 + b * w0 + ty; + + // xy + vertexData[4] = a * w0 + c * h0 + tx; + vertexData[5] = d * h0 + b * w0 + ty; + + // xy + vertexData[6] = a * w1 + c * h0 + tx; + vertexData[7] = d * h0 + b * w1 + ty; +}; + +/** + * we need this method to be compatible with pixiv3. v3 does calculate bounds of original texture are, not trimmed one + */ +Sprite.prototype.calculateBoundsVertices = function () +{ + var texture = this._texture, + trim = texture.trim, + vertexData = this.vertexData, + orig = texture.orig; + + if (!trim || trim.width === orig.width && trim.height === orig.height) { + vertexData[8] = vertexData[0]; + vertexData[9] = vertexData[1]; + vertexData[10] = vertexData[2]; + vertexData[11] = vertexData[3]; + vertexData[12] = vertexData[4]; + vertexData[13] = vertexData[5]; + vertexData[14] = vertexData[6]; + vertexData[15] = vertexData[7]; + return; + } + + var wt = this.transform.worldTransform, + a = wt.a, b = wt.b, c = wt.c, d = wt.d, tx = wt.tx, ty = wt.ty, + w0, w1, h0, h1; + + + w0 = (orig.width ) * (1-this.anchor.x); + w1 = (orig.width ) * -this.anchor.x; + + h0 = orig.height * (1-this.anchor.y); + h1 = orig.height * -this.anchor.y; + + // xy + vertexData[8] = a * w1 + c * h1 + tx; + vertexData[9] = d * h1 + b * w1 + ty; + + // xy + vertexData[10] = a * w0 + c * h1 + tx; + vertexData[11] = d * h1 + b * w0 + ty; + + // xy + vertexData[12] = a * w0 + c * h0 + tx; + vertexData[13] = d * h0 + b * w0 + ty; + + // xy + vertexData[14] = a * w1 + c * h0 + tx; + vertexData[15] = d * h0 + b * w1 + ty; +}; + +/** +* +* Renders the object using the WebGL renderer +* +* @param renderer {PIXI.WebGLRenderer} +* @private +*/ +Sprite.prototype._renderWebGL = function (renderer) +{ + this.calculateVertices(); + + renderer.setObjectRenderer(renderer.plugins.sprite); + renderer.plugins.sprite.render(this); +}; + +/** +* Renders the object using the Canvas renderer +* +* @param renderer {PIXI.CanvasRenderer} The renderer +* @private +*/ +Sprite.prototype._renderCanvas = function (renderer) +{ + renderer.plugins.sprite.render(this); +}; + +Sprite.prototype._calculateBounds = function () +{ + this.calculateVertices(); + // if we have already done this on THIS frame. + this._bounds.addQuad(this.vertexData); +}; + +/** + * Gets the local bounds of the sprite object. + * + */ + +Sprite.prototype.getLocalBounds = function () +{ + + this._bounds.minX = -this._texture.orig.width * this.anchor.x; + this._bounds.minY = -this._texture.orig.height * this.anchor.y; + this._bounds.maxX = this._texture.orig.width; + this._bounds.maxY = this._texture.orig.height; + + return this._bounds.getRectangle(this._bounds); +}; + +/** +* Tests if a point is inside this sprite +* +* @param point {PIXI.Point} the point to test +* @return {boolean} the result of the test +*/ +Sprite.prototype.containsPoint = function( point ) +{ + this.worldTransform.applyInverse(point, tempPoint); + + var width = this._texture.orig.width; + var height = this._texture.orig.height; + var x1 = -width * this.anchor.x; + var y1; + + if ( tempPoint.x > x1 && tempPoint.x < x1 + width ) + { + y1 = -height * this.anchor.y; + + if ( tempPoint.y > y1 && tempPoint.y < y1 + height ) + { + return true; + } + } + + return false; +}; + + +/** + * Destroys this sprite and optionally its texture and children + * + * @param [options] {object|boolean} Options parameter. A boolean will act as if all options have been set to that value + * @param [options.children=false] {boolean} if set to true, all the children will have their destroy + * method called as well. 'options' will be passed on to those calls. + * @param [options.texture=false] {boolean} Should it destroy the current texture of the sprite as well + * @param [options.baseTexture=false] {boolean} Should it destroy the base texture of the sprite as well + */ +Sprite.prototype.destroy = function (options) +{ + Container.prototype.destroy.call(this, options); + + this.anchor = null; + + var destroyTexture = typeof options === 'boolean' ? options : options && options.texture; + if (destroyTexture) + { + var destroyBaseTexture = typeof options === 'boolean' ? options : options && options.baseTexture; + this._texture.destroy(!!destroyBaseTexture); + } + + this._texture = null; + this.shader = null; +}; + +// some helper functions.. + +/** + * Helper function that creates a new sprite based on the source you provide. + * The source can be - frame id, image url, video url, canvas element, video element, base texture + * + * @static + * @param {number|string|PIXI.BaseTexture|HTMLCanvasElement|HTMLVideoElement} source Source to create texture from + * @return {PIXI.Texture} The newly created texture + */ +Sprite.from = function (source) +{ + return new Sprite(Texture.from(source)); +}; + +/** + * Helper function that creates a sprite that will contain a texture from the TextureCache based on the frameId + * The frame ids are created when a Texture packer file has been loaded + * + * @static + * @param frameId {string} The frame Id of the texture in the cache + * @return {PIXI.Sprite} A new Sprite using a texture from the texture cache matching the frameId + */ +Sprite.fromFrame = function (frameId) +{ + var texture = utils.TextureCache[frameId]; + + if (!texture) + { + throw new Error('The frameId "' + frameId + '" does not exist in the texture cache'); + } + + return new Sprite(texture); +}; + +/** + * Helper function that creates a sprite that will contain a texture based on an image url + * If the image is not in the texture cache it will be loaded + * + * @static + * @param imageId {string} The image url of the texture + * @param [crossorigin=(auto)] {boolean} if you want to specify the cross-origin parameter + * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} if you want to specify the scale mode, see {@link PIXI.SCALE_MODES} for possible values + * @return {PIXI.Sprite} A new Sprite using a texture from the texture cache matching the image id + */ +Sprite.fromImage = function (imageId, crossorigin, scaleMode) +{ + return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); +}; - if (this.crossOrigin) { - this.data.crossOrigin = this.crossOrigin; - } +},{"../const":42,"../display/Container":44,"../math":66,"../textures/Texture":108,"../utils":115}],98:[function(require,module,exports){ +var CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), + CONST = require('../../const'), + math = require('../../math'), + canvasRenderWorldTransform = new math.Matrix(), + CanvasTinter = require('./CanvasTinter'); + +/** + * @author Mat Groves + * + * Big thanks to the very clever Matt DesLauriers https://github.com/mattdesl/ + * for creating the original pixi version! + * Also a thanks to https://github.com/bchevalier for tweaking the tint and alpha so that they now share 4 bytes on the vertex buffer + * + * Heavily inspired by LibGDX's CanvasSpriteRenderer: + * https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/graphics/g2d/CanvasSpriteRenderer.java + */ + +/** + * Renderer dedicated to drawing and batching sprites. + * + * @class + * @private + * @memberof PIXI + * @extends PIXI.ObjectRenderer + * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. + */ +function CanvasSpriteRenderer(renderer) +{ + this.renderer = renderer; +} + + +CanvasSpriteRenderer.prototype.constructor = CanvasSpriteRenderer; +module.exports = CanvasSpriteRenderer; + +CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +/** + * Renders the sprite object. + * + * @param sprite {PIXI.Sprite} the sprite to render when using this spritebatch + */ +CanvasSpriteRenderer.prototype.render = function (sprite) +{ + var texture = sprite._texture, + renderer = this.renderer, + wt = sprite.transform.worldTransform, + dx, + dy, + width = texture._frame.width, + height = texture._frame.height; + + if (texture.orig.width <= 0 || texture.orig.height <= 0 || !texture.baseTexture.source) + { + return; + } + + renderer.setBlendMode(sprite.blendMode); + + // Ignore null sources + if (texture.valid) + { + renderer.context.globalAlpha = sprite.worldAlpha; + + // If smoothingEnabled is supported and we need to change the smoothing property for sprite texture + var smoothingEnabled = texture.baseTexture.scaleMode === CONST.SCALE_MODES.LINEAR; + if (renderer.smoothProperty && renderer.context[renderer.smoothProperty] !== smoothingEnabled) + { + renderer.context[renderer.smoothProperty] = smoothingEnabled; + } + + if (texture.trim) { + dx = texture.trim.width/2 + texture.trim.x - sprite.anchor.x * texture.orig.width; + dy = texture.trim.height/2 + texture.trim.y - sprite.anchor.y * texture.orig.height; + } else { + dx = (0.5 - sprite.anchor.x) * texture.orig.width; + dy = (0.5 - sprite.anchor.y) * texture.orig.height; + } + if(texture.rotate) { + wt.copy(canvasRenderWorldTransform); + wt = canvasRenderWorldTransform; + math.GroupD8.matrixAppendRotationInv(wt, texture.rotate, dx, dy); + // the anchor has already been applied above, so lets set it to zero + dx = 0; + dy = 0; + } + dx -= width/2; + dy -= height/2; + // Allow for pixel rounding + if (renderer.roundPixels) + { + renderer.context.setTransform( + wt.a, + wt.b, + wt.c, + wt.d, + (wt.tx * renderer.resolution) | 0, + (wt.ty * renderer.resolution) | 0 + ); + + dx = dx | 0; + dy = dy | 0; + } + else + { + renderer.context.setTransform( + wt.a, + wt.b, + wt.c, + wt.d, + wt.tx * renderer.resolution, + wt.ty * renderer.resolution + ); + } + + var resolution = texture.baseTexture.resolution; + + if (sprite.tint !== 0xFFFFFF) + { + if (sprite.cachedTint !== sprite.tint) + { + sprite.cachedTint = sprite.tint; + + // TODO clean up caching - how to clean up the caches? + sprite.tintedTexture = CanvasTinter.getTintedTexture(sprite, sprite.tint); + } + + renderer.context.drawImage( + sprite.tintedTexture, + 0, + 0, + width * resolution, + height * resolution, + dx * renderer.resolution, + dy * renderer.resolution, + width * renderer.resolution, + height * renderer.resolution + ); + } + else + { + + renderer.context.drawImage( + texture.baseTexture.source, + texture._frame.x * resolution, + texture._frame.y * resolution, + width * resolution, + height * resolution, + dx * renderer.resolution, + dy * renderer.resolution, + width * renderer.resolution, + height * renderer.resolution + ); + } + } +}; + +/** + * destroy the sprite object. + * + */ +CanvasSpriteRenderer.prototype.destroy = function (){ + this.renderer = null; +}; - this.isImage = true; +},{"../../const":42,"../../math":66,"../../renderers/canvas/CanvasRenderer":73,"./CanvasTinter":99}],99:[function(require,module,exports){ +var utils = require('../../utils'), + canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); + +/** + * Utility methods for Sprite/Texture tinting. + * + * @namespace PIXI.CanvasTinter + */ +var CanvasTinter = module.exports = { + /** + * Basically this method just needs a sprite and a color and tints the sprite with the given color. + * + * @memberof PIXI.CanvasTinter + * @param sprite {PIXI.Sprite} the sprite to tint + * @param color {number} the color to use to tint the sprite with + * @return {HTMLCanvasElement} The tinted canvas + */ + getTintedTexture: function (sprite, color) + { + var texture = sprite.texture; + + color = CanvasTinter.roundColor(color); + + var stringColor = '#' + ('00000' + ( color | 0).toString(16)).substr(-6); + + texture.tintCache = texture.tintCache || {}; + + if (texture.tintCache[stringColor]) + { + return texture.tintCache[stringColor]; + } + + // clone texture.. + var canvas = CanvasTinter.canvas || document.createElement('canvas'); + + //CanvasTinter.tintWithPerPixel(texture, stringColor, canvas); + CanvasTinter.tintMethod(texture, color, canvas); + + if (CanvasTinter.convertTintToImage) + { + // is this better? + var tintImage = new Image(); + tintImage.src = canvas.toDataURL(); + + texture.tintCache[stringColor] = tintImage; + } + else + { + texture.tintCache[stringColor] = canvas; + // if we are not converting the texture to an image then we need to lose the reference to the canvas + CanvasTinter.canvas = null; + } + + return canvas; + }, + + /** + * Tint a texture using the 'multiply' operation. + * + * @memberof PIXI.CanvasTinter + * @param texture {PIXI.Texture} the texture to tint + * @param color {number} the color to use to tint the sprite with + * @param canvas {HTMLCanvasElement} the current canvas + */ + tintWithMultiply: function (texture, color, canvas) + { + var context = canvas.getContext( '2d' ); + var crop = texture._frame.clone(); + var resolution = texture.baseTexture.resolution; + + crop.x *= resolution; + crop.y *= resolution; + crop.width *= resolution; + crop.height *= resolution; + + canvas.width = crop.width; + canvas.height = crop.height; + + context.fillStyle = '#' + ('00000' + ( color | 0).toString(16)).substr(-6); + + context.fillRect(0, 0, crop.width, crop.height); + + context.globalCompositeOperation = 'multiply'; + + context.drawImage( + texture.baseTexture.source, + crop.x, + crop.y, + crop.width, + crop.height, + 0, + 0, + crop.width, + crop.height + ); + + context.globalCompositeOperation = 'destination-atop'; + + context.drawImage( + texture.baseTexture.source, + crop.x, + crop.y, + crop.width, + crop.height, + 0, + 0, + crop.width, + crop.height + ); + }, + + /** + * Tint a texture using the 'overlay' operation. + * + * @memberof PIXI.CanvasTinter + * @param texture {PIXI.Texture} the texture to tint + * @param color {number} the color to use to tint the sprite with + * @param canvas {HTMLCanvasElement} the current canvas + */ + tintWithOverlay: function (texture, color, canvas) + { + var context = canvas.getContext( '2d' ); + var crop = texture._frame.clone(); + var resolution = texture.baseTexture.resolution; + + crop.x *= resolution; + crop.y *= resolution; + crop.width *= resolution; + crop.height *= resolution; + + canvas.width = crop.width; + canvas.height = crop.height; + + context.globalCompositeOperation = 'copy'; + context.fillStyle = '#' + ('00000' + ( color | 0).toString(16)).substr(-6); + context.fillRect(0, 0, crop.width, crop.height); + + context.globalCompositeOperation = 'destination-atop'; + context.drawImage( + texture.baseTexture.source, + crop.x, + crop.y, + crop.width, + crop.height, + 0, + 0, + crop.width, + crop.height + ); + + // context.globalCompositeOperation = 'copy'; + }, + + /** + * Tint a texture pixel per pixel. + * + * @memberof PIXI.CanvasTinter + * @param texture {PIXI.Texture} the texture to tint + * @param color {number} the color to use to tint the sprite with + * @param canvas {HTMLCanvasElement} the current canvas + */ + tintWithPerPixel: function (texture, color, canvas) + { + var context = canvas.getContext( '2d' ); + var crop = texture._frame.clone(); + var resolution = texture.baseTexture.resolution; + + crop.x *= resolution; + crop.y *= resolution; + crop.width *= resolution; + crop.height *= resolution; + + canvas.width = crop.width; + canvas.height = crop.height; + + context.globalCompositeOperation = 'copy'; + context.drawImage( + texture.baseTexture.source, + crop.x, + crop.y, + crop.width, + crop.height, + 0, + 0, + crop.width, + crop.height + ); + + var rgbValues = utils.hex2rgb(color); + var r = rgbValues[0], g = rgbValues[1], b = rgbValues[2]; + + var pixelData = context.getImageData(0, 0, crop.width, crop.height); + + var pixels = pixelData.data; + + for (var i = 0; i < pixels.length; i += 4) + { + pixels[i+0] *= r; + pixels[i+1] *= g; + pixels[i+2] *= b; + } + + context.putImageData(pixelData, 0, 0); + }, + + /** + * Rounds the specified color according to the CanvasTinter.cacheStepsPerColorChannel. + * + * @memberof PIXI.CanvasTinter + * @param color {number} the color to round, should be a hex color + */ + roundColor: function (color) + { + var step = CanvasTinter.cacheStepsPerColorChannel; + + var rgbValues = utils.hex2rgb(color); + + rgbValues[0] = Math.min(255, (rgbValues[0] / step) * step); + rgbValues[1] = Math.min(255, (rgbValues[1] / step) * step); + rgbValues[2] = Math.min(255, (rgbValues[2] / step) * step); + + return utils.rgb2hex(rgbValues); + }, + + /** + * Number of steps which will be used as a cap when rounding colors. + * + * @memberof PIXI.CanvasTinter + * @type {number} + */ + cacheStepsPerColorChannel: 8, + + /** + * Tint cache boolean flag. + * + * @memberof PIXI.CanvasTinter + * @type {boolean} + */ + convertTintToImage: false, + + /** + * Whether or not the Canvas BlendModes are supported, consequently the ability to tint using the multiply method. + * + * @memberof PIXI.CanvasTinter + * @type {boolean} + */ + canUseMultiply: canUseNewCanvasBlendModes(), + + /** + * The tinting method that will be used. + * + * @memberof PIXI.CanvasTinter + * @type {tintMethodFunctionType} + */ + tintMethod: 0 +}; + +CanvasTinter.tintMethod = CanvasTinter.canUseMultiply ? CanvasTinter.tintWithMultiply : CanvasTinter.tintWithPerPixel; + +/** + * The tintMethod type. + * + * @memberof PIXI.CanvasTinter + * @callback tintMethodFunctionType + * @param texture {PIXI.Texture} the texture to tint + * @param color {number} the color to use to tint the sprite with + * @param canvas {HTMLCanvasElement} the current canvas + */ - this.data.addEventListener('error', this._boundOnError, false); - this.data.addEventListener('load', this._boundComplete, false); - this.data.addEventListener('progress', this._boundOnProgress, false); -}; +},{"../../renderers/canvas/utils/canUseNewCanvasBlendModes":76,"../../utils":115}],100:[function(require,module,exports){ + + + var Buffer = function(size) + { + + this.vertices = new ArrayBuffer(size); + + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); + + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + }; + + module.exports = Buffer; + + Buffer.prototype.destroy = function(){ + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + }; +},{}],101:[function(require,module,exports){ +var ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), + WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), + createIndicesForQuads = require('../../utils/createIndicesForQuads'), + generateMultiTextureShader = require('./generateMultiTextureShader'), + checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), + Buffer = require('./BatchBuffer'), + CONST = require('../../const'), + glCore = require('pixi-gl-core'), + bitTwiddle = require('bit-twiddle'); + + +/** + * Renderer dedicated to drawing and batching sprites. + * + * @class + * @private + * @memberof PIXI + * @extends PIXI.ObjectRenderer + * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. + */ +function SpriteRenderer(renderer) +{ + ObjectRenderer.call(this, renderer); + + /** + * Number of values sent in the vertex buffer. + * positionX, positionY, colorR, colorG, colorB = 5 + * + * @member {number} + */ + this.vertSize = 5; + + /** + * The size of the vertex information in bytes. + * + * @member {number} + */ + this.vertByteSize = this.vertSize * 4; + + /** + * The number of images in the SpriteBatch before it flushes. + * + * @member {number} + */ + this.size = CONST.SPRITE_BATCH_SIZE; // 2000 is a nice balance between mobile / desktop + + // the total number of bytes in our batch + // var numVerts = this.size * 4 * this.vertByteSize; + + this.buffers = []; + for (var i = 1; i <= bitTwiddle.nextPow2(this.size); i*=2) { + var numVertsTemp = i * 4 * this.vertByteSize; + this.buffers.push(new Buffer(numVertsTemp)); + } + + /** + * Holds the indices of the geometry (quads) to draw + * + * @member {Uint16Array} + */ + this.indices = createIndicesForQuads(this.size); + + /** + * The default shaders that is used if a sprite doesn't have a more specific one. + * there is a shader for each number of textures that can be rendererd. + * These shaders will also be generated on the fly as required. + * @member {PIXI.Shader} + */ + this.shaders = null; + + this.textureCount = 0; + this.currentIndex = 0; + this.tick =0; + this.groups = []; + + for (var k = 0; k < this.size; k++) + { + this.groups[k] = {textures:[], textureCount:0, ids:[], size:0, start:0, blend:0}; + } + + this.sprites = []; + + this.vertexBuffers = []; + this.vaos = []; + + this.vaoMax = 2; + this.vertexCount = 0; + + this.renderer.on('prerender', this.onPrerender, this); +} + + +SpriteRenderer.prototype = Object.create(ObjectRenderer.prototype); +SpriteRenderer.prototype.constructor = SpriteRenderer; +module.exports = SpriteRenderer; + +WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +/** + * Sets up the renderer context and necessary buffers. + * + * @private + */ +SpriteRenderer.prototype.onContextChange = function () +{ + var gl = this.renderer.gl; + + // step 1: first check max textures the GPU can handle. + this.MAX_TEXTURES = Math.min(gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS), CONST.SPRITE_MAX_TEXTURES); + + // step 2: check the maximum number of if statements the shader can have too.. + this.MAX_TEXTURES = checkMaxIfStatmentsInShader( this.MAX_TEXTURES, gl ); + + this.shaders = new Array(this.MAX_TEXTURES); + this.shaders[0] = generateMultiTextureShader(gl, 1); + this.shaders[1] = generateMultiTextureShader(gl, 2); + + // create a couple of buffers + this.indexBuffer = glCore.GLBuffer.createIndexBuffer(gl, this.indices, gl.STATIC_DRAW); + + // we use the second shader as the first one depending on your browser may omit aTextureId + // as it is not used by the shader so is optimized out. + var shader = this.shaders[1]; + + for (var i = 0; i < this.vaoMax; i++) { + this.vertexBuffers[i] = glCore.GLBuffer.createVertexBuffer(gl, null, gl.STREAM_DRAW); + + // build the vao object that will render.. + this.vaos[i] = this.renderer.createVao() + .addIndex(this.indexBuffer) + .addAttribute(this.vertexBuffers[i], shader.attributes.aVertexPosition, gl.FLOAT, false, this.vertByteSize, 0) + .addAttribute(this.vertexBuffers[i], shader.attributes.aTextureCoord, gl.UNSIGNED_SHORT, true, this.vertByteSize, 2 * 4) + .addAttribute(this.vertexBuffers[i], shader.attributes.aColor, gl.UNSIGNED_BYTE, true, this.vertByteSize, 3 * 4) + .addAttribute(this.vertexBuffers[i], shader.attributes.aTextureId, gl.FLOAT, false, this.vertByteSize, 4 * 4); + } + + this.vao = this.vaos[0]; + this.currentBlendMode = 99999; +}; + +SpriteRenderer.prototype.onPrerender = function () +{ + this.vertexCount = 0; +}; + +/** + * Renders the sprite object. + * + * @param sprite {PIXI.Sprite} the sprite to render when using this spritebatch + */ +SpriteRenderer.prototype.render = function (sprite) +{ + //TODO set blend modes.. + // check texture.. + if (this.currentIndex >= this.size) + { + this.flush(); + } + + + // get the uvs for the texture + + + // if the uvs have not updated then no point rendering just yet! + if (!sprite.texture._uvs) + { + return; + } + + // push a texture. + // increment the batchsize + this.sprites[this.currentIndex++] = sprite; +}; + +/** + * Renders the content and empties the current batch. + * + */ +SpriteRenderer.prototype.flush = function () +{ + if (this.currentIndex === 0) { + return; + } + + var gl = this.renderer.gl; + + var np2 = bitTwiddle.nextPow2(this.currentIndex); + var log2 = bitTwiddle.log2(np2); + var buffer = this.buffers[log2]; + + var sprites = this.sprites; + var groups = this.groups; + + var float32View = buffer.float32View; + var uint32View = buffer.uint32View; + + var index = 0; + var nextTexture; + var currentTexture; + var groupCount = 1; + var textureCount = 0; + var currentGroup = groups[0]; + var vertexData; + var tint; + var uvs; + var textureId; + var blendMode = sprites[0].blendMode; + var shader; + + currentGroup.textureCount = 0; + currentGroup.start = 0; + currentGroup.blend = blendMode; + + this.tick++; + + for (var i = 0; i < this.currentIndex; i++) + { + // upload the sprite elemetns... + // they have all ready been calculated so we just need to push them into the buffer. + var sprite = sprites[i]; + + nextTexture = sprite._texture.baseTexture; + + if(blendMode !== sprite.blendMode) + { + blendMode = sprite.blendMode; + + // force the batch to break! + currentTexture = null; + textureCount = this.MAX_TEXTURES; + this.tick++; + } + + if(currentTexture !== nextTexture) + { + currentTexture = nextTexture; + + if(nextTexture._enabled !== this.tick) + { + if(textureCount === this.MAX_TEXTURES) + { + this.tick++; + + textureCount = 0; + + currentGroup.size = i - currentGroup.start; + + currentGroup = groups[groupCount++]; + currentGroup.textureCount = 0; + currentGroup.blend = blendMode; + currentGroup.start = i; + } + + nextTexture._enabled = this.tick; + nextTexture._id = textureCount; + + currentGroup.textures[currentGroup.textureCount++] = nextTexture; + textureCount++; + } + + } + + vertexData = sprite.vertexData; + + //TODO this sum does not need to be set each frame.. + tint = (sprite.tint >> 16) + (sprite.tint & 0xff00) + ((sprite.tint & 0xff) << 16) + (sprite.worldAlpha * 255 << 24); + uvs = sprite._texture._uvs.uvsUint32; + textureId = nextTexture._id; + + //xy + float32View[index++] = vertexData[0]; + float32View[index++] = vertexData[1]; + uint32View[index++] = uvs[0]; + uint32View[index++] = tint; + float32View[index++] = textureId; + + // xy + float32View[index++] = vertexData[2]; + float32View[index++] = vertexData[3]; + uint32View[index++] = uvs[1]; + uint32View[index++] = tint; + float32View[index++] = textureId; + + // xy + float32View[index++] = vertexData[4]; + float32View[index++] = vertexData[5]; + uint32View[index++] = uvs[2]; + uint32View[index++] = tint; + float32View[index++] = textureId; + + // xy + float32View[index++] = vertexData[6]; + float32View[index++] = vertexData[7]; + uint32View[index++] = uvs[3]; + uint32View[index++] = tint; + float32View[index++] = textureId; + } + + currentGroup.size = i - currentGroup.start; + + this.vertexCount++; + + if(this.vaoMax <= this.vertexCount) + { + this.vaoMax++; + shader = this.shaders[1]; + this.vertexBuffers[this.vertexCount] = glCore.GLBuffer.createVertexBuffer(gl, null, gl.STREAM_DRAW); + // build the vao object that will render.. + this.vaos[this.vertexCount] = this.renderer.createVao() + .addIndex(this.indexBuffer) + .addAttribute(this.vertexBuffers[this.vertexCount], shader.attributes.aVertexPosition, gl.FLOAT, false, this.vertByteSize, 0) + .addAttribute(this.vertexBuffers[this.vertexCount], shader.attributes.aTextureCoord, gl.UNSIGNED_SHORT, true, this.vertByteSize, 2 * 4) + .addAttribute(this.vertexBuffers[this.vertexCount], shader.attributes.aColor, gl.UNSIGNED_BYTE, true, this.vertByteSize, 3 * 4) + .addAttribute(this.vertexBuffers[this.vertexCount], shader.attributes.aTextureId, gl.FLOAT, false, this.vertByteSize, 4 * 4); + } + + this.vertexBuffers[this.vertexCount].upload(buffer.vertices, 0); + this.vao = this.vaos[this.vertexCount].bind(); + + /// render the groups.. + for (i = 0; i < groupCount; i++) { + + var group = groups[i]; + var groupTextureCount = group.textureCount; + shader = this.shaders[groupTextureCount-1]; + + if(!shader) + { + shader = this.shaders[groupTextureCount-1] = generateMultiTextureShader(gl, groupTextureCount); + //console.log("SHADER generated for " + textureCount + " textures") + } + + this.renderer.bindShader(shader); + + for (var j = 0; j < groupTextureCount; j++) + { + this.renderer.bindTexture(group.textures[j], j); + } + + // set the blend mode.. + this.renderer.state.setBlendMode( group.blend ); + + gl.drawElements(gl.TRIANGLES, group.size * 6, gl.UNSIGNED_SHORT, group.start * 6 * 2); + } + + // reset elements for the next flush + this.currentIndex = 0; +}; + +/** + * Starts a new sprite batch. + * + */ +SpriteRenderer.prototype.start = function () +{ + // this.renderer.bindShader(this.shader); + this.tick %= 1000; +}; + +SpriteRenderer.prototype.stop = function () +{ + this.flush(); + this.vao.unbind(); +}; +/** + * Destroys the SpriteBatch. + * + */ +SpriteRenderer.prototype.destroy = function () +{ + for (var i = 0; i < this.vertexCount; i++) { + this.vertexBuffers[i].destroy(); + this.vaos[i].destroy(); + } + + this.indexBuffer.destroy(); + + this.renderer.off('prerender', this.onPrerender, this); + ObjectRenderer.prototype.destroy.call(this); + + for (i = 0; i < this.shaders.length; i++) { + + if(this.shaders[i]) + { + this.shaders[i].destroy(); + } + } + + this.vertexBuffers = null; + this.vaos = null; + this.indexBuffer = null; + this.indices = null; + + this.sprites = null; + + for (i = 0; i < this.buffers.length; i++) { + this.buffers[i].destroy(); + } + +}; -/** - * Loads this resources using an HTMLAudioElement or HTMLVideoElement. - * - * @private - */ -Resource.prototype._loadElement = function (type) { - if (type === 'audio' && typeof Audio !== 'undefined') { - this.data = new Audio(); - } - else { - this.data = document.createElement(type); - } +},{"../../const":42,"../../renderers/webgl/WebGLRenderer":80,"../../renderers/webgl/utils/ObjectRenderer":90,"../../renderers/webgl/utils/checkMaxIfStatmentsInShader":93,"../../utils/createIndicesForQuads":113,"./BatchBuffer":100,"./generateMultiTextureShader":102,"bit-twiddle":2,"pixi-gl-core":14}],102:[function(require,module,exports){ +var Shader = require('../../Shader'); + + +var fragTemplate = [ + 'varying vec2 vTextureCoord;', + 'varying vec4 vColor;', + 'varying float vTextureId;', + 'uniform sampler2D uSamplers[%count%];', + + 'void main(void){', + 'vec4 color;', + 'float textureId = floor(vTextureId+0.5);', + '%forloop%', + 'gl_FragColor = color * vColor;', + '}' +].join('\n'); + +function generateMultiTextureShader(gl, maxTextures) +{ + var vertexSrc = "#define GLSLIFY 1\nattribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec4 aColor;\nattribute float aTextureId;\n\nuniform mat3 projectionMatrix;\n\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nvarying float vTextureId;\n\nvoid main(void){\n gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n vTextureId = aTextureId;\n vColor = vec4(aColor.rgb * aColor.a, aColor.a);\n}\n"; + var fragmentSrc = fragTemplate; + + fragmentSrc = fragmentSrc.replace(/%count%/gi, maxTextures); + fragmentSrc = fragmentSrc.replace(/%forloop%/gi, generateSampleSrc(maxTextures)); + + var shader = new Shader(gl, vertexSrc, fragmentSrc); + + var sampleValues = []; + for (var i = 0; i < maxTextures; i++) + { + sampleValues[i] = i; + } + + shader.bind(); + shader.uniforms.uSamplers = sampleValues; + + return shader; +} + +function generateSampleSrc(maxTextures) +{ + var src = ''; + + src += '\n'; + src += '\n'; + + for (var i = 0; i < maxTextures; i++) + { + if(i > 0) + { + src += '\nelse '; + } + + if(i < maxTextures-1) + { + src += 'if(textureId == ' + i + '.0)'; + } + + src += '\n{'; + src += '\n\tcolor = texture2D(uSamplers['+i+'], vTextureCoord);'; + src += '\n}'; + } + + src += '\n'; + src += '\n'; + + return src; +} + + + +module.exports = generateMultiTextureShader; - if (this.data === null) { - this.error = new Error('Unsupported element ' + type); - this.complete(); - return; - } +},{"../../Shader":41}],103:[function(require,module,exports){ +var Sprite = require('../sprites/Sprite'), + Texture = require('../textures/Texture'), + math = require('../math'), + utils = require('../utils'), + CONST = require('../const'), + TextStyle = require('./TextStyle'); + +/** + * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, + * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. + * + * A Text can be created directly from a string and a style object + * + * ```js + * var text = new PIXI.Text('This is a pixi text',{font : '24px Arial', fill : 0xff1010, align : 'center'}); + * ``` + * + * @class + * @extends PIXI.Sprite + * @memberof PIXI + * @param text {string} The string that you would like the text to display + * @param [style] {object|PIXI.TextStyle} The style parameters + * @param [resolution=1] {number} The current resolution / device pixel ratio of the canvas + */ +function Text(text, style, resolution) +{ + /** + * The canvas element that everything is drawn to + * + * @member {HTMLCanvasElement} + */ + this.canvas = document.createElement('canvas'); + + /** + * The canvas 2d context that everything is drawn with + * @member {HTMLCanvasElement} + */ + this.context = this.canvas.getContext('2d'); + + /** + * The resolution / device pixel ratio of the canvas + * @member {number} + * @default 1 + */ + this.resolution = resolution || CONST.RESOLUTION; + + /** + * Private tracker for the current text. + * + * @member {string} + * @private + */ + this._text = null; + + /** + * Private tracker for the current style. + * + * @member {object} + * @private + */ + this._style = null; + /** + * Private listener to track style changes. + * + * @member {Function} + * @private + */ + this._styleListener = null; + + /** + * Private tracker for the current font. + * + * @member {string} + * @private + */ + this._font = ''; + + var texture = Texture.fromCanvas(this.canvas); + texture.orig = new math.Rectangle(); + texture.trim = new math.Rectangle(); + Sprite.call(this, texture); + + this.text = text; + this.style = style; +} + +// constructor +Text.prototype = Object.create(Sprite.prototype); +Text.prototype.constructor = Text; +module.exports = Text; + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +Object.defineProperties(Text.prototype, { + /** + * The width of the Text, setting this will actually modify the scale to achieve the value set + * + * @member {number} + * @memberof PIXI.Text# + */ + width: { + get: function () + { + this.updateText(true); + + return Math.abs(this.scale.x) * this.texture.orig.width; + }, + set: function (value) + { + this.updateText(true); + + var sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } + }, + + /** + * The height of the Text, setting this will actually modify the scale to achieve the value set + * + * @member {number} + * @memberof PIXI.Text# + */ + height: { + get: function () + { + this.updateText(true); + + return Math.abs(this.scale.y) * this._texture.orig.height; + }, + set: function (value) + { + this.updateText(true); + + var sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } + }, + + /** + * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. + * + * @member {object|PIXI.TextStyle} + * @memberof PIXI.Text# + */ + style: { + get: function () + { + return this._style; + }, + set: function (style) + { + if (this._style) + { + this._style.off(CONST.TEXT_STYLE_CHANGED, this._onStyleChange, this); + } + + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; + } + else + { + this._style = new TextStyle(style); + } + this._style.on(CONST.TEXT_STYLE_CHANGED, this._onStyleChange, this); + this.dirty = true; + } + }, + + /** + * Set the copy for the text object. To split a line you can use '\n'. + * + * @member {string} + * @memberof PIXI.Text# + */ + text: { + get: function() + { + return this._text; + }, + set: function (text){ + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } + } +}); + +/** + * Renders text and updates it when needed + * @param respectDirty {boolean} Whether to abort updating the text if the Text isn't dirty and the function is called. + * @private + */ +Text.prototype.updateText = function (respectDirty) +{ + if (!this.dirty && respectDirty) { + return; + } + var style = this._style; + + // build canvas api font setting from invididual components. Convert a numeric style.fontSize to px + var fontSizeString = (typeof style.fontSize === 'number') ? style.fontSize + 'px' : style.fontSize; + this._font = style.fontStyle + ' ' + style.fontVariant + ' ' + style.fontWeight + ' ' + fontSizeString + ' ' + style.fontFamily; + + this.context.font = this._font; + + // word wrap + // preserve original text + var outputText = style.wordWrap ? this.wordWrap(this._text) : this._text; + + // split text into lines + var lines = outputText.split(/(?:\r\n|\r|\n)/); + + // calculate text width + var lineWidths = new Array(lines.length); + var maxLineWidth = 0; + var fontProperties = this.determineFontProperties(this._font); + + var i; + for (i = 0; i < lines.length; i++) + { + var lineWidth = this.context.measureText(lines[i]).width + ((lines[i].length - 1) * style.letterSpacing); + lineWidths[i] = lineWidth; + maxLineWidth = Math.max(maxLineWidth, lineWidth); + } + + var width = maxLineWidth + style.strokeThickness; + if (style.dropShadow) + { + width += style.dropShadowDistance; + } + + this.canvas.width = Math.ceil( ( width + this.context.lineWidth ) * this.resolution ); + + // calculate text height + var lineHeight = this.style.lineHeight || fontProperties.fontSize + style.strokeThickness; + + var height = lineHeight * lines.length; + if (style.dropShadow) + { + height += style.dropShadowDistance; + } + + this.canvas.height = Math.ceil( ( height + this._style.padding * 2 ) * this.resolution ); + + this.context.scale( this.resolution, this.resolution); + + if (navigator.isCocoonJS) + { + this.context.clearRect(0, 0, this.canvas.width, this.canvas.height); + + } + + //this.context.fillStyle="#FF0000"; + //this.context.fillRect(0, 0, this.canvas.width, this.canvas.height); + + this.context.font = this._font; + this.context.strokeStyle = style.stroke; + this.context.lineWidth = style.strokeThickness; + this.context.textBaseline = style.textBaseline; + this.context.lineJoin = style.lineJoin; + this.context.miterLimit = style.miterLimit; + + var linePositionX; + var linePositionY; + + if (style.dropShadow) + { + if (style.dropShadowBlur > 0) { + this.context.shadowColor = style.dropShadowColor; + this.context.shadowBlur = style.dropShadowBlur; + } else { + this.context.fillStyle = style.dropShadowColor; + } + + var xShadowOffset = Math.cos(style.dropShadowAngle) * style.dropShadowDistance; + var yShadowOffset = Math.sin(style.dropShadowAngle) * style.dropShadowDistance; + + for (i = 0; i < lines.length; i++) + { + linePositionX = style.strokeThickness / 2; + linePositionY = (style.strokeThickness / 2 + i * lineHeight) + fontProperties.ascent; + + if (style.align === 'right') + { + linePositionX += maxLineWidth - lineWidths[i]; + } + else if (style.align === 'center') + { + linePositionX += (maxLineWidth - lineWidths[i]) / 2; + } + + if (style.fill) + { + this.drawLetterSpacing(lines[i], linePositionX + xShadowOffset, linePositionY + yShadowOffset + style.padding); + + if (style.stroke && style.strokeThickness) + { + this.context.strokeStyle = style.dropShadowColor; + this.drawLetterSpacing(lines[i], linePositionX + xShadowOffset, linePositionY + yShadowOffset + style.padding, true); + this.context.strokeStyle = style.stroke; + } + } + } + } + + //set canvas text styles + this.context.fillStyle = this._generateFillStyle(style, lines); + + //draw lines line by line + for (i = 0; i < lines.length; i++) + { + linePositionX = style.strokeThickness / 2; + linePositionY = (style.strokeThickness / 2 + i * lineHeight) + fontProperties.ascent; + + if (style.align === 'right') + { + linePositionX += maxLineWidth - lineWidths[i]; + } + else if (style.align === 'center') + { + linePositionX += (maxLineWidth - lineWidths[i]) / 2; + } + + if (style.stroke && style.strokeThickness) + { + this.drawLetterSpacing(lines[i], linePositionX, linePositionY + style.padding, true); + } + + if (style.fill) + { + this.drawLetterSpacing(lines[i], linePositionX, linePositionY + style.padding); + } + } + + this.updateTexture(); +}; + +/** + * Render the text with letter-spacing. + * @param {string} text - The text to draw + * @param {number} x - Horizontal position to draw the text + * @param {number} y - Vertical position to draw the text + * @param {boolean} isStroke - Is this drawing for the outside stroke of the text? If not, it's for the inside fill + * @private + */ +Text.prototype.drawLetterSpacing = function(text, x, y, isStroke) +{ + var style = this._style; + + // letterSpacing of 0 means normal + var letterSpacing = style.letterSpacing; + + if (letterSpacing === 0) + { + if (isStroke) + { + this.context.strokeText(text, x, y); + } + else + { + this.context.fillText(text, x, y); + } + return; + } + + var characters = String.prototype.split.call(text, ''), + index = 0, + current, + currentPosition = x; + + while (index < text.length) + { + current = characters[index++]; + if (isStroke) + { + this.context.strokeText(current, currentPosition, y); + } + else + { + this.context.fillText(current, currentPosition, y); + } + currentPosition += this.context.measureText(current).width + letterSpacing; + } +}; + +/** + * Updates texture size based on canvas size + * + * @private + */ +Text.prototype.updateTexture = function () +{ + var texture = this._texture; + var style = this._style; + + texture.baseTexture.hasLoaded = true; + texture.baseTexture.resolution = this.resolution; + + texture.baseTexture.realWidth = this.canvas.width; + texture.baseTexture.realHeight = this.canvas.height; + texture.baseTexture.width = this.canvas.width / this.resolution; + texture.baseTexture.height = this.canvas.height / this.resolution; + texture.trim.width = texture._frame.width = this.canvas.width / this.resolution; + texture.trim.height = texture._frame.height = this.canvas.height / this.resolution; + + texture.trim.x = 0; + texture.trim.y = -style.padding; + + texture.orig.width = texture._frame.width; + texture.orig.height = texture._frame.height - style.padding*2; + + //call sprite onTextureUpdate to update scale if _width or _height were set + this._onTextureUpdate(); + + texture.baseTexture.emit('update', texture.baseTexture); + + this.dirty = false; +}; + +/** + * Renders the object using the WebGL renderer + * + * @param renderer {PIXI.WebGLRenderer} The renderer + */ +Text.prototype.renderWebGL = function (renderer) +{ + this.updateText(true); + + Sprite.prototype.renderWebGL.call(this, renderer); +}; + +/** + * Renders the object using the Canvas renderer + * + * @param renderer {PIXI.CanvasRenderer} The renderer + * @private + */ +Text.prototype._renderCanvas = function (renderer) +{ + this.updateText(true); + + Sprite.prototype._renderCanvas.call(this, renderer); +}; + +/** + * Calculates the ascent, descent and fontSize of a given fontStyle + * + * @param fontStyle {string} String representing the style of the font + * @return {Object} Font properties object + * @private + */ +Text.prototype.determineFontProperties = function (fontStyle) +{ + var properties = Text.fontPropertiesCache[fontStyle]; + + if (!properties) + { + properties = {}; + + var canvas = Text.fontPropertiesCanvas; + var context = Text.fontPropertiesContext; + + context.font = fontStyle; + + var width = Math.ceil(context.measureText('|MÉq').width); + var baseline = Math.ceil(context.measureText('M').width); + var height = 2 * baseline; + + baseline = baseline * 1.4 | 0; + + canvas.width = width; + canvas.height = height; + + context.fillStyle = '#f00'; + context.fillRect(0, 0, width, height); + + context.font = fontStyle; + + context.textBaseline = 'alphabetic'; + context.fillStyle = '#000'; + context.fillText('|MÉq', 0, baseline); + + var imagedata = context.getImageData(0, 0, width, height).data; + var pixels = imagedata.length; + var line = width * 4; + + var i, j; + + var idx = 0; + var stop = false; + + // ascent. scan from top to bottom until we find a non red pixel + for (i = 0; i < baseline; i++) + { + for (j = 0; j < line; j += 4) + { + if (imagedata[idx + j] !== 255) + { + stop = true; + break; + } + } + if (!stop) + { + idx += line; + } + else + { + break; + } + } + + properties.ascent = baseline - i; + + idx = pixels - line; + stop = false; + + // descent. scan from bottom to top until we find a non red pixel + for (i = height; i > baseline; i--) + { + for (j = 0; j < line; j += 4) + { + if (imagedata[idx + j] !== 255) + { + stop = true; + break; + } + } + if (!stop) + { + idx -= line; + } + else + { + break; + } + } + + properties.descent = i - baseline; + properties.fontSize = properties.ascent + properties.descent; + + Text.fontPropertiesCache[fontStyle] = properties; + } + + return properties; +}; + +/** + * Applies newlines to a string to have it optimally fit into the horizontal + * bounds set by the Text object's wordWrapWidth property. + * + * @param text {string} String to apply word wrapping to + * @return {string} New string with new lines applied where required + * @private + */ +Text.prototype.wordWrap = function (text) +{ + // Greedy wrapping algorithm that will wrap words as the line grows longer + // than its horizontal bounds. + var result = ''; + var lines = text.split('\n'); + var wordWrapWidth = this._style.wordWrapWidth; + for (var i = 0; i < lines.length; i++) + { + var spaceLeft = wordWrapWidth; + var words = lines[i].split(' '); + for (var j = 0; j < words.length; j++) + { + var wordWidth = this.context.measureText(words[j]).width; + if (this._style.breakWords && wordWidth > wordWrapWidth) + { + // Word should be split in the middle + var characters = words[j].split(''); + for (var c = 0; c < characters.length; c++) + { + var characterWidth = this.context.measureText(characters[c]).width; + if (characterWidth > spaceLeft) + { + result += '\n' + characters[c]; + spaceLeft = wordWrapWidth - characterWidth; + } + else + { + if (c === 0) + { + result += ' '; + } + result += characters[c]; + spaceLeft -= characterWidth; + } + } + } + else + { + var wordWidthWithSpace = wordWidth + this.context.measureText(' ').width; + if (j === 0 || wordWidthWithSpace > spaceLeft) + { + // Skip printing the newline if it's the first word of the line that is + // greater than the word wrap width. + if (j > 0) + { + result += '\n'; + } + result += words[j]; + spaceLeft = wordWrapWidth - wordWidth; + } + else + { + spaceLeft -= wordWidthWithSpace; + result += ' ' + words[j]; + } + } + } + + if (i < lines.length-1) + { + result += '\n'; + } + } + return result; +}; + +/** + * calculates the bounds of the Text as a rectangle. The bounds calculation takes the worldTransform into account. + */ +Text.prototype._calculateBounds = function () +{ + this.updateText(true); + this.calculateVertices(); + // if we have already done this on THIS frame. + this._bounds.addQuad(this.vertexData); +}; + +/** + * Method to be called upon a TextStyle change. + * @private + */ +Text.prototype._onStyleChange = function () +{ + this.dirty = true; +}; + +/** + * Generates the fill style. Can automatically generate a gradient based on the fill style being an array + * @return string|Number|CanvasGradient + * @private + */ +Text.prototype._generateFillStyle = function (style, lines) +{ + if (!Array.isArray(style.fill)) + { + return style.fill; + } + else + { + // the gradient will be evenly spaced out according to how large the array is. + // ['#FF0000', '#00FF00', '#0000FF'] would created stops at 0.25, 0.5 and 0.75 + var i; + var gradient; + var totalIterations; + var currentIteration; + var stop; + + var width = this.canvas.width / this.resolution; + var height = this.canvas.height / this.resolution; + + if (style.fillGradientType === CONST.TEXT_GRADIENT.LINEAR_VERTICAL) + { + // start the gradient at the top center of the canvas, and end at the bottom middle of the canvas + gradient = this.context.createLinearGradient(width / 2, 0, width / 2, height); + + // we need to repeat the gradient so that each invididual line of text has the same vertical gradient effect + // ['#FF0000', '#00FF00', '#0000FF'] over 2 lines would create stops at 0.125, 0.25, 0.375, 0.625, 0.75, 0.875 + totalIterations = ( style.fill.length + 1 ) * lines.length; + currentIteration = 0; + for (i = 0; i < lines.length; i++) + { + currentIteration += 1; + for (var j = 0; j < style.fill.length; j++) + { + stop = (currentIteration / totalIterations); + gradient.addColorStop(stop, style.fill[j]); + currentIteration++; + } + } + } + else + { + // start the gradient at the center left of the canvas, and end at the center right of the canvas + gradient = this.context.createLinearGradient(0, height / 2, width, height / 2); + + // can just evenly space out the gradients in this case, as multiple lines makes no difference to an even left to right gradient + totalIterations = style.fill.length + 1; + currentIteration = 1; + + for (i = 0; i < style.fill.length; i++) + { + stop = currentIteration / totalIterations; + gradient.addColorStop(stop, style.fill[i]); + currentIteration++; + } + } + + return gradient; + } +}; + +/** + * Destroys this text object. + * + * @param [options] {object|boolean} Options parameter. A boolean will act as if all options have been set to that value + * @param [options.children=false] {boolean} if set to true, all the children will have their destroy + * method called as well. 'options' will be passed on to those calls. + * @param [options.texture=false] {boolean} Should it destroy the current texture of the sprite as well + * @param [options.baseTexture=false] {boolean} Should it destroy the base texture of the sprite as well + */ +Text.prototype.destroy = function (options) +{ + Sprite.prototype.destroy.call(this, options); + + // make sure to reset the the context and canvas.. dont want this hanging around in memory! + this.context = null; + this.canvas = null; + + this._style.off(CONST.TEXT_STYLE_CHANGED, this._onStyleChange, this); + this._style = null; +}; - // support for CocoonJS Canvas+ runtime, lacks document.createElement('source') - if (navigator.isCocoonJS) { - this.data.src = Array.isArray(this.url) ? this.url[0] : this.url; - } - else { - if (Array.isArray(this.url)) { - for (var i = 0; i < this.url.length; ++i) { - this.data.appendChild(this._createSource(type, this.url[i])); - } - } - else { - this.data.appendChild(this._createSource(type, this.url)); - } - } +},{"../const":42,"../math":66,"../sprites/Sprite":97,"../textures/Texture":108,"../utils":115,"./TextStyle":104}],104:[function(require,module,exports){ +var EventEmitter = require('eventemitter3'), + CONST = require('../const'), + utils = require('../utils'); + +/** + * A TextStyle Object decorates a Text Object. It acts as an event emitter, and can be shared between + * multiple Text objects. + * + * @class + * @extends EventEmitter + * @memberof PIXI + * @param [style] {object} The style parameters + * @param [style.align='left'] {string} Alignment for multiline text ('left', 'center' or 'right'), does not affect single line text + * @param [style.breakWords=false] {boolean} Indicates if lines can be wrapped within words, it needs wordWrap to be set to true + * @param [style.dropShadow=false] {boolean} Set a drop shadow for the text + * @param [style.dropShadowAngle=Math.PI/6] {number} Set a angle of the drop shadow + * @param [style.dropShadowBlur=0] {number} Set a shadow blur radius + * @param [style.dropShadowColor='#000000'] {string} A fill style to be used on the dropshadow e.g 'red', '#00FF00' + * @param [style.dropShadowDistance=5] {number} Set a distance of the drop shadow + * @param [style.fill='black'] {string|string[]|number|number[]|CanvasGradient|CanvasPattern} A canvas fillstyle that will be used on the + * text e.g 'red', '#00FF00'. Can be an array to create a gradient eg ['#000000','#FFFFFF'] @see {@link https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/fillStyle|MDN} + * @param [style.fillGradientType=PIXI.TEXT_GRADIENT.LINEAR_VERTICAL] {number} If fills styles are supplied, this can change the type/direction of the gradient. See {@link PIXI.TEXT_GRADIENT} for possible values + * @param [style.fontFamily='Arial'] {string} The font family + * @param [style.fontSize=26] {number|string} The font size (as a number it converts to px, but as a string, equivalents are '26px','20pt','160%' or '1.6em') + * @param [style.fontStyle='normal'] {string} The font style ('normal', 'italic' or 'oblique') + * @param [style.fontVariant='normal'] {string} The font variant ('normal' or 'small-caps') + * @param [style.fontWeight='normal'] {string} The font weight ('normal', 'bold', 'bolder', 'lighter' and '100', '200', '300', '400', '500', '600', '700', 800' or '900') + * @param [style.letterSpacing=0] {number} The amount of spacing between letters, default is 0 + * @param [style.lineHeight] {number} The line height, a number that represents the vertical space that a letter uses + * @param [style.lineJoin='miter'] {string} The lineJoin property sets the type of corner created, it can resolve + * spiked text issues. Default is 'miter' (creates a sharp corner). + * @param [style.miterLimit=10] {number} The miter limit to use when using the 'miter' lineJoin mode. This can reduce + * or increase the spikiness of rendered text. + * @param [style.padding=0] {number} Occasionally some fonts are cropped on top or bottom. Adding some padding will + * prevent this from happening by adding padding to the top and bottom of text height. + * @param [style.stroke='black'] {string|number} A canvas fillstyle that will be used on the text stroke e.g 'blue', '#FCFF00' + * @param [style.strokeThickness=0] {number} A number that represents the thickness of the stroke. Default is 0 (no stroke) + * @param [style.textBaseline='alphabetic'] {string} The baseline of the text that is rendered. + * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used + * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true + */ +function TextStyle(style) +{ + EventEmitter.call(this); + Object.assign(this, this._defaults, style); +} + +TextStyle.prototype = Object.create(EventEmitter.prototype); +TextStyle.prototype.constructor = TextStyle; +module.exports = TextStyle; + +// Default settings. Explained in the constructor. +TextStyle.prototype._defaults = { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 +}; + +/** + * Creates a new TextStyle object with the same values as this one. + * Note that the only the properties of the object are cloned, not its event emitter. + * + * @return {PIXI.TextStyle} New cloned TextStyle object + */ +TextStyle.prototype.clone = function () +{ + var clonedProperties = {}; + for (var key in this._defaults) + { + clonedProperties[key] = this[key]; + } + return new TextStyle(clonedProperties); +}; + +/** + * Resets all properties to the defaults specified in TextStyle.prototype._default + */ +TextStyle.prototype.reset = function () +{ + Object.assign(this, this._defaults); +}; + +/** + * Create setters and getters for each of the style properties. Converts colors where necessary. + * Any set operation will emit a styleChanged event. + */ +Object.defineProperties(TextStyle.prototype, { + align: { + get: function () + { + return this._align; + }, + set: function (align) + { + if (this._align !== align) + { + this._align = align; + this.emit(CONST.TEXT_STYLE_CHANGED); + } + } + }, + + breakWords: { + get: function () + { + return this._breakWords; + }, + set: function (breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.emit(CONST.TEXT_STYLE_CHANGED); + } + } + }, + + dropShadow: { + get: function () + { + return this._dropShadow; + }, + set: function (dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.emit(CONST.TEXT_STYLE_CHANGED); + } + } + }, + + dropShadowAngle: { + get: function () + { + return this._dropShadowAngle; + }, + set: function (dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.emit(CONST.TEXT_STYLE_CHANGED); + } + } + }, + + dropShadowBlur: { + get: function () + { + return this._dropShadowBlur; + }, + set: function (dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.emit(CONST.TEXT_STYLE_CHANGED); + } + } + }, + + dropShadowColor: { + get: function () + { + return this._dropShadowColor; + }, + set: function (dropShadowColor) + { + var outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.emit(CONST.TEXT_STYLE_CHANGED); + } + } + }, + + dropShadowDistance: { + get: function () + { + return this._dropShadowDistance; + }, + set: function (dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.emit(CONST.TEXT_STYLE_CHANGED); + } + } + }, + + fill: { + get: function () + { + return this._fill; + }, + set: function (fill) + { + var outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.emit(CONST.TEXT_STYLE_CHANGED); + } + } + }, + + fillGradientType: { + get: function () + { + return this._fillGradientType; + }, + set: function (fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.emit(CONST.TEXT_STYLE_CHANGED); + } + } + }, + + fontFamily: { + get: function () + { + return this._fontFamily; + }, + set: function (fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.emit(CONST.TEXT_STYLE_CHANGED); + } + } + }, + + fontSize: { + get: function () + { + return this._fontSize; + }, + set: function (fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.emit(CONST.TEXT_STYLE_CHANGED); + } + } + }, + + fontStyle: { + get: function () + { + return this._fontStyle; + }, + set: function (fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.emit(CONST.TEXT_STYLE_CHANGED); + } + } + }, + + fontVariant: { + get: function () + { + return this._fontVariant; + }, + set: function (fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.emit(CONST.TEXT_STYLE_CHANGED); + } + } + }, + + fontWeight: { + get: function () + { + return this._fontWeight; + }, + set: function (fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.emit(CONST.TEXT_STYLE_CHANGED); + } + } + }, + + letterSpacing: { + get: function () + { + return this._letterSpacing; + }, + set: function (letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.emit(CONST.TEXT_STYLE_CHANGED); + } + } + }, + + lineHeight: { + get: function () + { + return this._lineHeight; + }, + set: function (lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.emit(CONST.TEXT_STYLE_CHANGED); + } + } + }, + + lineJoin: { + get: function () + { + return this._lineJoin; + }, + set: function (lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.emit(CONST.TEXT_STYLE_CHANGED); + } + } + }, + + miterLimit: { + get: function () + { + return this._miterLimit; + }, + set: function (miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.emit(CONST.TEXT_STYLE_CHANGED); + } + } + }, + + padding: { + get: function () + { + return this._padding; + }, + set: function (padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.emit(CONST.TEXT_STYLE_CHANGED); + } + } + }, + + stroke: { + get: function () + { + return this._stroke; + }, + set: function (stroke) + { + var outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.emit(CONST.TEXT_STYLE_CHANGED); + } + } + }, + + strokeThickness: { + get: function () + { + return this._strokeThickness; + }, + set: function (strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.emit(CONST.TEXT_STYLE_CHANGED); + } + } + }, + + textBaseline: { + get: function () + { + return this._textBaseline; + }, + set: function (textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.emit(CONST.TEXT_STYLE_CHANGED); + } + } + }, + + wordWrap: { + get: function () + { + return this._wordWrap; + }, + set: function (wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.emit(CONST.TEXT_STYLE_CHANGED); + } + } + }, + + wordWrapWidth: { + get: function () + { + return this._wordWrapWidth; + }, + set: function (wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.emit(CONST.TEXT_STYLE_CHANGED); + } + } + } +}); + +/** + * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. + * + * @return {string} The color as a string. + */ +function getColor(color) +{ + if (typeof color === 'number') + { + return utils.hex2string(color); + } + else if (Array.isArray(color)) + { + for (var i = 0; i < color.length; ++i) + { + if (typeof color[i] === 'number') + { + color[i] = utils.hex2string(color[i]); + } + } + } + + return color; +} - this['is' + type[0].toUpperCase() + type.substring(1)] = true; +},{"../const":42,"../utils":115,"eventemitter3":4}],105:[function(require,module,exports){ +var BaseTexture = require('./BaseTexture'), + CONST = require('../const'); + +/** + * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. + * + * __Hint__: All DisplayObjects (i.e. Sprites) that render to a BaseRenderTexture should be preloaded + * otherwise black rectangles will be drawn instead. + * + * A BaseRenderTexture takes a snapshot of any Display Object given to its render method. The position + * and rotation of the given Display Objects is ignored. For example: + * + * ```js + * var renderer = PIXI.autoDetectRenderer(1024, 1024, { view: canvas, ratio: 1 }); + * var BaserenderTexture = new PIXI.BaseRenderTexture(renderer, 800, 600); + * var sprite = PIXI.Sprite.fromImage("spinObj_01.png"); + * + * sprite.position.x = 800/2; + * sprite.position.y = 600/2; + * sprite.anchor.x = 0.5; + * sprite.anchor.y = 0.5; + * + * BaserenderTexture.render(sprite); + * ``` + * + * The Sprite in this case will be rendered to a position of 0,0. To render this sprite at its actual + * position a Container should be used: + * + * ```js + * var doc = new PIXI.Container(); + * + * doc.addChild(sprite); + * + * var baseRenderTexture = new PIXI.BaserenderTexture(100, 100); + * var renderTexture = new PIXI.RenderTexture(baseRenderTexture); + * + * renderer.render(doc, renderTexture); // Renders to center of RenderTexture + * ``` + * + * @class + * @extends PIXI.BaseTexture + * @memberof PIXI + * @param [width=100] {number} The width of the base render texture + * @param [height=100] {number} The height of the base render texture + * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values + * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated + */ +function BaseRenderTexture(width, height, scaleMode, resolution) +{ + BaseTexture.call(this, null, scaleMode); + + this.width = width || 100; + this.height = height || 100; + + this.realWidth = this.width * resolution; + this.realHeight = this.height * resolution; + + this.resolution = resolution || CONST.RESOLUTION; + this.scaleMode = scaleMode || CONST.SCALE_MODES.DEFAULT; + this.hasLoaded = true; + + /** + * A map of renderer IDs to webgl renderTargets + * + * @member {object} + * @private + */ + this._glRenderTargets = []; + + /** + * A reference to the canvas render target (we only need one as this can be shared accross renderers) + * + * @member {object} + * @private + */ + this._canvasRenderTarget = null; + + /** + * This will let the renderer know if the texture is valid. If it's not then it cannot be rendered. + * + * @member {boolean} + */ + this.valid = false; +} + +BaseRenderTexture.prototype = Object.create(BaseTexture.prototype); +BaseRenderTexture.prototype.constructor = BaseRenderTexture; +module.exports = BaseRenderTexture; + +/** + * Resizes the BaseRenderTexture. + * + * @param width {number} The width to resize to. + * @param height {number} The height to resize to. + */ +BaseRenderTexture.prototype.resize = function (width, height) +{ + + if (width === this.width && height === this.height) + { + return; + } + + this.valid = (width > 0 && height > 0); + + this.width = width; + this.height = height; + + this.realWidth = this.width * this.resolution; + this.realHeight = this.height * this.resolution; + + if (!this.valid) + { + return; + } + + this.emit('update', this); + +}; + +/** + * Destroys this texture + * + */ +BaseRenderTexture.prototype.destroy = function () +{ + BaseTexture.prototype.destroy.call(this, true); + this.renderer = null; +}; + - this.data.addEventListener('error', this._boundOnError, false); - this.data.addEventListener('load', this._boundComplete, false); - this.data.addEventListener('progress', this._boundOnProgress, false); - this.data.addEventListener('canplaythrough', this._boundComplete, false); +},{"../const":42,"./BaseTexture":106}],106:[function(require,module,exports){ +var utils = require('../utils'), + CONST = require('../const'), + EventEmitter = require('eventemitter3'), + determineCrossOrigin = require('../utils/determineCrossOrigin'), + bitTwiddle = require('bit-twiddle'); + +/** + * A texture stores the information that represents an image. All textures have a base texture. + * + * @class + * @memberof PIXI + * @param [source ]{HTMLImageElement|HTMLCanvasElement} the source object of the texture. + * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values + * @param [resolution=1] {number} The resolution / device pixel ratio of the texture + */ +function BaseTexture(source, scaleMode, resolution) +{ + EventEmitter.call(this); + + this.uid = utils.uid(); + + this.touched = 0; + + /** + * The resolution / device pixel ratio of the texture + * + * @member {number} + * @default 1 + */ + this.resolution = resolution || CONST.RESOLUTION; + + /** + * The width of the base texture set when the image has loaded + * + * @member {number} + * @readonly + */ + this.width = 100; + + /** + * The height of the base texture set when the image has loaded + * + * @member {number} + * @readonly + */ + this.height = 100; + + // TODO docs + // used to store the actual dimensions of the source + /** + * Used to store the actual width of the source of this texture + * + * @member {number} + * @readonly + */ + this.realWidth = 100; + /** + * Used to store the actual height of the source of this texture + * + * @member {number} + * @readonly + */ + this.realHeight = 100; + + /** + * The scale mode to apply when scaling this texture + * + * @member {number} + * @default PIXI.SCALE_MODES.LINEAR + * @see PIXI.SCALE_MODES + */ + this.scaleMode = scaleMode || CONST.SCALE_MODES.DEFAULT; + + /** + * Set to true once the base texture has successfully loaded. + * + * This is never true if the underlying source fails to load or has no texture data. + * + * @member {boolean} + * @readonly + */ + this.hasLoaded = false; + + /** + * Set to true if the source is currently loading. + * + * If an Image source is loading the 'loaded' or 'error' event will be + * dispatched when the operation ends. An underyling source that is + * immediately-available bypasses loading entirely. + * + * @member {boolean} + * @readonly + */ + this.isLoading = false; + + /** + * The image source that is used to create the texture. + * + * TODO: Make this a setter that calls loadSource(); + * + * @member {HTMLImageElement|HTMLCanvasElement} + * @readonly + */ + this.source = null; // set in loadSource, if at all + + /** + * Controls if RGB channels should be pre-multiplied by Alpha (WebGL only) + * All blend modes, and shaders written for default value. Change it on your own risk. + * + * @member {boolean} + * @default true + */ + this.premultipliedAlpha = true; + + /** + * The image url of the texture + * + * @member {string} + */ + this.imageUrl = null; + + /** + * Wether or not the texture is a power of two, try to use power of two textures as much as you can + * @member {boolean} + * @private + */ + this.isPowerOfTwo = false; + + // used for webGL + + /** + * + * Set this to true if a mipmap of this texture needs to be generated. This value needs to be set before the texture is used + * Also the texture must be a power of two size to work + * + * @member {boolean} + * @see PIXI.MIPMAP_TEXTURES + */ + this.mipmap = CONST.MIPMAP_TEXTURES; + + /** + * + * WebGL Texture wrap mode + * + * @member {number} + * @see PIXI.WRAP_MODES + */ + this.wrapMode = CONST.WRAP_MODES.DEFAULT; + + /** + * A map of renderer IDs to webgl textures + * + * @member {object} + * @private + */ + this._glTextures = []; + this._enabled = 0; + this._id = 0; + + // if no source passed don't try to load + if (source) + { + this.loadSource(source); + } + + /** + * Fired when a not-immediately-available source finishes loading. + * + * @event loaded + * @memberof PIXI.BaseTexture# + * @protected + */ + + /** + * Fired when a not-immediately-available source fails to load. + * + * @event error + * @memberof PIXI.BaseTexture# + * @protected + */ +} + +BaseTexture.prototype = Object.create(EventEmitter.prototype); +BaseTexture.prototype.constructor = BaseTexture; +module.exports = BaseTexture; + +/** + * Updates the texture on all the webgl renderers, this also assumes the src has changed. + * + * @fires update + */ +BaseTexture.prototype.update = function () +{ + this.realWidth = this.source.naturalWidth || this.source.videoWidth || this.source.width; + this.realHeight = this.source.naturalHeight || this.source.videoHeight || this.source.height; + + this.width = this.realWidth / this.resolution; + this.height = this.realHeight / this.resolution; + + this.isPowerOfTwo = bitTwiddle.isPow2(this.realWidth) && bitTwiddle.isPow2(this.realHeight); + + this.emit('update', this); +}; + +/** + * Load a source. + * + * If the source is not-immediately-available, such as an image that needs to be + * downloaded, then the 'loaded' or 'error' event will be dispatched in the future + * and `hasLoaded` will remain false after this call. + * + * The logic state after calling `loadSource` directly or indirectly (eg. `fromImage`, `new BaseTexture`) is: + * + * if (texture.hasLoaded) { + * // texture ready for use + * } else if (texture.isLoading) { + * // listen to 'loaded' and/or 'error' events on texture + * } else { + * // not loading, not going to load UNLESS the source is reloaded + * // (it may still make sense to listen to the events) + * } + * + * @protected + * @param source {HTMLImageElement|HTMLCanvasElement} the source object of the texture. + */ +BaseTexture.prototype.loadSource = function (source) +{ + var wasLoading = this.isLoading; + this.hasLoaded = false; + this.isLoading = false; + + if (wasLoading && this.source) + { + this.source.onload = null; + this.source.onerror = null; + } + + this.source = source; + + // Apply source if loaded. Otherwise setup appropriate loading monitors. + if ((this.source.complete || this.source.getContext) && this.source.width && this.source.height) + { + this._sourceLoaded(); + } + else if (!source.getContext) + { + + // Image fail / not ready + this.isLoading = true; + + var scope = this; + + source.onload = function () + { + source.onload = null; + source.onerror = null; + + if (!scope.isLoading) + { + return; + } + + scope.isLoading = false; + scope._sourceLoaded(); + + scope.emit('loaded', scope); + }; + + source.onerror = function () + { + source.onload = null; + source.onerror = null; + + if (!scope.isLoading) + { + return; + } + + scope.isLoading = false; + scope.emit('error', scope); + }; + + // Per http://www.w3.org/TR/html5/embedded-content-0.html#the-img-element + // "The value of `complete` can thus change while a script is executing." + // So complete needs to be re-checked after the callbacks have been added.. + // NOTE: complete will be true if the image has no src so best to check if the src is set. + if (source.complete && source.src) + { + this.isLoading = false; + + // ..and if we're complete now, no need for callbacks + source.onload = null; + source.onerror = null; + + if (source.width && source.height) + { + this._sourceLoaded(); + + // If any previous subscribers possible + if (wasLoading) + { + this.emit('loaded', this); + } + } + else + { + // If any previous subscribers possible + if (wasLoading) + { + this.emit('error', this); + } + } + } + } +}; + +/** + * Used internally to update the width, height, and some other tracking vars once + * a source has successfully loaded. + * + * @private + */ +BaseTexture.prototype._sourceLoaded = function () +{ + this.hasLoaded = true; + this.update(); +}; + +/** + * Destroys this base texture + * + */ +BaseTexture.prototype.destroy = function () +{ + if (this.imageUrl) + { + delete utils.BaseTextureCache[this.imageUrl]; + delete utils.TextureCache[this.imageUrl]; + + this.imageUrl = null; + + if (!navigator.isCocoonJS) + { + this.source.src = ''; + } + } + else if (this.source && this.source._pixiId) + { + delete utils.BaseTextureCache[this.source._pixiId]; + } + + this.source = null; + + this.dispose(); +}; + +/** + * Frees the texture from WebGL memory without destroying this texture object. + * This means you can still use the texture later which will upload it to GPU + * memory again. + * + */ +BaseTexture.prototype.dispose = function () +{ + this.emit('dispose', this); + + // this should no longer be needed, the renderers should cleanup all the gl textures. + // this._glTextures = {}; +}; + +/** + * Changes the source image of the texture. + * The original source must be an Image element. + * + * @param newSrc {string} the path of the image + */ +BaseTexture.prototype.updateSourceImage = function (newSrc) +{ + this.source.src = newSrc; + + this.loadSource(this.source); +}; + +/** + * Helper function that creates a base texture from the given image url. + * If the image is not in the base texture cache it will be created and loaded. + * + * @static + * @param imageUrl {string} The image url of the texture + * @param [crossorigin=(auto)] {boolean} Should use anonymous CORS? Defaults to true if the URL is not a data-URI. + * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values + * @return PIXI.BaseTexture + */ +BaseTexture.fromImage = function (imageUrl, crossorigin, scaleMode) +{ + var baseTexture = utils.BaseTextureCache[imageUrl]; + + if (!baseTexture) + { + // new Image() breaks tex loading in some versions of Chrome. + // See https://code.google.com/p/chromium/issues/detail?id=238071 + var image = new Image();//document.createElement('img'); + + + if (crossorigin === undefined && imageUrl.indexOf('data:') !== 0) + { + image.crossOrigin = determineCrossOrigin(imageUrl); + } + + baseTexture = new BaseTexture(image, scaleMode); + baseTexture.imageUrl = imageUrl; + + image.src = imageUrl; + + utils.BaseTextureCache[imageUrl] = baseTexture; + + // if there is an @2x at the end of the url we are going to assume its a highres image + baseTexture.resolution = utils.getResolutionOfUrl(imageUrl); + } + + return baseTexture; +}; + +/** + * Helper function that creates a base texture from the given canvas element. + * + * @static + * @param canvas {HTMLCanvasElement} The canvas element source of the texture + * @param scaleMode {number} See {@link PIXI.SCALE_MODES} for possible values + * @return PIXI.BaseTexture + */ +BaseTexture.fromCanvas = function (canvas, scaleMode) +{ + if (!canvas._pixiId) + { + canvas._pixiId = 'canvas_' + utils.uid(); + } + + var baseTexture = utils.BaseTextureCache[canvas._pixiId]; + + if (!baseTexture) + { + baseTexture = new BaseTexture(canvas, scaleMode); + utils.BaseTextureCache[canvas._pixiId] = baseTexture; + } + + return baseTexture; +}; - this.data.load(); -}; +},{"../const":42,"../utils":115,"../utils/determineCrossOrigin":114,"bit-twiddle":2,"eventemitter3":4}],107:[function(require,module,exports){ +var BaseRenderTexture = require('./BaseRenderTexture'), + Texture = require('./Texture'); + +/** + * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. + * + * __Hint__: All DisplayObjects (i.e. Sprites) that render to a RenderTexture should be preloaded + * otherwise black rectangles will be drawn instead. + * + * A RenderTexture takes a snapshot of any Display Object given to its render method. The position + * and rotation of the given Display Objects is ignored. For example: + * + * ```js + * var renderer = PIXI.autoDetectRenderer(1024, 1024, { view: canvas, ratio: 1 }); + * var renderTexture = PIXI.RenderTexture.create(800, 600); + * var sprite = PIXI.Sprite.fromImage("spinObj_01.png"); + * + * sprite.position.x = 800/2; + * sprite.position.y = 600/2; + * sprite.anchor.x = 0.5; + * sprite.anchor.y = 0.5; + * + * renderer.render(sprite, renderTexture); + * ``` + * + * The Sprite in this case will be rendered to a position of 0,0. To render this sprite at its actual + * position a Container should be used: + * + * ```js + * var doc = new PIXI.Container(); + * + * doc.addChild(sprite); + * + * renderer.render(doc, renderTexture); // Renders to center of renderTexture + * ``` + * + * @class + * @extends PIXI.Texture + * @memberof PIXI + * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture + * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show + */ +function RenderTexture(baseRenderTexture, frame) +{ + // suport for legacy.. + this.legacyRenderer = null; + + if( !(baseRenderTexture instanceof BaseRenderTexture) ) + { + var width = arguments[1]; + var height = arguments[2]; + var scaleMode = arguments[3] || 0; + var resolution = arguments[4] || 1; + + // we have an old render texture.. + console.warn('v4 RenderTexture now expects a new BaseRenderTexture. Please use RenderTexture.create('+width+', '+height+')'); // jshint ignore:line + this.legacyRenderer = arguments[0]; + + frame = null; + baseRenderTexture = new BaseRenderTexture(width, height, scaleMode, resolution); + } + + + /** + * The base texture object that this texture uses + * + * @member {BaseTexture} + */ + Texture.call(this, + baseRenderTexture, + frame + ); + + /** + * This will let the renderer know if the texture is valid. If it's not then it cannot be rendered. + * + * @member {boolean} + */ + this.valid = true; + + this._updateUvs(); +} + +RenderTexture.prototype = Object.create(Texture.prototype); +RenderTexture.prototype.constructor = RenderTexture; +module.exports = RenderTexture; + +/** + * Resizes the RenderTexture. + * + * @param width {number} The width to resize to. + * @param height {number} The height to resize to. + * @param doNotResizeBaseTexture {boolean} Should the baseTexture.width and height values be resized as well? + */ +RenderTexture.prototype.resize = function (width, height, doNotResizeBaseTexture) +{ + + //TODO - could be not required.. + this.valid = (width > 0 && height > 0); + + this._frame.width = this.orig.width = width; + this._frame.height = this.orig.height = height; + + if (!doNotResizeBaseTexture) + { + this.baseTexture.resize(width, height); + } + + this._updateUvs(); +}; + +/** + * A short hand way of creating a render texture.. + * @param [width=100] {number} The width of the render texture + * @param [height=100] {number} The height of the render texture + * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values + * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated + */ +RenderTexture.create = function(width, height, scaleMode, resolution) +{ + return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); +}; -/** - * Loads this resources using an XMLHttpRequest. - * - * @private - */ -Resource.prototype._loadXhr = function () { - // if unset, determine the value - if (typeof this.xhrType !== 'string') { - this.xhrType = this._determineXhrType(); - } +},{"./BaseRenderTexture":105,"./Texture":108}],108:[function(require,module,exports){ +var BaseTexture = require('./BaseTexture'), + VideoBaseTexture = require('./VideoBaseTexture'), + TextureUvs = require('./TextureUvs'), + EventEmitter = require('eventemitter3'), + math = require('../math'), + utils = require('../utils'); + +/** + * A texture stores the information that represents an image or part of an image. It cannot be added + * to the display list directly. Instead use it as the texture for a Sprite. If no frame is provided then the whole image is used. + * + * You can directly create a texture from an image and then reuse it multiple times like this : + * + * ```js + * var texture = PIXI.Texture.fromImage('assets/image.png'); + * var sprite1 = new PIXI.Sprite(texture); + * var sprite2 = new PIXI.Sprite(texture); + * ``` + * + * @class + * @memberof PIXI + * @param baseTexture {PIXI.BaseTexture} The base texture source to create the texture from + * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show + * @param [orig] {PIXI.Rectangle} The area of original texture + * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture + * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} + */ +function Texture(baseTexture, frame, orig, trim, rotate) +{ + EventEmitter.call(this); + + /** + * Does this Texture have any frame data assigned to it? + * + * @member {boolean} + */ + this.noFrame = false; + + if (!frame) + { + this.noFrame = true; + frame = new math.Rectangle(0, 0, 1, 1); + } + + if (baseTexture instanceof Texture) + { + baseTexture = baseTexture.baseTexture; + } + + /** + * The base texture that this texture uses. + * + * @member {PIXI.BaseTexture} + */ + this.baseTexture = baseTexture; + + /** + * This is the area of the BaseTexture image to actually copy to the Canvas / WebGL when rendering, + * irrespective of the actual frame size or placement (which can be influenced by trimmed texture atlases) + * + * @member {PIXI.Rectangle} + */ + this._frame = frame; + + /** + * This is the trimmed area of original texture, before it was put in atlas + * + * @member {PIXI.Rectangle} + */ + this.trim = trim; + + /** + * This will let the renderer know if the texture is valid. If it's not then it cannot be rendered. + * + * @member {boolean} + */ + this.valid = false; + + /** + * This will let a renderer know that a texture has been updated (used mainly for webGL uv updates) + * + * @member {boolean} + */ + this.requiresUpdate = false; + + /** + * The WebGL UV data cache. + * + * @member {PIXI.TextureUvs} + * @private + */ + this._uvs = null; + + /** + * This is the area of original texture, before it was put in atlas + * + * @member {PIXI.Rectangle} + */ + this.orig = orig || frame;//new math.Rectangle(0, 0, 1, 1); + + this._rotate = +(rotate || 0); + + if (rotate === true) { + // this is old texturepacker legacy, some games/libraries are passing "true" for rotated textures + this._rotate = 2; + } else { + if (this._rotate % 2 !== 0) { + throw 'attempt to use diamond-shaped UVs. If you are sure, set rotation manually'; + } + } + + if (baseTexture.hasLoaded) + { + if (this.noFrame) + { + frame = new math.Rectangle(0, 0, baseTexture.width, baseTexture.height); + + // if there is no frame we should monitor for any base texture changes.. + baseTexture.on('update', this.onBaseTextureUpdated, this); + } + this.frame = frame; + } + else + { + baseTexture.once('loaded', this.onBaseTextureLoaded, this); + } + + /** + * Fired when the texture is updated. This happens if the frame or the baseTexture is updated. + * + * @event update + * @memberof PIXI.Texture# + * @protected + */ + + + this._updateID = 0; +} + +Texture.prototype = Object.create(EventEmitter.prototype); +Texture.prototype.constructor = Texture; +module.exports = Texture; + +Object.defineProperties(Texture.prototype, { + /** + * The frame specifies the region of the base texture that this texture uses. + * + * @member {PIXI.Rectangle} + * @memberof PIXI.Texture# + */ + frame: { + get: function () + { + return this._frame; + }, + set: function (frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) + { + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); + } + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + }, + /** + * Indicates whether the texture is rotated inside the atlas + * set to 2 to compensate for texture packer rotation + * set to 6 to compensate for spine packer rotation + * can be used to rotate or mirror sprites + * See {@link PIXI.GroupD8} for explanation + * + * @member {number} + */ + rotate: { + get: function () + { + return this._rotate; + }, + set: function (rotate) + { + this._rotate = rotate; + if (this.valid) + { + this._updateUvs(); + } + } + }, + + /** + * The width of the Texture in pixels. + * + * @member {number} + */ + width: { + get: function() { + return this.orig ? this.orig.width : 0; + } + }, + + /** + * The height of the Texture in pixels. + * + * @member {number} + */ + height: { + get: function() { + return this.orig ? this.orig.height : 0; + } + } +}); + +/** + * Updates this texture on the gpu. + * + */ +Texture.prototype.update = function () +{ + this.baseTexture.update(); +}; + +/** + * Called when the base texture is loaded + * + * @private + */ +Texture.prototype.onBaseTextureLoaded = function (baseTexture) +{ + this._updateID++; + + // TODO this code looks confusing.. boo to abusing getters and setterss! + if (this.noFrame) + { + this.frame = new math.Rectangle(0, 0, baseTexture.width, baseTexture.height); + } + else + { + this.frame = this._frame; + } + + this.baseTexture.on('update', this.onBaseTextureUpdated, this); + this.emit('update', this); + +}; + +/** + * Called when the base texture is updated + * + * @private + */ +Texture.prototype.onBaseTextureUpdated = function (baseTexture) +{ + this._updateID++; + + this._frame.width = baseTexture.width; + this._frame.height = baseTexture.height; + + this.emit('update', this); +}; + +/** + * Destroys this texture + * + * @param [destroyBase=false] {boolean} Whether to destroy the base texture as well + */ +Texture.prototype.destroy = function (destroyBase) +{ + if (this.baseTexture) + { + + if (destroyBase) + { + // delete the texture if it exists in the texture cache.. + // this only needs to be removed if the base texture is actually destoryed too.. + if(utils.TextureCache[this.baseTexture.imageUrl]) + { + delete utils.TextureCache[this.baseTexture.imageUrl]; + } + + this.baseTexture.destroy(); + } + + this.baseTexture.off('update', this.onBaseTextureUpdated, this); + this.baseTexture.off('loaded', this.onBaseTextureLoaded, this); + + this.baseTexture = null; + } + + this._frame = null; + this._uvs = null; + this.trim = null; + this.orig = null; + + this.valid = false; + + this.off('dispose', this.dispose, this); + this.off('update', this.update, this); +}; + +/** + * Creates a new texture object that acts the same as this one. + * + * @return {PIXI.Texture} + */ +Texture.prototype.clone = function () +{ + return new Texture(this.baseTexture, this.frame, this.orig, this.trim, this.rotate); +}; + +/** + * Updates the internal WebGL UV cache. + * + * @protected + */ +Texture.prototype._updateUvs = function () +{ + if (!this._uvs) + { + this._uvs = new TextureUvs(); + } + + this._uvs.set(this._frame, this.baseTexture, this.rotate); + + this._updateID++; +}; + +/** + * Helper function that creates a Texture object from the given image url. + * If the image is not in the texture cache it will be created and loaded. + * + * @static + * @param imageUrl {string} The image url of the texture + * @param [crossorigin] {boolean} Whether requests should be treated as crossorigin + * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values + * @return {PIXI.Texture} The newly created texture + */ +Texture.fromImage = function (imageUrl, crossorigin, scaleMode) +{ + var texture = utils.TextureCache[imageUrl]; + + if (!texture) + { + texture = new Texture(BaseTexture.fromImage(imageUrl, crossorigin, scaleMode)); + utils.TextureCache[imageUrl] = texture; + } + + return texture; +}; + +/** + * Helper function that creates a sprite that will contain a texture from the TextureCache based on the frameId + * The frame ids are created when a Texture packer file has been loaded + * + * @static + * @param frameId {string} The frame Id of the texture in the cache + * @return {PIXI.Texture} The newly created texture + */ +Texture.fromFrame = function (frameId) +{ + var texture = utils.TextureCache[frameId]; + + if (!texture) + { + throw new Error('The frameId "' + frameId + '" does not exist in the texture cache'); + } + + return texture; +}; + +/** + * Helper function that creates a new Texture based on the given canvas element. + * + * @static + * @param canvas {HTMLCanvasElement} The canvas element source of the texture + * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values + * @return {PIXI.Texture} The newly created texture + */ +Texture.fromCanvas = function (canvas, scaleMode) +{ + return new Texture(BaseTexture.fromCanvas(canvas, scaleMode)); +}; + +/** + * Helper function that creates a new Texture based on the given video element. + * + * @static + * @param video {HTMLVideoElement|string} The URL or actual element of the video + * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values + * @return {PIXI.Texture} The newly created texture + */ +Texture.fromVideo = function (video, scaleMode) +{ + if (typeof video === 'string') + { + return Texture.fromVideoUrl(video, scaleMode); + } + else + { + return new Texture(VideoBaseTexture.fromVideo(video, scaleMode)); + } +}; + +/** + * Helper function that creates a new Texture based on the video url. + * + * @static + * @param videoUrl {string} URL of the video + * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values + * @return {PIXI.Texture} The newly created texture + */ +Texture.fromVideoUrl = function (videoUrl, scaleMode) +{ + return new Texture(VideoBaseTexture.fromUrl(videoUrl, scaleMode)); +}; + +/** + * Helper function that creates a new Texture based on the source you provide. + * The soucre can be - frame id, image url, video url, canvae element, video element, base texture + * + * @static + * @param {number|string|PIXI.BaseTexture|HTMLCanvasElement|HTMLVideoElement} source Source to create texture from + * @return {PIXI.Texture} The newly created texture + */ +Texture.from = function (source) +{ + //TODO auto detect cross origin.. + //TODO pass in scale mode? + if(typeof source === 'string') + { + var texture = utils.TextureCache[source]; + + if (!texture) + { + // check if its a video.. + var isVideo = source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/) !== null; + if(isVideo) + { + return Texture.fromVideoUrl(source); + } + + return Texture.fromImage(source); + } + + return texture; + } + else if(source instanceof HTMLCanvasElement) + { + return Texture.fromCanvas(source); + } + else if(source instanceof HTMLVideoElement) + { + return Texture.fromVideo(source); + } + else if(source instanceof BaseTexture) + { + return new Texture(BaseTexture); + } +}; + + +/** + * Adds a texture to the global utils.TextureCache. This cache is shared across the whole PIXI object. + * + * @static + * @param texture {PIXI.Texture} The Texture to add to the cache. + * @param id {string} The id that the texture will be stored against. + */ +Texture.addTextureToCache = function (texture, id) +{ + utils.TextureCache[id] = texture; +}; + +/** + * Remove a texture from the global utils.TextureCache. + * + * @static + * @param id {string} The id of the texture to be removed + * @return {PIXI.Texture} The texture that was removed + */ +Texture.removeTextureFromCache = function (id) +{ + var texture = utils.TextureCache[id]; + + delete utils.TextureCache[id]; + delete utils.BaseTextureCache[id]; + + return texture; +}; + +/** + * An empty texture, used often to not have to create multiple empty textures. + * Can not be destroyed. + * + * @static + * @constant + */ +Texture.EMPTY = new Texture(new BaseTexture()); +Texture.EMPTY.destroy = function() {}; +Texture.EMPTY.on = function() {}; +Texture.EMPTY.once = function() {}; +Texture.EMPTY.emit = function() {}; + - var xhr = this.xhr = new XMLHttpRequest(); +},{"../math":66,"../utils":115,"./BaseTexture":106,"./TextureUvs":109,"./VideoBaseTexture":110,"eventemitter3":4}],109:[function(require,module,exports){ + +/** + * A standard object to store the Uvs of a texture + * + * @class + * @private + * @memberof PIXI + */ +function TextureUvs() +{ + this.x0 = 0; + this.y0 = 0; + + this.x1 = 1; + this.y1 = 0; + + this.x2 = 1; + this.y2 = 1; + + this.x3 = 0; + this.y3 = 1; + + this.uvsUint32 = new Uint32Array(4); +} + +module.exports = TextureUvs; + +var GroupD8 = require('../math/GroupD8'); + +/** + * Sets the texture Uvs based on the given frame information + * @param frame {PIXI.Rectangle} + * @param baseFrame {PIXI.Rectangle} + * @param rotate {number} Rotation of frame, see {@link PIXI.GroupD8} + * @private + */ +TextureUvs.prototype.set = function (frame, baseFrame, rotate) +{ + var tw = baseFrame.width; + var th = baseFrame.height; + + if(rotate) + { + //width and height div 2 div baseFrame size + var w2 = frame.width / 2 / tw; + var h2 = frame.height / 2 / th; + //coordinates of center + var cX = frame.x / tw + w2; + var cY = frame.y / th + h2; + rotate = GroupD8.add(rotate, GroupD8.NW); //NW is top-left corner + this.x0 = cX + w2 * GroupD8.uX(rotate); + this.y0 = cY + h2 * GroupD8.uY(rotate); + rotate = GroupD8.add(rotate, 2); //rotate 90 degrees clockwise + this.x1 = cX + w2 * GroupD8.uX(rotate); + this.y1 = cY + h2 * GroupD8.uY(rotate); + rotate = GroupD8.add(rotate, 2); + this.x2 = cX + w2 * GroupD8.uX(rotate); + this.y2 = cY + h2 * GroupD8.uY(rotate); + rotate = GroupD8.add(rotate, 2); + this.x3 = cX + w2 * GroupD8.uX(rotate); + this.y3 = cY + h2 * GroupD8.uY(rotate); + } + else + { + + this.x0 = frame.x / tw; + this.y0 = frame.y / th; + + this.x1 = (frame.x + frame.width) / tw; + this.y1 = frame.y / th; + + this.x2 = (frame.x + frame.width) / tw; + this.y2 = (frame.y + frame.height) / th; + + this.x3 = frame.x / tw; + this.y3 = (frame.y + frame.height) / th; + } + + this.uvsUint32[0] = (((this.y0 * 65535) & 0xFFFF) << 16) | ((this.x0 * 65535) & 0xFFFF); + this.uvsUint32[1] = (((this.y1 * 65535) & 0xFFFF) << 16) | ((this.x1 * 65535) & 0xFFFF); + this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); + this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); +}; - // set the request type and url - xhr.open('GET', this.url, true); +},{"../math/GroupD8":62}],110:[function(require,module,exports){ +var BaseTexture = require('./BaseTexture'), + utils = require('../utils'); + +/** + * A texture of a [playing] Video. + * + * Video base textures mimic Pixi BaseTexture.from.... method in their creation process. + * + * This can be used in several ways, such as: + * + * ```js + * var texture = PIXI.VideoBaseTexture.fromUrl('http://mydomain.com/video.mp4'); + * + * var texture = PIXI.VideoBaseTexture.fromUrl({ src: 'http://mydomain.com/video.mp4', mime: 'video/mp4' }); + * + * var texture = PIXI.VideoBaseTexture.fromUrls(['/video.webm', '/video.mp4']); + * + * var texture = PIXI.VideoBaseTexture.fromUrls([ + * { src: '/video.webm', mime: 'video/webm' }, + * { src: '/video.mp4', mime: 'video/mp4' } + * ]); + * ``` + * + * See the ["deus" demo](http://www.goodboydigital.com/pixijs/examples/deus/). + * + * @class + * @extends PIXI.BaseTexture + * @memberof PIXI + * @param source {HTMLVideoElement} Video source + * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values + */ +function VideoBaseTexture(source, scaleMode) +{ + if (!source) + { + throw new Error('No video source element specified.'); + } + + // hook in here to check if video is already available. + // BaseTexture looks for a source.complete boolean, plus width & height. + + if ((source.readyState === source.HAVE_ENOUGH_DATA || source.readyState === source.HAVE_FUTURE_DATA) && source.width && source.height) + { + source.complete = true; + } + + BaseTexture.call(this, source, scaleMode); + + /** + * Should the base texture automatically update itself, set to true by default + * + * @member {boolean} + * @default true + */ + this.autoUpdate = false; + + this._onUpdate = this._onUpdate.bind(this); + this._onCanPlay = this._onCanPlay.bind(this); + + if (!source.complete) + { + source.addEventListener('canplay', this._onCanPlay); + source.addEventListener('canplaythrough', this._onCanPlay); + + // started playing.. + source.addEventListener('play', this._onPlayStart.bind(this)); + source.addEventListener('pause', this._onPlayStop.bind(this)); + } + + this.__loaded = false; +} + +VideoBaseTexture.prototype = Object.create(BaseTexture.prototype); +VideoBaseTexture.prototype.constructor = VideoBaseTexture; +module.exports = VideoBaseTexture; + +/** + * The internal update loop of the video base texture, only runs when autoUpdate is set to true + * + * @private + */ +VideoBaseTexture.prototype._onUpdate = function () +{ + if (this.autoUpdate) + { + window.requestAnimationFrame(this._onUpdate); + this.update(); + } +}; + +/** + * Runs the update loop when the video is ready to play + * + * @private + */ +VideoBaseTexture.prototype._onPlayStart = function () +{ + if (!this.autoUpdate) + { + window.requestAnimationFrame(this._onUpdate); + this.autoUpdate = true; + } +}; + +/** + * Fired when a pause event is triggered, stops the update loop + * + * @private + */ +VideoBaseTexture.prototype._onPlayStop = function () +{ + this.autoUpdate = false; +}; + +/** + * Fired when the video is loaded and ready to play + * + * @private + */ +VideoBaseTexture.prototype._onCanPlay = function () +{ + this.hasLoaded = true; + + if (this.source) + { + this.source.removeEventListener('canplay', this._onCanPlay); + this.source.removeEventListener('canplaythrough', this._onCanPlay); + + this.width = this.source.videoWidth; + this.height = this.source.videoHeight; + + this.source.play(); + + // prevent multiple loaded dispatches.. + if (!this.__loaded) + { + this.__loaded = true; + this.emit('loaded', this); + } + } +}; + +/** + * Destroys this texture + * + */ +VideoBaseTexture.prototype.destroy = function () +{ + if (this.source && this.source._pixiId) + { + delete utils.BaseTextureCache[ this.source._pixiId ]; + delete this.source._pixiId; + } + + BaseTexture.prototype.destroy.call(this); +}; + +/** + * Mimic Pixi BaseTexture.from.... method. + * + * @static + * @param video {HTMLVideoElement} Video to create texture from + * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values + * @return {PIXI.VideoBaseTexture} Newly created VideoBaseTexture + */ +VideoBaseTexture.fromVideo = function (video, scaleMode) +{ + if (!video._pixiId) + { + video._pixiId = 'video_' + utils.uid(); + } + + var baseTexture = utils.BaseTextureCache[video._pixiId]; + + if (!baseTexture) + { + baseTexture = new VideoBaseTexture(video, scaleMode); + utils.BaseTextureCache[ video._pixiId ] = baseTexture; + } + + return baseTexture; +}; + +/** + * Helper function that creates a new BaseTexture based on the given video element. + * This BaseTexture can then be used to create a texture + * + * @static + * @param videoSrc {string|object|string[]|object[]} The URL(s) for the video. + * @param [videoSrc.src] {string} One of the source urls for the video + * @param [videoSrc.mime] {string} The mimetype of the video (e.g. 'video/mp4'). If not specified + * the url's extension will be used as the second part of the mime type. + * @param scaleMode {number} See {@link PIXI.SCALE_MODES} for possible values + * @return {PIXI.VideoBaseTexture} Newly created VideoBaseTexture + */ +VideoBaseTexture.fromUrl = function (videoSrc, scaleMode) +{ + var video = document.createElement('video'); + + // array of objects or strings + if (Array.isArray(videoSrc)) + { + for (var i = 0; i < videoSrc.length; ++i) + { + video.appendChild(createSource(videoSrc[i].src || videoSrc[i], videoSrc[i].mime)); + } + } + // single object or string + else + { + video.appendChild(createSource(videoSrc.src || videoSrc, videoSrc.mime)); + } + + video.load(); + video.play(); + + return VideoBaseTexture.fromVideo(video, scaleMode); +}; + +VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; + +function createSource(path, type) +{ + if (!type) + { + type = 'video/' + path.substr(path.lastIndexOf('.') + 1); + } + + var source = document.createElement('source'); + + source.src = path; + source.type = type; + + return source; +} - // load json as text and parse it ourselves. We do this because some browsers - // *cough* safari *cough* can't deal with it. - if (this.xhrType === Resource.XHR_RESPONSE_TYPE.JSON || this.xhrType === Resource.XHR_RESPONSE_TYPE.DOCUMENT) { - xhr.responseType = Resource.XHR_RESPONSE_TYPE.TEXT; - } - else { - xhr.responseType = this.xhrType; - } +},{"../utils":115,"./BaseTexture":106}],111:[function(require,module,exports){ +var CONST = require('../const'), + EventEmitter = require('eventemitter3'), + // Internal event used by composed emitter + TICK = 'tick'; + +/** + * A Ticker class that runs an update loop that other objects listen to. + * This class is composed around an EventEmitter object to add listeners + * meant for execution on the next requested animation frame. + * Animation frames are requested only when necessary, + * e.g. When the ticker is started and the emitter has listeners. + * + * @class + * @memberof PIXI.ticker + */ +function Ticker() +{ + var _this = this; + + /** + * Internal tick method bound to ticker instance. + * This is because in early 2015, Function.bind + * is still 60% slower in high performance scenarios. + * Also separating frame requests from update method + * so listeners may be called at any time and with + * any animation API, just invoke ticker.update(time). + * + * @private + */ + this._tick = function _tick(time) { + + _this._requestId = null; + + if (_this.started) + { + // Invoke listeners now + _this.update(time); + // Listener side effects may have modified ticker state. + if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + { + _this._requestId = requestAnimationFrame(_this._tick); + } + } + }; + + /** + * Internal emitter used to fire 'tick' event + * @private + */ + this._emitter = new EventEmitter(); + + /** + * Internal current frame request ID + * @private + */ + this._requestId = null; + + /** + * Internal value managed by minFPS property setter and getter. + * This is the maximum allowed milliseconds between updates. + * @private + */ + this._maxElapsedMS = 100; + + /** + * Whether or not this ticker should invoke the method + * {@link PIXI.ticker.Ticker#start} automatically + * when a listener is added. + * + * @member {boolean} + * @default false + */ + this.autoStart = false; + + /** + * Scalar time value from last frame to this frame. + * This value is capped by setting {@link PIXI.ticker.Ticker#minFPS} + * and is scaled with {@link PIXI.ticker.Ticker#speed}. + * **Note:** The cap may be exceeded by scaling. + * + * @member {number} + * @default 1 + */ + this.deltaTime = 1; + + /** + * Time elapsed in milliseconds from last frame to this frame. + * Opposed to what the scalar {@link PIXI.ticker.Ticker#deltaTime} + * is based, this value is neither capped nor scaled. + * If the platform supports DOMHighResTimeStamp, + * this value will have a precision of 1 µs. + * + * @member {number} + * @default 1 / TARGET_FPMS + */ + this.elapsedMS = 1 / CONST.TARGET_FPMS; // default to target frame time + + /** + * The last time {@link PIXI.ticker.Ticker#update} was invoked. + * This value is also reset internally outside of invoking + * update, but only when a new animation frame is requested. + * If the platform supports DOMHighResTimeStamp, + * this value will have a precision of 1 µs. + * + * @member {number} + * @default 0 + */ + this.lastTime = 0; + + /** + * Factor of current {@link PIXI.ticker.Ticker#deltaTime}. + * @example + * // Scales ticker.deltaTime to what would be + * // the equivalent of approximately 120 FPS + * ticker.speed = 2; + * + * @member {number} + * @default 1 + */ + this.speed = 1; + + /** + * Whether or not this ticker has been started. + * `true` if {@link PIXI.ticker.Ticker#start} has been called. + * `false` if {@link PIXI.ticker.Ticker#stop} has been called. + * While `false`, this value may change to `true` in the + * event of {@link PIXI.ticker.Ticker#autoStart} being `true` + * and a listener is added. + * + * @member {boolean} + * @default false + */ + this.started = false; +} + +Object.defineProperties(Ticker.prototype, { + /** + * The frames per second at which this ticker is running. + * The default is approximately 60 in most modern browsers. + * **Note:** This does not factor in the value of + * {@link PIXI.ticker.Ticker#speed}, which is specific + * to scaling {@link PIXI.ticker.Ticker#deltaTime}. + * + * @memberof PIXI.ticker.Ticker# + * @readonly + */ + FPS: { + get: function() + { + return 1000 / this.elapsedMS; + } + }, + + /** + * Manages the maximum amount of milliseconds allowed to + * elapse between invoking {@link PIXI.ticker.Ticker#update}. + * This value is used to cap {@link PIXI.ticker.Ticker#deltaTime}, + * but does not effect the measured value of {@link PIXI.ticker.Ticker#FPS}. + * When setting this property it is clamped to a value between + * `0` and `PIXI.TARGET_FPMS * 1000`. + * + * @memberof PIXI.ticker.Ticker# + * @default 10 + */ + minFPS: { + get: function() + { + return 1000 / this._maxElapsedMS; + }, + set: function(fps) + { + // Clamp: 0 to TARGET_FPMS + var minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } + } +}); + +/** + * Conditionally requests a new animation frame. + * If a frame has not already been requested, and if the internal + * emitter has listeners, a new frame is requested. + * + * @private + */ +Ticker.prototype._requestIfNeeded = function _requestIfNeeded() +{ + if (this._requestId === null && this._emitter.listeners(TICK, true)) + { + // ensure callbacks get correct delta + this.lastTime = performance.now(); + this._requestId = requestAnimationFrame(this._tick); + } +}; + +/** + * Conditionally cancels a pending animation frame. + * + * @private + */ +Ticker.prototype._cancelIfNeeded = function _cancelIfNeeded() +{ + if (this._requestId !== null) + { + cancelAnimationFrame(this._requestId); + this._requestId = null; + } +}; + +/** + * Conditionally requests a new animation frame. + * If the ticker has been started it checks if a frame has not already + * been requested, and if the internal emitter has listeners. If these + * conditions are met, a new frame is requested. If the ticker has not + * been started, but autoStart is `true`, then the ticker starts now, + * and continues with the previous conditions to request a new frame. + * + * @private + */ +Ticker.prototype._startIfPossible = function _startIfPossible() +{ + if (this.started) + { + this._requestIfNeeded(); + } + else if (this.autoStart) + { + this.start(); + } +}; + +/** + * Calls {@link module:eventemitter3.EventEmitter#on} internally for the + * internal 'tick' event. It checks if the emitter has listeners, + * and if so it requests a new animation frame at this point. + * + * @param fn {Function} The listener function to be added for updates + * @param [context] {Function} The listener context + * @returns {PIXI.ticker.Ticker} This instance of a ticker + */ +Ticker.prototype.add = function add(fn, context) +{ + this._emitter.on(TICK, fn, context); + + this._startIfPossible(); + + return this; +}; + +/** + * Calls {@link module:eventemitter3.EventEmitter#once} internally for the + * internal 'tick' event. It checks if the emitter has listeners, + * and if so it requests a new animation frame at this point. + * + * @param fn {Function} The listener function to be added for one update + * @param [context] {Function} The listener context + * @returns {PIXI.ticker.Ticker} This instance of a ticker + */ +Ticker.prototype.addOnce = function addOnce(fn, context) +{ + this._emitter.once(TICK, fn, context); + + this._startIfPossible(); + + return this; +}; + +/** + * Calls {@link module:eventemitter3.EventEmitter#off} internally for 'tick' event. + * It checks if the emitter has listeners for 'tick' event. + * If it does, then it cancels the animation frame. + * + * @param [fn] {Function} The listener function to be removed + * @param [context] {Function} The listener context to be removed + * @returns {PIXI.ticker.Ticker} This instance of a ticker + */ +Ticker.prototype.remove = function remove(fn, context) +{ + this._emitter.off(TICK, fn, context); + + if (!this._emitter.listeners(TICK, true)) + { + this._cancelIfNeeded(); + } + + return this; +}; + +/** + * Starts the ticker. If the ticker has listeners + * a new animation frame is requested at this point. + */ +Ticker.prototype.start = function start() +{ + if (!this.started) + { + this.started = true; + this._requestIfNeeded(); + } +}; + +/** + * Stops the ticker. If the ticker has requested + * an animation frame it is canceled at this point. + */ +Ticker.prototype.stop = function stop() +{ + if (this.started) + { + this.started = false; + this._cancelIfNeeded(); + } +}; + +/** + * Triggers an update. An update entails setting the + * current {@link PIXI.ticker.Ticker#elapsedMS}, + * the current {@link PIXI.ticker.Ticker#deltaTime}, + * invoking all listeners with current deltaTime, + * and then finally setting {@link PIXI.ticker.Ticker#lastTime} + * with the value of currentTime that was provided. + * This method will be called automatically by animation + * frame callbacks if the ticker instance has been started + * and listeners are added. + * + * @param [currentTime=performance.now()] {number} the current time of execution + */ +Ticker.prototype.update = function update(currentTime) +{ + var elapsedMS; + + // Allow calling update directly with default currentTime. + currentTime = currentTime || performance.now(); + + // If the difference in time is zero or negative, we ignore most of the work done here. + // If there is no valid difference, then should be no reason to let anyone know about it. + // A zero delta, is exactly that, nothing should update. + // + // The difference in time can be negative, and no this does not mean time traveling. + // This can be the result of a race condition between when an animation frame is requested + // on the current JavaScript engine event loop, and when the ticker's start method is invoked + // (which invokes the internal _requestIfNeeded method). If a frame is requested before + // _requestIfNeeded is invoked, then the callback for the animation frame the ticker requests, + // can receive a time argument that can be less than the lastTime value that was set within + // _requestIfNeeded. This difference is in microseconds, but this is enough to cause problems. + // + // This check covers this browser engine timing issue, as well as if consumers pass an invalid + // currentTime value. This may happen if consumers opt-out of the autoStart, and update themselves. + + if (currentTime > this.lastTime) + { + // Save uncapped elapsedMS for measurement + elapsedMS = this.elapsedMS = currentTime - this.lastTime; + + // cap the milliseconds elapsed used for deltaTime + if (elapsedMS > this._maxElapsedMS) + { + elapsedMS = this._maxElapsedMS; + } + + this.deltaTime = elapsedMS * CONST.TARGET_FPMS * this.speed; + + // Invoke listeners added to internal emitter + this._emitter.emit(TICK, this.deltaTime); + } + else + { + this.deltaTime = this.elapsedMS = 0; + } + + this.lastTime = currentTime; +}; + +module.exports = Ticker; - xhr.addEventListener('error', this._boundXhrOnError, false); - xhr.addEventListener('abort', this._boundXhrOnAbort, false); - xhr.addEventListener('progress', this._boundOnProgress, false); - xhr.addEventListener('load', this._boundXhrOnLoad, false); +},{"../const":42,"eventemitter3":4}],112:[function(require,module,exports){ +var Ticker = require('./Ticker'); + +/** + * The shared ticker instance used by {@link PIXI.extras.MovieClip}. + * and by {@link PIXI.interaction.InteractionManager}. + * The property {@link PIXI.ticker.Ticker#autoStart} is set to `true` + * for this instance. Please follow the examples for usage, including + * how to opt-out of auto-starting the shared ticker. + * + * @example + * var ticker = PIXI.ticker.shared; + * // Set this to prevent starting this ticker when listeners are added. + * // By default this is true only for the PIXI.ticker.shared instance. + * ticker.autoStart = false; + * // FYI, call this to ensure the ticker is stopped. It should be stopped + * // if you have not attempted to render anything yet. + * ticker.stop(); + * // Call this when you are ready for a running shared ticker. + * ticker.start(); + * + * @example + * // You may use the shared ticker to render... + * var renderer = PIXI.autoDetectRenderer(800, 600); + * var stage = new PIXI.Container(); + * var interactionManager = PIXI.interaction.InteractionManager(renderer); + * document.body.appendChild(renderer.view); + * ticker.add(function (time) { + * renderer.render(stage); + * }); + * + * @example + * // Or you can just update it manually. + * ticker.autoStart = false; + * ticker.stop(); + * function animate(time) { + * ticker.update(time); + * renderer.render(stage); + * requestAnimationFrame(animate); + * } + * animate(performance.now()); + * + * @type {PIXI.ticker.Ticker} + * @memberof PIXI.ticker + */ +var shared = new Ticker(); +shared.autoStart = true; + +/** + * @namespace PIXI.ticker + */ +module.exports = { + shared: shared, + Ticker: Ticker +}; - xhr.send(); -}; +},{"./Ticker":111}],113:[function(require,module,exports){ +/** + * Generic Mask Stack data structure + * @class + * @memberof PIXI + * @param size {number} Number of quads + * @return {Uint16Array} indices + */ +var createIndicesForQuads = function (size) +{ + // the total number of indices in our array, there are 6 points per quad. + + var totalIndices = size * 6; + + var indices = new Uint16Array(totalIndices); + + // fill the indices with the quads to draw + for (var i=0, j=0; i < totalIndices; i += 6, j += 4) + { + indices[i + 0] = j + 0; + indices[i + 1] = j + 1; + indices[i + 2] = j + 2; + indices[i + 3] = j + 0; + indices[i + 4] = j + 2; + indices[i + 5] = j + 3; + } + + return indices; +}; + +module.exports = createIndicesForQuads; -/** - * Loads this resources using an XDomainRequest. This is here because we need to support IE9 (gross). - * - * @private - */ -Resource.prototype._loadXdr = function () { - // if unset, determine the value - if (typeof this.xhrType !== 'string') { - this.xhrType = this._determineXhrType(); - } +},{}],114:[function(require,module,exports){ +var tempAnchor; +var _url = require('url'); + +/** + * Sets the `crossOrigin` property for this resource based on if the url + * for this resource is cross-origin. If crossOrigin was manually set, this + * function does nothing. + * Nipped from the resource loader! + * @private + * @param url {string} The url to test. + * @param loc [location=window.location] {object} The location object to test against. + * @return {string} The crossOrigin value to use (or empty string for none). + */ +var determineCrossOrigin = function (url, loc) { + // data: and javascript: urls are considered same-origin + if (url.indexOf('data:') === 0) { + return ''; + } + + // default is window.location + loc = loc || window.location; + + if (!tempAnchor) { + tempAnchor = document.createElement('a'); + } + + // let the browser determine the full href for the url of this resource and then + // parse with the node url lib, we can't use the properties of the anchor element + // because they don't work in IE9 :( + tempAnchor.href = url; + url = _url.parse(tempAnchor.href); + + var samePort = (!url.port && loc.port === '') || (url.port === loc.port); + + // if cross origin + if (url.hostname !== loc.hostname || !samePort || url.protocol !== loc.protocol) { + return 'anonymous'; + } + + return ''; +}; + +module.exports = determineCrossOrigin; - var xdr = this.xhr = new XDomainRequest(); +},{"url":36}],115:[function(require,module,exports){ +var CONST = require('../const'); + +/** + * @namespace PIXI.utils + */ +var utils = module.exports = { + _uid: 0, + _saidHello: false, + + EventEmitter: require('eventemitter3'), + pluginTarget: require('./pluginTarget'), + + /** + * Gets the next unique identifier + * + * @memberof PIXI.utils + * @return {number} The next unique identifier to use. + */ + uid: function () + { + return ++utils._uid; + }, + + /** + * Converts a hex color number to an [R, G, B] array + * + * @memberof PIXI.utils + * @param hex {number} + * @param {number[]} [out=[]] If supplied, this array will be used rather than returning a new one + * @return {number[]} An array representing the [R, G, B] of the color. + */ + hex2rgb: function (hex, out) + { + out = out || []; + + out[0] = (hex >> 16 & 0xFF) / 255; + out[1] = (hex >> 8 & 0xFF) / 255; + out[2] = (hex & 0xFF) / 255; + + return out; + }, + + /** + * Converts a hex color number to a string. + * + * @memberof PIXI.utils + * @param hex {number} Number in hex + * @return {string} The string color. + */ + hex2string: function (hex) + { + hex = hex.toString(16); + hex = '000000'.substr(0, 6 - hex.length) + hex; + + return '#' + hex; + }, + + /** + * Converts a color as an [R, G, B] array to a hex number + * + * @memberof PIXI.utils + * @param rgb {number[]} rgb array + * @return {number} The color number + */ + rgb2hex: function (rgb) + { + return ((rgb[0]*255 << 16) + (rgb[1]*255 << 8) + rgb[2]*255); + }, + + + /** + * get the resolution / device pixel ratio of an asset by looking for the prefix + * used by spritesheets and image urls + * + * @memberof PIXI.utils + * @param url {string} the image path + * @return {number} resolution / device pixel ratio of an asset + */ + getResolutionOfUrl: function (url) + { + var resolution = CONST.RETINA_PREFIX.exec(url); + + if (resolution) + { + return parseFloat(resolution[1]); + } + + return 1; + }, + + /** + * Logs out the version and renderer information for this running instance of PIXI. + * If you don't want to see this message you can set `PIXI.utils._saidHello = true;` + * so the library thinks it already said it. Keep in mind that doing that will forever + * makes you a jerk face. + * + * @memberof PIXI.utils + * @param {string} type - The string renderer type to log. + * @constant + * @static + */ + sayHello: function (type) + { + if (utils._saidHello) + { + return; + } + + if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1) + { + var args = [ + '\n %c %c %c Pixi.js ' + CONST.VERSION + ' - ✰ ' + type + ' ✰ %c ' + ' %c ' + ' http://www.pixijs.com/ %c %c ♥%c♥%c♥ \n\n', + 'background: #ff66a5; padding:5px 0;', + 'background: #ff66a5; padding:5px 0;', + 'color: #ff66a5; background: #030307; padding:5px 0;', + 'background: #ff66a5; padding:5px 0;', + 'background: #ffc3dc; padding:5px 0;', + 'background: #ff66a5; padding:5px 0;', + 'color: #ff2424; background: #fff; padding:5px 0;', + 'color: #ff2424; background: #fff; padding:5px 0;', + 'color: #ff2424; background: #fff; padding:5px 0;' + ]; + + window.console.log.apply(console, args); //jshint ignore:line + } + else if (window.console) + { + window.console.log('Pixi.js ' + CONST.VERSION + ' - ' + type + ' - http://www.pixijs.com/'); //jshint ignore:line + } + + utils._saidHello = true; + }, + + /** + * Helper for checking for webgl support + * + * @memberof PIXI.utils + * @return {boolean} is webgl supported + */ + isWebGLSupported: function () + { + var contextOptions = { stencil: true, failIfMajorPerformanceCaveat: true }; + try + { + if (!window.WebGLRenderingContext) + { + return false; + } + + var canvas = document.createElement('canvas'), + gl = canvas.getContext('webgl', contextOptions) || canvas.getContext('experimental-webgl', contextOptions); + + var success = !!(gl && gl.getContextAttributes().stencil); + if (gl) + { + var loseContext = gl.getExtension('WEBGL_lose_context'); + + if(loseContext) + { + loseContext.loseContext(); + } + } + gl = null; + + return success; + } + catch (e) + { + return false; + } + }, + + /** + * Returns sign of number + * + * @memberof PIXI.utils + * @param n {number} + * @returns {number} 0 if n is 0, -1 if n is negative, 1 if n i positive + */ + sign: function (n) + { + return n ? (n < 0 ? -1 : 1) : 0; + }, + + /** + * Remove a range of items from an array + * + * @memberof PIXI.utils + * @param {Array<*>} arr The target array + * @param {number} startIdx The index to begin removing from (inclusive) + * @param {number} removeCount How many items to remove + */ + removeItems: function (arr, startIdx, removeCount) + { + var length = arr.length; + + if (startIdx >= length || removeCount === 0) + { + return; + } + + removeCount = (startIdx+removeCount > length ? length-startIdx : removeCount); + for (var i = startIdx, len = length-removeCount; i < len; ++i) + { + arr[i] = arr[i + removeCount]; + } + + arr.length = len; + }, + + /** + * @todo Describe property usage + * + * @memberof PIXI.utils + * @private + */ + TextureCache: {}, + + /** + * @todo Describe property usage + * + * @memberof PIXI.utils + * @private + */ + BaseTextureCache: {} +}; - // XDomainRequest has a few quirks. Occasionally it will abort requests - // A way to avoid this is to make sure ALL callbacks are set even if not used - // More info here: http://stackoverflow.com/questions/15786966/xdomainrequest-aborts-post-on-ie-9 - xdr.timeout = 5000; +},{"../const":42,"./pluginTarget":117,"eventemitter3":4}],116:[function(require,module,exports){ + + +var Device = require('ismobilejs'); + +var maxRecommendedTextures = function(max) +{ + + if(Device.tablet || Device.phone) + { + // check if the res is iphone 6 or higher.. + return 2; + } + else + { + // desktop should be ok + return max; + } +}; + +module.exports = maxRecommendedTextures; +},{"ismobilejs":5}],117:[function(require,module,exports){ +/** + * Mixins functionality to make an object have "plugins". + * + * @mixin + * @memberof PIXI.utils + * @param obj {object} The object to mix into. + * @example + * function MyObject() {} + * + * pluginTarget.mixin(MyObject); + */ +function pluginTarget(obj) +{ + obj.__plugins = {}; + + /** + * Adds a plugin to an object + * + * @param pluginName {string} The events that should be listed. + * @param ctor {Function} The constructor function for the plugin. + */ + obj.registerPlugin = function (pluginName, ctor) + { + obj.__plugins[pluginName] = ctor; + }; + + /** + * Instantiates all the plugins of this object + * + */ + obj.prototype.initPlugins = function () + { + this.plugins = this.plugins || {}; + + for (var o in obj.__plugins) + { + this.plugins[o] = new (obj.__plugins[o])(this); + } + }; + + /** + * Removes all the plugins of this object + * + */ + obj.prototype.destroyPlugins = function () + { + for (var o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + + this.plugins = null; + }; +} + + +module.exports = { + /** + * Mixes in the properties of the pluginTarget into another object + * + * @param obj {object} The obj to mix into + */ + mixin: function mixin(obj) + { + pluginTarget(obj); + } +}; - xdr.onerror = this._boundXhrOnError; - xdr.ontimeout = this._boundXdrOnTimeout; - xdr.onprogress = this._boundOnProgress; - xdr.onload = this._boundXhrOnLoad; +},{}],118:[function(require,module,exports){ +/*global console */ +var core = require('./core'), + mesh = require('./mesh'), + particles = require('./particles'), + extras = require('./extras'), + filters = require('./filters'), + CONST = require('./core/const'); + +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) { + var stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') { + console.warn('Deprecation Warning: ', msg); + } + else { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) { + console.groupCollapsed('%cDeprecation Warning: %c%s', 'color:#614108;background:#fffbe6', 'font-weight:normal;color:#614108;background:#fffbe6', msg); + console.warn(stack); + console.groupEnd(); + } + else { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } +} + +/** + * @class + * @private + * @name SpriteBatch + * @memberof PIXI + * @see PIXI.ParticleContainer + * @throws {ReferenceError} SpriteBatch does not exist any more, please use the new ParticleContainer instead. + * @deprecated since version 3.0.0 + */ +core.SpriteBatch = function() +{ + throw new ReferenceError('SpriteBatch does not exist any more, please use the new ParticleContainer instead.'); +}; + +/** + * @class + * @private + * @name AssetLoader + * @memberof PIXI + * @see PIXI.loaders.Loader + * @throws {ReferenceError} The loader system was overhauled in pixi v3, please see the new PIXI.loaders.Loader class. + * @deprecated since version 3.0.0 + */ +core.AssetLoader = function() +{ + throw new ReferenceError('The loader system was overhauled in pixi v3, please see the new PIXI.loaders.Loader class.'); +}; + +Object.defineProperties(core, { + + /** + * @class + * @private + * @name Stage + * @memberof PIXI + * @see PIXI.Container + * @deprecated since version 3.0.0 + */ + Stage: { + get: function() + { + warn('You do not need to use a PIXI Stage any more, you can simply render any container.'); + return core.Container; + } + }, + + /** + * @class + * @private + * @name DisplayObjectContainer + * @memberof PIXI + * @see PIXI.Container + * @deprecated since version 3.0.0 + */ + DisplayObjectContainer: { + get: function() + { + warn('DisplayObjectContainer has been shortened to Container, please use Container from now on.'); + return core.Container; + } + }, + + /** + * @class + * @private + * @name Strip + * @memberof PIXI + * @see PIXI.mesh.Mesh + * @deprecated since version 3.0.0 + */ + Strip: { + get: function() + { + warn('The Strip class has been renamed to Mesh and moved to mesh.Mesh, please use mesh.Mesh from now on.'); + return mesh.Mesh; + } + }, + + /** + * @class + * @private + * @name Rope + * @memberof PIXI + * @see PIXI.mesh.Rope + * @deprecated since version 3.0.0 + */ + Rope: { + get: function() + { + warn('The Rope class has been moved to mesh.Rope, please use mesh.Rope from now on.'); + return mesh.Rope; + } + }, + + /** + * @class + * @private + * @name ParticleContainer + * @memberof PIXI + * @see PIXI.particles.ParticleContainer + * @deprecated since version 4.0.0 + */ + ParticleContainer: { + get: function() { + warn('The ParticleContainer class has been moved to particles.ParticleContainer, please use particles.ParticleContainer from now on.'); + return particles.ParticleContainer; + } + }, + + /** + * @class + * @private + * @name MovieClip + * @memberof PIXI + * @see PIXI.extras.MovieClip + * @deprecated since version 3.0.0 + */ + MovieClip: { + get: function() + { + warn('The MovieClip class has been moved to extras.MovieClip, please use extras.MovieClip from now on.'); + return extras.MovieClip; + } + }, + + /** + * @class + * @private + * @name TilingSprite + * @memberof PIXI + * @see PIXI.extras.TilingSprite + * @deprecated since version 3.0.0 + */ + TilingSprite: { + get: function() + { + warn('The TilingSprite class has been moved to extras.TilingSprite, please use extras.TilingSprite from now on.'); + return extras.TilingSprite; + } + }, + + /** + * @class + * @private + * @name BitmapText + * @memberof PIXI + * @see PIXI.extras.BitmapText + * @deprecated since version 3.0.0 + */ + BitmapText: { + get: function() + { + warn('The BitmapText class has been moved to extras.BitmapText, please use extras.BitmapText from now on.'); + return extras.BitmapText; + } + }, + + /** + * @class + * @private + * @name blendModes + * @memberof PIXI + * @see PIXI.BLEND_MODES + * @deprecated since version 3.0.0 + */ + blendModes: { + get: function() + { + warn('The blendModes has been moved to BLEND_MODES, please use BLEND_MODES from now on.'); + return core.BLEND_MODES; + } + }, + + /** + * @class + * @private + * @name scaleModes + * @memberof PIXI + * @see PIXI.SCALE_MODES + * @deprecated since version 3.0.0 + */ + scaleModes: { + get: function() + { + warn('The scaleModes has been moved to SCALE_MODES, please use SCALE_MODES from now on.'); + return core.SCALE_MODES; + } + }, + + /** + * @class + * @private + * @name BaseTextureCache + * @memberof PIXI + * @see PIXI.utils.BaseTextureCache + * @deprecated since version 3.0.0 + */ + BaseTextureCache: { + get: function () + { + warn('The BaseTextureCache class has been moved to utils.BaseTextureCache, please use utils.BaseTextureCache from now on.'); + return core.utils.BaseTextureCache; + } + }, + + /** + * @class + * @private + * @name TextureCache + * @memberof PIXI + * @see PIXI.utils.TextureCache + * @deprecated since version 3.0.0 + */ + TextureCache: { + get: function () + { + warn('The TextureCache class has been moved to utils.TextureCache, please use utils.TextureCache from now on.'); + return core.utils.TextureCache; + } + }, + + /** + * @namespace + * @private + * @name math + * @memberof PIXI + * @see PIXI + * @deprecated since version 3.0.6 + */ + math: { + get: function () + { + warn('The math namespace is deprecated, please access members already accessible on PIXI.'); + return core; + } + }, + + /** + * @class + * @private + * @name PIXI.AbstractFilter + * @see PIXI.Filter + * @deprecated since version 3.0.6 + */ + AbstractFilter: { + get: function() + { + warn('AstractFilter has been renamed to Filter, please use PIXI.Filter'); + return core.Filter; + } + }, + + /** + * @class + * @private + * @name PIXI.TransformManual + * @see PIXI.TransformBase + * @deprecated since version 4.0.0 + */ + TransformManual: { + get: function() + { + warn('TransformManual has been renamed to TransformBase, please update your pixi-spine'); + return core.TransformBase; + } + } +}); + +core.DisplayObject.prototype.generateTexture = function(renderer, scaleMode, resolution) +{ + warn('generateTexture has moved to the renderer, please use renderer.generateTexture(displayObject)'); + return renderer.generateTexture(this, scaleMode, resolution); +}; + + +core.Graphics.prototype.generateTexture = function(scaleMode, resolution) +{ + warn('graphics generate texture has moved to the renderer. Or to render a graphics to a texture using canvas please use generateCanvasTexture'); + return this.generateCanvasTexture(scaleMode, resolution); +}; + +core.RenderTexture.prototype.render = function(displayObject, matrix, clear, updateTransform) +{ + this.legacyRenderer.render(displayObject, this, clear, matrix, !updateTransform); + warn('RenderTexture.render is now deprecated, please use renderer.render(displayObject, renderTexture)'); +}; + +core.RenderTexture.prototype.getImage = function(target) +{ + warn('RenderTexture.getImage is now deprecated, please use renderer.extract.image(target)'); + return this.legacyRenderer.extract.image(target); +}; + +core.RenderTexture.prototype.getBase64 = function(target) +{ + warn('RenderTexture.getBase64 is now deprecated, please use renderer.extract.base64(target)'); + return this.legacyRenderer.extract.base64(target); +}; + +core.RenderTexture.prototype.getCanvas = function(target) +{ + warn('RenderTexture.getCanvas is now deprecated, please use renderer.extract.canvas(target)'); + return this.legacyRenderer.extract.canvas(target); +}; + +core.RenderTexture.prototype.getPixels = function(target) +{ + warn('RenderTexture.getPixels is now deprecated, please use renderer.extract.pixels(target)'); + return this.legacyRenderer.pixels(target); +}; + + + +/** + * @method + * @private + * @name PIXI.Sprite#setTexture + * @see PIXI.Sprite#texture + * @deprecated since version 3.0.0 + */ +core.Sprite.prototype.setTexture = function(texture) +{ + this.texture = texture; + warn('setTexture is now deprecated, please use the texture property, e.g : sprite.texture = texture;'); +}; + + + +/** + * @method + * @name PIXI.extras.BitmapText#setText + * @see PIXI.extras.BitmapText#text + * @deprecated since version 3.0.0 + */ +extras.BitmapText.prototype.setText = function(text) +{ + this.text = text; + warn('setText is now deprecated, please use the text property, e.g : myBitmapText.text = \'my text\';'); +}; + +/** + * @method + * @name PIXI.Text#setText + * @see PIXI.Text#text + * @deprecated since version 3.0.0 + */ +core.Text.prototype.setText = function(text) +{ + this.text = text; + warn('setText is now deprecated, please use the text property, e.g : myText.text = \'my text\';'); +}; + +/** + * @method + * @name PIXI.Text#setStyle + * @see PIXI.Text#style + * @deprecated since version 3.0.0 + */ +core.Text.prototype.setStyle = function(style) +{ + this.style = style; + warn('setStyle is now deprecated, please use the style property, e.g : myText.style = style;'); +}; + +Object.defineProperties(core.TextStyle.prototype, { + /** + * Set all properties of a font as a single string + * + * @name PIXI.TextStyle#font + * @deprecated since version 4.0.0 + */ + font: { + get: function () + { + warn('text style property \'font\' is now deprecated, please use the \'fontFamily\',\'fontSize\',fontStyle\',\'fontVariant\' and \'fontWeight\' properties from now on'); + var fontSizeString = (typeof this._fontSize === 'number') ? this._fontSize + 'px' : this._fontSize; + return this._fontStyle + ' ' + this._fontVariant + ' ' + this._fontWeight + ' ' + fontSizeString + ' ' + this._fontFamily; + }, + set: function (font) + { + warn('text style property \'font\' is now deprecated, please use the \'fontFamily\',\'fontSize\',fontStyle\',\'fontVariant\' and \'fontWeight\' properties from now on'); + + // can work out fontStyle from search of whole string + if ( font.indexOf('italic') > 1 ) + { + this._fontStyle = 'italic'; + } + else if ( font.indexOf('oblique') > -1 ) + { + this._fontStyle = 'oblique'; + } + else + { + this._fontStyle = 'normal'; + } + + // can work out fontVariant from search of whole string + if ( font.indexOf('small-caps') > -1 ) + { + this._fontVariant = 'small-caps'; + } + else + { + this._fontVariant = 'normal'; + } + + // fontWeight and fontFamily are tricker to find, but it's easier to find the fontSize due to it's units + var splits = font.split(' '); + var i; + var fontSizeIndex = -1; + + this._fontSize = 26; + for ( i = 0; i < splits.length; ++i ) + { + if ( splits[i].match( /(px|pt|em|%)/ ) ) + { + fontSizeIndex = i; + this._fontSize = splits[i]; + break; + } + } + + // we can now search for fontWeight as we know it must occur before the fontSize + this._fontWeight = 'normal'; + for ( i = 0; i < fontSizeIndex; ++i ) + { + if ( splits[i].match( /(bold|bolder|lighter|100|200|300|400|500|600|700|800|900)/ ) ) + { + this._fontWeight = splits[i]; + break; + } + } + + // and finally join everything together after the fontSize in case the font family has multiple words + if ( fontSizeIndex > -1 && fontSizeIndex < splits.length-1 ) + { + this._fontFamily = ''; + for ( i = fontSizeIndex + 1; i < splits.length; ++i ) + { + this._fontFamily += splits[i] + ' '; + } + + this._fontFamily = this._fontFamily.slice(0, -1); + } + else + { + this._fontFamily = 'Arial'; + } + + this.emit(CONST.TEXT_STYLE_CHANGED); + } + } +} ); + +/** + * @method + * @name PIXI.Texture#setFrame + * @see PIXI.Texture#setFrame + * @deprecated since version 3.0.0 + */ +core.Texture.prototype.setFrame = function(frame) +{ + this.frame = frame; + warn('setFrame is now deprecated, please use the frame property, e.g : myTexture.frame = frame;'); +}; + +Object.defineProperties(filters, { + + /** + * @class + * @private + * @name PIXI.filters.AbstractFilter + * @see PIXI.AbstractFilter + * @deprecated since version 3.0.6 + */ + AbstractFilter: { + get: function() + { + warn('AstractFilter has been renamed to Filter, please use PIXI.Filter'); + return core.AbstractFilter; + } + }, + + /** + * @class + * @private + * @name PIXI.filters.SpriteMaskFilter + * @see PIXI.SpriteMaskFilter + * @deprecated since version 3.0.6 + */ + SpriteMaskFilter: { + get: function() + { + warn('filters.SpriteMaskFilter is an undocumented alias, please use SpriteMaskFilter from now on.'); + return core.SpriteMaskFilter; + } + } +}); + +/** + * @method + * @name PIXI.utils.uuid + * @see PIXI.utils.uid + * @deprecated since version 3.0.6 + */ +core.utils.uuid = function () +{ + warn('utils.uuid() is deprecated, please use utils.uid() from now on.'); + return core.utils.uid(); +}; + +/** + * @method + * @name PIXI.utils.canUseNewCanvasBlendModes + * @see PIXI.CanvasTinter + * @deprecated + */ +core.utils.canUseNewCanvasBlendModes = function() { + warn('utils.canUseNewCanvasBlendModes() is deprecated, please use CanvasTinter.canUseMultiply from now on'); + return core.CanvasTinter.canUseMultiply; +}; + - xdr.open('GET', this.url, true); +},{"./core":61,"./core/const":42,"./extras":128,"./filters":139,"./mesh":155,"./particles":158}],119:[function(require,module,exports){ +var core = require('../../core'), + tempRect = new core.Rectangle(); + +/** + * The extract manager provides functionality to export content from the renderers + * @class + * @memberof PIXI + * @param renderer {PIXI.CanvasRenderer} A reference to the current renderer + */ +function CanvasExtract(renderer) +{ + this.renderer = renderer; + renderer.extract = this; +} + + +CanvasExtract.prototype.constructor = CanvasExtract; +module.exports = CanvasExtract; + +/** + * Will return a HTML Image of the target + * + * @param target {PIXI.DisplayObject|PIXI.RenderTexture} A displayObject or renderTexture to convert. If left empty will use use the main renderer + * @return {HTMLImageElement} HTML Image of the target + */ +CanvasExtract.prototype.image = function ( target ) +{ + var image = new Image(); + image.src = this.base64( target ); + return image; +}; + +/** + * Will return a a base64 encoded string of this target. It works by calling CanvasExtract.getCanvas and then running toDataURL on that. + * @param target {PIXI.DisplayObject|PIXI.RenderTexture} A displayObject or renderTexture to convert. If left empty will use use the main renderer + * @return {string} A base64 encoded string of the texture. + */ +CanvasExtract.prototype.base64 = function ( target ) +{ + return this.canvas( target ).toDataURL(); +}; + +/** + * Creates a Canvas element, renders this target to it and then returns it. + * @param target {PIXI.DisplayObject|PIXI.RenderTexture} A displayObject or renderTexture to convert. If left empty will use use the main renderer + * @return {HTMLCanvasElement} A Canvas element with the texture rendered on. + */ +CanvasExtract.prototype.canvas = function ( target ) +{ + var renderer = this.renderer; + var context; + var resolution; + var frame; + var renderTexture; + + if(target) + { + if(target instanceof core.RenderTexture) + { + renderTexture = target; + } + else + { + renderTexture = renderer.generateTexture(target); + } + } + + if(renderTexture) + { + context = renderTexture.baseTexture._canvasRenderTarget.context; + resolution = renderTexture.baseTexture._canvasRenderTarget.resolution; + frame = renderTexture.frame; + } + else + { + context = renderer.rootContext; + resolution = renderer.rootResolution; + + frame = tempRect; + frame.width = this.renderer.width; + frame.height = this.renderer.height; + } + + var width = frame.width * resolution; + var height = frame.height * resolution; + + var canvasBuffer = new core.CanvasRenderTarget(width, height); + var canvasData = context.getImageData(frame.x * resolution, frame.y * resolution, width, height); + canvasBuffer.context.putImageData(canvasData, 0, 0); + + + // send the canvas back.. + return canvasBuffer.canvas; +}; + +/** + * Will return a one-dimensional array containing the pixel data of the entire texture in RGBA order, with integer values between 0 and 255 (included). + * @param target {PIXI.DisplayObject|PIXI.RenderTexture} A displayObject or renderTexture to convert. If left empty will use use the main renderer + * @return {Uint8ClampedArray} One-dimensional array containing the pixel data of the entire texture + */ +CanvasExtract.prototype.pixels = function ( target ) +{ + var renderer = this.renderer; + var context; + var resolution; + var frame; + var renderTexture; + + if(target) + { + if(target instanceof core.RenderTexture) + { + renderTexture = target; + } + else + { + renderTexture = renderer.generateTexture(target); + } + } + + if(renderTexture) + { + context = renderTexture.baseTexture._canvasRenderTarget.context; + resolution = renderTexture.baseTexture._canvasRenderTarget.resolution; + frame = renderTexture.frame; + } + else + { + context = renderer.rootContext; + resolution = renderer.rootResolution; + + frame = tempRect; + frame.width = renderer.width; + frame.height = renderer.height; + } + + return context.getImageData(0, 0, frame.width * resolution, frame.height * resolution).data; +}; + +/** + * Destroys the extract + * + */ +CanvasExtract.prototype.destroy = function () +{ + this.renderer.extract = null; + this.renderer = null; +}; + +core.CanvasRenderer.registerPlugin('extract', CanvasExtract); - // Note: The xdr.send() call is wrapped in a timeout to prevent an issue with the interface where some requests are lost - // if multiple XDomainRequests are being sent at the same time. - // Some info here: https://github.com/photonstorm/phaser/issues/1248 - setTimeout(function () { - xdr.send(); - }, 0); +},{"../../core":61}],120:[function(require,module,exports){ + +module.exports = { + webGL: require('./webgl/WebGLExtract'), + canvas: require('./canvas/CanvasExtract') }; +},{"./canvas/CanvasExtract":119,"./webgl/WebGLExtract":121}],121:[function(require,module,exports){ +var core = require('../../core'), + tempRect = new core.Rectangle(); + +/** + * The extract manager provides functionality to export content from the renderers + * @class + * @memberof PIXI + * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer + */ +function WebGLExtract(renderer) +{ + this.renderer = renderer; + renderer.extract = this; +} + + +WebGLExtract.prototype.constructor = WebGLExtract; +module.exports = WebGLExtract; + +/** + * Will return a HTML Image of the target + * + * @param target {PIXI.DisplayObject|PIXI.RenderTexture} A displayObject or renderTexture to convert. If left empty will use use the main renderer + * @return {HTMLImageElement} HTML Image of the target + */ +WebGLExtract.prototype.image = function ( target ) +{ + var image = new Image(); + image.src = this.base64( target ); + return image; +}; + +/** + * Will return a a base64 encoded string of this target. It works by calling WebGLExtract.getCanvas and then running toDataURL on that. + * @param target {PIXI.DisplayObject|PIXI.RenderTexture} A displayObject or renderTexture to convert. If left empty will use use the main renderer + * @return {string} A base64 encoded string of the texture. + */ +WebGLExtract.prototype.base64 = function ( target ) +{ + return this.canvas( target ).toDataURL(); +}; + +/** + * Creates a Canvas element, renders this target to it and then returns it. + * @param target {PIXI.DisplayObject|PIXI.RenderTexture} A displayObject or renderTexture to convert. If left empty will use use the main renderer + * @return {HTMLCanvasElement} A Canvas element with the texture rendered on. + */ +WebGLExtract.prototype.canvas = function ( target ) +{ + var renderer = this.renderer; + var textureBuffer; + var resolution; + var frame; + var flipY = false; + var renderTexture; + + if(target) + { + if(target instanceof core.RenderTexture) + { + renderTexture = target; + } + else + { + renderTexture = this.renderer.generateTexture(target); + + } + } + + if(renderTexture) + { + textureBuffer = renderTexture.baseTexture._glRenderTargets[this.renderer.CONTEXT_UID]; + resolution = textureBuffer.resolution; + frame = renderTexture.frame; + flipY = false; + } + else + { + textureBuffer = this.renderer.rootRenderTarget; + resolution = textureBuffer.resolution; + flipY = true; + + frame = tempRect; + frame.width = textureBuffer.size.width; + frame.height = textureBuffer.size.height; + + } + + + + var width = frame.width * resolution; + var height = frame.height * resolution; + + var canvasBuffer = new core.CanvasRenderTarget(width, height); + + if(textureBuffer) + { + // bind the buffer + renderer.bindRenderTarget(textureBuffer); + + // set up an array of pixels + var webGLPixels = new Uint8Array(4 * width * height); + + // read pixels to the array + var gl = renderer.gl; + gl.readPixels(frame.x * resolution, frame.y * resolution, width, height, gl.RGBA, gl.UNSIGNED_BYTE, webGLPixels); + + // add the pixels to the canvas + var canvasData = canvasBuffer.context.getImageData(0, 0, width, height); + canvasData.data.set(webGLPixels); + + canvasBuffer.context.putImageData(canvasData, 0, 0); + + // pulling pixels + if(flipY) + { + canvasBuffer.context.scale(1, -1); + canvasBuffer.context.drawImage(canvasBuffer.canvas, 0,-height); + } + } + + // send the canvas back.. + return canvasBuffer.canvas; +}; + +/** + * Will return a one-dimensional array containing the pixel data of the entire texture in RGBA order, with integer values between 0 and 255 (included). + * @param target {PIXI.DisplayObject|PIXI.RenderTexture} A displayObject or renderTexture to convert. If left empty will use use the main renderer + * @return {Uint8ClampedArray} One-dimensional array containing the pixel data of the entire texture + */ +WebGLExtract.prototype.pixels = function ( target ) +{ + var renderer = this.renderer; + var textureBuffer; + var resolution; + var frame; + var renderTexture; + + if(target) + { + if(target instanceof core.RenderTexture) + { + renderTexture = target; + } + else + { + renderTexture = this.renderer.generateTexture(target); + } + } + + if(renderTexture) + { + textureBuffer = renderTexture.baseTexture._glRenderTargets[this.renderer.CONTEXT_UID]; + resolution = textureBuffer.resolution; + frame = renderTexture.frame; + + } + else + { + textureBuffer = this.renderer.rootRenderTarget; + resolution = textureBuffer.resolution; + + frame = tempRect; + frame.width = textureBuffer.size.width; + frame.height = textureBuffer.size.height; + } + + var width = frame.width * resolution; + var height = frame.height * resolution; + + var webGLPixels = new Uint8Array(4 * width * height); + + if(textureBuffer) + { + // bind the buffer + renderer.bindRenderTarget(textureBuffer); + // read pixels to the array + var gl = renderer.gl; + gl.readPixels(frame.x * resolution, frame.y * resolution, width, height, gl.RGBA, gl.UNSIGNED_BYTE, webGLPixels); + } + + return webGLPixels; +}; + +/** + * Destroys the extract + * + */ +WebGLExtract.prototype.destroy = function () +{ + this.renderer.extract = null; + this.renderer = null; +}; + +core.WebGLRenderer.registerPlugin('extract', WebGLExtract); -/** - * Creates a source used in loading via an element. - * - * @param type {string} The element type (video or audio). - * @param url {string} The source URL to load from. - * @param [mime] {string} The mime type of the video - * @private - */ -Resource.prototype._createSource = function (type, url, mime) { - if (!mime) { - mime = type + '/' + url.substr(url.lastIndexOf('.') + 1); - } - - var source = document.createElement('source'); +},{"../../core":61}],122:[function(require,module,exports){ +var core = require('../core'), + ObservablePoint = require('../core/math/ObservablePoint'); + +/** + * A BitmapText object will create a line or multiple lines of text using bitmap font. To + * split a line you can use '\n', '\r' or '\r\n' in your string. You can generate the fnt files using: + * + * A BitmapText can only be created when the font is loaded + * + * ```js + * // in this case the font is in a file called 'desyrel.fnt' + * var bitmapText = new PIXI.extras.BitmapText("text using a fancy font!", {font: "35px Desyrel", align: "right"}); + * ``` + * + * http://www.angelcode.com/products/bmfont/ for windows or + * http://www.bmglyph.com/ for mac. + * + * @class + * @extends PIXI.Container + * @memberof PIXI.extras + * @param text {string} The copy that you would like the text to display + * @param style {object} The style parameters + * @param style.font {string|object} The font descriptor for the object, can be passed as a string of form + * "24px FontName" or "FontName" or as an object with explicit name/size properties. + * @param [style.font.name] {string} The bitmap font id + * @param [style.font.size] {number} The size of the font in pixels, e.g. 24 + * @param [style.align='left'] {string} Alignment for multiline text ('left', 'center' or 'right'), does not affect + * single line text + * @param [style.tint=0xFFFFFF] {number} The tint color + */ +function BitmapText(text, style) +{ + core.Container.call(this); + + style = style || {}; + + /** + * The width of the overall text, different from fontSize, + * which is defined in the style object + * + * @member {number} + * @readonly + */ + this.textWidth = 0; + + /** + * The height of the overall text, different from fontSize, + * which is defined in the style object + * + * @member {number} + * @readonly + */ + this.textHeight = 0; + + /** + * Private tracker for the letter sprite pool. + * + * @member {PIXI.Sprite[]} + * @private + */ + this._glyphs = []; + + /** + * Private tracker for the current style. + * + * @member {object} + * @private + */ + this._font = { + tint: style.tint !== undefined ? style.tint : 0xFFFFFF, + align: style.align || 'left', + name: null, + size: 0 + }; + + /** + * Private tracker for the current font. + * + * @member {object} + * @private + */ + this.font = style.font; // run font setter + + /** + * Private tracker for the current text. + * + * @member {string} + * @private + */ + this._text = text; + + /** + * The max width of this bitmap text in pixels. If the text provided is longer than the value provided, line breaks will be automatically inserted in the last whitespace. + * Disable by setting value to 0 + * + * @member {number} + */ + this.maxWidth = 0; + + /** + * The max line height. This is useful when trying to use the total height of the Text, ie: when trying to vertically align. + * + * @member {number} + */ + this.maxLineHeight = 0; + + /** + * Text anchor. read-only + * + * @member {PIXI.ObservablePoint} + * @private + */ + this._anchor = new ObservablePoint(this.makeDirty, this, 0, 0); + + /** + * The dirty state of this object. + * + * @member {boolean} + */ + this.dirty = false; + + this.updateText(); +} + +// constructor +BitmapText.prototype = Object.create(core.Container.prototype); +BitmapText.prototype.constructor = BitmapText; +module.exports = BitmapText; + +Object.defineProperties(BitmapText.prototype, { + /** + * The tint of the BitmapText object + * + * @member {number} + * @memberof PIXI.extras.BitmapText# + */ + tint: { + get: function () + { + return this._font.tint; + }, + set: function (value) + { + this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; + + this.dirty = true; + } + }, + + /** + * The alignment of the BitmapText object + * + * @member {string} + * @default 'left' + * @memberof PIXI.extras.BitmapText# + */ + align: { + get: function () + { + return this._font.align; + }, + set: function (value) + { + this._font.align = value || 'left'; + + this.dirty = true; + } + }, + + /** + * The anchor sets the origin point of the text. + * The default is 0,0 this means the text's origin is the top left + * Setting the anchor to 0.5,0.5 means the text's origin is centered + * Setting the anchor to 1,1 would mean the text's origin point will be the bottom right corner + * + * @member {PIXI.Point | number} + * @memberof PIXI.extras.BitmapText# + */ + anchor: { + get : function() { + return this._anchor; + }, + set: function(value) { + if (typeof value === 'number'){ + this._anchor.set(value); + } + else { + this._anchor.copy(value); + } + } + }, + + /** + * The font descriptor of the BitmapText object + * + * @member {string|object} + * @memberof PIXI.extras.BitmapText# + */ + font: { + get: function () + { + return this._font; + }, + set: function (value) + { + if (!value) { + return; + } + + if (typeof value === 'string') { + value = value.split(' '); + + this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); + this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; + } + else { + this._font.name = value.name; + this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); + } + + this.dirty = true; + } + }, + + /** + * The text of the BitmapText object + * + * @member {string} + * @memberof PIXI.extras.BitmapText# + */ + text: { + get: function () + { + return this._text; + }, + set: function (value) + { + value = value.toString() || ' '; + if (this._text === value) + { + return; + } + this._text = value; + this.dirty = true; + } + } +}); + +/** + * Renders text and updates it when needed + * + * @private + */ +BitmapText.prototype.updateText = function () +{ + var data = BitmapText.fonts[this._font.name]; + var pos = new core.Point(); + var prevCharCode = null; + var chars = []; + var lastLineWidth = 0; + var maxLineWidth = 0; + var lineWidths = []; + var line = 0; + var scale = this._font.size / data.size; + var lastSpace = -1; + var maxLineHeight = 0; + + for (var i = 0; i < this.text.length; i++) + { + var charCode = this.text.charCodeAt(i); + lastSpace = /(\s)/.test(this.text.charAt(i)) ? i : lastSpace; + + if (/(?:\r\n|\r|\n)/.test(this.text.charAt(i))) + { + lineWidths.push(lastLineWidth); + maxLineWidth = Math.max(maxLineWidth, lastLineWidth); + line++; + + pos.x = 0; + pos.y += data.lineHeight; + prevCharCode = null; + continue; + } + + if (lastSpace !== -1 && this.maxWidth > 0 && pos.x * scale > this.maxWidth) + { + core.utils.removeItems(chars, lastSpace, i - lastSpace); + i = lastSpace; + lastSpace = -1; + + lineWidths.push(lastLineWidth); + maxLineWidth = Math.max(maxLineWidth, lastLineWidth); + line++; + + pos.x = 0; + pos.y += data.lineHeight; + prevCharCode = null; + continue; + } + + var charData = data.chars[charCode]; + + if (!charData) + { + continue; + } + + if (prevCharCode && charData.kerning[prevCharCode]) + { + pos.x += charData.kerning[prevCharCode]; + } + + chars.push({texture:charData.texture, line: line, charCode: charCode, position: new core.Point(pos.x + charData.xOffset, pos.y + charData.yOffset)}); + lastLineWidth = pos.x + (charData.texture.width + charData.xOffset); + pos.x += charData.xAdvance; + maxLineHeight = Math.max(maxLineHeight, (charData.yOffset + charData.texture.height)); + prevCharCode = charCode; + } + + lineWidths.push(lastLineWidth); + maxLineWidth = Math.max(maxLineWidth, lastLineWidth); + + var lineAlignOffsets = []; + + for (i = 0; i <= line; i++) + { + var alignOffset = 0; + + if (this._font.align === 'right') + { + alignOffset = maxLineWidth - lineWidths[i]; + } + else if (this._font.align === 'center') + { + alignOffset = (maxLineWidth - lineWidths[i]) / 2; + } + + lineAlignOffsets.push(alignOffset); + } + + var lenChars = chars.length; + var tint = this.tint; + + for (i = 0; i < lenChars; i++) + { + var c = this._glyphs[i]; // get the next glyph sprite + + if (c) + { + c.texture = chars[i].texture; + } + else + { + c = new core.Sprite(chars[i].texture); + this._glyphs.push(c); + } + + c.position.x = (chars[i].position.x + lineAlignOffsets[chars[i].line]) * scale; + c.position.y = chars[i].position.y * scale; + c.scale.x = c.scale.y = scale; + c.tint = tint; + + if (!c.parent) + { + this.addChild(c); + } + } + + // remove unnecessary children. + for (i = lenChars; i < this._glyphs.length; ++i) + { + this.removeChild(this._glyphs[i]); + } + + this.textWidth = maxLineWidth * scale; + this.textHeight = (pos.y + data.lineHeight) * scale; + + // apply anchor + if (this.anchor.x !== 0 || this.anchor.y !== 0) + { + for (i = 0; i < lenChars; i++) + { + this._glyphs[i].x -= this.textWidth * this.anchor.x; + this._glyphs[i].y -= this.textHeight * this.anchor.y; + } + } + this.maxLineHeight = maxLineHeight * scale; +}; + +/** + * Updates the transform of this object + * + * @private + */ +BitmapText.prototype.updateTransform = function () +{ + this.validate(); + this.containerUpdateTransform(); +}; + +/** + * Validates text before calling parent's getLocalBounds + * + * @return {PIXI.Rectangle} The rectangular bounding area + */ + +BitmapText.prototype.getLocalBounds = function() +{ + this.validate(); + return core.Container.prototype.getLocalBounds.call(this); +}; + +/** + * Updates text when needed + * + * @private + */ +BitmapText.prototype.validate = function() +{ + if (this.dirty) + { + this.updateText(); + this.dirty = false; + } +}; + +BitmapText.prototype.makeDirty = function() { + this.dirty = true; +}; + +BitmapText.fonts = {}; - source.src = url; - source.type = mime; +},{"../core":61,"../core/math/ObservablePoint":64}],123:[function(require,module,exports){ +var core = require('../core'); + +/** + * @typedef FrameObject + * @type {object} + * @property texture {PIXI.Texture} The {@link PIXI.Texture} of the frame + * @property time {number} the duration of the frame in ms + */ + +/** + * A MovieClip is a simple way to display an animation depicted by a list of textures. + * + * ```js + * var alienImages = ["image_sequence_01.png","image_sequence_02.png","image_sequence_03.png","image_sequence_04.png"]; + * var textureArray = []; + * + * for (var i=0; i < 4; i++) + * { + * var texture = PIXI.Texture.fromImage(alienImages[i]); + * textureArray.push(texture); + * }; + * + * var mc = new PIXI.MovieClip(textureArray); + * ``` + * + * + * @class + * @extends PIXI.Sprite + * @memberof PIXI.extras + * @param textures {PIXI.Texture[]|FrameObject[]} an array of {@link PIXI.Texture} or frame objects that make up the animation + */ +function MovieClip(textures) +{ + core.Sprite.call(this, textures[0] instanceof core.Texture ? textures[0] : textures[0].texture); + + /** + * @private + */ + this._textures = null; + + /** + * @private + */ + this._durations = null; + + this.textures = textures; + + /** + * The speed that the MovieClip will play at. Higher is faster, lower is slower + * + * @member {number} + * @default 1 + */ + this.animationSpeed = 1; + + /** + * Whether or not the movie clip repeats after playing. + * + * @member {boolean} + * @default true + */ + this.loop = true; + + /** + * Function to call when a MovieClip finishes playing + * + * @method + * @memberof PIXI.extras.MovieClip# + */ + this.onComplete = null; + + /** + * Elapsed time since animation has been started, used internally to display current texture + * + * @member {number} + * @private + */ + this._currentTime = 0; + + /** + * Indicates if the MovieClip is currently playing + * + * @member {boolean} + * @readonly + */ + this.playing = false; +} + +// constructor +MovieClip.prototype = Object.create(core.Sprite.prototype); +MovieClip.prototype.constructor = MovieClip; +module.exports = MovieClip; + +Object.defineProperties(MovieClip.prototype, { + /** + * totalFrames is the total number of frames in the MovieClip. This is the same as number of textures + * assigned to the MovieClip. + * + * @member {number} + * @memberof PIXI.extras.MovieClip# + * @default 0 + * @readonly + */ + totalFrames: { + get: function() + { + return this._textures.length; + } + }, + + /** + * The array of textures used for this MovieClip + * + * @member {PIXI.Texture[]} + * @memberof PIXI.extras.MovieClip# + * + */ + textures: { + get: function () + { + return this._textures; + }, + set: function (value) + { + if(value[0] instanceof core.Texture) + { + this._textures = value; + this._durations = null; + } + else + { + this._textures = []; + this._durations = []; + for(var i = 0; i < value.length; i++) + { + this._textures.push(value[i].texture); + this._durations.push(value[i].time); + } + } + } + }, + + /** + * The MovieClips current frame index + * + * @member {number} + * @memberof PIXI.extras.MovieClip# + * @readonly + */ + currentFrame: { + get: function () + { + var currentFrame = Math.floor(this._currentTime) % this._textures.length; + if (currentFrame < 0) + { + currentFrame += this._textures.length; + } + return currentFrame; + } + } + +}); + +/** + * Stops the MovieClip + * + */ +MovieClip.prototype.stop = function () +{ + if(!this.playing) + { + return; + } + + this.playing = false; + core.ticker.shared.remove(this.update, this); +}; + +/** + * Plays the MovieClip + * + */ +MovieClip.prototype.play = function () +{ + if(this.playing) + { + return; + } + + this.playing = true; + core.ticker.shared.add(this.update, this); +}; + +/** + * Stops the MovieClip and goes to a specific frame + * + * @param frameNumber {number} frame index to stop at + */ +MovieClip.prototype.gotoAndStop = function (frameNumber) +{ + this.stop(); + + this._currentTime = frameNumber; + + this._texture = this._textures[this.currentFrame]; + this._textureID = -1; +}; + +/** + * Goes to a specific frame and begins playing the MovieClip + * + * @param frameNumber {number} frame index to start at + */ +MovieClip.prototype.gotoAndPlay = function (frameNumber) +{ + this._currentTime = frameNumber; + + this.play(); +}; + +/* + * Updates the object transform for rendering + * @private + */ +MovieClip.prototype.update = function (deltaTime) +{ + var elapsed = this.animationSpeed * deltaTime; + + if (this._durations !== null) + { + var lag = this._currentTime % 1 * this._durations[this.currentFrame]; + + lag += elapsed / 60 * 1000; + + while (lag < 0) + { + this._currentTime--; + lag += this._durations[this.currentFrame]; + } + + var sign = Math.sign(this.animationSpeed * deltaTime); + this._currentTime = Math.floor(this._currentTime); + + while (lag >= this._durations[this.currentFrame]) + { + lag -= this._durations[this.currentFrame] * sign; + this._currentTime += sign; + } + + this._currentTime += lag / this._durations[this.currentFrame]; + } + else + { + this._currentTime += elapsed; + } + + if (this._currentTime < 0 && !this.loop) + { + this.gotoAndStop(0); + + if (this.onComplete) + { + this.onComplete(); + } + } + else if (this._currentTime >= this._textures.length && !this.loop) + { + this.gotoAndStop(this._textures.length - 1); + + if (this.onComplete) + { + this.onComplete(); + } + } + else + { + this._texture = this._textures[this.currentFrame]; + this._textureID = -1; + } + +}; + +/* + * Stops the MovieClip and destroys it + * + */ +MovieClip.prototype.destroy = function ( ) +{ + this.stop(); + core.Sprite.prototype.destroy.call(this); +}; + +/** + * A short hand way of creating a movieclip from an array of frame ids + * + * @static + * @param frames {string[]} the array of frames ids the movieclip will use as its texture frames + */ +MovieClip.fromFrames = function (frames) +{ + var textures = []; + + for (var i = 0; i < frames.length; ++i) + { + textures.push(core.Texture.fromFrame(frames[i])); + } + + return new MovieClip(textures); +}; + +/** + * A short hand way of creating a movieclip from an array of image ids + * + * @static + * @param images {string[]} the array of image urls the movieclip will use as its texture frames + */ +MovieClip.fromImages = function (images) +{ + var textures = []; + + for (var i = 0; i < images.length; ++i) + { + textures.push(core.Texture.fromImage(images[i])); + } + + return new MovieClip(textures); +}; - return source; -}; +},{"../core":61}],124:[function(require,module,exports){ +var core = require('../core'), + tempPoint = new core.Point(), + CanvasTinter = require('../core/sprites/canvas/CanvasTinter'), + TilingShader = require('./webgl/TilingShader'), + tempArray = new Float32Array(4); +/** + * A tiling sprite is a fast way of rendering a tiling image + * + * @class + * @extends PIXI.Sprite + * @memberof PIXI.extras + * @param texture {PIXI.Texture} the texture of the tiling sprite + * @param width {number} the width of the tiling sprite + * @param height {number} the height of the tiling sprite + */ +function TilingSprite(texture, width, height) +{ + core.Sprite.call(this, texture); + + /** + * The scaling of the image that is being tiled + * + * @member {PIXI.Point} + */ + this.tileScale = new core.Point(1,1); + + + /** + * The offset position of the image that is being tiled + * + * @member {PIXI.Point} + */ + this.tilePosition = new core.Point(0,0); + + ///// private + + /** + * The with of the tiling sprite + * + * @member {number} + * @private + */ + this._width = width || 100; + + /** + * The height of the tiling sprite + * + * @member {number} + * @private + */ + this._height = height || 100; + + /** + * An internal WebGL UV cache. + * + * @member {PIXI.TextureUvs} + * @private + */ + this._uvs = new core.TextureUvs(); + + this._canvasPattern = null; + + this._glDatas = []; +} + +TilingSprite.prototype = Object.create(core.Sprite.prototype); +TilingSprite.prototype.constructor = TilingSprite; +module.exports = TilingSprite; + + +Object.defineProperties(TilingSprite.prototype, { + /** + * The width of the sprite, setting this will actually modify the scale to achieve the value set + * + * @member {number} + * @memberof PIXI.extras.TilingSprite# + */ + width: { + get: function () + { + return this._width; + }, + set: function (value) + { + this._width = value; + } + }, + + /** + * The height of the TilingSprite, setting this will actually modify the scale to achieve the value set + * + * @member {number} + * @memberof PIXI.extras.TilingSprite# + */ + height: { + get: function () + { + return this._height; + }, + set: function (value) + { + this._height = value; + } + } +}); + +TilingSprite.prototype._onTextureUpdate = function () +{ + return; +}; + + +/** + * Renders the object using the WebGL renderer + * + * @param renderer {PIXI.WebGLRenderer} The renderer + * @private + */ +TilingSprite.prototype._renderWebGL = function (renderer) +{ + + // tweak our texture temporarily.. + var texture = this._texture; + + if(!texture || !texture._uvs) + { + return; + } + + // get rid of any thing that may be batching. + renderer.flush(); + + var gl = renderer.gl; + var glData = this._glDatas[renderer.CONTEXT_UID]; + + if(!glData) + { + glData = { + shader:new TilingShader(gl), + quad:new core.Quad(gl) + }; + + this._glDatas[renderer.CONTEXT_UID] = glData; + + glData.quad.initVao(glData.shader); + } + + // if the sprite is trimmed and is not a tilingsprite then we need to add the extra space before transforming the sprite coords.. + var vertices = glData.quad.vertices; + + vertices[0] = vertices[6] = ( this._width ) * -this.anchor.x; + vertices[1] = vertices[3] = this._height * -this.anchor.y; + + vertices[2] = vertices[4] = ( this._width ) * (1-this.anchor.x); + vertices[5] = vertices[7] = this._height * (1-this.anchor.y); + + glData.quad.upload(); + + renderer.bindShader(glData.shader); + + var textureUvs = texture._uvs, + textureWidth = texture._frame.width, + textureHeight = texture._frame.height, + textureBaseWidth = texture.baseTexture.width, + textureBaseHeight = texture.baseTexture.height; + + var uPixelSize = glData.shader.uniforms.uPixelSize; + uPixelSize[0] = 1.0/textureBaseWidth; + uPixelSize[1] = 1.0/textureBaseHeight; + glData.shader.uniforms.uPixelSize = uPixelSize; + + var uFrame = glData.shader.uniforms.uFrame; + uFrame[0] = textureUvs.x0; + uFrame[1] = textureUvs.y0; + uFrame[2] = textureUvs.x1 - textureUvs.x0; + uFrame[3] = textureUvs.y2 - textureUvs.y0; + glData.shader.uniforms.uFrame = uFrame; + + var uTransform = glData.shader.uniforms.uTransform; + uTransform[0] = (this.tilePosition.x % (textureWidth * this.tileScale.x)) / this._width; + uTransform[1] = (this.tilePosition.y % (textureHeight * this.tileScale.y)) / this._height; + uTransform[2] = ( textureBaseWidth / this._width ) * this.tileScale.x; + uTransform[3] = ( textureBaseHeight / this._height ) * this.tileScale.y; + glData.shader.uniforms.uTransform = uTransform; + + glData.shader.uniforms.translationMatrix = this.worldTransform.toArray(true); + + var color = tempArray; + + core.utils.hex2rgb(this.tint, color); + color[3] = this.worldAlpha; + + glData.shader.uniforms.uColor = color; + + renderer.bindTexture(this._texture, 0); + + renderer.state.setBlendMode( this.blendMode ); + glData.quad.draw(); +}; + +/** + * Renders the object using the Canvas renderer + * + * @param renderer {PIXI.CanvasRenderer} a reference to the canvas renderer + * @private + */ +TilingSprite.prototype._renderCanvas = function (renderer) +{ + var texture = this._texture; + + if (!texture.baseTexture.hasLoaded) + { + return; + } + + var context = renderer.context, + transform = this.worldTransform, + resolution = renderer.resolution, + baseTexture = texture.baseTexture, + modX = (this.tilePosition.x / this.tileScale.x) % texture._frame.width, + modY = (this.tilePosition.y / this.tileScale.y) % texture._frame.height; + + // create a nice shiny pattern! + // TODO this needs to be refreshed if texture changes.. + if(!this._canvasPattern) + { + // cut an object from a spritesheet.. + var tempCanvas = new core.CanvasRenderTarget(texture._frame.width, texture._frame.height); + + // Tint the tiling sprite + if (this.tint !== 0xFFFFFF) + { + if (this.cachedTint !== this.tint) + { + this.cachedTint = this.tint; + + this.tintedTexture = CanvasTinter.getTintedTexture(this, this.tint); + } + tempCanvas.context.drawImage(this.tintedTexture, 0, 0); + } + else + { + tempCanvas.context.drawImage(baseTexture.source, -texture._frame.x, -texture._frame.y); + } + this._canvasPattern = tempCanvas.context.createPattern( tempCanvas.canvas, 'repeat' ); + } + + // set context state.. + context.globalAlpha = this.worldAlpha; + context.setTransform(transform.a * resolution, + transform.b * resolution, + transform.c * resolution, + transform.d * resolution, + transform.tx * resolution, + transform.ty * resolution); + + // TODO - this should be rolled into the setTransform above.. + context.scale(this.tileScale.x,this.tileScale.y); + + context.translate(modX + (this.anchor.x * -this._width ), + modY + (this.anchor.y * -this._height)); + + // check blend mode + var compositeOperation = renderer.blendModes[this.blendMode]; + if (compositeOperation !== renderer.context.globalCompositeOperation) + { + context.globalCompositeOperation = compositeOperation; + } + + // fill the pattern! + context.fillStyle = this._canvasPattern; + context.fillRect(-modX, + -modY, + this._width / this.tileScale.x, + this._height / this.tileScale.y); + + + //TODO - pretty sure this can be deleted... + //context.translate(-this.tilePosition.x + (this.anchor.x * this._width), -this.tilePosition.y + (this.anchor.y * this._height)); + //context.scale(1 / this.tileScale.x, 1 / this.tileScale.y); +}; + + +/** + * Returns the framing rectangle of the sprite as a Rectangle object +* + * @return {PIXI.Rectangle} the framing rectangle + */ +TilingSprite.prototype.getBounds = function () +{ + var width = this._width; + var height = this._height; + + var w0 = width * (1-this.anchor.x); + var w1 = width * -this.anchor.x; + + var h0 = height * (1-this.anchor.y); + var h1 = height * -this.anchor.y; + + var worldTransform = this.worldTransform; + + var a = worldTransform.a; + var b = worldTransform.b; + var c = worldTransform.c; + var d = worldTransform.d; + var tx = worldTransform.tx; + var ty = worldTransform.ty; + + var x1 = a * w1 + c * h1 + tx; + var y1 = d * h1 + b * w1 + ty; + + var x2 = a * w0 + c * h1 + tx; + var y2 = d * h1 + b * w0 + ty; + + var x3 = a * w0 + c * h0 + tx; + var y3 = d * h0 + b * w0 + ty; + + var x4 = a * w1 + c * h0 + tx; + var y4 = d * h0 + b * w1 + ty; + + var minX, + maxX, + minY, + maxY; + + minX = x1; + minX = x2 < minX ? x2 : minX; + minX = x3 < minX ? x3 : minX; + minX = x4 < minX ? x4 : minX; + + minY = y1; + minY = y2 < minY ? y2 : minY; + minY = y3 < minY ? y3 : minY; + minY = y4 < minY ? y4 : minY; + + maxX = x1; + maxX = x2 > maxX ? x2 : maxX; + maxX = x3 > maxX ? x3 : maxX; + maxX = x4 > maxX ? x4 : maxX; + + maxY = y1; + maxY = y2 > maxY ? y2 : maxY; + maxY = y3 > maxY ? y3 : maxY; + maxY = y4 > maxY ? y4 : maxY; + + var bounds = this._bounds; + + bounds.x = minX; + bounds.width = maxX - minX; + + bounds.y = minY; + bounds.height = maxY - minY; + + // store a reference so that if this function gets called again in the render cycle we do not have to recalculate + this._currentBounds = bounds; + + return bounds; +}; + +/** + * Checks if a point is inside this tiling sprite + * @param point {PIXI.Point} the point to check + */ +TilingSprite.prototype.containsPoint = function( point ) +{ + this.worldTransform.applyInverse(point, tempPoint); + + var width = this._width; + var height = this._height; + var x1 = -width * this.anchor.x; + var y1; + + if ( tempPoint.x > x1 && tempPoint.x < x1 + width ) + { + y1 = -height * this.anchor.y; + + if ( tempPoint.y > y1 && tempPoint.y < y1 + height ) + { + return true; + } + } + + return false; +}; + +/** + * Destroys this tiling sprite + * + */ +TilingSprite.prototype.destroy = function () { + core.Sprite.prototype.destroy.call(this); + + this.tileScale = null; + this._tileScaleOffset = null; + this.tilePosition = null; + + this._uvs = null; +}; + +/** + * Helper function that creates a tiling sprite that will use a texture from the TextureCache based on the frameId + * The frame ids are created when a Texture packer file has been loaded + * + * @static + * @param frameId {string} The frame Id of the texture in the cache + * @return {PIXI.extras.TilingSprite} A new TilingSprite using a texture from the texture cache matching the frameId + * @param width {number} the width of the tiling sprite + * @param height {number} the height of the tiling sprite + * @return {PIXI.extras.TilingSprite} A new TilingSprite + */ +TilingSprite.fromFrame = function (frameId,width,height) +{ + var texture = core.utils.TextureCache[frameId]; + + if (!texture) + { + throw new Error('The frameId "' + frameId + '" does not exist in the texture cache ' + this); + } + + return new TilingSprite(texture,width,height); +}; + +/** + * Helper function that creates a sprite that will contain a texture based on an image url + * If the image is not in the texture cache it will be loaded + * + * @static + * @param imageId {string} The image url of the texture + * @param width {number} the width of the tiling sprite + * @param height {number} the height of the tiling sprite + * @param [crossorigin=(auto)] {boolean} if you want to specify the cross-origin parameter + * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} if you want to specify the scale mode, see {@link PIXI.SCALE_MODES} for possible values + * @return {PIXI.extras.TilingSprite} A new TilingSprite using a texture from the texture cache matching the image id + */ +TilingSprite.fromImage = function (imageId, width, height, crossorigin, scaleMode) +{ + return new TilingSprite(core.Texture.fromImage(imageId, crossorigin, scaleMode),width,height); +}; -/** - * Called if a load errors out. - * - * @param event {Event} The error event from the element that emits it. - * @private - */ -Resource.prototype._onError = function (event) { - this.error = new Error('Failed to load element using ' + event.target.nodeName); - this.complete(); -}; +},{"../core":61,"../core/sprites/canvas/CanvasTinter":99,"./webgl/TilingShader":129}],125:[function(require,module,exports){ +var core = require('../core'), + DisplayObject = core.DisplayObject, + _tempMatrix = new core.Matrix(); + +DisplayObject.prototype._cacheAsBitmap = false; +DisplayObject.prototype._cacheData = false; + +// figured theres no point adding ALL the extra variables to prototype. +// this model can hold the information needed. This can also be generated on demand as +// most objects are not cached as bitmaps. +var CacheData = function(){ + + this.originalRenderWebGL = null; + this.originalRenderCanvas = null; + + this.originalUpdateTransform = null; + this.originalHitTest = null; + this.originalDestroy = null; + this.originalMask = null; + this.originalFilterArea = null; + this.sprite = null; +}; + + +Object.defineProperties(DisplayObject.prototype, { + + /** + * Set this to true if you want this display object to be cached as a bitmap. + * This basically takes a snap shot of the display object as it is at that moment. It can provide a performance benefit for complex static displayObjects. + * To remove simply set this property to 'false' + * + * @member {boolean} + * @memberof PIXI.DisplayObject# + */ + cacheAsBitmap: { + get: function () + { + return this._cacheAsBitmap; + }, + set: function (value) + { + if (this._cacheAsBitmap === value) + { + return; + } + + this._cacheAsBitmap = value; + + var data; + + if (value) + { + + if(!this._cacheData) + { + this._cacheData = new CacheData(); + } + + data = this._cacheData; + + data.originalRenderWebGL = this.renderWebGL; + data.originalRenderCanvas = this.renderCanvas; + + data.originalUpdateTransform = this.updateTransform; + data.originalGetBounds = this.getBounds; + + data.originalDestroy = this.destroy; + + data.originalContainsPoint = this.containsPoint; + + data.originalMask = this._mask; + data.originalFilterArea = this.filterArea; + + + + this.renderWebGL = this._renderCachedWebGL; + this.renderCanvas = this._renderCachedCanvas; + + this.destroy = this._cacheAsBitmapDestroy; + + } + else + { + data = this._cacheData; + + if (data.sprite) + { + this._destroyCachedDisplayObject(); + } + + + this.renderWebGL = data.originalRenderWebGL; + this.renderCanvas = data.originalRenderCanvas; + this.getBounds = data.originalGetBounds; + + this.destroy = data.originalDestroy; + + this.updateTransform = data.originalUpdateTransform; + this.containsPoint = data.originalContainsPoint; + + this._mask = data.originalMask; + this.filterArea = data.originalFilterArea; + } + } + } +}); +/** +* Renders a cached version of the sprite with WebGL +* +* @param renderer {PIXI.WebGLRenderer} the WebGL renderer +* @private +*/ +DisplayObject.prototype._renderCachedWebGL = function (renderer) +{ + if (!this.visible || this.worldAlpha <= 0 || !this.renderable) + { + return; + } + + this._initCachedDisplayObject( renderer ); + + this._cacheData.sprite._transformID = -1; + this._cacheData.sprite.worldAlpha = this.worldAlpha; + this._cacheData.sprite._renderWebGL(renderer); +}; + +/** +* Prepares the WebGL renderer to cache the sprite +* +* @param renderer {PIXI.WebGLRenderer} the WebGL renderer +* @private +*/ +DisplayObject.prototype._initCachedDisplayObject = function (renderer) +{ + if(this._cacheData && this._cacheData.sprite) + { + return; + } + + // first we flush anything left in the renderer (otherwise it would get rendered to the cached texture) + renderer.currentRenderer.flush(); + //this.filters= []; + // next we find the dimensions of the untransformed object + // this function also calls updatetransform on all its children as part of the measuring. This means we don't need to update the transform again in this function + // TODO pass an object to clone too? saves having to create a new one each time! + var bounds = this.getLocalBounds().clone(); + + // add some padding! + if(this._filters) + { + var padding = this._filters[0].padding; + bounds.x -= padding; + bounds.y -= padding; + + bounds.width += padding * 2; + bounds.height += padding * 2; + } + + // for now we cache the current renderTarget that the webGL renderer is currently using. + // this could be more elegent.. + var cachedRenderTarget = renderer._activeRenderTarget; + // We also store the filter stack - I will definitely look to change how this works a little later down the line. + var stack = renderer.filterManager.filterStack; + + // this renderTexture will be used to store the cached DisplayObject + + var renderTexture = core.RenderTexture.create(bounds.width | 0, bounds.height | 0); + + // need to set // + var m = _tempMatrix; + + m.tx = -bounds.x; + m.ty = -bounds.y; + + // set all properties to there original so we can render to a texture + this.renderWebGL = this._cacheData.originalRenderWebGL; + + renderer.render(this, renderTexture, true, m, true); + // now restore the state be setting the new properties + + renderer.bindRenderTarget(cachedRenderTarget); + + renderer.filterManager.filterStack = stack; + + this.renderWebGL = this._renderCachedWebGL; + this.updateTransform = this.displayObjectUpdateTransform; + this.getBounds = this._getCachedBounds; + + this._mask = null; + this.filterArea = null; + + // create our cached sprite + var cachedSprite = new core.Sprite(renderTexture); + cachedSprite.transform.worldTransform = this.transform.worldTransform; + cachedSprite.anchor.x = -( bounds.x / bounds.width ); + cachedSprite.anchor.y = -( bounds.y / bounds.height ); + + this._cacheData.sprite = cachedSprite; + + // restore the transform of the cached sprite to avoid the nasty flicker.. + this.updateTransform(); + + // map the hit test.. + this.containsPoint = cachedSprite.containsPoint.bind(cachedSprite); +}; + +/** +* Renders a cached version of the sprite with canvas +* +* @param renderer {PIXI.CanvasRenderer} the Canvas renderer +* @private +*/ +DisplayObject.prototype._renderCachedCanvas = function (renderer) +{ + if (!this.visible || this.worldAlpha <= 0 || !this.renderable) + { + return; + } + + this._initCachedDisplayObjectCanvas( renderer ); + + this._cacheData.sprite.worldAlpha = this.worldAlpha; + + this._cacheData.sprite.renderCanvas(renderer); +}; + +//TODO this can be the same as the webGL verison.. will need to do a little tweaking first though.. +/** +* Prepares the Canvas renderer to cache the sprite +* +* @param renderer {PIXI.CanvasRenderer} the Canvas renderer +* @private +*/ +DisplayObject.prototype._initCachedDisplayObjectCanvas = function (renderer) +{ + if(this._cacheData && this._cacheData.sprite) + { + return; + } + + //get bounds actually transforms the object for us already! + var bounds = this.getLocalBounds(); + + var cachedRenderTarget = renderer.context; + + var renderTexture = new core.RenderTexture.create(bounds.width | 0, bounds.height | 0); + + // need to set // + var m = _tempMatrix; + this.transform.worldTransform.copy(m); + m.invert(); + + m.tx -= bounds.x; + m.ty -= bounds.y; + + //m.append(this.transform.worldTransform.) + // set all properties to there original so we can render to a texture + this.renderCanvas = this._cacheData.originalRenderCanvas; + + //renderTexture.render(this, m, true); + renderer.render(this, renderTexture, true, m, false); + + // now restore the state be setting the new properties + renderer.context = cachedRenderTarget; + + this.renderCanvas = this._renderCachedCanvas; + this.updateTransform = this.displayObjectUpdateTransform; + this.getBounds = this._getCachedBounds; + + this._mask = null; + this.filterArea = null; + + // create our cached sprite + var cachedSprite = new core.Sprite(renderTexture); + cachedSprite.transform.worldTransform = this.transform.worldTransform; + cachedSprite.anchor.x = -( bounds.x / bounds.width ); + cachedSprite.anchor.y = -( bounds.y / bounds.height ); + + this.updateTransform(); + + this._cacheData.sprite = cachedSprite; + + this.containsPoint = cachedSprite.containsPoint.bind(cachedSprite); +}; + +/** +* Calculates the bounds of the cached sprite +* +* @private +*/ +DisplayObject.prototype._getCachedBounds = function () +{ + this._cacheData.sprite._currentBounds = null; + + return this._cacheData.sprite.getBounds(); +}; + +/** +* Destroys the cached sprite. +* +* @private +*/ +DisplayObject.prototype._destroyCachedDisplayObject = function () +{ + this._cacheData.sprite._texture.destroy(true); + this._cacheData.sprite = null; +}; + +DisplayObject.prototype._cacheAsBitmapDestroy = function () +{ + this.cacheAsBitmap = false; + this.destroy(); +}; -/** - * Called if a load progress event fires for xhr/xdr. - * - * @fires progress - * @param event {XMLHttpRequestProgressEvent|Event} - * @private - */ -Resource.prototype._onProgress = function (event) { - if (event && event.lengthComputable) { - this.emit('progress', this, event.loaded / event.total); - } -}; +},{"../core":61}],126:[function(require,module,exports){ +var core = require('../core'); + +/** + * The instance name of the object. + * + * @memberof PIXI.DisplayObject# + * @member {string} + */ +core.DisplayObject.prototype.name = null; + +/** +* Returns the display object in the container +* +* @memberof PIXI.Container# +* @param name {string} instance name +* @return {PIXI.DisplayObject} +*/ +core.Container.prototype.getChildByName = function (name) +{ + for (var i = 0; i < this.children.length; i++) + { + if (this.children[i].name === name) + { + return this.children[i]; + } + } + return null; +}; -/** - * Called if an error event fires for xhr/xdr. - * - * @param event {XMLHttpRequestErrorEvent|Event} - * @private - */ -Resource.prototype._xhrOnError = function () { - this.error = new Error( - reqType(this.xhr) + ' Request failed. ' + - 'Status: ' + this.xhr.status + ', text: "' + this.xhr.statusText + '"' - ); +},{"../core":61}],127:[function(require,module,exports){ +var core = require('../core'); + +/** +* Returns the global position of the displayObject +* +* @memberof PIXI.DisplayObject# +* @param point {Point} the point to write the global value to. If null a new point will be returned +* @return {Point} +*/ +core.DisplayObject.prototype.getGlobalPosition = function (point) +{ + point = point || new core.Point(); + + if(this.parent) + { + this.displayObjectUpdateTransform(); + + point.x = this.worldTransform.tx; + point.y = this.worldTransform.ty; + } + else + { + point.x = this.position.x; + point.y = this.position.y; + } + + return point; +}; - this.complete(); -}; +},{"../core":61}],128:[function(require,module,exports){ +/** + * @file Main export of the PIXI extras library + * @author Mat Groves + * @copyright 2013-2015 GoodBoyDigital + * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} + */ + +require('./cacheAsBitmap'); +require('./getChildByName'); +require('./getGlobalPosition'); + +/** + * @namespace PIXI.extras + */ +module.exports = { + MovieClip: require('./MovieClip'), + TilingSprite: require('./TilingSprite'), + BitmapText: require('./BitmapText') +}; -/** - * Called if an abort event fires for xhr. - * - * @param event {XMLHttpRequestAbortEvent} - * @private - */ -Resource.prototype._xhrOnAbort = function () { - this.error = new Error(reqType(this.xhr) + ' Request was aborted by the user.'); - this.complete(); -}; +},{"./BitmapText":122,"./MovieClip":123,"./TilingSprite":124,"./cacheAsBitmap":125,"./getChildByName":126,"./getGlobalPosition":127}],129:[function(require,module,exports){ +var Shader = require('../../core/Shader'); + + +/** + * @class + * @extends PIXI.Shader + * @memberof PIXI.mesh + * @param gl {PIXI.Shader} The WebGL shader manager this shader works for. + */ +function TilingShader(gl) +{ + Shader.call(this, + gl, + "#define GLSLIFY 1\nattribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\n\nuniform mat3 projectionMatrix;\nuniform mat3 translationMatrix;\n\nuniform vec4 uFrame;\nuniform vec4 uTransform;\n\nvarying vec2 vTextureCoord;\n\nvoid main(void)\n{\n gl_Position = vec4((projectionMatrix * translationMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\n\n vec2 coord = aTextureCoord;\n coord -= uTransform.xy;\n coord /= uTransform.zw;\n vTextureCoord = coord;\n}\n", + "#define GLSLIFY 1\nvarying vec2 vTextureCoord;\n\nuniform sampler2D uSampler;\nuniform vec4 uColor;\nuniform vec4 uFrame;\nuniform vec2 uPixelSize;\n\nvoid main(void)\n{\n\n \tvec2 coord = mod(vTextureCoord, uFrame.zw);\n \tcoord = clamp(coord, uPixelSize, uFrame.zw - uPixelSize);\n \tcoord += uFrame.xy;\n\n \tvec4 sample = texture2D(uSampler, coord);\n \tvec4 color = vec4(uColor.rgb * uColor.a, uColor.a);\n\n \tgl_FragColor = sample * color ;\n}\n" + ); +} + +TilingShader.prototype = Object.create(Shader.prototype); +TilingShader.prototype.constructor = TilingShader; +module.exports = TilingShader; + -/** - * Called if a timeout event fires for xdr. - * - * @param event {Event} - * @private - */ -Resource.prototype._xdrOnTimeout = function () { - this.error = new Error(reqType(this.xhr) + ' Request timed out.'); - this.complete(); -}; +},{"../../core/Shader":41}],130:[function(require,module,exports){ +var core = require('../../core'), + BlurXFilter = require('./BlurXFilter'), + BlurYFilter = require('./BlurYFilter'); + +/** + * The BlurFilter applies a Gaussian blur to an object. + * The strength of the blur can be set for x- and y-axis separately. + * + * @class + * @extends PIXI.Filter + * @memberof PIXI.filters + */ +function BlurFilter(strength, quality, resolution) +{ + core.Filter.call(this); + + this.blurXFilter = new BlurXFilter(); + this.blurYFilter = new BlurYFilter(); + this.resolution = 1; + + this.padding = 0; + this.resolution = resolution || 1; + this.quality = quality || 4; + this.blur = strength || 8; +} + +BlurFilter.prototype = Object.create(core.Filter.prototype); +BlurFilter.prototype.constructor = BlurFilter; +module.exports = BlurFilter; + +BlurFilter.prototype.apply = function (filterManager, input, output) +{ + + var renderTarget = filterManager.getRenderTarget(true); + + this.blurXFilter.apply(filterManager, input, renderTarget, true); + this.blurYFilter.apply(filterManager, renderTarget, output, false); + + filterManager.returnRenderTarget(renderTarget); +}; + +Object.defineProperties(BlurFilter.prototype, { + /** + * Sets the strength of both the blurX and blurY properties simultaneously + * + * @member {number} + * @memberOf PIXI.filters.BlurFilter# + * @default 2 + */ + blur: { + get: function () + { + return this.blurXFilter.blur; + }, + set: function (value) + { + this.blurXFilter.blur = this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } + }, + + /** + * Sets the number of passes for blur. More passes means higher quaility bluring. + * + * @member {number} + * @memberof PIXI.filters.BlurYFilter# + * @default 1 + */ + quality: { + get: function () + { + return this.blurXFilter.quality; + }, + set: function (value) + { + + this.blurXFilter.quality = this.blurYFilter.quality = value; + } + }, + + /** + * Sets the strength of the blurX property + * + * @member {number} + * @memberOf PIXI.filters.BlurFilter# + * @default 2 + */ + blurX: { + get: function () + { + return this.blurXFilter.blur; + }, + set: function (value) + { + this.blurXFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } + }, + + /** + * Sets the strength of the blurY property + * + * @member {number} + * @memberOf PIXI.filters.BlurFilter# + * @default 2 + */ + blurY: { + get: function () + { + return this.blurYFilter.blur; + }, + set: function (value) + { + this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } + } +}); -/** - * Called when data successfully loads from an xhr/xdr request. - * - * @param event {XMLHttpRequestLoadEvent|Event} - * @private - */ -Resource.prototype._xhrOnLoad = function () { - var xhr = this.xhr, - status = xhr.status !== undefined ? xhr.status : 200; //XDR has no `.status`, assume 200. +},{"../../core":61,"./BlurXFilter":131,"./BlurYFilter":132}],131:[function(require,module,exports){ +var core = require('../../core'); +var generateBlurVertSource = require('./generateBlurVertSource'); +var generateBlurFragSource = require('./generateBlurFragSource'); +var getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); + +/** + * The BlurXFilter applies a horizontal Gaussian blur to an object. + * + * @class + * @extends PIXI.Filter + * @memberof PIXI.filters + */ +function BlurXFilter(strength, quality, resolution) +{ + var vertSrc = generateBlurVertSource(5, true); + var fragSrc = generateBlurFragSource(5); + + core.Filter.call(this, + // vertex shader + vertSrc, + // fragment shader + fragSrc + ); + + this.resolution = resolution || 1; + + this._quality = 0; + + this.quality = quality || 4; + this.strength = strength || 8; + + this.firstRun = true; + +} + +BlurXFilter.prototype = Object.create(core.Filter.prototype); +BlurXFilter.prototype.constructor = BlurXFilter; +module.exports = BlurXFilter; + +BlurXFilter.prototype.apply = function (filterManager, input, output, clear) +{ + if(this.firstRun) + { + var gl = filterManager.renderer.gl; + var kernelSize = getMaxBlurKernelSize(gl); + + this.vertexSrc = generateBlurVertSource(kernelSize, true); + this.fragmentSrc = generateBlurFragSource(kernelSize); + + this.firstRun = false; + } + + this.uniforms.strength = (1/output.size.width) * (output.size.width/input.size.width); /// // * 2 //4//this.strength / 4 / this.passes * (input.frame.width / input.size.width); + + // screen space! + this.uniforms.strength *= this.strength; + this.uniforms.strength /= this.passes;// / this.passes//Math.pow(1, this.passes); + + if(this.passes === 1) + { + filterManager.applyFilter(this, input, output, clear); + } + else + { + var renderTarget = filterManager.getRenderTarget(true); + var flip = input; + var flop = renderTarget; + + for(var i = 0; i < this.passes-1; i++) + { + filterManager.applyFilter(this, flip, flop, true); + + var temp = flop; + flop = flip; + flip = temp; + } + + filterManager.applyFilter(this, flip, output, clear); + + filterManager.returnRenderTarget(renderTarget); + } +}; + + +Object.defineProperties(BlurXFilter.prototype, { + /** + * Sets the strength of both the blur. + * + * @member {number} + * @memberof PIXI.filters.BlurXFilter# + * @default 16 + */ + blur: { + get: function () + { + return this.strength; + }, + set: function (value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } + }, + + /** + * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. + * + * @member {number} + * @memberof PIXI.filters.BlurXFilter# + * @default 4 + */ + quality: { + get: function () + { + return this._quality; + }, + set: function (value) + { + this._quality = value; + this.passes = value; + } + } +}); - // status can be 0 when using the file:// protocol, also check if a response was found - if (status === 200 || status === 204 || (status === 0 && xhr.responseText.length > 0)) { - // if text, just return it - if (this.xhrType === Resource.XHR_RESPONSE_TYPE.TEXT) { - this.data = xhr.responseText; - } - // if json, parse into json object - else if (this.xhrType === Resource.XHR_RESPONSE_TYPE.JSON) { - try { - this.data = JSON.parse(xhr.responseText); - this.isJson = true; - } catch(e) { - this.error = new Error('Error trying to parse loaded json:', e); - } - } - // if xml, parse into an xml document or div element - else if (this.xhrType === Resource.XHR_RESPONSE_TYPE.DOCUMENT) { - try { - if (window.DOMParser) { - var domparser = new DOMParser(); - this.data = domparser.parseFromString(xhr.responseText, 'text/xml'); - } - else { - var div = document.createElement('div'); - div.innerHTML = xhr.responseText; - this.data = div; - } - this.isXml = true; - } catch (e) { - this.error = new Error('Error trying to parse loaded xml:', e); - } - } - // other types just return the response - else { - this.data = xhr.response || xhr.responseText; - } - } - else { - this.error = new Error('[' + xhr.status + ']' + xhr.statusText + ':' + xhr.responseURL); - } +},{"../../core":61,"./generateBlurFragSource":133,"./generateBlurVertSource":134,"./getMaxBlurKernelSize":135}],132:[function(require,module,exports){ +var core = require('../../core'); +var generateBlurVertSource = require('./generateBlurVertSource'); +var generateBlurFragSource = require('./generateBlurFragSource'); +var getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); + +/** + * The BlurYFilter applies a horizontal Gaussian blur to an object. + * + * @class + * @extends PIXI.Filter + * @memberof PIXI.filters + */ +function BlurYFilter(strength, quality, resolution) +{ + var vertSrc = generateBlurVertSource(5, false); + var fragSrc = generateBlurFragSource(5); + + core.Filter.call(this, + // vertex shader + vertSrc, + // fragment shader + fragSrc + ); + + this.resolution = resolution || 1; + + this._quality = 0; + + this.quality = quality || 4; + this.strength = strength || 8; + + this.firstRun = true; +} + +BlurYFilter.prototype = Object.create(core.Filter.prototype); +BlurYFilter.prototype.constructor = BlurYFilter; +module.exports = BlurYFilter; + +BlurYFilter.prototype.apply = function (filterManager, input, output, clear) +{ + if(this.firstRun) + { + var gl = filterManager.renderer.gl; + var kernelSize = getMaxBlurKernelSize(gl); + + this.vertexSrc = generateBlurVertSource(kernelSize, false); + this.fragmentSrc = generateBlurFragSource(kernelSize); + + this.firstRun = false; + } + + this.uniforms.strength = (1/output.size.height) * (output.size.height/input.size.height); /// // * 2 //4//this.strength / 4 / this.passes * (input.frame.width / input.size.width); + + this.uniforms.strength *= this.strength; + this.uniforms.strength /= this.passes; + + if(this.passes === 1) + { + filterManager.applyFilter(this, input, output, clear); + } + else + { + var renderTarget = filterManager.getRenderTarget(true); + var flip = input; + var flop = renderTarget; + + for(var i = 0; i < this.passes-1; i++) + { + filterManager.applyFilter(this, flip, flop, true); + + var temp = flop; + flop = flip; + flip = temp; + } + + filterManager.applyFilter(this, flip, output, clear); + + filterManager.returnRenderTarget(renderTarget); + } +}; + + +Object.defineProperties(BlurYFilter.prototype, { + /** + * Sets the strength of both the blur. + * + * @member {number} + * @memberof PIXI.filters.BlurYFilter# + * @default 2 + */ + blur: { + get: function () + { + return this.strength; + }, + set: function (value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } + }, + + /** + * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. + * + * @member {number} + * @memberof PIXI.filters.BlurXFilter# + * @default 4 + */ + quality: { + get: function () + { + return this._quality; + }, + set: function (value) + { + this._quality = value; + this.passes = value; + } + } +}); - this.complete(); -}; +},{"../../core":61,"./generateBlurFragSource":133,"./generateBlurVertSource":134,"./getMaxBlurKernelSize":135}],133:[function(require,module,exports){ +var GAUSSIAN_VALUES = { + 5:[0.153388, 0.221461, 0.250301], + 7:[0.071303, 0.131514, 0.189879, 0.214607], + 9:[0.028532, 0.067234, 0.124009, 0.179044, 0.20236], + 11:[0.0093, 0.028002, 0.065984, 0.121703, 0.175713, 0.198596], + 13:[0.002406, 0.009255, 0.027867, 0.065666, 0.121117, 0.174868, 0.197641], + 15:[0.000489, 0.002403, 0.009246, 0.02784, 0.065602, 0.120999, 0.174697, 0.197448] +}; + +var fragTemplate = [ + 'varying vec2 vBlurTexCoords[%size%];', + 'uniform sampler2D uSampler;', + + 'void main(void)', + '{', + ' gl_FragColor = vec4(0.0);', + ' %blur%', + '}' + +].join('\n'); + +var generateFragBlurSource = function(kernelSize) +{ + var kernel = GAUSSIAN_VALUES[kernelSize]; + var halfLength = kernel.length; + + var fragSource = fragTemplate; + + var blurLoop = ''; + var template = 'gl_FragColor += texture2D(uSampler, vBlurTexCoords[%index%]) * %value%;'; + var value; + + for (var i = 0; i < kernelSize; i++) + { + var blur = template.replace('%index%', i); + + value = i; + + if(i >= halfLength) + { + value = kernelSize - i - 1; + } + + + blur = blur.replace('%value%', kernel[value]); + + blurLoop += blur; + blurLoop += '\n'; + } + + fragSource = fragSource.replace('%blur%', blurLoop); + fragSource = fragSource.replace('%size%', kernelSize); + + + return fragSource; +}; + + + +module.exports = generateFragBlurSource; -function reqType(xhr) { - return xhr.toString().replace('object ', ''); -} +},{}],134:[function(require,module,exports){ + +var vertTemplate = [ + 'attribute vec2 aVertexPosition;', + 'attribute vec2 aTextureCoord;', + + 'uniform float strength;', + 'uniform mat3 projectionMatrix;', + + 'varying vec2 vBlurTexCoords[%size%];', + + 'void main(void)', + '{', + 'gl_Position = vec4((projectionMatrix * vec3((aVertexPosition), 1.0)).xy, 0.0, 1.0);', + '%blur%', + '}' +].join('\n'); + +var generateVertBlurSource = function(kernelSize, x) +{ + var halfLength = Math.ceil(kernelSize/2); + + var vertSource = vertTemplate; + + var blurLoop = ''; + var template; + var value; + + if(x) + { + template = 'vBlurTexCoords[%index%] = aTextureCoord + vec2(%sampleIndex% * strength, 0.0);'; + } + else + { + template = 'vBlurTexCoords[%index%] = aTextureCoord + vec2(0.0, %sampleIndex% * strength);'; + + } + + + for (var i = 0; i < kernelSize; i++) + { + var blur = template.replace('%index%', i); + + value = i; + + if(i >= halfLength) + { + value = kernelSize - i - 1; + } + + blur = blur.replace('%sampleIndex%', (i - (halfLength-1)) + '.0'); + + blurLoop += blur; + blurLoop += '\n'; + } + + vertSource = vertSource.replace('%blur%', blurLoop); + vertSource = vertSource.replace('%size%', kernelSize); + + return vertSource; +}; + + + +module.exports = generateVertBlurSource; -/** - * Sets the `crossOrigin` property for this resource based on if the url - * for this resource is cross-origin. If crossOrigin was manually set, this - * function does nothing. - * - * @private - * @param url {string} The url to test. - * @param [location=window.location] {object} The location object to test against. - * @return {string} The crossOrigin value to use (or empty string for none). - */ -Resource.prototype._determineCrossOrigin = function (url, loc) { - // data: and javascript: urls are considered same-origin - if (url.indexOf('data:') === 0) { - return ''; - } +},{}],135:[function(require,module,exports){ + + +var getMaxKernelSize = function(gl) +{ + var maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); + var kernelSize = 15; + + while(kernelSize > maxVaryings) + { + kernelSize -= 2; + } + + return kernelSize; +}; + +module.exports = getMaxKernelSize; - // default is window.location - loc = loc || window.location; +},{}],136:[function(require,module,exports){ +var core = require('../../core'); +// @see https://github.com/substack/brfs/issues/25 + + +/** + * The ColorMatrixFilter class lets you apply a 5x4 matrix transformation on the RGBA + * color and alpha values of every pixel on your displayObject to produce a result + * with a new set of RGBA color and alpha values. It's pretty powerful! + * + * ```js + * var colorMatrix = new PIXI.ColorMatrixFilter(); + * container.filters = [colorMatrix]; + * colorMatrix.contrast(2); + * ``` + * @author Clément Chenebault + * @class + * @extends PIXI.Filter + * @memberof PIXI.filters + */ +function ColorMatrixFilter() +{ + core.Filter.call(this, + // vertex shader + "#define GLSLIFY 1\nattribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\n\nuniform mat3 projectionMatrix;\n\nvarying vec2 vTextureCoord;\n\nvoid main(void)\n{\n gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}", + // fragment shader + "#define GLSLIFY 1\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\nuniform float m[20];\n\nvoid main(void)\n{\n\n vec4 c = texture2D(uSampler, vTextureCoord);\n\n gl_FragColor.r = (m[0] * c.r);\n gl_FragColor.r += (m[1] * c.g);\n gl_FragColor.r += (m[2] * c.b);\n gl_FragColor.r += (m[3] * c.a);\n gl_FragColor.r += m[4] * c.a;\n\n gl_FragColor.g = (m[5] * c.r);\n gl_FragColor.g += (m[6] * c.g);\n gl_FragColor.g += (m[7] * c.b);\n gl_FragColor.g += (m[8] * c.a);\n gl_FragColor.g += m[9] * c.a;\n\n gl_FragColor.b = (m[10] * c.r);\n gl_FragColor.b += (m[11] * c.g);\n gl_FragColor.b += (m[12] * c.b);\n gl_FragColor.b += (m[13] * c.a);\n gl_FragColor.b += m[14] * c.a;\n\n gl_FragColor.a = (m[15] * c.r);\n gl_FragColor.a += (m[16] * c.g);\n gl_FragColor.a += (m[17] * c.b);\n gl_FragColor.a += (m[18] * c.a);\n gl_FragColor.a += m[19] * c.a;\n\n// gl_FragColor = vec4(m[0]);\n}\n" + ); + + this.uniforms.m = [ + 1, 0, 0, 0, 0, + 0, 1, 0, 0, 0, + 0, 0, 1, 0, 0, + 0, 0, 0, 1, 0]; + + +} + +ColorMatrixFilter.prototype = Object.create(core.Filter.prototype); +ColorMatrixFilter.prototype.constructor = ColorMatrixFilter; +module.exports = ColorMatrixFilter; + + +/** + * Transforms current matrix and set the new one + * + * @param matrix {number[]} (mat 5x4) + * @param multiply {boolean} if true, current matrix and matrix are multiplied. If false, just set the current matrix with @param matrix + */ +ColorMatrixFilter.prototype._loadMatrix = function (matrix, multiply) +{ + multiply = !!multiply; + + var newMatrix = matrix; + + if (multiply) { + this._multiply(newMatrix, this.uniforms.m, matrix); + newMatrix = this._colorMatrix(newMatrix); + } + + // set the new matrix + this.uniforms.m = newMatrix; +}; + +/** + * Multiplies two mat5's + * + * @param out {number[]} (mat 5x4) the receiving matrix + * @param a {number[]} (mat 5x4) the first operand + * @param b {number[]} (mat 5x4) the second operand + * @returns out {number[]} (mat 5x4) + */ +ColorMatrixFilter.prototype._multiply = function (out, a, b) +{ + + // Red Channel + out[0] = (a[0] * b[0]) + (a[1] * b[5]) + (a[2] * b[10]) + (a[3] * b[15]); + out[1] = (a[0] * b[1]) + (a[1] * b[6]) + (a[2] * b[11]) + (a[3] * b[16]); + out[2] = (a[0] * b[2]) + (a[1] * b[7]) + (a[2] * b[12]) + (a[3] * b[17]); + out[3] = (a[0] * b[3]) + (a[1] * b[8]) + (a[2] * b[13]) + (a[3] * b[18]); + out[4] = (a[0] * b[4]) + (a[1] * b[9]) + (a[2] * b[14]) + (a[3] * b[19]); + + // Green Channel + out[5] = (a[5] * b[0]) + (a[6] * b[5]) + (a[7] * b[10]) + (a[8] * b[15]); + out[6] = (a[5] * b[1]) + (a[6] * b[6]) + (a[7] * b[11]) + (a[8] * b[16]); + out[7] = (a[5] * b[2]) + (a[6] * b[7]) + (a[7] * b[12]) + (a[8] * b[17]); + out[8] = (a[5] * b[3]) + (a[6] * b[8]) + (a[7] * b[13]) + (a[8] * b[18]); + out[9] = (a[5] * b[4]) + (a[6] * b[9]) + (a[7] * b[14]) + (a[8] * b[19]); + + // Blue Channel + out[10] = (a[10] * b[0]) + (a[11] * b[5]) + (a[12] * b[10]) + (a[13] * b[15]); + out[11] = (a[10] * b[1]) + (a[11] * b[6]) + (a[12] * b[11]) + (a[13] * b[16]); + out[12] = (a[10] * b[2]) + (a[11] * b[7]) + (a[12] * b[12]) + (a[13] * b[17]); + out[13] = (a[10] * b[3]) + (a[11] * b[8]) + (a[12] * b[13]) + (a[13] * b[18]); + out[14] = (a[10] * b[4]) + (a[11] * b[9]) + (a[12] * b[14]) + (a[13] * b[19]); + + // Alpha Channel + out[15] = (a[15] * b[0]) + (a[16] * b[5]) + (a[17] * b[10]) + (a[18] * b[15]); + out[16] = (a[15] * b[1]) + (a[16] * b[6]) + (a[17] * b[11]) + (a[18] * b[16]); + out[17] = (a[15] * b[2]) + (a[16] * b[7]) + (a[17] * b[12]) + (a[18] * b[17]); + out[18] = (a[15] * b[3]) + (a[16] * b[8]) + (a[17] * b[13]) + (a[18] * b[18]); + out[19] = (a[15] * b[4]) + (a[16] * b[9]) + (a[17] * b[14]) + (a[18] * b[19]); + + return out; +}; + +/** + * Create a Float32 Array and normalize the offset component to 0-1 + * + * @param matrix {number[]} (mat 5x4) + * @return m {number[]} (mat 5x4) with all values between 0-1 + */ +ColorMatrixFilter.prototype._colorMatrix = function (matrix) +{ + // Create a Float32 Array and normalize the offset component to 0-1 + var m = new Float32Array(matrix); + m[4] /= 255; + m[9] /= 255; + m[14] /= 255; + m[19] /= 255; + + return m; +}; + +/** + * Adjusts brightness + * + * @param b {number} value of the brigthness (0 is black) + * @param multiply {boolean} refer to ._loadMatrix() method + */ +ColorMatrixFilter.prototype.brightness = function (b, multiply) +{ + var matrix = [ + b, 0, 0, 0, 0, + 0, b, 0, 0, 0, + 0, 0, b, 0, 0, + 0, 0, 0, 1, 0 + ]; + + this._loadMatrix(matrix, multiply); +}; + +/** + * Set the matrices in grey scales + * + * @param scale {number} value of the grey (0 is black) + * @param multiply {boolean} refer to ._loadMatrix() method + */ +ColorMatrixFilter.prototype.greyscale = function (scale, multiply) +{ + var matrix = [ + scale, scale, scale, 0, 0, + scale, scale, scale, 0, 0, + scale, scale, scale, 0, 0, + 0, 0, 0, 1, 0 + ]; + + this._loadMatrix(matrix, multiply); +}; +//Americanized alias +ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; + +/** + * Set the black and white matrice + * Multiply the current matrix + * + * @param multiply {boolean} refer to ._loadMatrix() method + */ +ColorMatrixFilter.prototype.blackAndWhite = function (multiply) +{ + var matrix = [ + 0.3, 0.6, 0.1, 0, 0, + 0.3, 0.6, 0.1, 0, 0, + 0.3, 0.6, 0.1, 0, 0, + 0, 0, 0, 1, 0 + ]; + + this._loadMatrix(matrix, multiply); +}; + +/** + * Set the hue property of the color + * + * @param rotation {number} in degrees + * @param multiply {boolean} refer to ._loadMatrix() method + */ +ColorMatrixFilter.prototype.hue = function (rotation, multiply) +{ + rotation = (rotation || 0) / 180 * Math.PI; + + var cosR = Math.cos(rotation), + sinR = Math.sin(rotation), + sqrt = Math.sqrt; + + /*a good approximation for hue rotation + This matrix is far better than the versions with magic luminance constants + formerly used here, but also used in the starling framework (flash) and known from this + old part of the internet: quasimondo.com/archives/000565.php + + This new matrix is based on rgb cube rotation in space. Look here for a more descriptive + implementation as a shader not a general matrix: + https://github.com/evanw/glfx.js/blob/58841c23919bd59787effc0333a4897b43835412/src/filters/adjust/huesaturation.js + + This is the source for the code: + see http://stackoverflow.com/questions/8507885/shift-hue-of-an-rgb-color/8510751#8510751 + */ + + var w = 1/3, sqrW = sqrt(w);//weight is + + var a00 = cosR + (1.0 - cosR) * w; + var a01 = w * (1.0 - cosR) - sqrW * sinR; + var a02 = w * (1.0 - cosR) + sqrW * sinR; + + var a10 = w * (1.0 - cosR) + sqrW * sinR; + var a11 = cosR + w*(1.0 - cosR); + var a12 = w * (1.0 - cosR) - sqrW * sinR; + + var a20 = w * (1.0 - cosR) - sqrW * sinR; + var a21 = w * (1.0 - cosR) + sqrW * sinR; + var a22 = cosR + w * (1.0 - cosR); + + + var matrix = [ + a00, a01, a02, 0, 0, + a10, a11, a12, 0, 0, + a20, a21, a22, 0, 0, + 0, 0, 0, 1, 0, + ]; + + this._loadMatrix(matrix, multiply); +}; + + +/** + * Set the contrast matrix, increase the separation between dark and bright + * Increase contrast : shadows darker and highlights brighter + * Decrease contrast : bring the shadows up and the highlights down + * + * @param amount {number} value of the contrast + * @param multiply {boolean} refer to ._loadMatrix() method + */ +ColorMatrixFilter.prototype.contrast = function (amount, multiply) +{ + var v = (amount || 0) + 1; + var o = -128 * (v - 1); + + var matrix = [ + v, 0, 0, 0, o, + 0, v, 0, 0, o, + 0, 0, v, 0, o, + 0, 0, 0, 1, 0 + ]; + + this._loadMatrix(matrix, multiply); +}; + +/** + * Set the saturation matrix, increase the separation between colors + * Increase saturation : increase contrast, brightness, and sharpness + * + * @param [amount=0] {number} + * @param [multiply] {boolean} refer to ._loadMatrix() method + */ +ColorMatrixFilter.prototype.saturate = function (amount, multiply) +{ + var x = (amount || 0) * 2 / 3 + 1; + var y = ((x - 1) * -0.5); + + var matrix = [ + x, y, y, 0, 0, + y, x, y, 0, 0, + y, y, x, 0, 0, + 0, 0, 0, 1, 0 + ]; + + this._loadMatrix(matrix, multiply); +}; + +/** + * Desaturate image (remove color) + * + * Call the saturate function + * + */ +ColorMatrixFilter.prototype.desaturate = function () // jshint unused:false +{ + this.saturate(-1); +}; + +/** + * Negative image (inverse of classic rgb matrix) + * + * @param multiply {boolean} refer to ._loadMatrix() method + */ +ColorMatrixFilter.prototype.negative = function (multiply) +{ + var matrix = [ + 0, 1, 1, 0, 0, + 1, 0, 1, 0, 0, + 1, 1, 0, 0, 0, + 0, 0, 0, 1, 0 + ]; + + this._loadMatrix(matrix, multiply); +}; + +/** + * Sepia image + * + * @param multiply {boolean} refer to ._loadMatrix() method + */ +ColorMatrixFilter.prototype.sepia = function (multiply) +{ + var matrix = [ + 0.393, 0.7689999, 0.18899999, 0, 0, + 0.349, 0.6859999, 0.16799999, 0, 0, + 0.272, 0.5339999, 0.13099999, 0, 0, + 0, 0, 0, 1, 0 + ]; + + this._loadMatrix(matrix, multiply); +}; + +/** + * Color motion picture process invented in 1916 (thanks Dominic Szablewski) + * + * @param multiply {boolean} refer to ._loadMatrix() method + */ +ColorMatrixFilter.prototype.technicolor = function (multiply) +{ + var matrix = [ + 1.9125277891456083, -0.8545344976951645, -0.09155508482755585, 0, 11.793603434377337, + -0.3087833385928097, 1.7658908555458428, -0.10601743074722245, 0, -70.35205161461398, + -0.231103377548616, -0.7501899197440212, 1.847597816108189, 0, 30.950940869491138, + 0, 0, 0, 1, 0 + ]; + + this._loadMatrix(matrix, multiply); +}; + +/** + * Polaroid filter + * + * @param multiply {boolean} refer to ._loadMatrix() method + */ +ColorMatrixFilter.prototype.polaroid = function (multiply) +{ + var matrix = [ + 1.438, -0.062, -0.062, 0, 0, + -0.122, 1.378, -0.122, 0, 0, + -0.016, -0.016, 1.483, 0, 0, + 0, 0, 0, 1, 0 + ]; + + this._loadMatrix(matrix, multiply); +}; + +/** + * Filter who transforms : Red -> Blue and Blue -> Red + * + * @param multiply {boolean} refer to ._loadMatrix() method + */ +ColorMatrixFilter.prototype.toBGR = function (multiply) +{ + var matrix = [ + 0, 0, 1, 0, 0, + 0, 1, 0, 0, 0, + 1, 0, 0, 0, 0, + 0, 0, 0, 1, 0 + ]; + + this._loadMatrix(matrix, multiply); +}; + +/** + * Color reversal film introduced by Eastman Kodak in 1935. (thanks Dominic Szablewski) + * + * @param multiply {boolean} refer to ._loadMatrix() method + */ +ColorMatrixFilter.prototype.kodachrome = function (multiply) +{ + var matrix = [ + 1.1285582396593525, -0.3967382283601348, -0.03992559172921793, 0, 63.72958762196502, + -0.16404339962244616, 1.0835251566291304, -0.05498805115633132, 0, 24.732407896706203, + -0.16786010706155763, -0.5603416277695248, 1.6014850761964943, 0, 35.62982807460946, + 0, 0, 0, 1, 0 + ]; + + this._loadMatrix(matrix, multiply); +}; + +/** + * Brown delicious browni filter (thanks Dominic Szablewski) + * + * @param multiply {boolean} refer to ._loadMatrix() method + */ +ColorMatrixFilter.prototype.browni = function (multiply) +{ + var matrix = [ + 0.5997023498159715, 0.34553243048391263, -0.2708298674538042, 0, 47.43192855600873, + -0.037703249837783157, 0.8609577587992641, 0.15059552388459913, 0, -36.96841498319127, + 0.24113635128153335, -0.07441037908422492, 0.44972182064877153, 0, -7.562075277591283, + 0, 0, 0, 1, 0 + ]; + + this._loadMatrix(matrix, multiply); +}; + +/* + * Vintage filter (thanks Dominic Szablewski) + * + * @param multiply {boolean} refer to ._loadMatrix() method + */ +ColorMatrixFilter.prototype.vintage = function (multiply) +{ + var matrix = [ + 0.6279345635605994, 0.3202183420819367, -0.03965408211312453, 0, 9.651285835294123, + 0.02578397704808868, 0.6441188644374771, 0.03259127616149294, 0, 7.462829176470591, + 0.0466055556782719, -0.0851232987247891, 0.5241648018700465, 0, 5.159190588235296, + 0, 0, 0, 1, 0 + ]; + + this._loadMatrix(matrix, multiply); +}; + +/* + * We don't know exactly what it does, kind of gradient map, but funny to play with! + * + * @param desaturation {number} + * @param toned {number} + * @param lightColor {string} (example : "0xFFE580") + * @param darkColor {string} (example : "0xFFE580") + * + * @param multiply {boolean} refer to ._loadMatrix() method + */ +ColorMatrixFilter.prototype.colorTone = function (desaturation, toned, lightColor, darkColor, multiply) +{ + desaturation = desaturation || 0.2; + toned = toned || 0.15; + lightColor = lightColor || 0xFFE580; + darkColor = darkColor || 0x338000; + + var lR = ((lightColor >> 16) & 0xFF) / 255; + var lG = ((lightColor >> 8) & 0xFF) / 255; + var lB = (lightColor & 0xFF) / 255; + + var dR = ((darkColor >> 16) & 0xFF) / 255; + var dG = ((darkColor >> 8) & 0xFF) / 255; + var dB = (darkColor & 0xFF) / 255; + + var matrix = [ + 0.3, 0.59, 0.11, 0, 0, + lR, lG, lB, desaturation, 0, + dR, dG, dB, toned, 0, + lR - dR, lG - dG, lB - dB, 0, 0 + ]; + + this._loadMatrix(matrix, multiply); +}; + +/* + * Night effect + * + * @param intensity {number} + * @param multiply {boolean} refer to ._loadMatrix() method + */ +ColorMatrixFilter.prototype.night = function (intensity, multiply) +{ + intensity = intensity || 0.1; + var matrix = [ + intensity * ( -2.0), -intensity, 0, 0, 0, + -intensity, 0, intensity, 0, 0, + 0, intensity, intensity * 2.0, 0, 0, + 0, 0, 0, 1, 0 + ]; + + this._loadMatrix(matrix, multiply); +}; + + +/* + * Predator effect + * + * Erase the current matrix by setting a new indepent one + * + * @param amount {number} how much the predator feels his future victim + * @param multiply {boolean} refer to ._loadMatrix() method + */ +ColorMatrixFilter.prototype.predator = function (amount, multiply) +{ + var matrix = [ + 11.224130630493164 * amount, -4.794486999511719 * amount, -2.8746118545532227 * amount, 0 * amount, 0.40342438220977783 * amount, + -3.6330697536468506 * amount, 9.193157196044922 * amount, -2.951810836791992 * amount, 0 * amount, -1.316135048866272 * amount, + -3.2184197902679443 * amount, -4.2375030517578125 * amount, 7.476448059082031 * amount, 0 * amount, 0.8044459223747253 * amount, + 0, 0, 0, 1, 0 + ]; + + this._loadMatrix(matrix, multiply); +}; + +/* + * LSD effect + * + * Multiply the current matrix + * + * @param amount {number} How crazy is your effect + * @param multiply {boolean} refer to ._loadMatrix() method + */ +ColorMatrixFilter.prototype.lsd = function (multiply) +{ + var matrix = [ + 2, -0.4, 0.5, 0, 0, + -0.5, 2, -0.4, 0, 0, + -0.4, -0.5, 3, 0, 0, + 0, 0, 0, 1, 0 + ]; + + this._loadMatrix(matrix, multiply); +}; + +/* + * Erase the current matrix by setting the default one + * + */ +ColorMatrixFilter.prototype.reset = function () +{ + var matrix = [ + 1, 0, 0, 0, 0, + 0, 1, 0, 0, 0, + 0, 0, 1, 0, 0, + 0, 0, 0, 1, 0 + ]; + + this._loadMatrix(matrix, false); +}; + + +Object.defineProperties(ColorMatrixFilter.prototype, { + /** + * Sets the matrix of the color matrix filter + * + * @member {number[]} + * @memberof PIXI.filters.ColorMatrixFilter# + * @default [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0] + */ + matrix: { + get: function () + { + return this.uniforms.m; + }, + set: function (value) + { + this.uniforms.m = value; + } + } +}); - if (!tempAnchor) { - tempAnchor = document.createElement('a'); - } +},{"../../core":61}],137:[function(require,module,exports){ +var core = require('../../core'); + + +/** + * The DisplacementFilter class uses the pixel values from the specified texture (called the displacement map) to perform a displacement of an object. + * You can use this filter to apply all manor of crazy warping effects + * Currently the r property of the texture is used to offset the x and the g property of the texture is used to offset the y. + * + * @class + * @extends PIXI.Filter + * @memberof PIXI.filters + * @param sprite {PIXI.Sprite} The sprite used for the displacement map. (make sure its added to the scene!) + * @param scale {number} The scale of the displacement + */ +function DisplacementFilter(sprite, scale) +{ + var maskMatrix = new core.Matrix(); + sprite.renderable = false; + + core.Filter.call(this, + // vertex shader +// glslify('./displacement.vert'), + "#define GLSLIFY 1\nattribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\n\nuniform mat3 projectionMatrix;\nuniform mat3 filterMatrix;\n\nvarying vec2 vTextureCoord;\nvarying vec2 vFilterCoord;\n\nvoid main(void)\n{\n gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\n vFilterCoord = ( filterMatrix * vec3( aTextureCoord, 1.0) ).xy;\n vTextureCoord = aTextureCoord;\n}", + // fragment shader + "#define GLSLIFY 1\nvarying vec2 vFilterCoord;\nvarying vec2 vTextureCoord;\n\nuniform vec2 scale;\n\nuniform sampler2D uSampler;\nuniform sampler2D mapSampler;\n\nuniform vec4 filterClamp;\n\nvoid main(void)\n{\n vec4 map = texture2D(mapSampler, vFilterCoord);\n\n map -= 0.5;\n map.xy *= scale;\n\n gl_FragColor = texture2D(uSampler, clamp(vec2(vTextureCoord.x + map.x, vTextureCoord.y + map.y), filterClamp.xy, filterClamp.zw));\n}\n" + + ); + + this.maskSprite = sprite; + this.maskMatrix = maskMatrix; + + this.uniforms.mapSampler = sprite.texture; + this.uniforms.filterMatrix = maskMatrix.toArray(true); + this.uniforms.scale = { x: 1, y: 1 }; + + if (scale === null || scale === undefined) + { + scale = 20; + } + + this.scale = new core.Point(scale, scale); +} + +DisplacementFilter.prototype = Object.create(core.Filter.prototype); +DisplacementFilter.prototype.constructor = DisplacementFilter; +module.exports = DisplacementFilter; + +DisplacementFilter.prototype.apply = function (filterManager, input, output) +{ + var ratio = (1/output.destinationFrame.width) * (output.size.width/input.size.width); /// // * 2 //4//this.strength / 4 / this.passes * (input.frame.width / input.size.width); + + this.uniforms.filterMatrix = filterManager.calculateSpriteMatrix(this.maskMatrix, this.maskSprite); + this.uniforms.scale.x = this.scale.x * ratio; + this.uniforms.scale.y = this.scale.y * ratio; + + // draw the filter... + filterManager.applyFilter(this, input, output); +}; + + +Object.defineProperties(DisplacementFilter.prototype, { + /** + * The texture used for the displacement map. Must be power of 2 sized texture. + * + * @member {PIXI.Texture} + * @memberof PIXI.filters.DisplacementFilter# + */ + map: { + get: function () + { + return this.uniforms.mapSampler; + }, + set: function (value) + { + this.uniforms.mapSampler = value; + + } + } +}); - // let the browser determine the full href for the url of this resource and then - // parse with the node url lib, we can't use the properties of the anchor element - // because they don't work in IE9 :( - tempAnchor.href = url; - url = _url.parse(tempAnchor.href); +},{"../../core":61}],138:[function(require,module,exports){ +var core = require('../../core'); + + +/** + * + * Basic FXAA implementation based on the code on geeks3d.com with the + * modification that the texture2DLod stuff was removed since it's + * unsupported by WebGL. + * + * @see https://github.com/mitsuhiko/webgl-meincraft + * + * @class + * @extends PIXI.Filter + * @memberof PIXI + * + */ +function FXAAFilter() +{ + //TODO - needs work + core.Filter.call(this, + + // vertex shader + "#define GLSLIFY 1\nattribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\n\nuniform mat3 projectionMatrix;\n\nvarying vec2 v_rgbNW;\nvarying vec2 v_rgbNE;\nvarying vec2 v_rgbSW;\nvarying vec2 v_rgbSE;\nvarying vec2 v_rgbM;\n\nuniform vec4 filterArea;\n\nvarying vec2 vTextureCoord;\n\nvec2 mapCoord( vec2 coord )\n{\n coord *= filterArea.xy;\n coord += filterArea.zw;\n\n return coord;\n}\n\nvec2 unmapCoord( vec2 coord )\n{\n coord -= filterArea.zw;\n coord /= filterArea.xy;\n\n return coord;\n}\n\nvoid texcoords(vec2 fragCoord, vec2 resolution,\n out vec2 v_rgbNW, out vec2 v_rgbNE,\n out vec2 v_rgbSW, out vec2 v_rgbSE,\n out vec2 v_rgbM) {\n vec2 inverseVP = 1.0 / resolution.xy;\n v_rgbNW = (fragCoord + vec2(-1.0, -1.0)) * inverseVP;\n v_rgbNE = (fragCoord + vec2(1.0, -1.0)) * inverseVP;\n v_rgbSW = (fragCoord + vec2(-1.0, 1.0)) * inverseVP;\n v_rgbSE = (fragCoord + vec2(1.0, 1.0)) * inverseVP;\n v_rgbM = vec2(fragCoord * inverseVP);\n}\n\nvoid main(void) {\n\n gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\n\n vTextureCoord = aTextureCoord;\n\n vec2 fragCoord = vTextureCoord * filterArea.xy;\n\n texcoords(fragCoord, filterArea.xy, v_rgbNW, v_rgbNE, v_rgbSW, v_rgbSE, v_rgbM);\n}", + // fragment shader + "#define GLSLIFY 1\nvarying vec2 v_rgbNW;\nvarying vec2 v_rgbNE;\nvarying vec2 v_rgbSW;\nvarying vec2 v_rgbSE;\nvarying vec2 v_rgbM;\n\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\nuniform vec4 filterArea;\n\n/**\n Basic FXAA implementation based on the code on geeks3d.com with the\n modification that the texture2DLod stuff was removed since it's\n unsupported by WebGL.\n \n --\n \n From:\n https://github.com/mitsuhiko/webgl-meincraft\n \n Copyright (c) 2011 by Armin Ronacher.\n \n Some rights reserved.\n \n Redistribution and use in source and binary forms, with or without\n modification, are permitted provided that the following conditions are\n met:\n \n * Redistributions of source code must retain the above copyright\n notice, this list of conditions and the following disclaimer.\n \n * Redistributions in binary form must reproduce the above\n copyright notice, this list of conditions and the following\n disclaimer in the documentation and/or other materials provided\n with the distribution.\n \n * The names of the contributors may not be used to endorse or\n promote products derived from this software without specific\n prior written permission.\n \n THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n */\n\n#ifndef FXAA_REDUCE_MIN\n#define FXAA_REDUCE_MIN (1.0/ 128.0)\n#endif\n#ifndef FXAA_REDUCE_MUL\n#define FXAA_REDUCE_MUL (1.0 / 8.0)\n#endif\n#ifndef FXAA_SPAN_MAX\n#define FXAA_SPAN_MAX 8.0\n#endif\n\n//optimized version for mobile, where dependent\n//texture reads can be a bottleneck\nvec4 fxaa(sampler2D tex, vec2 fragCoord, vec2 resolution,\n vec2 v_rgbNW, vec2 v_rgbNE,\n vec2 v_rgbSW, vec2 v_rgbSE,\n vec2 v_rgbM) {\n vec4 color;\n mediump vec2 inverseVP = vec2(1.0 / resolution.x, 1.0 / resolution.y);\n vec3 rgbNW = texture2D(tex, v_rgbNW).xyz;\n vec3 rgbNE = texture2D(tex, v_rgbNE).xyz;\n vec3 rgbSW = texture2D(tex, v_rgbSW).xyz;\n vec3 rgbSE = texture2D(tex, v_rgbSE).xyz;\n vec4 texColor = texture2D(tex, v_rgbM);\n vec3 rgbM = texColor.xyz;\n vec3 luma = vec3(0.299, 0.587, 0.114);\n float lumaNW = dot(rgbNW, luma);\n float lumaNE = dot(rgbNE, luma);\n float lumaSW = dot(rgbSW, luma);\n float lumaSE = dot(rgbSE, luma);\n float lumaM = dot(rgbM, luma);\n float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));\n float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));\n \n mediump vec2 dir;\n dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));\n dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));\n \n float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) *\n (0.25 * FXAA_REDUCE_MUL), FXAA_REDUCE_MIN);\n \n float rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);\n dir = min(vec2(FXAA_SPAN_MAX, FXAA_SPAN_MAX),\n max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX),\n dir * rcpDirMin)) * inverseVP;\n \n vec3 rgbA = 0.5 * (\n texture2D(tex, fragCoord * inverseVP + dir * (1.0 / 3.0 - 0.5)).xyz +\n texture2D(tex, fragCoord * inverseVP + dir * (2.0 / 3.0 - 0.5)).xyz);\n vec3 rgbB = rgbA * 0.5 + 0.25 * (\n texture2D(tex, fragCoord * inverseVP + dir * -0.5).xyz +\n texture2D(tex, fragCoord * inverseVP + dir * 0.5).xyz);\n \n float lumaB = dot(rgbB, luma);\n if ((lumaB < lumaMin) || (lumaB > lumaMax))\n color = vec4(rgbA, texColor.a);\n else\n color = vec4(rgbB, texColor.a);\n return color;\n}\n\nvoid main() {\n\n \tvec2 fragCoord = vTextureCoord * filterArea.xy;\n\n \tvec4 color;\n\n color = fxaa(uSampler, fragCoord, filterArea.xy, v_rgbNW, v_rgbNE, v_rgbSW, v_rgbSE, v_rgbM);\n\n \tgl_FragColor = color;\n}\n" + ); + +} + +FXAAFilter.prototype = Object.create(core.Filter.prototype); +FXAAFilter.prototype.constructor = FXAAFilter; + +module.exports = FXAAFilter; - var samePort = (!url.port && loc.port === '') || (url.port === loc.port); +},{"../../core":61}],139:[function(require,module,exports){ +/** + * @file Main export of the PIXI filters library + * @author Mat Groves + * @copyright 2013-2015 GoodBoyDigital + * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} + */ + +/** + * @namespace PIXI.filters + */ +module.exports = { + FXAAFilter: require('./fxaa/FXAAFilter'), + NoiseFilter: require('./noise/NoiseFilter'), + DisplacementFilter: require('./displacement/DisplacementFilter'), + BlurFilter: require('./blur/BlurFilter'), + BlurXFilter: require('./blur/BlurXFilter'), + BlurYFilter: require('./blur/BlurYFilter'), + ColorMatrixFilter: require('./colormatrix/ColorMatrixFilter'), + VoidFilter: require('./void/VoidFilter') +}; - // if cross origin - if (url.hostname !== loc.hostname || !samePort || url.protocol !== loc.protocol) { - return 'anonymous'; - } +},{"./blur/BlurFilter":130,"./blur/BlurXFilter":131,"./blur/BlurYFilter":132,"./colormatrix/ColorMatrixFilter":136,"./displacement/DisplacementFilter":137,"./fxaa/FXAAFilter":138,"./noise/NoiseFilter":140,"./void/VoidFilter":141}],140:[function(require,module,exports){ +var core = require('../../core'); + + +/** + * @author Vico @vicocotea + * original filter: https://github.com/evanw/glfx.js/blob/master/src/filters/adjust/noise.js + */ + +/** + * A Noise effect filter. + * + * @class + * @extends PIXI.Filter + * @memberof PIXI.filters + */ +function NoiseFilter() +{ + core.Filter.call(this, + // vertex shader + "#define GLSLIFY 1\nattribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\n\nuniform mat3 projectionMatrix;\n\nvarying vec2 vTextureCoord;\n\nvoid main(void)\n{\n gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}", + // fragment shader + "precision highp float;\n#define GLSLIFY 1\n\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\n\nuniform float noise;\nuniform sampler2D uSampler;\n\nfloat rand(vec2 co)\n{\n return fract(sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453);\n}\n\nvoid main()\n{\n vec4 color = texture2D(uSampler, vTextureCoord);\n\n float diff = (rand(gl_FragCoord.xy) - 0.5) * noise;\n\n color.r += diff;\n color.g += diff;\n color.b += diff;\n\n gl_FragColor = color;\n}\n" + ); + + this.noise = 0.5; +} + +NoiseFilter.prototype = Object.create(core.Filter.prototype); +NoiseFilter.prototype.constructor = NoiseFilter; +module.exports = NoiseFilter; + +Object.defineProperties(NoiseFilter.prototype, { + /** + * The amount of noise to apply. + * + * @member {number} + * @memberof PIXI.filters.NoiseFilter# + * @default 0.5 + */ + noise: { + get: function () + { + return this.uniforms.noise; + }, + set: function (value) + { + this.uniforms.noise = value; + } + } +}); - return ''; -}; +},{"../../core":61}],141:[function(require,module,exports){ +var core = require('../../core'); +// @see https://github.com/substack/brfs/issues/25 + + +/** + * Does nothing. Very handy. + * + * @class + * @extends PIXI.Filter + * @memberof PIXI.filters + */ +function VoidFilter() +{ + core.Filter.call(this, + // vertex shader + "#define GLSLIFY 1\nattribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\n\nuniform mat3 projectionMatrix;\n\nvarying vec2 vTextureCoord;\n\nvoid main(void)\n{\n gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}", + // fragment shader + "#define GLSLIFY 1\nvarying vec2 vTextureCoord;\n\nuniform sampler2D uSampler;\n\nvoid main(void)\n{\n gl_FragColor = texture2D(uSampler, vTextureCoord);\n}\n" + ); + + this.glShaderKey = 'void'; +} + +VoidFilter.prototype = Object.create(core.Filter.prototype); +VoidFilter.prototype.constructor = VoidFilter; +module.exports = VoidFilter; -/** - * Determines the responseType of an XHR request based on the extension of the - * resource being loaded. - * - * @private - * @return {Resource.XHR_RESPONSE_TYPE} The responseType to use. - */ -Resource.prototype._determineXhrType = function () { - return Resource._xhrTypeMap[this._getExtension()] || Resource.XHR_RESPONSE_TYPE.TEXT; -}; +},{"../../core":61}],142:[function(require,module,exports){ +var core = require('../core'); + +/** + * Holds all information related to an Interaction event + * + * @class + * @memberof PIXI.interaction + */ +function InteractionData() +{ + /** + * This point stores the global coords of where the touch/mouse event happened + * + * @member {PIXI.Point} + */ + this.global = new core.Point(); + + /** + * The target Sprite that was interacted with + * + * @member {PIXI.Sprite} + */ + this.target = null; + + /** + * When passed to an event handler, this will be the original DOM Event that was captured + * + * @member {Event} + */ + this.originalEvent = null; +} + +InteractionData.prototype.constructor = InteractionData; +module.exports = InteractionData; + +/** + * This will return the local coordinates of the specified displayObject for this InteractionData + * + * @param displayObject {PIXI.DisplayObject} The DisplayObject that you would like the local coords off + * @param [point] {PIXI.Point} A Point object in which to store the value, optional (otherwise will create a new point) + * @param [globalPos] {PIXI.Point} A Point object containing your custom global coords, optional (otherwise will use the current global coords) + * @return {PIXI.Point} A point containing the coordinates of the InteractionData position relative to the DisplayObject + */ +InteractionData.prototype.getLocalPosition = function (displayObject, point, globalPos) +{ + return displayObject.worldTransform.applyInverse(globalPos || this.global, point); +}; -Resource.prototype._determineLoadType = function () { - return Resource._loadTypeMap[this._getExtension()] || Resource.LOAD_TYPE.XHR; -}; +},{"../core":61}],143:[function(require,module,exports){ +var core = require('../core'), + InteractionData = require('./InteractionData'), + EventEmitter = require('eventemitter3'); + +// Mix interactiveTarget into core.DisplayObject.prototype +Object.assign( + core.DisplayObject.prototype, + require('./interactiveTarget') +); + +/** + * The interaction manager deals with mouse and touch events. Any DisplayObject can be interactive + * if its interactive parameter is set to true + * This manager also supports multitouch. + * + * @class + * @extends EventEmitter + * @memberof PIXI.interaction + * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer + * @param [options] {object} + * @param [options.autoPreventDefault=true] {boolean} Should the manager automatically prevent default browser actions. + * @param [options.interactionFrequency=10] {number} Frequency increases the interaction events will be checked. + */ +function InteractionManager(renderer, options) +{ + EventEmitter.call(this); + + options = options || {}; + + /** + * The renderer this interaction manager works for. + * + * @member {PIXI.SystemRenderer} + */ + this.renderer = renderer; + + /** + * Should default browser actions automatically be prevented. + * + * @member {boolean} + * @default true + */ + this.autoPreventDefault = options.autoPreventDefault !== undefined ? options.autoPreventDefault : true; + + /** + * As this frequency increases the interaction events will be checked more often. + * + * @member {number} + * @default 10 + */ + this.interactionFrequency = options.interactionFrequency || 10; + + /** + * The mouse data + * + * @member {PIXI.interaction.InteractionData} + */ + this.mouse = new InteractionData(); + + // setting the pointer to start off far off screen will mean that mouse over does + // not get called before we even move the mouse. + this.mouse.global.set(-999999); + + /** + * An event data object to handle all the event tracking/dispatching + * + * @member {object} + */ + this.eventData = { + stopped: false, + target: null, + type: null, + data: this.mouse, + stopPropagation:function(){ + this.stopped = true; + } + }; + + /** + * Tiny little interactiveData pool ! + * + * @member {PIXI.interaction.InteractionData[]} + */ + this.interactiveDataPool = []; + + /** + * The DOM element to bind to. + * + * @member {HTMLElement} + * @private + */ + this.interactionDOMElement = null; + + /** + * This property determins if mousemove and touchmove events are fired only when the cursror is over the object + * Setting to true will make things work more in line with how the DOM verison works. + * Setting to false can make things easier for things like dragging + * It is currently set to false as this is how pixi used to work. This will be set to true in future versions of pixi. + * @member {boolean} + * @private + */ + this.moveWhenInside = false; + + /** + * Have events been attached to the dom element? + * + * @member {boolean} + * @private + */ + this.eventsAdded = false; + + //this will make it so that you don't have to call bind all the time + + /** + * @member {Function} + * @private + */ + this.onMouseUp = this.onMouseUp.bind(this); + this.processMouseUp = this.processMouseUp.bind( this ); + + + /** + * @member {Function} + * @private + */ + this.onMouseDown = this.onMouseDown.bind(this); + this.processMouseDown = this.processMouseDown.bind( this ); + + /** + * @member {Function} + * @private + */ + this.onMouseMove = this.onMouseMove.bind( this ); + this.processMouseMove = this.processMouseMove.bind( this ); + + /** + * @member {Function} + * @private + */ + this.onMouseOut = this.onMouseOut.bind(this); + this.processMouseOverOut = this.processMouseOverOut.bind( this ); + + /** + * @member {Function} + * @private + */ + this.onMouseOver = this.onMouseOver.bind(this); + + + /** + * @member {Function} + * @private + */ + this.onTouchStart = this.onTouchStart.bind(this); + this.processTouchStart = this.processTouchStart.bind(this); + + /** + * @member {Function} + * @private + */ + this.onTouchEnd = this.onTouchEnd.bind(this); + this.processTouchEnd = this.processTouchEnd.bind(this); + + /** + * @member {Function} + * @private + */ + this.onTouchMove = this.onTouchMove.bind(this); + this.processTouchMove = this.processTouchMove.bind(this); + + /** + * Every update cursor will be reset to this value, if some element wont override it in its hitTest + * @member {string} + * @default 'inherit' + */ + this.defaultCursorStyle = 'inherit'; + + /** + * The css style of the cursor that is being used + * @member {string} + */ + this.currentCursorStyle = 'inherit'; + + /** + * Internal cached var + * @member {PIXI.Point} + * @private + */ + this._tempPoint = new core.Point(); + + + /** + * The current resolution / device pixel ratio. + * @member {number} + * @default 1 + */ + this.resolution = 1; + + this.setTargetElement(this.renderer.view, this.renderer.resolution); +} + +InteractionManager.prototype = Object.create(EventEmitter.prototype); +InteractionManager.prototype.constructor = InteractionManager; +module.exports = InteractionManager; + +/** + * Sets the DOM element which will receive mouse/touch events. This is useful for when you have + * other DOM elements on top of the renderers Canvas element. With this you'll be bale to deletegate + * another DOM element to receive those events. + * + * @param element {HTMLElement} the DOM element which will receive mouse and touch events. + * @param [resolution=1] {number} The resolution / device pixel ratio of the new element (relative to the canvas). + * @private + */ +InteractionManager.prototype.setTargetElement = function (element, resolution) +{ + this.removeEvents(); + + this.interactionDOMElement = element; + + this.resolution = resolution || 1; + + this.addEvents(); +}; + +/** + * Registers all the DOM events + * + * @private + */ +InteractionManager.prototype.addEvents = function () +{ + if (!this.interactionDOMElement) + { + return; + } + + core.ticker.shared.add(this.update, this); + + if (window.navigator.msPointerEnabled) + { + this.interactionDOMElement.style['-ms-content-zooming'] = 'none'; + this.interactionDOMElement.style['-ms-touch-action'] = 'none'; + } + + window.document.addEventListener('mousemove', this.onMouseMove, true); + this.interactionDOMElement.addEventListener('mousedown', this.onMouseDown, true); + this.interactionDOMElement.addEventListener('mouseout', this.onMouseOut, true); + this.interactionDOMElement.addEventListener('mouseover', this.onMouseOver, true); + + this.interactionDOMElement.addEventListener('touchstart', this.onTouchStart, true); + this.interactionDOMElement.addEventListener('touchend', this.onTouchEnd, true); + this.interactionDOMElement.addEventListener('touchmove', this.onTouchMove, true); + + window.addEventListener('mouseup', this.onMouseUp, true); + + this.eventsAdded = true; +}; + +/** + * Removes all the DOM events that were previously registered + * + * @private + */ +InteractionManager.prototype.removeEvents = function () +{ + if (!this.interactionDOMElement) + { + return; + } + + core.ticker.shared.remove(this.update); + + if (window.navigator.msPointerEnabled) + { + this.interactionDOMElement.style['-ms-content-zooming'] = ''; + this.interactionDOMElement.style['-ms-touch-action'] = ''; + } + + window.document.removeEventListener('mousemove', this.onMouseMove, true); + this.interactionDOMElement.removeEventListener('mousedown', this.onMouseDown, true); + this.interactionDOMElement.removeEventListener('mouseout', this.onMouseOut, true); + this.interactionDOMElement.removeEventListener('mouseover', this.onMouseOver, true); + + this.interactionDOMElement.removeEventListener('touchstart', this.onTouchStart, true); + this.interactionDOMElement.removeEventListener('touchend', this.onTouchEnd, true); + this.interactionDOMElement.removeEventListener('touchmove', this.onTouchMove, true); + + this.interactionDOMElement = null; + + window.removeEventListener('mouseup', this.onMouseUp, true); + + this.eventsAdded = false; +}; + +/** + * Updates the state of interactive objects. + * Invoked by a throttled ticker update from + * {@link PIXI.ticker.shared}. + * + * @param deltaTime {number} time delta since last tick + */ +InteractionManager.prototype.update = function (deltaTime) +{ + this._deltaTime += deltaTime; + + if (this._deltaTime < this.interactionFrequency) + { + return; + } + + this._deltaTime = 0; + + if (!this.interactionDOMElement) + { + return; + } + + // if the user move the mouse this check has already been dfone using the mouse move! + if(this.didMove) + { + this.didMove = false; + return; + } + + this.cursor = this.defaultCursorStyle; + + this.processInteractive(this.mouse.global, this.renderer._lastObjectRendered, this.processMouseOverOut, true ); + + if (this.currentCursorStyle !== this.cursor) + { + this.currentCursorStyle = this.cursor; + this.interactionDOMElement.style.cursor = this.cursor; + } + + //TODO +}; + +/** + * Dispatches an event on the display object that was interacted with + * + * @param displayObject {PIXI.Container|PIXI.Sprite|PIXI.extras.TilingSprite} the display object in question + * @param eventString {string} the name of the event (e.g, mousedown) + * @param eventData {object} the event data object + * @private + */ +InteractionManager.prototype.dispatchEvent = function ( displayObject, eventString, eventData ) +{ + if(!eventData.stopped) + { + eventData.target = displayObject; + eventData.type = eventString; + + displayObject.emit( eventString, eventData ); + + if( displayObject[eventString] ) + { + displayObject[eventString]( eventData ); + } + } +}; + +/** + * Maps x and y coords from a DOM object and maps them correctly to the pixi view. The resulting value is stored in the point. + * This takes into account the fact that the DOM element could be scaled and positioned anywhere on the screen. + * + * @param {PIXI.Point} point the point that the result will be stored in + * @param {number} x the x coord of the position to map + * @param {number} y the y coord of the position to map + */ +InteractionManager.prototype.mapPositionToPoint = function ( point, x, y ) +{ + var rect; + // IE 11 fix + if(!this.interactionDOMElement.parentElement) + { + rect = { x: 0, y: 0, width: 0, height: 0 }; + } else { + rect = this.interactionDOMElement.getBoundingClientRect(); + } + + point.x = ( ( x - rect.left ) * (this.interactionDOMElement.width / rect.width ) ) / this.resolution; + point.y = ( ( y - rect.top ) * (this.interactionDOMElement.height / rect.height ) ) / this.resolution; +}; + +/** + * This function is provides a neat way of crawling through the scene graph and running a specified function on all interactive objects it finds. + * It will also take care of hit testing the interactive objects and passes the hit across in the function. + * + * @param point {PIXI.Point} the point that is tested for collision + * @param displayObject {PIXI.Container|PIXI.Sprite|PIXI.extras.TilingSprite} the displayObject that will be hit test (recurcsivly crawls its children) + * @param [func] {Function} the function that will be called on each interactive object. The displayObject and hit will be passed to the function + * @param [hitTest] {boolean} this indicates if the objects inside should be hit test against the point + * @param [interactive] {boolean} Whether the displayObject is interactive + * @return {boolean} returns true if the displayObject hit the point + */ +InteractionManager.prototype.processInteractive = function (point, displayObject, func, hitTest, interactive) +{ + if(!displayObject || !displayObject.visible) + { + return false; + } + + // Took a little while to rework this function correctly! But now it is done and nice and optimised. ^_^ + // + // This function will now loop through all objects and then only hit test the objects it HAS to, not all of them. MUCH faster.. + // An object will be hit test if the following is true: + // + // 1: It is interactive. + // 2: It belongs to a parent that is interactive AND one of the parents children have not already been hit. + // + // As another little optimisation once an interactive object has been hit we can carry on through the scenegraph, but we know that there will be no more hits! So we can avoid extra hit tests + // A final optimisation is that an object is not hit test directly if a child has already been hit. + + var hit = false, + interactiveParent = interactive = displayObject.interactive || interactive; + + + + + // if the displayobject has a hitArea, then it does not need to hitTest children. + if(displayObject.hitArea) + { + interactiveParent = false; + } + + // it has a mask! Then lets hit test that before continuing.. + if(hitTest && displayObject._mask) + { + if(!displayObject._mask.containsPoint(point)) + { + hitTest = false; + } + } + + // it has a filterArea! Same as mask but easier, its a rectangle + if(hitTest && displayObject.filterArea) + { + if(!displayObject.filterArea.contains(point.x, point.y)) + { + hitTest = false; + } + } + + // ** FREE TIP **! If an object is not interactive or has no buttons in it (such as a game scene!) set interactiveChildren to false for that displayObject. + // This will allow pixi to completly ignore and bypass checking the displayObjects children. + if(displayObject.interactiveChildren) + { + var children = displayObject.children; + + for (var i = children.length-1; i >= 0; i--) + { + var child = children[i]; + + // time to get recursive.. if this function will return if somthing is hit.. + if(this.processInteractive(point, child, func, hitTest, interactiveParent)) + { + // its a good idea to check if a child has lost its parent. + // this means it has been removed whilst looping so its best + if(!child.parent) + { + continue; + } + + hit = true; + + // we no longer need to hit test any more objects in this container as we we now know the parent has been hit + interactiveParent = false; + + // If the child is interactive , that means that the object hit was actually interactive and not just the child of an interactive object. + // This means we no longer need to hit test anything else. We still need to run through all objects, but we don't need to perform any hit tests. + + //{ + hitTest = false; + //} + + // we can break now as we have hit an object. + } + } + } + + + + // no point running this if the item is not interactive or does not have an interactive parent. + if(interactive) + { + // if we are hit testing (as in we have no hit any objects yet) + // We also don't need to worry about hit testing if once of the displayObjects children has already been hit! + if(hitTest && !hit) + { + + if(displayObject.hitArea) + { + displayObject.worldTransform.applyInverse(point, this._tempPoint); + hit = displayObject.hitArea.contains( this._tempPoint.x, this._tempPoint.y ); + } + else if(displayObject.containsPoint) + { + hit = displayObject.containsPoint(point); + } + + + } + + if(displayObject.interactive) + { + func(displayObject, hit); + } + } + + return hit; + +}; + + +/** + * Is called when the mouse button is pressed down on the renderer element + * + * @param event {Event} The DOM event of a mouse button being pressed down + * @private + */ +InteractionManager.prototype.onMouseDown = function (event) +{ + this.mouse.originalEvent = event; + this.eventData.data = this.mouse; + this.eventData.stopped = false; + + // Update internal mouse reference + this.mapPositionToPoint( this.mouse.global, event.clientX, event.clientY); + + if (this.autoPreventDefault) + { + this.mouse.originalEvent.preventDefault(); + } + + this.processInteractive(this.mouse.global, this.renderer._lastObjectRendered, this.processMouseDown, true ); + + var isRightButton = event.button === 2 || event.which === 3; + this.emit(isRightButton ? 'rightdown' : 'mousedown', this.eventData); +}; + +/** + * Processes the result of the mouse down check and dispatches the event if need be + * + * @param displayObject {PIXI.Container|PIXI.Sprite|PIXI.extras.TilingSprite} The display object that was tested + * @param hit {boolean} the result of the hit test on the dispay object + * @private + */ +InteractionManager.prototype.processMouseDown = function ( displayObject, hit ) +{ + var e = this.mouse.originalEvent; + + var isRightButton = e.button === 2 || e.which === 3; + + if(hit) + { + displayObject[ isRightButton ? '_isRightDown' : '_isLeftDown' ] = true; + this.dispatchEvent( displayObject, isRightButton ? 'rightdown' : 'mousedown', this.eventData ); + } +}; + + + + +/** + * Is called when the mouse button is released on the renderer element + * + * @param event {Event} The DOM event of a mouse button being released + * @private + */ +InteractionManager.prototype.onMouseUp = function (event) +{ + this.mouse.originalEvent = event; + this.eventData.data = this.mouse; + this.eventData.stopped = false; + + // Update internal mouse reference + this.mapPositionToPoint( this.mouse.global, event.clientX, event.clientY); + + this.processInteractive(this.mouse.global, this.renderer._lastObjectRendered, this.processMouseUp, true ); + + var isRightButton = event.button === 2 || event.which === 3; + this.emit(isRightButton ? 'rightup' : 'mouseup', this.eventData); +}; + +/** + * Processes the result of the mouse up check and dispatches the event if need be + * + * @param displayObject {PIXI.Container|PIXI.Sprite|PIXI.extras.TilingSprite} The display object that was tested + * @param hit {boolean} the result of the hit test on the display object + * @private + */ +InteractionManager.prototype.processMouseUp = function ( displayObject, hit ) +{ + var e = this.mouse.originalEvent; + + var isRightButton = e.button === 2 || e.which === 3; + var isDown = isRightButton ? '_isRightDown' : '_isLeftDown'; + + if(hit) + { + this.dispatchEvent( displayObject, isRightButton ? 'rightup' : 'mouseup', this.eventData ); + + if( displayObject[ isDown ] ) + { + displayObject[ isDown ] = false; + this.dispatchEvent( displayObject, isRightButton ? 'rightclick' : 'click', this.eventData ); + } + } + else + { + if( displayObject[ isDown ] ) + { + displayObject[ isDown ] = false; + this.dispatchEvent( displayObject, isRightButton ? 'rightupoutside' : 'mouseupoutside', this.eventData ); + } + } +}; + + +/** + * Is called when the mouse moves across the renderer element + * + * @param event {Event} The DOM event of the mouse moving + * @private + */ +InteractionManager.prototype.onMouseMove = function (event) +{ + this.mouse.originalEvent = event; + this.eventData.data = this.mouse; + this.eventData.stopped = false; + + this.mapPositionToPoint( this.mouse.global, event.clientX, event.clientY); + + this.didMove = true; + + this.cursor = this.defaultCursorStyle; + + this.processInteractive(this.mouse.global, this.renderer._lastObjectRendered, this.processMouseMove, true ); + + this.emit('mousemove', this.eventData); + + if (this.currentCursorStyle !== this.cursor) + { + this.currentCursorStyle = this.cursor; + this.interactionDOMElement.style.cursor = this.cursor; + } + + //TODO BUG for parents ineractive object (border order issue) +}; + +/** + * Processes the result of the mouse move check and dispatches the event if need be + * + * @param displayObject {PIXI.Container|PIXI.Sprite|PIXI.extras.TilingSprite} The display object that was tested + * @param hit {boolean} the result of the hit test on the display object + * @private + */ +InteractionManager.prototype.processMouseMove = function ( displayObject, hit ) +{ + this.processMouseOverOut(displayObject, hit); + + // only display on mouse over + if(!this.moveWhenInside || hit) + { + this.dispatchEvent( displayObject, 'mousemove', this.eventData); + } +}; + + +/** + * Is called when the mouse is moved out of the renderer element + * + * @param event {Event} The DOM event of a mouse being moved out + * @private + */ +InteractionManager.prototype.onMouseOut = function (event) +{ + this.mouse.originalEvent = event; + this.eventData.data = this.mouse; + this.eventData.stopped = false; + + // Update internal mouse reference + this.mapPositionToPoint( this.mouse.global, event.clientX, event.clientY); + + this.interactionDOMElement.style.cursor = this.defaultCursorStyle; + + // TODO optimize by not check EVERY TIME! maybe half as often? // + this.mapPositionToPoint( this.mouse.global, event.clientX, event.clientY ); + + this.processInteractive( this.mouse.global, this.renderer._lastObjectRendered, this.processMouseOverOut, false ); + + this.emit('mouseout', this.eventData); +}; + +/** + * Processes the result of the mouse over/out check and dispatches the event if need be + * + * @param displayObject {PIXI.Container|PIXI.Sprite|PIXI.extras.TilingSprite} The display object that was tested + * @param hit {boolean} the result of the hit test on the display object + * @private + */ +InteractionManager.prototype.processMouseOverOut = function ( displayObject, hit ) +{ + if(hit) + { + if(!displayObject._over) + { + displayObject._over = true; + this.dispatchEvent( displayObject, 'mouseover', this.eventData ); + } + + if (displayObject.buttonMode) + { + this.cursor = displayObject.defaultCursor; + } + } + else + { + if(displayObject._over) + { + displayObject._over = false; + this.dispatchEvent( displayObject, 'mouseout', this.eventData); + } + } +}; + +/** + * Is called when the mouse enters the renderer element area + * + * @param event {Event} The DOM event of the mouse moving into the renderer view + * @private + */ +InteractionManager.prototype.onMouseOver = function(event) +{ + this.mouse.originalEvent = event; + this.eventData.data = this.mouse; + this.eventData.stopped = false; + + this.emit('mouseover', this.eventData); +}; + + +/** + * Is called when a touch is started on the renderer element + * + * @param event {Event} The DOM event of a touch starting on the renderer view + * @private + */ +InteractionManager.prototype.onTouchStart = function (event) +{ + if (this.autoPreventDefault) + { + event.preventDefault(); + } + + var changedTouches = event.changedTouches; + var cLength = changedTouches.length; + + for (var i=0; i < cLength; i++) + { + var touchEvent = changedTouches[i]; + //TODO POOL + var touchData = this.getTouchData( touchEvent ); + + touchData.originalEvent = event; + + this.eventData.data = touchData; + this.eventData.stopped = false; + + this.processInteractive( touchData.global, this.renderer._lastObjectRendered, this.processTouchStart, true ); + + this.emit('touchstart', this.eventData); + + this.returnTouchData( touchData ); + } +}; + +/** + * Processes the result of a touch check and dispatches the event if need be + * + * @param displayObject {PIXI.Container|PIXI.Sprite|PIXI.extras.TilingSprite} The display object that was tested + * @param hit {boolean} the result of the hit test on the display object + * @private + */ +InteractionManager.prototype.processTouchStart = function ( displayObject, hit ) +{ + if(hit) + { + displayObject._touchDown = true; + this.dispatchEvent( displayObject, 'touchstart', this.eventData ); + } +}; + + +/** + * Is called when a touch ends on the renderer element + * + * @param event {Event} The DOM event of a touch ending on the renderer view + * @private + */ +InteractionManager.prototype.onTouchEnd = function (event) +{ + if (this.autoPreventDefault) + { + event.preventDefault(); + } + + var changedTouches = event.changedTouches; + var cLength = changedTouches.length; + + for (var i=0; i < cLength; i++) + { + var touchEvent = changedTouches[i]; + + var touchData = this.getTouchData( touchEvent ); + + touchData.originalEvent = event; + + //TODO this should be passed along.. no set + this.eventData.data = touchData; + this.eventData.stopped = false; + + + this.processInteractive( touchData.global, this.renderer._lastObjectRendered, this.processTouchEnd, true ); + + this.emit('touchend', this.eventData); + + this.returnTouchData( touchData ); + } +}; + +/** + * Processes the result of the end of a touch and dispatches the event if need be + * + * @param displayObject {PIXI.Container|PIXI.Sprite|PIXI.extras.TilingSprite} The display object that was tested + * @param hit {boolean} the result of the hit test on the display object + * @private + */ +InteractionManager.prototype.processTouchEnd = function ( displayObject, hit ) +{ + if(hit) + { + this.dispatchEvent( displayObject, 'touchend', this.eventData ); + + if( displayObject._touchDown ) + { + displayObject._touchDown = false; + this.dispatchEvent( displayObject, 'tap', this.eventData ); + } + } + else + { + if( displayObject._touchDown ) + { + displayObject._touchDown = false; + this.dispatchEvent( displayObject, 'touchendoutside', this.eventData ); + } + } +}; + +/** + * Is called when a touch is moved across the renderer element + * + * @param event {Event} The DOM event of a touch moving across the renderer view + * @private + */ +InteractionManager.prototype.onTouchMove = function (event) +{ + if (this.autoPreventDefault) + { + event.preventDefault(); + } + + var changedTouches = event.changedTouches; + var cLength = changedTouches.length; + + for (var i=0; i < cLength; i++) + { + var touchEvent = changedTouches[i]; + + var touchData = this.getTouchData( touchEvent ); + + touchData.originalEvent = event; + + this.eventData.data = touchData; + this.eventData.stopped = false; + + this.processInteractive( touchData.global, this.renderer._lastObjectRendered, this.processTouchMove, this.moveWhenInside ); + + this.emit('touchmove', this.eventData); + + this.returnTouchData( touchData ); + } +}; + +/** + * Processes the result of a touch move check and dispatches the event if need be + * + * @param displayObject {PIXI.Container|PIXI.Sprite|PIXI.extras.TilingSprite} The display object that was tested + * @param hit {boolean} the result of the hit test on the display object + * @private + */ +InteractionManager.prototype.processTouchMove = function ( displayObject, hit ) +{ + if(!this.moveWhenInside || hit) + { + this.dispatchEvent( displayObject, 'touchmove', this.eventData); + } +}; + +/** + * Grabs an interaction data object from the internal pool + * + * @param touchEvent {object} The touch event we need to pair with an interactionData object + * + * @private + */ +InteractionManager.prototype.getTouchData = function (touchEvent) +{ + var touchData = this.interactiveDataPool.pop(); + + if(!touchData) + { + touchData = new InteractionData(); + } + + touchData.identifier = touchEvent.identifier; + this.mapPositionToPoint( touchData.global, touchEvent.clientX, touchEvent.clientY ); + + if(navigator.isCocoonJS) + { + touchData.global.x = touchData.global.x / this.resolution; + touchData.global.y = touchData.global.y / this.resolution; + } + + touchEvent.globalX = touchData.global.x; + touchEvent.globalY = touchData.global.y; + + return touchData; +}; + +/** + * Returns an interaction data object to the internal pool + * + * @param touchData {PIXI.interaction.InteractionData} The touch data object we want to return to the pool + * + * @private + */ +InteractionManager.prototype.returnTouchData = function ( touchData ) +{ + this.interactiveDataPool.push( touchData ); +}; + +/** + * Destroys the interaction manager + * + */ +InteractionManager.prototype.destroy = function () { + this.removeEvents(); + + this.removeAllListeners(); + + this.renderer = null; + + this.mouse = null; + + this.eventData = null; + + this.interactiveDataPool = null; + + this.interactionDOMElement = null; + + this.onMouseUp = null; + this.processMouseUp = null; + + + this.onMouseDown = null; + this.processMouseDown = null; + + this.onMouseMove = null; + this.processMouseMove = null; + + this.onMouseOut = null; + this.processMouseOverOut = null; + + this.onMouseOver = null; + + this.onTouchStart = null; + this.processTouchStart = null; + + this.onTouchEnd = null; + this.processTouchEnd = null; + + this.onTouchMove = null; + this.processTouchMove = null; + + this._tempPoint = null; +}; + +core.WebGLRenderer.registerPlugin('interaction', InteractionManager); +core.CanvasRenderer.registerPlugin('interaction', InteractionManager); -Resource.prototype._getExtension = function () { - var url = this.url, - ext; +},{"../core":61,"./InteractionData":142,"./interactiveTarget":145,"eventemitter3":4}],144:[function(require,module,exports){ +/** + * @file Main export of the PIXI interactions library + * @author Mat Groves + * @copyright 2013-2015 GoodBoyDigital + * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} + */ + +/** + * @namespace PIXI.interaction + */ +module.exports = { + InteractionData: require('./InteractionData'), + InteractionManager: require('./InteractionManager'), + interactiveTarget: require('./interactiveTarget') +}; - if (this.isDataUrl) { - var slashIndex = url.indexOf('/'); - ext = url.substring(slashIndex + 1, url.indexOf(';', slashIndex)); - } - else { - var queryStart = url.indexOf('?'); - if (queryStart !== -1) { - url = url.substring(0, queryStart); - } +},{"./InteractionData":142,"./InteractionManager":143,"./interactiveTarget":145}],145:[function(require,module,exports){ +/** + * Default property values of interactive objects + * Used by {@link PIXI.interaction.InteractionManager} to automatically give all DisplayObjects these properties + * + * @mixin + * @memberof PIXI.interaction + * @example + * function MyObject() {} + * + * Object.assign( + * MyObject.prototype, + * PIXI.interaction.interactiveTarget + * ); + */ +var interactiveTarget = { + /** + * Determines if the displayObject be clicked/touched + * + * @inner {boolean} + */ + interactive: false, + + /** + * Determines if the children to the displayObject can be clicked/touched + * Setting this to false allows pixi to bypass a recursive hitTest function + * + * @inner {boolean} + */ + interactiveChildren: true, + + /** + * Interaction shape. Children will be hit first, then this shape will be checked. + * + * @inner {PIXI.Rectangle|PIXI.Circle|PIXI.Ellipse|PIXI.Polygon|PIXI.RoundedRectangle} + */ + hitArea: null, + + /** + * If enabled, the mouse cursor will change when hovered over the displayObject if it is interactive + * + * @inner {boolean} + */ + buttonMode: false, + + /** + * If buttonMode is enabled, this defines what CSS cursor property is used when the mouse cursor is hovered over the displayObject + * https://developer.mozilla.org/en/docs/Web/CSS/cursor + * + * @inner {string} + */ + defaultCursor: 'pointer', + + // some internal checks.. + /** + * Internal check to detect if the mouse cursor is hovered over the displayObject + * + * @inner {boolean} + * @private + */ + _over: false, + + /** + * Internal check to detect if the left mouse button is pressed on the displayObject + * + * @inner {boolean} + * @private + */ + _isLeftDown: false, + + /** + * Internal check to detect if the right mouse button is pressed on the displayObject + * + * @inner {boolean} + * @private + */ + _isRightDown: false, + + /** + * Internal check to detect if a user has touched the displayObject + * + * @inner {boolean} + * @private + */ + _touchDown: false + }; + +module.exports = interactiveTarget; - ext = url.substring(url.lastIndexOf('.') + 1); - } +},{}],146:[function(require,module,exports){ +var Resource = require('resource-loader').Resource, + core = require('../core'), + extras = require('../extras'), + path = require('path'); + + +function parse(resource, texture) { + var data = {}; + var info = resource.data.getElementsByTagName('info')[0]; + var common = resource.data.getElementsByTagName('common')[0]; + + data.font = info.getAttribute('face'); + data.size = parseInt(info.getAttribute('size'), 10); + data.lineHeight = parseInt(common.getAttribute('lineHeight'), 10); + data.chars = {}; + + //parse letters + var letters = resource.data.getElementsByTagName('char'); + + for (var i = 0; i < letters.length; i++) + { + var charCode = parseInt(letters[i].getAttribute('id'), 10); + + var textureRect = new core.Rectangle( + parseInt(letters[i].getAttribute('x'), 10) + texture.frame.x, + parseInt(letters[i].getAttribute('y'), 10) + texture.frame.y, + parseInt(letters[i].getAttribute('width'), 10), + parseInt(letters[i].getAttribute('height'), 10) + ); + + data.chars[charCode] = { + xOffset: parseInt(letters[i].getAttribute('xoffset'), 10), + yOffset: parseInt(letters[i].getAttribute('yoffset'), 10), + xAdvance: parseInt(letters[i].getAttribute('xadvance'), 10), + kerning: {}, + texture: new core.Texture(texture.baseTexture, textureRect) + + }; + } + + //parse kernings + var kernings = resource.data.getElementsByTagName('kerning'); + for (i = 0; i < kernings.length; i++) + { + var first = parseInt(kernings[i].getAttribute('first'), 10); + var second = parseInt(kernings[i].getAttribute('second'), 10); + var amount = parseInt(kernings[i].getAttribute('amount'), 10); + + if(data.chars[second]) + { + data.chars[second].kerning[first] = amount; + } + } + + resource.bitmapFont = data; + + // I'm leaving this as a temporary fix so we can test the bitmap fonts in v3 + // but it's very likely to change + extras.BitmapText.fonts[data.font] = data; +} + + +module.exports = function () +{ + return function (resource, next) + { + // skip if no data or not xml data + if (!resource.data || !resource.isXml) + { + return next(); + } + + // skip if not bitmap font data, using some silly duck-typing + if ( + resource.data.getElementsByTagName('page').length === 0 || + resource.data.getElementsByTagName('info').length === 0 || + resource.data.getElementsByTagName('info')[0].getAttribute('face') === null + ) + { + return next(); + } + + var xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; + + if (resource.isDataUrl) { + if (xmlUrl === '.') { + xmlUrl = ''; + } + + if (this.baseUrl && xmlUrl) { + // if baseurl has a trailing slash then add one to xmlUrl so the replace works below + if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') { + xmlUrl += '/'; + } + + // remove baseUrl from xmlUrl + xmlUrl = xmlUrl.replace(this.baseUrl, ''); + } + } + + // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. + if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') { + xmlUrl += '/'; + } + + var textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); + if (core.utils.TextureCache[textureUrl]) { + //reuse existing texture + parse(resource, core.utils.TextureCache[textureUrl]); + next(); + } + else { + var loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata + }; + // load the texture for the font + this.add(resource.name + '_image', textureUrl, loadOptions, function (res) { + parse(resource, res.texture); + next(); + }); + } + }; +}; - return ext; -}; +},{"../core":61,"../extras":128,"path":7,"resource-loader":33}],147:[function(require,module,exports){ +/** + * @file Main export of the PIXI loaders library + * @author Mat Groves + * @copyright 2013-2015 GoodBoyDigital + * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} + */ + +/** + * @namespace PIXI.loaders + */ +module.exports = { + Loader: require('./loader'), + + // parsers + bitmapFontParser: require('./bitmapFontParser'), + spritesheetParser: require('./spritesheetParser'), + textureParser: require('./textureParser'), + Resource: require('resource-loader').Resource +}; -/** - * Determines the mime type of an XHR request based on the responseType of - * resource being loaded. - * - * @private - * @return {string} The mime type to use. - */ -Resource.prototype._getMimeFromXhrType = function (type) { - switch(type) { - case Resource.XHR_RESPONSE_TYPE.BUFFER: - return 'application/octet-binary'; +},{"./bitmapFontParser":146,"./loader":148,"./spritesheetParser":149,"./textureParser":150,"resource-loader":33}],148:[function(require,module,exports){ +var ResourceLoader = require('resource-loader'), + textureParser = require('./textureParser'), + spritesheetParser = require('./spritesheetParser'), + bitmapFontParser = require('./bitmapFontParser'); + +/** + * + * The new loader, extends Resource Loader by Chad Engler : https://github.com/englercj/resource-loader + * + * ```js + * var loader = PIXI.loader; // pixi exposes a premade instance for you to use. + * //or + * var loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * loader.add('bunny',"data/bunny.png"); + * + * loader.once('complete',onAssetsLoaded); + * + * loader.load(); + * ``` + * + * @class + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param [baseUrl=''] {string} The base url for all resources loaded by this loader. + * @param [concurrency=10] {number} The number of resources to load concurrently. + * @see https://github.com/englercj/resource-loader + */ +function Loader(baseUrl, concurrency) +{ + ResourceLoader.call(this, baseUrl, concurrency); + + for (var i = 0; i < Loader._pixiMiddleware.length; ++i) { + this.use(Loader._pixiMiddleware[i]()); + } +} + +Loader.prototype = Object.create(ResourceLoader.prototype); +Loader.prototype.constructor = Loader; + +module.exports = Loader; + +Loader._pixiMiddleware = [ + // parse any blob into more usable objects (e.g. Image) + ResourceLoader.middleware.parsing.blob, + // parse any Image objects into textures + textureParser, + // parse any spritesheet data into multiple textures + spritesheetParser, + // parse any spritesheet data into multiple textures + bitmapFontParser +]; + +Loader.addPixiMiddleware = function (fn) { + Loader._pixiMiddleware.push(fn); +}; + +// Add custom extentions +var Resource = ResourceLoader.Resource; + +Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); - case Resource.XHR_RESPONSE_TYPE.BLOB: - return 'application/blob'; +},{"./bitmapFontParser":146,"./spritesheetParser":149,"./textureParser":150,"resource-loader":33}],149:[function(require,module,exports){ +var Resource = require('resource-loader').Resource, + path = require('path'), + core = require('../core'), + async = require('async'); + +var BATCH_SIZE = 1000; + +module.exports = function () +{ + return function (resource, next) + { + var resourcePath; + var imageResourceName = resource.name + '_image'; + + // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists + if (!resource.data || !resource.isJson || !resource.data.frames || this.resources[imageResourceName]) + { + return next(); + } + + var loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata + }; + + // Prepend url path unless the resource image is a data url + if (resource.isDataUrl) + { + resourcePath = resource.data.meta.image; + } + else + { + resourcePath = path.dirname(resource.url.replace(this.baseUrl, '')) + '/' + resource.data.meta.image; + } + + // load the image for this sheet + this.add(imageResourceName, resourcePath, loadOptions, function (res) + { + resource.textures = {}; + + var frames = resource.data.frames; + var frameKeys = Object.keys(frames); + var resolution = core.utils.getResolutionOfUrl(resource.url); + var batchIndex = 0; + + function processFrames(initialFrameIndex, maxFrames) + { + var frameIndex = initialFrameIndex; + + while (frameIndex - initialFrameIndex < maxFrames && frameIndex < frameKeys.length) + { + var i = frameKeys[frameIndex]; + var rect = frames[i].frame; + + if (rect) + { + + var frame = null; + var trim = null; + var orig = new core.Rectangle(0, 0, frames[i].sourceSize.w / resolution, frames[i].sourceSize.h / resolution); + + if (frames[i].rotated) { + frame = new core.Rectangle(rect.x / resolution, rect.y / resolution, rect.h / resolution, rect.w / resolution); + } + else { + frame = new core.Rectangle(rect.x / resolution, rect.y / resolution, rect.w / resolution, rect.h / resolution); + } + + // Check to see if the sprite is trimmed + if (frames[i].trimmed) + { + trim = new core.Rectangle( + frames[i].spriteSourceSize.x / resolution, + frames[i].spriteSourceSize.y / resolution, + frames[i].spriteSourceSize.w / resolution, + frames[i].spriteSourceSize.h / resolution + ); + } + + resource.textures[i] = new core.Texture(res.texture.baseTexture, frame, orig, trim, frames[i].rotated ? 2 : 0); + + // lets also add the frame to pixi's global cache for fromFrame and fromImage functions + core.utils.TextureCache[i] = resource.textures[i]; + + } + + frameIndex++; + } + } + + function shouldProcessNextBatch() + { + return batchIndex * BATCH_SIZE < frameKeys.length; + } + + function processNextBatch(done) + { + processFrames(batchIndex * BATCH_SIZE, BATCH_SIZE); + batchIndex++; + setTimeout(done, 0); + } + + if (frameKeys.length <= BATCH_SIZE) + { + processFrames(0, BATCH_SIZE); + next(); + } + else + { + async.whilst(shouldProcessNextBatch, processNextBatch, next); + } + }); + }; +}; - case Resource.XHR_RESPONSE_TYPE.DOCUMENT: - return 'application/xml'; +},{"../core":61,"async":1,"path":7,"resource-loader":33}],150:[function(require,module,exports){ +var core = require('../core'); + +module.exports = function () +{ + return function (resource, next) + { + // create a new texture if the data is an Image object + if (resource.data && resource.isImage) + { + var baseTexture = new core.BaseTexture(resource.data, null, core.utils.getResolutionOfUrl(resource.url)); + baseTexture.imageUrl = resource.url; + resource.texture = new core.Texture(baseTexture); + // lets also add the frame to pixi's global cache for fromFrame and fromImage fucntions + core.utils.BaseTextureCache[resource.url] = baseTexture; + core.utils.TextureCache[resource.url] = resource.texture; + } + + next(); + }; +}; - case Resource.XHR_RESPONSE_TYPE.JSON: - return 'application/json'; +},{"../core":61}],151:[function(require,module,exports){ +var core = require('../core'), + glCore = require('pixi-gl-core'), + Shader = require('./webgl/MeshShader'), + tempPoint = new core.Point(), + tempPolygon = new core.Polygon(); + +/** + * Base mesh class + * @class + * @extends PIXI.Container + * @memberof PIXI.mesh + * @param texture {PIXI.Texture} The texture to use + * @param [vertices] {Float32Array} if you want to specify the vertices + * @param [uvs] {Float32Array} if you want to specify the uvs + * @param [indices] {Uint16Array} if you want to specify the indices + * @param [drawMode] {number} the drawMode, can be any of the Mesh.DRAW_MODES consts + */ +function Mesh(texture, vertices, uvs, indices, drawMode) +{ + core.Container.call(this); + + /** + * The texture of the Mesh + * + * @member {PIXI.Texture} + * @private + */ + this._texture = null; + + /** + * The Uvs of the Mesh + * + * @member {Float32Array} + */ + this.uvs = uvs || new Float32Array([0, 0, + 1, 0, + 1, 1, + 0, 1]); + + /** + * An array of vertices + * + * @member {Float32Array} + */ + this.vertices = vertices || new Float32Array([0, 0, + 100, 0, + 100, 100, + 0, 100]); + + /* + * @member {Uint16Array} An array containing the indices of the vertices + */ + // TODO auto generate this based on draw mode! + this.indices = indices || new Uint16Array([0, 1, 3, 2]); + + /** + * Whether the Mesh is dirty or not + * + * @member {boolean} + */ + this.dirty = true; + this.indexDirty = true; + + /** + * The blend mode to be applied to the sprite. Set to `PIXI.BLEND_MODES.NORMAL` to remove any blend mode. + * + * @member {number} + * @default PIXI.BLEND_MODES.NORMAL + * @see PIXI.BLEND_MODES + */ + this.blendMode = core.BLEND_MODES.NORMAL; + + /** + * Triangles in canvas mode are automatically antialiased, use this value to force triangles to overlap a bit with each other. + * + * @member {number} + */ + this.canvasPadding = 0; + + /** + * The way the Mesh should be drawn, can be any of the {@link PIXI.mesh.Mesh.DRAW_MODES} consts + * + * @member {number} + * @see PIXI.mesh.Mesh.DRAW_MODES + */ + this.drawMode = drawMode || Mesh.DRAW_MODES.TRIANGLE_MESH; + + // run texture setter; + this.texture = texture; + + /** + * The default shader that is used if a mesh doesn't have a more specific one. + * + * @member {PIXI.Shader} + */ + this.shader = null; + + + /** + * The tint applied to the mesh. This is a [r,g,b] value. A value of [1,1,1] will remove any tint effect. + * + * @member {number} + * @memberof PIXI.mesh.Mesh# + */ + this.tintRgb = new Float32Array([1, 1, 1]); + + this._glDatas = []; +} + +// constructor +Mesh.prototype = Object.create(core.Container.prototype); +Mesh.prototype.constructor = Mesh; +module.exports = Mesh; + +Object.defineProperties(Mesh.prototype, { + /** + * The texture that the sprite is using + * + * @member {PIXI.Texture} + * @memberof PIXI.mesh.Mesh# + */ + texture: { + get: function () + { + return this._texture; + }, + set: function (value) + { + if (this._texture === value) + { + return; + } + + this._texture = value; + + if (value) + { + // wait for the texture to load + if (value.baseTexture.hasLoaded) + { + this._onTextureUpdate(); + } + else + { + value.once('update', this._onTextureUpdate, this); + } + } + } + }, + /** + * The tint applied to the mesh. This is a hex value. A value of 0xFFFFFF will remove any tint effect. + * + * @member {number} + * @memberof PIXI.mesh.Mesh# + * @default 0xFFFFFF + */ + tint: { + get: function() { + return core.utils.rgb2hex(this.tintRgb); + }, + set: function(value) { + this.tintRgb = core.utils.hex2rgb(value, this.tintRgb); + } + } +}); + +/** + * Renders the object using the WebGL renderer + * + * @param renderer {PIXI.WebGLRenderer} a reference to the WebGL renderer + * @private + */ +Mesh.prototype._renderWebGL = function (renderer) +{ + // get rid of any thing that may be batching. + renderer.flush(); + + // renderer.plugins.mesh.render(this); + var gl = renderer.gl; + var glData = this._glDatas[renderer.CONTEXT_UID]; + + if(!glData) + { + glData = { + shader:new Shader(gl), + vertexBuffer:glCore.GLBuffer.createVertexBuffer(gl, this.vertices, gl.STREAM_DRAW), + uvBuffer:glCore.GLBuffer.createVertexBuffer(gl, this.uvs, gl.STREAM_DRAW), + indexBuffer:glCore.GLBuffer.createIndexBuffer(gl, this.indices, gl.STATIC_DRAW), + // build the vao object that will render.. + vao:new glCore.VertexArrayObject(gl) + }; + + // build the vao object that will render.. + glData.vao = new glCore.VertexArrayObject(gl) + .addIndex(glData.indexBuffer) + .addAttribute(glData.vertexBuffer, glData.shader.attributes.aVertexPosition, gl.FLOAT, false, 2 * 4, 0) + .addAttribute(glData.uvBuffer, glData.shader.attributes.aTextureCoord, gl.FLOAT, false, 2 * 4, 0); + + this._glDatas[renderer.CONTEXT_UID] = glData; + + + this.indexDirty = false; + } + + if(this.dirty) + { + this.dirty = false; + glData.uvBuffer.upload(); + + } + + if(this.indexDirty) + { + this.indexDirty = false; + glData.indexBuffer.upload(); + } + + glData.vertexBuffer.upload(); + + renderer.bindShader(glData.shader); + renderer.bindTexture(this._texture, 0); + renderer.state.setBlendMode(this.blendMode); + + glData.shader.uniforms.translationMatrix = this.worldTransform.toArray(true); + glData.shader.uniforms.alpha = this.worldAlpha; + glData.shader.uniforms.tint = this.tintRgb; + + var drawMode = this.drawMode === Mesh.DRAW_MODES.TRIANGLE_MESH ? gl.TRIANGLE_STRIP : gl.TRIANGLES; + + glData.vao.bind() + .draw(drawMode, this.indices.length) + .unbind(); +}; + +/** + * Renders the object using the Canvas renderer + * + * @param renderer {PIXI.CanvasRenderer} + * @private + */ +Mesh.prototype._renderCanvas = function (renderer) +{ + var context = renderer.context; + + var transform = this.worldTransform; + var res = renderer.resolution; + + if (renderer.roundPixels) + { + context.setTransform(transform.a * res, transform.b * res, transform.c * res, transform.d * res, (transform.tx * res) | 0, (transform.ty * res) | 0); + } + else + { + context.setTransform(transform.a * res, transform.b * res, transform.c * res, transform.d * res, transform.tx * res, transform.ty * res); + } + + if (this.drawMode === Mesh.DRAW_MODES.TRIANGLE_MESH) + { + this._renderCanvasTriangleMesh(context); + } + else + { + this._renderCanvasTriangles(context); + } +}; + +/** + * Draws the object in Triangle Mesh mode using canvas + * + * @param context {CanvasRenderingContext2D} the current drawing context + * @private + */ +Mesh.prototype._renderCanvasTriangleMesh = function (context) +{ + // draw triangles!! + var vertices = this.vertices; + var uvs = this.uvs; + + var length = vertices.length / 2; + // this.count++; + + for (var i = 0; i < length - 2; i++) + { + // draw some triangles! + var index = i * 2; + this._renderCanvasDrawTriangle(context, vertices, uvs, index, (index + 2), (index + 4)); + } +}; + +/** + * Draws the object in triangle mode using canvas + * + * @param context {CanvasRenderingContext2D} the current drawing context + * @private + */ +Mesh.prototype._renderCanvasTriangles = function (context) +{ + // draw triangles!! + var vertices = this.vertices; + var uvs = this.uvs; + var indices = this.indices; + + var length = indices.length; + // this.count++; + + for (var i = 0; i < length; i += 3) + { + // draw some triangles! + var index0 = indices[i] * 2, index1 = indices[i + 1] * 2, index2 = indices[i + 2] * 2; + this._renderCanvasDrawTriangle(context, vertices, uvs, index0, index1, index2); + } +}; + +/** + * Draws one of the triangles that form this Mesh + * + * @param context {CanvasRenderingContext2D} the current drawing context + * @param vertices {Float32Array} a reference to the vertices of the Mesh + * @param uvs {Float32Array} a reference to the uvs of the Mesh + * @param index0 {number} the index of the first vertex + * @param index1 {number} the index of the second vertex + * @param index2 {number} the index of the third vertex + * @private + */ +Mesh.prototype._renderCanvasDrawTriangle = function (context, vertices, uvs, index0, index1, index2) +{ + var base = this._texture.baseTexture; + var textureSource = base.source; + var textureWidth = base.width; + var textureHeight = base.height; + + var x0 = vertices[index0], x1 = vertices[index1], x2 = vertices[index2]; + var y0 = vertices[index0 + 1], y1 = vertices[index1 + 1], y2 = vertices[index2 + 1]; + + var u0 = uvs[index0] * base.width, u1 = uvs[index1] * base.width, u2 = uvs[index2] * base.width; + var v0 = uvs[index0 + 1] * base.height, v1 = uvs[index1 + 1] * base.height, v2 = uvs[index2 + 1] * base.height; + + if (this.canvasPadding > 0) + { + var paddingX = this.canvasPadding / this.worldTransform.a; + var paddingY = this.canvasPadding / this.worldTransform.d; + var centerX = (x0 + x1 + x2) / 3; + var centerY = (y0 + y1 + y2) / 3; + + var normX = x0 - centerX; + var normY = y0 - centerY; + + var dist = Math.sqrt(normX * normX + normY * normY); + x0 = centerX + (normX / dist) * (dist + paddingX); + y0 = centerY + (normY / dist) * (dist + paddingY); + + // + + normX = x1 - centerX; + normY = y1 - centerY; + + dist = Math.sqrt(normX * normX + normY * normY); + x1 = centerX + (normX / dist) * (dist + paddingX); + y1 = centerY + (normY / dist) * (dist + paddingY); + + normX = x2 - centerX; + normY = y2 - centerY; + + dist = Math.sqrt(normX * normX + normY * normY); + x2 = centerX + (normX / dist) * (dist + paddingX); + y2 = centerY + (normY / dist) * (dist + paddingY); + } + + context.save(); + context.beginPath(); + + + context.moveTo(x0, y0); + context.lineTo(x1, y1); + context.lineTo(x2, y2); + + context.closePath(); + + context.clip(); + + // Compute matrix transform + var delta = (u0 * v1) + (v0 * u2) + (u1 * v2) - (v1 * u2) - (v0 * u1) - (u0 * v2); + var deltaA = (x0 * v1) + (v0 * x2) + (x1 * v2) - (v1 * x2) - (v0 * x1) - (x0 * v2); + var deltaB = (u0 * x1) + (x0 * u2) + (u1 * x2) - (x1 * u2) - (x0 * u1) - (u0 * x2); + var deltaC = (u0 * v1 * x2) + (v0 * x1 * u2) + (x0 * u1 * v2) - (x0 * v1 * u2) - (v0 * u1 * x2) - (u0 * x1 * v2); + var deltaD = (y0 * v1) + (v0 * y2) + (y1 * v2) - (v1 * y2) - (v0 * y1) - (y0 * v2); + var deltaE = (u0 * y1) + (y0 * u2) + (u1 * y2) - (y1 * u2) - (y0 * u1) - (u0 * y2); + var deltaF = (u0 * v1 * y2) + (v0 * y1 * u2) + (y0 * u1 * v2) - (y0 * v1 * u2) - (v0 * u1 * y2) - (u0 * y1 * v2); + + context.transform(deltaA / delta, deltaD / delta, + deltaB / delta, deltaE / delta, + deltaC / delta, deltaF / delta); + + context.drawImage(textureSource, 0, 0, textureWidth * base.resolution, textureHeight * base.resolution, 0, 0, textureWidth, textureHeight); + context.restore(); +}; + + + +/** + * Renders a flat Mesh + * + * @param Mesh {PIXI.mesh.Mesh} The Mesh to render + * @private + */ +Mesh.prototype.renderMeshFlat = function (Mesh) +{ + var context = this.context; + var vertices = Mesh.vertices; + + var length = vertices.length/2; + // this.count++; + + context.beginPath(); + for (var i=1; i < length-2; i++) + { + // draw some triangles! + var index = i*2; + + var x0 = vertices[index], x1 = vertices[index+2], x2 = vertices[index+4]; + var y0 = vertices[index+1], y1 = vertices[index+3], y2 = vertices[index+5]; + + context.moveTo(x0, y0); + context.lineTo(x1, y1); + context.lineTo(x2, y2); + } + + context.fillStyle = '#FF0000'; + context.fill(); + context.closePath(); +}; + +/** + * When the texture is updated, this event will fire to update the scale and frame + * + * @private + */ +Mesh.prototype._onTextureUpdate = function () +{ + +}; + +/** + * Returns the bounds of the mesh as a rectangle. The bounds calculation takes the worldTransform into account. + * + * @param [matrix=this.worldTransform] {PIXI.Matrix} the transformation matrix of the sprite + * @return {PIXI.Rectangle} the framing rectangle + */ +Mesh.prototype._calculateBounds = function () +{ + //TODO - we can cache local bounds and use them if they are dirty (like graphics) + this._bounds.addVertices(this.transform, this.vertices, 0, this.vertices.length); +}; + +/** + * Tests if a point is inside this mesh. Works only for TRIANGLE_MESH + * + * @param point {PIXI.Point} the point to test + * @return {boolean} the result of the test + */ +Mesh.prototype.containsPoint = function( point ) { + if (!this.getBounds().contains(point.x, point.y)) { + return false; + } + this.worldTransform.applyInverse(point, tempPoint); + + var vertices = this.vertices; + var points = tempPolygon.points; + + var indices = this.indices; + var len = this.indices.length; + var step = this.drawMode === Mesh.DRAW_MODES.TRIANGLES ? 3 : 1; + for (var i=0;i+2 + * A B + * +---+----------------------+---+ + * C | 1 | 2 | 3 | + * +---+----------------------+---+ + * | | | | + * | 4 | 5 | 6 | + * | | | | + * +---+----------------------+---+ + * D | 7 | 8 | 9 | + * +---+----------------------+---+ + + * When changing this objects width and/or height: + * areas 1 3 7 and 9 will remain unscaled. + * areas 2 and 8 will be stretched horizontally + * areas 4 and 6 will be stretched vertically + * area 5 will be stretched both horizontally and vertically + * + * + * @class + * @extends PIXI.mesh.Plane + * @memberof PIXI.mesh + * @param {PIXI.Texture} texture - The texture to use on the NineSlicePlane. + * @param {int} [leftWidth=10] size of the left vertical bar (A) + * @param {int} [topHeight=10] size of the top horizontal bar (C) + * @param {int} [rightWidth=10] size of the right vertical bar (B) + * @param {int} [bottomHeight=10] size of the bottom horizontal bar (D) + * + */ +function NineSlicePlane(texture, leftWidth, topHeight, rightWidth, bottomHeight) +{ + Plane.call(this, texture, 4, 4); + + var uvs = this.uvs; + // right and bottom uv's are always 1 + uvs[6] = uvs[14] = uvs[22] = uvs[30] = 1; + uvs[25] = uvs[27] = uvs[29] = uvs[31] = 1; + + this._origWidth = texture.width; + this._origHeight = texture.height; + this._uvw = 1 / this._origWidth; + this._uvh = 1 / this._origHeight; + /** + * The width of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane + * + * @member {number} + * @memberof PIXI.NineSlicePlane# + * @override + */ + this.width = texture.width; + /** + * The height of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane + * + * @member {number} + * @memberof PIXI.NineSlicePlane# + * @override + */ + this.height = texture.height; + + uvs[2] = uvs[10] = uvs[18] = uvs[26] = this._uvw * leftWidth; + uvs[4] = uvs[12] = uvs[20] = uvs[28] = 1 - this._uvw * rightWidth; + uvs[9] = uvs[11] = uvs[13] = uvs[15] = this._uvh * topHeight; + uvs[17] = uvs[19] = uvs[21] = uvs[23] = 1 - this._uvh * bottomHeight; + + /** + * The width of the left column (a) + * + * @member {number} + */ + this.leftWidth = typeof leftWidth !== 'undefined' ? leftWidth : DEFAULT_BORDER_SIZE; + /** + * The width of the right column (b) + * + * @member {number} + */ + this.rightWidth = typeof rightWidth !== 'undefined' ? rightWidth : DEFAULT_BORDER_SIZE; + /** + * The height of the top row (c) + * + * @member {number} + */ + this.topHeight = typeof topHeight !== 'undefined' ? topHeight : DEFAULT_BORDER_SIZE; + /** + * The height of the bottom row (d) + * + * @member {number} + */ + this.bottomHeight = typeof bottomHeight !== 'undefined' ? bottomHeight : DEFAULT_BORDER_SIZE; +} + + +// constructor +NineSlicePlane.prototype = Object.create( Plane.prototype ); +NineSlicePlane.prototype.constructor = NineSlicePlane; +module.exports = NineSlicePlane; + +Object.defineProperties(NineSlicePlane.prototype, { + /** + * The width of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane + * + * @member {number} + * @memberof PIXI.NineSlicePlane# + * @override + */ + width: { + get: function () + { + return this._width; + }, + set: function (value) + { + this._width = value; + this.updateVerticalVertices(); + } + }, + + /** + * The height of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane + * + * @member {number} + * @memberof PIXI.NineSlicePlane# + * @override + */ + height: { + get: function () + { + return this._height; + }, + set: function (value) + { + this._height = value; + this.updateHorizontalVertices(); + } + }, + + /** + * The width of the left column + * + * @member {number} + */ + leftWidth: { + get: function() + { + return this._leftWidth; + }, + set: function (value) + { + this._leftWidth = value; + var uvs = this.uvs; + var vertices = this.vertices; + uvs[2] = uvs[10] = uvs[18] = uvs[26] = this._uvw * value; + vertices[2] = vertices[10] = vertices[18] = vertices[26] = value; + this.dirty=true; + } + }, + /** + * The width of the right column + * + * @member {number} + */ + rightWidth: { + get: function() + { + return this._rightWidth; + }, + set: function (value) + { + this._rightWidth = value; + var uvs = this.uvs; + var vertices = this.vertices; + uvs[4] = uvs[12] = uvs[20] = uvs[28] = 1 - this._uvw * value; + vertices[4] = vertices[12] = vertices[20] = vertices[28] = this._width - value; + this.dirty=true; + } + }, + /** + * The height of the top row + * + * @member {number} + */ + topHeight: { + get: function() + { + return this._topHeight; + }, + set: function (value) + { + this._topHeight = value; + var uvs = this.uvs; + var vertices = this.vertices; + uvs[9] = uvs[11] = uvs[13] = uvs[15] = this._uvh * value; + vertices[9] = vertices[11] = vertices[13] = vertices[15] = value; + this.dirty=true; + } + }, + /** + * The height of the bottom row + * + * @member {number} + */ + bottomHeight: { + get: function() + { + return this._bottomHeight; + }, + set: function (value) + { + this._bottomHeight = value; + var uvs = this.uvs; + var vertices = this.vertices; + uvs[17] = uvs[19] = uvs[21] = uvs[23] = 1 - this._uvh * value; + vertices[17] = vertices[19] = vertices[21] = vertices[23] = this._height - value; + this.dirty=true; + } + } +}); + +NineSlicePlane.prototype.updateHorizontalVertices = function() { + var vertices = this.vertices; + vertices[9] = vertices[11] = vertices[13] = vertices[15] = this._topHeight; + vertices[17] = vertices[19] = vertices[21] = vertices[23] = this._height - this._bottomHeight; + vertices[25] = vertices[27] = vertices[29] = vertices[31] = this._height; +}; + +NineSlicePlane.prototype.updateVerticalVertices = function() { + var vertices = this.vertices; + vertices[2] = vertices[10] = vertices[18] = vertices[26] = this._leftWidth; + vertices[4] = vertices[12] = vertices[20] = vertices[28] = this._width - this._rightWidth; + vertices[6] = vertices[14] = vertices[22] = vertices[30] = this._width ; +}; + +/** + * Renders the object using the Canvas renderer + * + * @param renderer {PIXI.CanvasRenderer} + * @private + */ +NineSlicePlane.prototype._renderCanvas= function (renderer) +{ + var context = renderer.context; + context.globalAlpha = this.worldAlpha; + + var transform = this.worldTransform; + var res = renderer.resolution; + + if (renderer.roundPixels) + { + context.setTransform(transform.a * res, transform.b * res, transform.c * res, transform.d * res, (transform.tx * res) | 0, (transform.ty * res) | 0); + } + else + { + context.setTransform(transform.a * res, transform.b * res, transform.c * res, transform.d * res, transform.tx * res, transform.ty * res); + } + + var base = this._texture.baseTexture; + var textureSource = base.source; + var w = base.width; + var h = base.height; + + this.drawSegment(context, textureSource, w, h, 0, 1, 10, 11); + this.drawSegment(context, textureSource, w, h, 2, 3, 12, 13); + this.drawSegment(context, textureSource, w, h, 4, 5, 14, 15); + this.drawSegment(context, textureSource, w, h, 8, 9, 18, 19); + this.drawSegment(context, textureSource, w, h, 10, 11, 20, 21); + this.drawSegment(context, textureSource, w, h, 12, 13, 22, 23); + this.drawSegment(context, textureSource, w, h, 16, 17, 26, 27); + this.drawSegment(context, textureSource, w, h, 18, 19, 28, 29); + this.drawSegment(context, textureSource, w, h, 20, 21, 30, 31); +}; + +/** + * Renders one segment of the plane. + * to mimic the exact drawing behavior of stretching the image like WebGL does, we need to make sure + * that the source area is at least 1 pixel in size, otherwise nothing gets drawn when a slice size of 0 is used. + * + * @param context + * @param textureSource + * @param w width of the texture + * @param h height of the texture + * @param x1 + * @param y1 + * @param x2 + * @param y2 + * @private + */ +NineSlicePlane.prototype.drawSegment= function (context, textureSource, w, h, x1, y1, x2, y2) +{ + // otherwise you get weird results when using slices of that are 0 wide or high. + var uvs = this.uvs; + var vertices = this.vertices; + + var sw = (uvs[x2]-uvs[x1]) * w; + var sh = (uvs[y2]-uvs[y1]) * h; + var dw = vertices[x2] - vertices[x1]; + var dh = vertices[y2] - vertices[y1]; + + // make sure the source is at least 1 pixel wide and high, otherwise nothing will be drawn. + if (sw<1) { + sw=1; + } + if (sh<1) { + sh=1; + } + // make sure destination is at least 1 pixel wide and high, otherwise you get lines when rendering close to original size. + if (dw<1) { + dw=1; + } + if (dh<1) { + dh=1; + } + context.drawImage(textureSource, uvs[x1] * w, uvs[y1] * h, sw, sh, vertices[x1], vertices[y1], dw, dh); +}; - } -}; +},{"./Plane":153}],153:[function(require,module,exports){ +var Mesh = require('./Mesh'); + +/** + * The Plane allows you to draw a texture across several points and them manipulate these points + * + *```js + * for (var i = 0; i < 20; i++) { + * points.push(new PIXI.Point(i * 50, 0)); + * }; + * var Plane = new PIXI.Plane(PIXI.Texture.fromImage("snake.png"), points); + * ``` + * + * @class + * @extends PIXI.mesh.Mesh + * @memberof PIXI.mesh + * @param {PIXI.Texture} texture - The texture to use on the Plane. + * @param {number} segmentsX - The number ox x segments + * @param {number} segmentsY - The number of y segments + * + */ +function Plane(texture, segmentsX, segmentsY) +{ + Mesh.call(this, texture); + + /** + * Tracker for if the Plane is ready to be drawn. Needed because Mesh ctor can + * call _onTextureUpdated which could call refresh too early. + * + * @member {boolean} + * @private + */ + this._ready = true; + + this.segmentsX = segmentsX || 10; + this.segmentsY = segmentsY || 10; + + this.drawMode = Mesh.DRAW_MODES.TRIANGLES; + this.refresh(); + +} + + +// constructor +Plane.prototype = Object.create( Mesh.prototype ); +Plane.prototype.constructor = Plane; +module.exports = Plane; + +/** + * Refreshes + * + */ +Plane.prototype.refresh = function() +{ + var total = this.segmentsX * this.segmentsY; + var verts = []; + var colors = []; + var uvs = []; + var indices = []; + var texture = this.texture; + + var segmentsXSub = this.segmentsX - 1; + var segmentsYSub = this.segmentsY - 1; + var i = 0; + + var sizeX = texture.width / segmentsXSub; + var sizeY = texture.height / segmentsYSub; + + for (i = 0; i < total; i++) { + + var x = (i % this.segmentsX); + var y = ( (i / this.segmentsX ) | 0 ); + + + verts.push((x * sizeX), + (y * sizeY)); + + // this works for rectangular textures. + uvs.push(texture._uvs.x0 + (texture._uvs.x1 - texture._uvs.x0) * (x / (this.segmentsX-1)), texture._uvs.y0 + (texture._uvs.y3-texture._uvs.y0) * (y/ (this.segmentsY-1))); + } + + // cons + + var totalSub = segmentsXSub * segmentsYSub; + + for (i = 0; i < totalSub; i++) { + + var xpos = i % segmentsXSub; + var ypos = (i / segmentsXSub ) | 0; + + + var value = (ypos * this.segmentsX) + xpos; + var value2 = (ypos * this.segmentsX) + xpos + 1; + var value3 = ((ypos+1) * this.segmentsX) + xpos; + var value4 = ((ypos+1) * this.segmentsX) + xpos + 1; + + indices.push(value, value2, value3); + indices.push(value2, value4, value3); + } + + + //console.log(indices) + this.vertices = new Float32Array(verts); + this.uvs = new Float32Array(uvs); + this.colors = new Float32Array(colors); + this.indices = new Uint16Array(indices); + + this.indexDirty = true; +}; + +/** + * Clear texture UVs when new texture is set + * + * @private + */ +Plane.prototype._onTextureUpdate = function () +{ + Mesh.prototype._onTextureUpdate.call(this); + + // wait for the Plane ctor to finish before calling refresh + if (this._ready) { + this.refresh(); + } +}; -/** - * The types of loading a resource can use. - * - * @static - * @constant - * @property {object} LOAD_TYPE - * @property {number} LOAD_TYPE.XHR - Uses XMLHttpRequest to load the resource. - * @property {number} LOAD_TYPE.IMAGE - Uses an `Image` object to load the resource. - * @property {number} LOAD_TYPE.AUDIO - Uses an `Audio` object to load the resource. - * @property {number} LOAD_TYPE.VIDEO - Uses a `Video` object to load the resource. - */ -Resource.LOAD_TYPE = { - XHR: 1, - IMAGE: 2, - AUDIO: 3, - VIDEO: 4 -}; +},{"./Mesh":151}],154:[function(require,module,exports){ +var Mesh = require('./Mesh'); +var core = require('../core'); + +/** + * The rope allows you to draw a texture across several points and them manipulate these points + * + *```js + * for (var i = 0; i < 20; i++) { + * points.push(new PIXI.Point(i * 50, 0)); + * }; + * var rope = new PIXI.Rope(PIXI.Texture.fromImage("snake.png"), points); + * ``` + * + * @class + * @extends PIXI.mesh.Mesh + * @memberof PIXI.mesh + * @param {PIXI.Texture} texture - The texture to use on the rope. + * @param {PIXI.Point[]} points - An array of {@link PIXI.Point} objects to construct this rope. + * + */ +function Rope(texture, points) +{ + Mesh.call(this, texture); + + /* + * @member {PIXI.Point[]} An array of points that determine the rope + */ + this.points = points; + + /* + * @member {Float32Array} An array of vertices used to construct this rope. + */ + this.vertices = new Float32Array(points.length * 4); + + /* + * @member {Float32Array} The WebGL Uvs of the rope. + */ + this.uvs = new Float32Array(points.length * 4); + + /* + * @member {Float32Array} An array containing the color components + */ + this.colors = new Float32Array(points.length * 2); + + /* + * @member {Uint16Array} An array containing the indices of the vertices + */ + this.indices = new Uint16Array(points.length * 2); + + /** + * Tracker for if the rope is ready to be drawn. Needed because Mesh ctor can + * call _onTextureUpdated which could call refresh too early. + * + * @member {boolean} + * @private + */ + this._ready = true; + + this.refresh(); +} + + +// constructor +Rope.prototype = Object.create(Mesh.prototype); +Rope.prototype.constructor = Rope; +module.exports = Rope; + +/** + * Refreshes + * + */ +Rope.prototype.refresh = function () +{ + var points = this.points; + + // if too little points, or texture hasn't got UVs set yet just move on. + if (points.length < 1 || !this._texture._uvs) + { + return; + } + + var uvs = this.uvs; + + var indices = this.indices; + var colors = this.colors; + + var textureUvs = this._texture._uvs; + var offset = new core.Point(textureUvs.x0, textureUvs.y0); + var factor = new core.Point(textureUvs.x2 - textureUvs.x0, textureUvs.y2 - textureUvs.y0); + + uvs[0] = 0 + offset.x; + uvs[1] = 0 + offset.y; + uvs[2] = 0 + offset.x; + uvs[3] = 1 * factor.y + offset.y; + + colors[0] = 1; + colors[1] = 1; + + indices[0] = 0; + indices[1] = 1; + + var total = points.length, + point, index, amount; + + for (var i = 1; i < total; i++) + { + point = points[i]; + index = i * 4; + // time to do some smart drawing! + amount = i / (total-1); + + uvs[index] = amount * factor.x + offset.x; + uvs[index+1] = 0 + offset.y; + + uvs[index+2] = amount * factor.x + offset.x; + uvs[index+3] = 1 * factor.y + offset.y; + + index = i * 2; + colors[index] = 1; + colors[index+1] = 1; + + index = i * 2; + indices[index] = index; + indices[index + 1] = index + 1; + } + + this.dirty = true; + this.indexDirty = true; +}; + +/** + * Clear texture UVs when new texture is set + * + * @private + */ +Rope.prototype._onTextureUpdate = function () +{ + + Mesh.prototype._onTextureUpdate.call(this); + + // wait for the Rope ctor to finish before calling refresh + if (this._ready) { + this.refresh(); + } +}; + +/** + * Updates the object transform for rendering + * + * @private + */ +Rope.prototype.updateTransform = function () +{ + var points = this.points; + + if (points.length < 1) + { + return; + } + + var lastPoint = points[0]; + var nextPoint; + var perpX = 0; + var perpY = 0; + + // this.count -= 0.2; + + var vertices = this.vertices; + var total = points.length, + point, index, ratio, perpLength, num; + + for (var i = 0; i < total; i++) + { + point = points[i]; + index = i * 4; + + if (i < points.length-1) + { + nextPoint = points[i+1]; + } + else + { + nextPoint = point; + } + + perpY = -(nextPoint.x - lastPoint.x); + perpX = nextPoint.y - lastPoint.y; + + ratio = (1 - (i / (total-1))) * 10; + + if (ratio > 1) + { + ratio = 1; + } + + perpLength = Math.sqrt(perpX * perpX + perpY * perpY); + num = this._texture.height / 2; //(20 + Math.abs(Math.sin((i + this.count) * 0.3) * 50) )* ratio; + perpX /= perpLength; + perpY /= perpLength; + + perpX *= num; + perpY *= num; + + vertices[index] = point.x + perpX; + vertices[index+1] = point.y + perpY; + vertices[index+2] = point.x - perpX; + vertices[index+3] = point.y - perpY; + + lastPoint = point; + } + + this.containerUpdateTransform(); +}; -/** - * The XHR ready states, used internally. - * - * @static - * @constant - * @property {object} XHR_READY_STATE - * @property {number} XHR_READY_STATE.UNSENT - open()has not been called yet. - * @property {number} XHR_READY_STATE.OPENED - send()has not been called yet. - * @property {number} XHR_READY_STATE.HEADERS_RECEIVED - send() has been called, and headers and status are available. - * @property {number} XHR_READY_STATE.LOADING - Downloading; responseText holds partial data. - * @property {number} XHR_READY_STATE.DONE - The operation is complete. - */ -Resource.XHR_READY_STATE = { - UNSENT: 0, - OPENED: 1, - HEADERS_RECEIVED: 2, - LOADING: 3, - DONE: 4 -}; +},{"../core":61,"./Mesh":151}],155:[function(require,module,exports){ +/** + * @file Main export of the PIXI extras library + * @author Mat Groves + * @copyright 2013-2015 GoodBoyDigital + * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} + */ + +/** + * @namespace PIXI.mesh + */ +module.exports = { + Mesh: require('./Mesh'), + Plane: require('./Plane'), + NineSlicePlane: require('./NineSlicePlane'), + Rope: require('./Rope'), + MeshShader: require('./webgl/MeshShader') +}; -/** - * The XHR ready states, used internally. - * - * @static - * @constant - * @property {object} XHR_RESPONSE_TYPE - * @property {string} XHR_RESPONSE_TYPE.DEFAULT - defaults to text - * @property {string} XHR_RESPONSE_TYPE.BUFFER - ArrayBuffer - * @property {string} XHR_RESPONSE_TYPE.BLOB - Blob - * @property {string} XHR_RESPONSE_TYPE.DOCUMENT - Document - * @property {string} XHR_RESPONSE_TYPE.JSON - Object - * @property {string} XHR_RESPONSE_TYPE.TEXT - String - */ -Resource.XHR_RESPONSE_TYPE = { - DEFAULT: 'text', - BUFFER: 'arraybuffer', - BLOB: 'blob', - DOCUMENT: 'document', - JSON: 'json', - TEXT: 'text' -}; +},{"./Mesh":151,"./NineSlicePlane":152,"./Plane":153,"./Rope":154,"./webgl/MeshShader":156}],156:[function(require,module,exports){ +var Shader = require('../../core/Shader'); + +/** + * @class + * @extends PIXI.Shader + * @memberof PIXI.mesh + * @param gl {PIXI.Shader} TODO: Find a good explanation for this. + */ +function MeshShader(gl) +{ + Shader.call(this, + gl, + // vertex shader + [ + 'attribute vec2 aVertexPosition;', + 'attribute vec2 aTextureCoord;', + + 'uniform mat3 translationMatrix;', + 'uniform mat3 projectionMatrix;', + + 'varying vec2 vTextureCoord;', + + 'void main(void){', + ' gl_Position = vec4((projectionMatrix * translationMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);', + ' vTextureCoord = aTextureCoord;', + '}' + ].join('\n'), + [ + 'varying vec2 vTextureCoord;', + 'uniform float alpha;', + 'uniform vec3 tint;', + + 'uniform sampler2D uSampler;', + + 'void main(void){', + ' gl_FragColor = texture2D(uSampler, vTextureCoord) * vec4(tint * alpha, alpha);', + // ' gl_FragColor = vec4(1.0);', + '}' + ].join('\n') + ); +} + +MeshShader.prototype = Object.create(Shader.prototype); +MeshShader.prototype.constructor = MeshShader; +module.exports = MeshShader; + -Resource._loadTypeMap = { - 'gif': Resource.LOAD_TYPE.IMAGE, - 'png': Resource.LOAD_TYPE.IMAGE, - 'bmp': Resource.LOAD_TYPE.IMAGE, - 'jpg': Resource.LOAD_TYPE.IMAGE, - 'jpeg': Resource.LOAD_TYPE.IMAGE, - 'tif': Resource.LOAD_TYPE.IMAGE, - 'tiff': Resource.LOAD_TYPE.IMAGE, - 'webp': Resource.LOAD_TYPE.IMAGE, - 'tga': Resource.LOAD_TYPE.IMAGE -}; +},{"../../core/Shader":41}],157:[function(require,module,exports){ +var core = require('../core'); + +/** + * The ParticleContainer class is a really fast version of the Container built solely for speed, + * so use when you need a lot of sprites or particles. The tradeoff of the ParticleContainer is that advanced + * functionality will not work. ParticleContainer implements only the basic object transform (position, scale, rotation). + * Any other functionality like tinting, masking, etc will not work on sprites in this batch. + * + * It's extremely easy to use : + * + * ```js + * var container = new ParticleContainer(); + * + * for (var i = 0; i < 100; ++i) + * { + * var sprite = new PIXI.Sprite.fromImage("myImage.png"); + * container.addChild(sprite); + * } + * ``` + * + * And here you have a hundred sprites that will be renderer at the speed of light. + * + * @class + * @extends PIXI.Container + * @memberof PIXI.particles + * @param [maxSize=15000] {number} The maximum number of particles that can be renderer by the container. + * @param [properties] {object} The properties of children that should be uploaded to the gpu and applied. + * @param [properties.scale=false] {boolean} When true, scale be uploaded and applied. + * @param [properties.position=true] {boolean} When true, position be uploaded and applied. + * @param [properties.rotation=false] {boolean} When true, rotation be uploaded and applied. + * @param [properties.uvs=false] {boolean} When true, uvs be uploaded and applied. + * @param [properties.alpha=false] {boolean} When true, alpha be uploaded and applied. + * @param [batchSize=15000] {number} Number of particles per batch. + */ +function ParticleContainer(maxSize, properties, batchSize) +{ + core.Container.call(this); + + batchSize = batchSize || 15000; //CONST.SPRITE_BATCH_SIZE; // 2000 is a nice balance between mobile / desktop + maxSize = maxSize || 15000; + + // Making sure the batch size is valid + // 65535 is max vertex index in the index buffer (see ParticleRenderer) + // so max number of particles is 65536 / 4 = 16384 + var maxBatchSize = 16384; + if (batchSize > maxBatchSize) { + batchSize = maxBatchSize; + } + + if (batchSize > maxSize) { + batchSize = maxSize; + } + + /** + * Set properties to be dynamic (true) / static (false) + * + * @member {boolean[]} + * @private + */ + this._properties = [false, true, false, false, false]; + + /** + * @member {number} + * @private + */ + this._maxSize = maxSize; + + /** + * @member {number} + * @private + */ + this._batchSize = batchSize; + + /** + * @member {WebGLBuffer} + * @private + */ + this._glBuffers = []; + + /** + * @member {number} + * @private + */ + this._bufferToUpdate = 0; + + /** + * @member {boolean} + * + */ + this.interactiveChildren = false; + + /** + * The blend mode to be applied to the sprite. Apply a value of `PIXI.BLEND_MODES.NORMAL` to reset the blend mode. + * + * @member {number} + * @default PIXI.BLEND_MODES.NORMAL + * @see PIXI.BLEND_MODES + */ + this.blendMode = core.BLEND_MODES.NORMAL; + + /** + * Used for canvas renderering. If true then the elements will be positioned at the nearest pixel. This provides a nice speed boost. + * + * @member {boolean} + * @default true; + */ + this.roundPixels = true; + + this.baseTexture = null; + + this.setProperties(properties); +} + +ParticleContainer.prototype = Object.create(core.Container.prototype); +ParticleContainer.prototype.constructor = ParticleContainer; +module.exports = ParticleContainer; + +/** + * Sets the private properties array to dynamic / static based on the passed properties object + * + * @param properties {object} The properties to be uploaded + */ +ParticleContainer.prototype.setProperties = function(properties) +{ + if ( properties ) { + this._properties[0] = 'scale' in properties ? !!properties.scale : this._properties[0]; + this._properties[1] = 'position' in properties ? !!properties.position : this._properties[1]; + this._properties[2] = 'rotation' in properties ? !!properties.rotation : this._properties[2]; + this._properties[3] = 'uvs' in properties ? !!properties.uvs : this._properties[3]; + this._properties[4] = 'alpha' in properties ? !!properties.alpha : this._properties[4]; + } +}; + +/** + * Updates the object transform for rendering + * + * @private + */ +ParticleContainer.prototype.updateTransform = function () +{ + + // TODO don't need to! + this.displayObjectUpdateTransform(); + // PIXI.Container.prototype.updateTransform.call( this ); +}; + +/** + * Renders the container using the WebGL renderer + * + * @param renderer {PIXI.WebGLRenderer} The webgl renderer + * @private + */ +ParticleContainer.prototype.renderWebGL = function (renderer) +{ + if (!this.visible || this.worldAlpha <= 0 || !this.children.length || !this.renderable) + { + return; + } + + + if(!this.baseTexture) + { + this.baseTexture = this.children[0]._texture.baseTexture; + if(!this.baseTexture.hasLoaded) + { + this.baseTexture.once('update', function(){ + this.onChildrenChange(0); + }, this); + } + } + + + renderer.setObjectRenderer( renderer.plugins.particle ); + renderer.plugins.particle.render( this ); +}; + +/** + * Set the flag that static data should be updated to true + * + * @private + */ +ParticleContainer.prototype.onChildrenChange = function (smallestChildIndex) +{ + var bufferIndex = Math.floor(smallestChildIndex / this._batchSize); + if (bufferIndex < this._bufferToUpdate) { + this._bufferToUpdate = bufferIndex; + } +}; + +/** + * Renders the object using the Canvas renderer + * + * @param renderer {PIXI.CanvasRenderer} The canvas renderer + * @private + */ +ParticleContainer.prototype.renderCanvas = function (renderer) +{ + if (!this.visible || this.worldAlpha <= 0 || !this.children.length || !this.renderable) + { + return; + } + + var context = renderer.context; + var transform = this.worldTransform; + var isRotated = true; + + var positionX = 0; + var positionY = 0; + + var finalWidth = 0; + var finalHeight = 0; + + var compositeOperation = renderer.blendModes[this.blendMode]; + if (compositeOperation !== context.globalCompositeOperation) + { + context.globalCompositeOperation = compositeOperation; + } + + context.globalAlpha = this.worldAlpha; + + this.displayObjectUpdateTransform(); + + for (var i = 0; i < this.children.length; ++i) + { + var child = this.children[i]; + + if (!child.visible) + { + continue; + } + + var frame = child.texture.frame; + + context.globalAlpha = this.worldAlpha * child.alpha; + + if (child.rotation % (Math.PI * 2) === 0) + { + // this is the fastest way to optimise! - if rotation is 0 then we can avoid any kind of setTransform call + if (isRotated) + { + context.setTransform( + transform.a, + transform.b, + transform.c, + transform.d, + transform.tx * renderer.resolution, + transform.ty * renderer.resolution + ); + + isRotated = false; + } + + positionX = ((child.anchor.x) * (-frame.width * child.scale.x) + child.position.x + 0.5); + positionY = ((child.anchor.y) * (-frame.height * child.scale.y) + child.position.y + 0.5); + + finalWidth = frame.width * child.scale.x; + finalHeight = frame.height * child.scale.y; + + } + else + { + if (!isRotated) + { + isRotated = true; + } + + child.displayObjectUpdateTransform(); + + var childTransform = child.worldTransform; + + if (renderer.roundPixels) + { + context.setTransform( + childTransform.a, + childTransform.b, + childTransform.c, + childTransform.d, + (childTransform.tx * renderer.resolution) | 0, + (childTransform.ty * renderer.resolution) | 0 + ); + } + else + { + context.setTransform( + childTransform.a, + childTransform.b, + childTransform.c, + childTransform.d, + childTransform.tx * renderer.resolution, + childTransform.ty * renderer.resolution + ); + } + + positionX = ((child.anchor.x) * (-frame.width) + 0.5); + positionY = ((child.anchor.y) * (-frame.height) + 0.5); + + finalWidth = frame.width; + finalHeight = frame.height; + } + + var resolution = child.texture.baseTexture.resolution; + + context.drawImage( + child.texture.baseTexture.source, + frame.x * resolution, + frame.y * resolution, + frame.width * resolution, + frame.height * resolution, + positionX * resolution, + positionY * resolution, + finalWidth * resolution, + finalHeight * resolution + ); + } +}; + +/** + * Destroys the container + * + */ +ParticleContainer.prototype.destroy = function () { + core.Container.prototype.destroy.apply(this, arguments); + + if (this._buffers) { + for (var i = 0; i < this._buffers.length; ++i) { + this._buffers[i].destroy(); + } + } + + this._properties = null; + this._buffers = null; +}; -Resource._xhrTypeMap = { - // xml - 'xhtml': Resource.XHR_RESPONSE_TYPE.DOCUMENT, - 'html': Resource.XHR_RESPONSE_TYPE.DOCUMENT, - 'htm': Resource.XHR_RESPONSE_TYPE.DOCUMENT, - 'xml': Resource.XHR_RESPONSE_TYPE.DOCUMENT, - 'tmx': Resource.XHR_RESPONSE_TYPE.DOCUMENT, - 'tsx': Resource.XHR_RESPONSE_TYPE.DOCUMENT, - 'svg': Resource.XHR_RESPONSE_TYPE.DOCUMENT, +},{"../core":61}],158:[function(require,module,exports){ +/** + * @file Main export of the PIXI extras library + * @author Mat Groves + * @copyright 2013-2015 GoodBoyDigital + * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} + */ + +/** + * @namespace PIXI.particles + */ +module.exports = { + ParticleContainer: require('./ParticleContainer'), + ParticleRenderer: require('./webgl/ParticleRenderer') +}; - // images - 'gif': Resource.XHR_RESPONSE_TYPE.BLOB, - 'png': Resource.XHR_RESPONSE_TYPE.BLOB, - 'bmp': Resource.XHR_RESPONSE_TYPE.BLOB, - 'jpg': Resource.XHR_RESPONSE_TYPE.BLOB, - 'jpeg': Resource.XHR_RESPONSE_TYPE.BLOB, - 'tif': Resource.XHR_RESPONSE_TYPE.BLOB, - 'tiff': Resource.XHR_RESPONSE_TYPE.BLOB, - 'webp': Resource.XHR_RESPONSE_TYPE.BLOB, - 'tga': Resource.XHR_RESPONSE_TYPE.BLOB, +},{"./ParticleContainer":157,"./webgl/ParticleRenderer":160}],159:[function(require,module,exports){ +var glCore = require('pixi-gl-core'), + createIndicesForQuads = require('../../core/utils/createIndicesForQuads'); + +/** + * @author Mat Groves + * + * Big thanks to the very clever Matt DesLauriers https://github.com/mattdesl/ + * for creating the original pixi version! + * Also a thanks to https://github.com/bchevalier for tweaking the tint and alpha so that they now share 4 bytes on the vertex buffer + * + * Heavily inspired by LibGDX's ParticleBuffer: + * https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/graphics/g2d/ParticleBuffer.java + */ + +/** + * The particle buffer manages the static and dynamic buffers for a particle container. + * + * @class + * @private + * @memberof PIXI + */ +function ParticleBuffer(gl, properties, dynamicPropertyFlags, size) +{ + /** + * The current WebGL drawing context. + * + * @member {WebGLRenderingContext} + */ + this.gl = gl; + + /** + * Size of a single vertex. + * + * @member {number} + */ + this.vertSize = 2; + + /** + * Size of a single vertex in bytes. + * + * @member {number} + */ + this.vertByteSize = this.vertSize * 4; + + /** + * The number of particles the buffer can hold + * + * @member {number} + */ + this.size = size; + + /** + * A list of the properties that are dynamic. + * + * @member {object[]} + */ + this.dynamicProperties = []; + + /** + * A list of the properties that are static. + * + * @member {object[]} + */ + this.staticProperties = []; + + for (var i = 0; i < properties.length; i++) + { + var property = properties[i]; + + // Make copy of properties object so that when we edit the offset it doesn't + // change all other instances of the object literal + property = + { + attribute:property.attribute, + size:property.size, + uploadFunction:property.uploadFunction, + offset:property.offset + }; + + if(dynamicPropertyFlags[i]) + { + this.dynamicProperties.push(property); + } + else + { + this.staticProperties.push(property); + } + } + + this.staticStride = 0; + this.staticBuffer = null; + this.staticData = null; + + this.dynamicStride = 0; + this.dynamicBuffer = null; + this.dynamicData = null; + + this.initBuffers(); + +} + +ParticleBuffer.prototype.constructor = ParticleBuffer; +module.exports = ParticleBuffer; + +/** + * Sets up the renderer context and necessary buffers. + * + * @private + */ +ParticleBuffer.prototype.initBuffers = function () +{ + var gl = this.gl; + var i; + var property; + + var dynamicOffset = 0; + + + /** + * Holds the indices of the geometry (quads) to draw + * + * @member {Uint16Array} + */ + this.indices = createIndicesForQuads(this.size); + this.indexBuffer = glCore.GLBuffer.createIndexBuffer(gl, this.indices, gl.STATIC_DRAW); + + + this.dynamicStride = 0; + + for (i = 0; i < this.dynamicProperties.length; i++) + { + property = this.dynamicProperties[i]; + + property.offset = dynamicOffset; + dynamicOffset += property.size; + this.dynamicStride += property.size; + } + + this.dynamicData = new Float32Array( this.size * this.dynamicStride * 4); + this.dynamicBuffer = glCore.GLBuffer.createVertexBuffer(gl, this.dynamicData, gl.STREAM_DRAW); + + // static // + var staticOffset = 0; + this.staticStride = 0; + + for (i = 0; i < this.staticProperties.length; i++) + { + property = this.staticProperties[i]; + + property.offset = staticOffset; + staticOffset += property.size; + this.staticStride += property.size; + + + } + + this.staticData = new Float32Array( this.size * this.staticStride * 4); + this.staticBuffer = glCore.GLBuffer.createVertexBuffer(gl, this.staticData, gl.STATIC_DRAW); + + + this.vao = new glCore.VertexArrayObject(gl) + .addIndex(this.indexBuffer); + + for (i = 0; i < this.dynamicProperties.length; i++) + { + property = this.dynamicProperties[i]; + this.vao.addAttribute(this.dynamicBuffer, property.attribute, gl.FLOAT, false, this.dynamicStride * 4, property.offset * 4); + } + + for (i = 0; i < this.staticProperties.length; i++) + { + property = this.staticProperties[i]; + this.vao.addAttribute(this.staticBuffer, property.attribute, gl.FLOAT, false, this.staticStride * 4, property.offset * 4); + } +}; + +/** + * Uploads the dynamic properties. + * + */ +ParticleBuffer.prototype.uploadDynamic = function(children, startIndex, amount) +{ + for (var i = 0; i < this.dynamicProperties.length; i++) + { + var property = this.dynamicProperties[i]; + property.uploadFunction(children, startIndex, amount, this.dynamicData, this.dynamicStride, property.offset); + } + + this.dynamicBuffer.upload(); +}; + +/** + * Uploads the static properties. + * + */ +ParticleBuffer.prototype.uploadStatic = function(children, startIndex, amount) +{ + for (var i = 0; i < this.staticProperties.length; i++) + { + var property = this.staticProperties[i]; + property.uploadFunction(children, startIndex, amount, this.staticData, this.staticStride, property.offset); + } + + this.staticBuffer.upload(); +}; + +/** + * Binds the buffers to the GPU + * + */ +ParticleBuffer.prototype.bind = function () +{ + this.vao.bind(); +}; + +/** + * Destroys the ParticleBuffer. + * + */ +ParticleBuffer.prototype.destroy = function () +{ + this.dynamicProperties = null; + this.dynamicData = null; + this.dynamicBuffer.destroy(); + + this.staticProperties = null; + this.staticData = null; + this.staticBuffer.destroy(); +}; - // json - 'json': Resource.XHR_RESPONSE_TYPE.JSON, +},{"../../core/utils/createIndicesForQuads":113,"pixi-gl-core":14}],160:[function(require,module,exports){ +var core = require('../../core'), + ParticleShader = require('./ParticleShader'), + ParticleBuffer = require('./ParticleBuffer'); + +/** + * @author Mat Groves + * + * Big thanks to the very clever Matt DesLauriers https://github.com/mattdesl/ + * for creating the original pixi version! + * Also a thanks to https://github.com/bchevalier for tweaking the tint and alpha so that they now share 4 bytes on the vertex buffer + * + * Heavily inspired by LibGDX's ParticleRenderer: + * https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/graphics/g2d/ParticleRenderer.java + */ + +/** + * + * @class + * @private + * @memberof PIXI + * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. + */ +function ParticleRenderer(renderer) +{ + core.ObjectRenderer.call(this, renderer); + + // 65535 is max vertex index in the index buffer (see ParticleRenderer) + // so max number of particles is 65536 / 4 = 16384 + // and max number of element in the index buffer is 16384 * 6 = 98304 + // Creating a full index buffer, overhead is 98304 * 2 = 196Ko + // var numIndices = 98304; + + /** + * The default shader that is used if a sprite doesn't have a more specific one. + * + * @member {PIXI.Shader} + */ + this.shader = null; + + this.indexBuffer = null; + + this.properties = null; + + this.tempMatrix = new core.Matrix(); + + this.CONTEXT_UID = 0; +} + +ParticleRenderer.prototype = Object.create(core.ObjectRenderer.prototype); +ParticleRenderer.prototype.constructor = ParticleRenderer; +module.exports = ParticleRenderer; + +core.WebGLRenderer.registerPlugin('particle', ParticleRenderer); + +/** + * When there is a WebGL context change + * + * @private + */ +ParticleRenderer.prototype.onContextChange = function () +{ + var gl = this.renderer.gl; + + this.CONTEXT_UID = this.renderer.CONTEXT_UID; + + // setup default shader + this.shader = new ParticleShader(gl); + + this.properties = [ + // verticesData + { + attribute:this.shader.attributes.aVertexPosition, + size:2, + uploadFunction:this.uploadVertices, + offset:0 + }, + // positionData + { + attribute:this.shader.attributes.aPositionCoord, + size:2, + uploadFunction:this.uploadPosition, + offset:0 + }, + // rotationData + { + attribute:this.shader.attributes.aRotation, + size:1, + uploadFunction:this.uploadRotation, + offset:0 + }, + // uvsData + { + attribute:this.shader.attributes.aTextureCoord, + size:2, + uploadFunction:this.uploadUvs, + offset:0 + }, + // alphaData + { + attribute:this.shader.attributes.aColor, + size:1, + uploadFunction:this.uploadAlpha, + offset:0 + } + ]; + +}; + +/** + * Starts a new particle batch. + * + */ +ParticleRenderer.prototype.start = function () +{ + this.renderer.bindShader(this.shader); +}; + + +/** + * Renders the particle container object. + * + * @param container {PIXI.ParticleContainer} The container to render using this ParticleRenderer + */ +ParticleRenderer.prototype.render = function (container) +{ + var children = container.children, + totalChildren = children.length, + maxSize = container._maxSize, + batchSize = container._batchSize; + + if(totalChildren === 0) + { + return; + } + else if(totalChildren > maxSize) + { + totalChildren = maxSize; + } + + var buffers = container._glBuffers[this.renderer.CONTEXT_UID]; + + if(!buffers) + { + buffers = container._glBuffers[this.renderer.CONTEXT_UID] = this.generateBuffers( container ); + } + + // if the uvs have not updated then no point rendering just yet! + this.renderer.setBlendMode(container.blendMode); + + var gl = this.renderer.gl; + + var m = container.worldTransform.copy( this.tempMatrix ); + m.prepend( this.renderer._activeRenderTarget.projectionMatrix ); + this.shader.uniforms.projectionMatrix = m.toArray(true); + this.shader.uniforms.uAlpha = container.worldAlpha; + + + // make sure the texture is bound.. + var baseTexture = children[0]._texture.baseTexture; + + this.renderer.bindTexture(baseTexture); + + // now lets upload and render the buffers.. + for (var i = 0, j = 0; i < totalChildren; i += batchSize, j += 1) + { + var amount = ( totalChildren - i); + if(amount > batchSize) + { + amount = batchSize; + } + + var buffer = buffers[j]; + + // we always upload the dynamic + buffer.uploadDynamic(children, i, amount); + + // we only upload the static content when we have to! + if(container._bufferToUpdate === j) + { + buffer.uploadStatic(children, i, amount); + container._bufferToUpdate = j + 1; + } + + // bind the buffer + buffer.vao.bind() + .draw(gl.TRIANGLES, amount * 6) + .unbind(); + + // now draw those suckas! + // gl.drawElements(gl.TRIANGLES, amount * 6, gl.UNSIGNED_SHORT, 0); + // this.renderer.drawCount++; + } +}; + +/** + * Creates one particle buffer for each child in the container we want to render and updates internal properties + * + * @param container {PIXI.ParticleContainer} The container to render using this ParticleRenderer + */ +ParticleRenderer.prototype.generateBuffers = function (container) +{ + var gl = this.renderer.gl, + buffers = [], + size = container._maxSize, + batchSize = container._batchSize, + dynamicPropertyFlags = container._properties, + i; + + for (i = 0; i < size; i += batchSize) + { + buffers.push(new ParticleBuffer(gl, this.properties, dynamicPropertyFlags, batchSize)); + } + + return buffers; +}; + +/** + * Uploads the verticies. + * + * @param children {PIXI.DisplayObject[]} the array of display objects to render + * @param startIndex {number} the index to start from in the children array + * @param amount {number} the amount of children that will have their vertices uploaded + * @param array {number[]} + * @param stride {number} + * @param offset {number} + */ +ParticleRenderer.prototype.uploadVertices = function (children, startIndex, amount, array, stride, offset) +{ + var sprite, + texture, + trim, + orig, + sx, + sy, + w0, w1, h0, h1; + + for (var i = 0; i < amount; i++) { + + sprite = children[startIndex + i]; + texture = sprite._texture; + sx = sprite.scale.x; + sy = sprite.scale.y; + trim = texture.trim; + orig = texture.orig; + + if (trim) + { + // if the sprite is trimmed and is not a tilingsprite then we need to add the extra space before transforming the sprite coords.. + w1 = trim.x - sprite.anchor.x * orig.width; + w0 = w1 + trim.width; + + h1 = trim.y - sprite.anchor.y * orig.height; + h0 = h1 + trim.height; + + } + else + { + w0 = (orig.width ) * (1-sprite.anchor.x); + w1 = (orig.width ) * -sprite.anchor.x; + + h0 = orig.height * (1-sprite.anchor.y); + h1 = orig.height * -sprite.anchor.y; + } + + array[offset] = w1 * sx; + array[offset + 1] = h1 * sy; + + array[offset + stride] = w0 * sx; + array[offset + stride + 1] = h1 * sy; + + array[offset + stride * 2] = w0 * sx; + array[offset + stride * 2 + 1] = h0 * sy; + + array[offset + stride * 3] = w1 * sx; + array[offset + stride * 3 + 1] = h0 * sy; + + offset += stride * 4; + } + +}; + +/** + * + * @param children {PIXI.DisplayObject[]} the array of display objects to render + * @param startIndex {number} the index to start from in the children array + * @param amount {number} the amount of children that will have their positions uploaded + * @param array {number[]} + * @param stride {number} + * @param offset {number} + */ +ParticleRenderer.prototype.uploadPosition = function (children,startIndex, amount, array, stride, offset) +{ + for (var i = 0; i < amount; i++) + { + var spritePosition = children[startIndex + i].position; + + array[offset] = spritePosition.x; + array[offset + 1] = spritePosition.y; + + array[offset + stride] = spritePosition.x; + array[offset + stride + 1] = spritePosition.y; + + array[offset + stride * 2] = spritePosition.x; + array[offset + stride * 2 + 1] = spritePosition.y; + + array[offset + stride * 3] = spritePosition.x; + array[offset + stride * 3 + 1] = spritePosition.y; + + offset += stride * 4; + } + +}; + +/** + * + * @param children {PIXI.DisplayObject[]} the array of display objects to render + * @param startIndex {number} the index to start from in the children array + * @param amount {number} the amount of children that will have their rotation uploaded + * @param array {number[]} + * @param stride {number} + * @param offset {number} + */ +ParticleRenderer.prototype.uploadRotation = function (children,startIndex, amount, array, stride, offset) +{ + for (var i = 0; i < amount; i++) + { + var spriteRotation = children[startIndex + i].rotation; + + + array[offset] = spriteRotation; + array[offset + stride] = spriteRotation; + array[offset + stride * 2] = spriteRotation; + array[offset + stride * 3] = spriteRotation; + + offset += stride * 4; + } +}; + +/** + * + * @param children {PIXI.DisplayObject[]} the array of display objects to render + * @param startIndex {number} the index to start from in the children array + * @param amount {number} the amount of children that will have their Uvs uploaded + * @param array {number[]} + * @param stride {number} + * @param offset {number} + */ +ParticleRenderer.prototype.uploadUvs = function (children,startIndex, amount, array, stride, offset) +{ + for (var i = 0; i < amount; i++) + { + var textureUvs = children[startIndex + i]._texture._uvs; + + if (textureUvs) + { + array[offset] = textureUvs.x0; + array[offset + 1] = textureUvs.y0; + + array[offset + stride] = textureUvs.x1; + array[offset + stride + 1] = textureUvs.y1; + + array[offset + stride * 2] = textureUvs.x2; + array[offset + stride * 2 + 1] = textureUvs.y2; + + array[offset + stride * 3] = textureUvs.x3; + array[offset + stride * 3 + 1] = textureUvs.y3; + + offset += stride * 4; + } + else + { + //TODO you know this can be easier! + array[offset] = 0; + array[offset + 1] = 0; + + array[offset + stride] = 0; + array[offset + stride + 1] = 0; + + array[offset + stride * 2] = 0; + array[offset + stride * 2 + 1] = 0; + + array[offset + stride * 3] = 0; + array[offset + stride * 3 + 1] = 0; + + offset += stride * 4; + } + } +}; + +/** + * + * @param children {PIXI.DisplayObject[]} the array of display objects to render + * @param startIndex {number} the index to start from in the children array + * @param amount {number} the amount of children that will have their alpha uploaded + * @param array {number[]} + * @param stride {number} + * @param offset {number} + */ +ParticleRenderer.prototype.uploadAlpha = function (children,startIndex, amount, array, stride, offset) +{ + for (var i = 0; i < amount; i++) + { + var spriteAlpha = children[startIndex + i].alpha; + + array[offset] = spriteAlpha; + array[offset + stride] = spriteAlpha; + array[offset + stride * 2] = spriteAlpha; + array[offset + stride * 3] = spriteAlpha; + + offset += stride * 4; + } +}; + + +/** + * Destroys the ParticleRenderer. + * + */ +ParticleRenderer.prototype.destroy = function () +{ + if (this.renderer.gl) { + this.renderer.gl.deleteBuffer(this.indexBuffer); + } + core.ObjectRenderer.prototype.destroy.apply(this, arguments); + + this.shader.destroy(); + + this.indices = null; + this.tempMatrix = null; +}; - // text - 'text': Resource.XHR_RESPONSE_TYPE.TEXT, - 'txt': Resource.XHR_RESPONSE_TYPE.TEXT -}; +},{"../../core":61,"./ParticleBuffer":159,"./ParticleShader":161}],161:[function(require,module,exports){ +var Shader = require('../../core/Shader'); + +/** + * @class + * @extends PIXI.Shader + * @memberof PIXI + * @param gl {PIXI.Shader} The webgl shader manager this shader works for. + */ +function ParticleShader(gl) +{ + Shader.call(this, + gl, + // vertex shader + [ + 'attribute vec2 aVertexPosition;', + 'attribute vec2 aTextureCoord;', + 'attribute float aColor;', + + 'attribute vec2 aPositionCoord;', + 'attribute vec2 aScale;', + 'attribute float aRotation;', + + 'uniform mat3 projectionMatrix;', + + 'varying vec2 vTextureCoord;', + 'varying float vColor;', + + 'void main(void){', + ' vec2 v = aVertexPosition;', + + ' v.x = (aVertexPosition.x) * cos(aRotation) - (aVertexPosition.y) * sin(aRotation);', + ' v.y = (aVertexPosition.x) * sin(aRotation) + (aVertexPosition.y) * cos(aRotation);', + ' v = v + aPositionCoord;', + + ' gl_Position = vec4((projectionMatrix * vec3(v, 1.0)).xy, 0.0, 1.0);', + + ' vTextureCoord = aTextureCoord;', + ' vColor = aColor;', + '}' + ].join('\n'), + // hello + [ + 'varying vec2 vTextureCoord;', + 'varying float vColor;', + + 'uniform sampler2D uSampler;', + 'uniform float uAlpha;', + + 'void main(void){', + ' vec4 color = texture2D(uSampler, vTextureCoord) * vColor * uAlpha;', + ' if (color.a == 0.0) discard;', + ' gl_FragColor = color;', + '}' + ].join('\n') + ); + + // TEMP HACK + +} + +ParticleShader.prototype = Object.create(Shader.prototype); +ParticleShader.prototype.constructor = ParticleShader; + +module.exports = ParticleShader; -/** - * Sets the load type to be used for a specific extension. - * - * @static - * @param extname {string} The extension to set the type for, e.g. "png" or "fnt" - * @param loadType {Resource.LOAD_TYPE} The load type to set it to. - */ -Resource.setExtensionLoadType = function (extname, loadType) { - setExtMap(Resource._loadTypeMap, extname, loadType); -}; +},{"../../core/Shader":41}],162:[function(require,module,exports){ +// References: +// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign + +if (!Math.sign) +{ + Math.sign = function (x) { + x = +x; + if (x === 0 || isNaN(x)) + { + return x; + } + return x > 0 ? 1 : -1; + }; +} -/** - * Sets the load type to be used for a specific extension. - * - * @static - * @param extname {string} The extension to set the type for, e.g. "png" or "fnt" - * @param xhrType {Resource.XHR_RESPONSE_TYPE} The xhr type to set it to. - */ -Resource.setExtensionXhrType = function (extname, xhrType) { - setExtMap(Resource._xhrTypeMap, extname, xhrType); -}; +},{}],163:[function(require,module,exports){ +// References: +// https://github.com/sindresorhus/object-assign +// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign + +if (!Object.assign) +{ + Object.assign = require('object-assign'); +} -function setExtMap(map, extname, val) { - if (extname && extname.indexOf('.') === 0) { - extname = extname.substring(1); - } +},{"object-assign":6}],164:[function(require,module,exports){ +require('./Object.assign'); +require('./requestAnimationFrame'); +require('./Math.sign'); + +if(!window.ArrayBuffer){ + window.ArrayBuffer = Array; +} +if(!window.Float32Array) { + window.Float32Array = Array; +} +if(!window.Uint32Array){ + window.Uint32Array = Array; +} +if(!window.Uint16Array){ + window.Uint16Array = Array; +} - if (!extname) { - return; - } +},{"./Math.sign":162,"./Object.assign":163,"./requestAnimationFrame":165}],165:[function(require,module,exports){ +(function (global){ +// References: +// http://paulirish.com/2011/requestanimationframe-for-smart-animating/ +// https://gist.github.com/1579671 +// http://updates.html5rocks.com/2012/05/requestAnimationFrame-API-now-with-sub-millisecond-precision +// https://gist.github.com/timhall/4078614 +// https://github.com/Financial-Times/polyfill-service/tree/master/polyfills/requestAnimationFrame + +// Expected to be used with Browserfiy +// Browserify automatically detects the use of `global` and passes the +// correct reference of `global`, `self`, and finally `window` + +// Date.now +if (!(Date.now && Date.prototype.getTime)) { + Date.now = function now() { + return new Date().getTime(); + }; +} + +// performance.now +if (!(global.performance && global.performance.now)) { + var startTime = Date.now(); + if (!global.performance) { + global.performance = {}; + } + global.performance.now = function () { + return Date.now() - startTime; + }; +} + +// requestAnimationFrame +var lastTime = Date.now(); +var vendors = ['ms', 'moz', 'webkit', 'o']; + +for(var x = 0; x < vendors.length && !global.requestAnimationFrame; ++x) { + global.requestAnimationFrame = global[vendors[x] + 'RequestAnimationFrame']; + global.cancelAnimationFrame = global[vendors[x] + 'CancelAnimationFrame'] || + global[vendors[x] + 'CancelRequestAnimationFrame']; +} + +if (!global.requestAnimationFrame) { + global.requestAnimationFrame = function (callback) { + if (typeof callback !== 'function') { + throw new TypeError(callback + 'is not a function'); + } + + var currentTime = Date.now(), + delay = 16 + lastTime - currentTime; + + if (delay < 0) { + delay = 0; + } + + lastTime = currentTime; + + return setTimeout(function () { + lastTime = Date.now(); + callback(performance.now()); + }, delay); + }; +} + +if (!global.cancelAnimationFrame) { + global.cancelAnimationFrame = function(id) { + clearTimeout(id); + }; +} - map[extname] = val; -} +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"eventemitter3":2,"url":10}],150:[function(require,module,exports){ +},{}],166:[function(require,module,exports){ +var core = require('../../core'); + +/** + * Prepare uploads elements to the GPU. The CanvasRenderer version of prepare + * provides the same APIs as the WebGL version, but doesn't do anything. + * @class + * @memberof PIXI + * @param renderer {PIXI.CanvasRenderer} A reference to the current renderer + */ +function CanvasPrepare() +{ +} + +CanvasPrepare.prototype.constructor = CanvasPrepare; +module.exports = CanvasPrepare; + +/** + * Stub method for upload. + * @param {Function|PIXI.DisplayObject|PIXI.Container} item Either + * the container or display object to search for items to upload or + * the callback function, if items have been added using `prepare.add`. + * @param {Function} done When completed + */ +CanvasPrepare.prototype.upload = function(displayObject, done) +{ + if (typeof displayObject === 'function') + { + done = displayObject; + displayObject = null; + } + done(); +}; + +/** + * Stub method for registering hooks. + * @return {PIXI.CanvasPrepare} Instance of plugin for chaining. + */ +CanvasPrepare.prototype.register = function() +{ + return this; +}; + +/** + * Stub method for adding items. + * @return {PIXI.CanvasPrepare} Instance of plugin for chaining. + */ +CanvasPrepare.prototype.add = function() +{ + return this; +}; + +/** + * Stub method for destroying plugin. + */ +CanvasPrepare.prototype.destroy = function() +{ +}; + +core.CanvasRenderer.registerPlugin('prepare', CanvasPrepare); +},{"../../core":61}],167:[function(require,module,exports){ + module.exports = { + webGL: require('./webgl/WebGLPrepare'), + canvas: require('./canvas/CanvasPrepare') +}; +},{"./canvas/CanvasPrepare":166,"./webgl/WebGLPrepare":168}],168:[function(require,module,exports){ +var core = require('../../core'), + SharedTicker = core.ticker.shared; - // private property - _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", - - encodeBinary: function (input) { - var output = ""; - var bytebuffer; - var encodedCharIndexes = new Array(4); - var inx = 0; - var jnx = 0; - var paddingBytes = 0; - - while (inx < input.length) { - // Fill byte buffer array - bytebuffer = new Array(3); - for (jnx = 0; jnx < bytebuffer.length; jnx++) { - if (inx < input.length) { - // throw away high-order byte, as documented at: - // https://developer.mozilla.org/En/Using_XMLHttpRequest#Handling_binary_data - bytebuffer[jnx] = input.charCodeAt(inx++) & 0xff; - } - else { - bytebuffer[jnx] = 0; - } - } +/** + * The prepare manager provides functionality to upload content to the GPU + * @class + * @memberof PIXI + * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer + */ +function WebGLPrepare(renderer) +{ + /** + * Reference to the renderer. + * @type {PIXI.WebGLRenderer} + * @private + */ + this.renderer = renderer; - // Get each encoded character, 6 bits at a time - // index 1: first 6 bits - encodedCharIndexes[0] = bytebuffer[0] >> 2; - // index 2: second 6 bits (2 least significant bits from input byte 1 + 4 most significant bits from byte 2) - encodedCharIndexes[1] = ((bytebuffer[0] & 0x3) << 4) | (bytebuffer[1] >> 4); - // index 3: third 6 bits (4 least significant bits from input byte 2 + 2 most significant bits from byte 3) - encodedCharIndexes[2] = ((bytebuffer[1] & 0x0f) << 2) | (bytebuffer[2] >> 6); - // index 3: forth 6 bits (6 least significant bits from input byte 3) - encodedCharIndexes[3] = bytebuffer[2] & 0x3f; - - // Determine whether padding happened, and adjust accordingly - paddingBytes = inx - (input.length - 1); - switch (paddingBytes) { - case 2: - // Set last 2 characters to padding char - encodedCharIndexes[3] = 64; - encodedCharIndexes[2] = 64; - break; + /** + * Collection of items to uploads at once. + * @type {Array<*>} + * @private + */ + this.queue = []; - case 1: - // Set last character to padding char - encodedCharIndexes[3] = 64; - break; + /** + * Collection of additional hooks for finding assets. + * @type {Array} + * @private + */ + this.addHooks = []; - default: - break; // No padding - proceed - } + /** + * Collection of additional hooks for processing assets. + * @type {Array} + * @private + */ + this.uploadHooks = []; - // Now we will grab each appropriate character out of our keystring - // based on our index array and append it to the output string - for (jnx = 0; jnx < encodedCharIndexes.length; jnx++) { - output += this._keyStr.charAt(encodedCharIndexes[jnx]); - } - } - return output; + /** + * Callback to call after completed. + * @type {Array} + * @private + */ + this.completes = []; + + /** + * If prepare is ticking (running). + * @type {boolean} + * @private + */ + this.ticking = false; + + // Add textures and graphics to upload + this.register(findBaseTextures, uploadBaseTextures) + .register(findGraphics, uploadGraphics); +} + +/** + * The number of graphics or textures to upload to the GPU + * @property {number} UPLOADS_PER_FRAME + * @static + * @default 4 + */ +WebGLPrepare.UPLOADS_PER_FRAME = 4; + +WebGLPrepare.prototype.constructor = WebGLPrepare; +module.exports = WebGLPrepare; + +/** + * Upload all the textures and graphics to the GPU. + * @param {Function|PIXI.DisplayObject|PIXI.Container} item Either + * the container or display object to search for items to upload or + * the callback function, if items have been added using `prepare.add`. + * @param {Function} done When completed + */ +WebGLPrepare.prototype.upload = function(item, done) +{ + if (typeof item === 'function') + { + done = item; + item = null; } -}; - -},{}],151:[function(require,module,exports){ -module.exports = require('./Loader'); -module.exports.Resource = require('./Resource'); + // If a display object, search for items + // that we could upload + if (item) + { + this.add(item); + } -module.exports.middleware = { - caching: { - memory: require('./middlewares/caching/memory') - }, - parsing: { - blob: require('./middlewares/parsing/blob') + // Get the items for upload from the display + if (this.queue.length) + { + this.numLeft = WebGLPrepare.UPLOADS_PER_FRAME; + this.completes.push(done); + if (!this.ticking) + { + this.ticking = true; + SharedTicker.add(this.tick, this); + } + } + else + { + done(); } }; - -},{"./Loader":148,"./Resource":149,"./middlewares/caching/memory":152,"./middlewares/parsing/blob":153}],152:[function(require,module,exports){ -// a simple in-memory cache for resources -var cache = {}; -module.exports = function () { - return function (resource, next) { - // if cached, then set data and complete the resource - if (cache[resource.url]) { - resource.data = cache[resource.url]; - resource.complete(); +/** + * Handle tick update + * @private + */ +WebGLPrepare.prototype.tick = function() +{ + var i, len; + + // Upload the graphics + while(this.queue.length && this.numLeft > 0) + { + var item = this.queue[0]; + var uploaded = false; + for (i = 0, len = this.uploadHooks.length; i < len; i++) + { + if (this.uploadHooks[i](this.renderer, item)) + { + this.numLeft--; + this.queue.shift(); + uploaded = true; + break; + } } - // if not cached, wait for complete and store it in the cache. - else { - resource.once('complete', function () { - cache[this.url] = this.data; - }); + if (!uploaded) + { + this.queue.shift(); } - - next(); - }; + } + + // We're finished + if (this.queue.length) + { + this.numLeft = WebGLPrepare.UPLOADS_PER_FRAME; + } + else + { + this.ticking = false; + SharedTicker.remove(this.tick, this); + var completes = this.completes.slice(0); + this.completes.length = 0; + for (i = 0, len = completes.length; i < len; i++) + { + completes[i](); + } + } }; - -},{}],153:[function(require,module,exports){ -var Resource = require('../../Resource'), - b64 = require('../../b64'); -window.URL = window.URL || window.webkitURL; +/** + * Adds hooks for finding and uploading items. + * @param {Function} [addHook] Function call that takes two parameters: `item:*, queue:Array` + function must return `true` if it was able to add item to the queue. + * @param {Function} [uploadHook] Function call that takes two parameters: `renderer:WebGLRenderer, item:*` and + * function must return `true` if it was able to handle upload of item. + * @return {PIXI.WebGLPrepare} Instance of plugin for chaining. + */ +WebGLPrepare.prototype.register = function(addHook, uploadHook) +{ + if (addHook) + { + this.addHooks.push(addHook); + } + if (uploadHook) + { + this.uploadHooks.push(uploadHook); + } + return this; +}; -// a middleware for transforming XHR loaded Blobs into more useful objects +/** + * Manually add an item to the uploading queue. + * @param {PIXI.DisplayObject|PIXI.Container|*} item Object to add to the queue + * @return {PIXI.WebGLPrepare} Instance of plugin for chaining. + */ +WebGLPrepare.prototype.add = function(item) +{ + var i, len; -module.exports = function () { - return function (resource, next) { - if (!resource.data) { - return next(); + // Add additional hooks for finding elements on special + // types of objects that + for (i = 0, len = this.addHooks.length; i < len; i++) + { + if (this.addHooks[i](item, this.queue)) + { + break; + } + } + + // Get childen recursively + if (item instanceof core.Container) + { + for (i = item.children.length - 1; i >= 0; i--) + { + this.add(item.children[i]); } + } + return this; +}; + +/** + * Destroys the plugin, don't use after this. + */ +WebGLPrepare.prototype.destroy = function() +{ + if (this.ticking) + { + SharedTicker.remove(this.tick, this); + } + this.ticking = false; + this.addHooks = null; + this.uploadHooks = null; + this.renderer = null; + this.completes = null; + this.queue = null; +}; + +/** + * Built-in hook to upload PIXI.Texture objects to the GPU + * @private + * @param {*} item Item to check + * @return {boolean} If item was uploaded. + */ +function uploadBaseTextures(renderer, item) +{ + if (item instanceof core.BaseTexture) + { + renderer.textureManager.updateTexture(item); + return true; + } + return false; +} - // if this was an XHR load of a blob - if (resource.xhr && resource.xhrType === Resource.XHR_RESPONSE_TYPE.BLOB) { - // if there is no blob support we probably got a binary string back - if (!window.Blob || typeof resource.data === 'string') { - var type = resource.xhr.getResponseHeader('content-type'); +/** + * Built-in hook to upload PIXI.Graphics to the GPU + * @private + * @param {*} item Item to check + * @return {boolean} If item was uploaded. + */ +function uploadGraphics(renderer, item) +{ + if (item instanceof core.Graphics) + { + renderer.plugins.graphics.updateGraphics(item); + return true; + } + return false; +} - // this is an image, convert the binary string into a data url - if (type && type.indexOf('image') === 0) { - resource.data = new Image(); - resource.data.src = 'data:' + type + ';base64,' + b64.encodeBinary(resource.xhr.responseText); +/** + * Built-in hook to find textures from Sprites + * @private + * @param {PIXI.DisplayObject} item Display object to check + * @param {Array<*>} queue Collection of items to upload + * @return {boolean} if a PIXI.Texture object was found. + */ +function findBaseTextures(item, queue) +{ + // Objects with textures, like Sprites/Text + if (item instanceof core.BaseTexture) + { + if (queue.indexOf(item) === -1) + { + queue.push(item); + } + return true; + } + else if (item._texture && item._texture instanceof core.Texture) + { + var texture = item._texture.baseTexture; + if (queue.indexOf(texture) === -1) + { + queue.push(texture); + } + return true; + } + return false; +} - resource.isImage = true; +/** + * Built-in hook to find graphics + * @private + * @param {PIXI.DisplayObject} item Display object to check + * @param {Array<*>} queue Collection of items to upload + * @return {boolean} if a PIXI.Graphics object was found. + */ +function findGraphics(item, queue) +{ + if (item instanceof core.Graphics) + { + queue.push(item); + return true; + } + return false; +} - // wait until the image loads and then callback - resource.data.onload = function () { - resource.data.onload = null; +core.WebGLRenderer.registerPlugin('prepare', WebGLPrepare); +},{"../../core":61}],169:[function(require,module,exports){ +(function (global){ +// run the polyfills +require('./polyfill'); - next(); - }; - } - } - // if content type says this is an image, then we should transform the blob into an Image object - else if (resource.data.type.indexOf('image') === 0) { - var src = URL.createObjectURL(resource.data); +var core = module.exports = require('./core'); - resource.blob = resource.data; - resource.data = new Image(); - resource.data.src = src; +// add core plugins. +core.extras = require('./extras'); +core.filters = require('./filters'); +core.interaction = require('./interaction'); +core.loaders = require('./loaders'); +core.mesh = require('./mesh'); +core.particles = require('./particles'); +core.accessibility = require('./accessibility'); +core.extract = require('./extract'); +core.prepare = require('./prepare'); - resource.isImage = true; +// export a premade loader instance +/** + * A premade instance of the loader that can be used to loader resources. + * + * @name loader + * @memberof PIXI + * @property {PIXI.loaders.Loader} + */ +core.loader = new core.loaders.Loader(); - // cleanup the no longer used blob after the image loads - resource.data.onload = function () { - URL.revokeObjectURL(src); - resource.data.onload = null; +// mixin the deprecation features. +Object.assign(core, require('./deprecation')); - next(); - }; - } - } - else { - next(); - } - }; -}; +// Always export pixi globally. +global.PIXI = core; + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) + +},{"./accessibility":40,"./core":61,"./deprecation":118,"./extract":120,"./extras":128,"./filters":139,"./interaction":144,"./loaders":147,"./mesh":155,"./particles":158,"./polyfill":164,"./prepare":167}]},{},[169]) + -},{"../../Resource":149,"../../b64":150}]},{},[124])(124) -}); //# sourceMappingURL=pixi.js.map diff --git a/_site/js/plugins/pixi-display.js b/_site/js/plugins/pixi-display.js new file mode 100644 index 0000000..683dde7 --- /dev/null +++ b/_site/js/plugins/pixi-display.js @@ -0,0 +1,734 @@ +(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 b.zOrder) { + return -1; + } + return a.updateOrder - b.updateOrder; +}; + +/** + * clears temporary variables + */ +DisplayGroup.prototype.clear = function () { + var list = this.computedChildren; + for (var i = 0; i < list.length; i++) { + var children = list[i].displayChildren; + if (children && children.length > 0) { + for (var j = 0; j < children.length; j++) { + children[j].displayParent = null; + } + children.length = 0; + } + list[i].displayParent = null; + } + list.length = 0; + this.currentDisplayList = null; + this.currentIndex = 0; +}; + +/** + * used only by displayList before sorting takes place + * @param container {PIXI.DisplayObject} + */ +DisplayGroup.prototype.add = function (displayObject) { + displayObject.displayOrder = this.computedChildren.length; + this.emit('add', displayObject); + this.computedChildren.push(displayObject); +}; + +/** + * Called after all childrens are computed + */ +DisplayGroup.prototype.update = function () { + this.emit('update'); + if (this.enableSort && this.computedChildren.length > 1) { + this.computedChildren.sort(DisplayGroup.compareZOrder); + } +}; + +},{}],5:[function(require,module,exports){ +var EventEmitter = PIXI.utils.EventEmitter, + Const = require('./Const'), + DisplayGroup = require('./DisplayGroup'); +/** + * A component for container, sorts all children inside according to their displayGroups + * + * @class + * @extends EventEmitter + * @memberof PIXI + */ +function DisplayList() { + EventEmitter.call(this); + /** + * Children that were rendered in last run + * @type {Array} + */ + this.displayGroups = []; + + this.container = null; + + /** + * how many elements were rendered by display list last time + * also it is used to generate updateOrder for them + * @type {number} + */ + this.totalElements = 0; + + this.defaultDisplayGroup = new DisplayGroup(0, false); +} + +DisplayList.prototype = Object.create(EventEmitter.prototype); +DisplayList.prototype.constructor = DisplayList; +module.exports = DisplayList; + +/** + * clears all display lists that were used in last rendering session + * please clear it when you stop using this displayList, otherwise you may have problems with GC in some cases + */ +DisplayList.prototype.clear = function () { + var list = this.displayGroups; + for (var i = 0; i < list.length; i++) { + list[i].clear(); + } + list.length = 0; + this.totalElements = 0; + this.container = null; +}; + +/** + * alias for clear() + * please call it if you stop using this displayList + */ +DisplayList.prototype.destroy = function () { + this.clear(); +}; + +DisplayList.compareZIndex = function (a, b) { + if (a.zIndex !== b.zIndex) { + return a.zIndex - b.zIndex; + } + return a.currentIndex - b.currentIndex; +}; + +/** + * + * @param displayObject {PIXI.DisplayObject} container that we are adding to displaylist + * @param parent {PIXI.Container} it is not direct parent, but some of ancestors + * @private + */ +DisplayList.prototype._addRecursive = function (container, parent) { + if (!container.visible || !container.renderable) { + return; + } + var groups = this.displayGroups; + var group = parent.displayGroup; + + container.updateOrder = this.totalElements++; + if (container.displayGroup) { + group = container.displayGroup; + if (!group.currentDisplayList) { + group.currentDisplayList = this; + group.currentIndex = groups.length; + groups.push(group); + } + group.add(container); + + container.displayParent = container; + } else { + container.displayParent = parent; + if (!parent.displayChildren) { + parent.displayChildren = []; + } + parent.displayChildren.push(container); + } + + if (container.displayFlag !== Const.DISPLAY_FLAG.MANUAL_CONTAINER) { + var children = container.children; + if (children && children.length > 0) { + if (container._mask || container._filters && container._filters.length || container.displayList) { + container.displayFlag = Const.DISPLAY_FLAG.AUTO_CONTAINER; + } else { + container.displayFlag = Const.DISPLAY_FLAG.AUTO_CHILDREN; + for (var i = 0; i < children.length; i++) { + this._addRecursive(children[i], container.displayParent); + } + } + } else { + container.displayFlag = Const.DISPLAY_FLAG.AUTO_OBJECT; + } + } +}; + +/** + * Called from container that owns this display list + * @param parentContainer + */ +DisplayList.prototype.update = function (parentContainer) { + this.clear(); + var tempGroup = parentContainer.displayGroup; + this.displayGroups.push(this.defaultDisplayGroup); + this.defaultDisplayGroup.add(parentContainer); + + this.container = parentContainer; + var children = parentContainer.children; + var i; + for (i = 0; i < children.length; i++) { + this._addRecursive(children[i], parentContainer); + } + var groups = this.displayGroups; + groups.sort(DisplayList.compareZIndex); + for (i = 0; i < groups.length; i++) { + groups[i].currentIndex = i; + groups[i].update(); + } + this.emit('afterUpdate'); +}; + +/** + * renders container with webgl context + * @param parentContainer + * @param renderer + */ +DisplayList.prototype.renderWebGL = function (parentContainer, renderer) { + var groups = this.displayGroups; + for (var i = 0; i < groups.length; i++) { + var group = groups[i]; + var list = group.computedChildren; + for (var j = 0; j < list.length; j++) { + var container = list[j]; + if (container.displayFlag) { + container.renderWebGL(renderer); + } else { + container.displayOrder = renderer.incDisplayOrder(); + container._renderWebGL(renderer); + var children = container.displayChildren; + if (children && children.length) { + for (var k = 0; k < children.length; k++) { + var child = children[k]; + child.displayOrder = renderer.incDisplayOrder(); + if (child.displayFlag) { + child.renderWebGL(renderer); + } else { + child._renderWebGL(renderer); + } + } + } + } + } + } +}; + +/** + * renders container with canvas2d context + * @param parentContainer + * @param renderer + */ +DisplayList.prototype.renderCanvas = function (parentContainer, renderer) { + var groups = this.displayGroups; + for (var i = 0; i < groups.length; i++) { + var group = groups[i]; + var list = group.computedChildren; + for (var j = 0; j < list.length; j++) { + var container = list[j]; + if (container.displayFlag) { + container.renderCanvas(renderer); + } else { + container.displayOrder = renderer.incDisplayOrder(); + container._renderCanvas(renderer); + var children = container.displayChildren; + if (children && children.length) { + for (var k = 0; k < children.length; k++) { + var child = children[k]; + child.displayOrder = renderer.incDisplayOrder(); + if (child.displayFlag) { + child.renderCanvas(renderer); + } else { + child._renderCanvas(renderer); + } + } + } + } + } + } +}; + +},{"./Const":2,"./DisplayGroup":4}],6:[function(require,module,exports){ +var Const = require('./Const'); + +/** + * @mixin + */ +var DisplayObjectMixin = { + /** + * please specify it to handle zOrder and zIndex + * @type {PIXI.DisplayGroup} + */ + displayGroup: null, + + /** + * calculated inside displayList. Can be set to manual mode + * @type {number} + */ + displayFlag: Const.DISPLAY_FLAG.AUTO_CHILDREN, + + /** + * calculated inside displayList. Cleared on displayList.clear() + * Equal to 'this' if displayGroup is specified + * @type {PIXI.Container} + */ + displayParent: null, + + /** + * zOrder is distance between screen and object. Objects with largest zOrder will appear first in their DisplayGroup + * @type {number} + */ + zOrder: 0, + + /** + * updateOrder is calculated by DisplayList, it is required for sorting inside DisplayGroup + * @type {number} + */ + updateOrder: 0 +}; + +module.exports = DisplayObjectMixin; + +},{"./Const":2}],7:[function(require,module,exports){ +//TODO: add maxDisplayOrder for displayObjects and use it to speed up the interaction here + +var gameofbombs = !!PIXI.Camera2d; + +/** + * @mixin + */ +var InteractionManagerMixin = { + /** + * This is private recursive copy of processInteractive + */ + _processInteractive: function (point, displayObject, hitTestOrder, interactive) { + if (!displayObject || !displayObject.visible) { + return false; + } + + // Took a little while to rework this function correctly! But now it is done and nice and optimised. ^_^ + // + // This function will now loop through all objects and then only hit test the objects it HAS to, not all of them. MUCH faster.. + // An object will be hit test if the following is true: + // + // 1: It is interactive. + // 2: It belongs to a parent that is interactive AND one of the parents children have not already been hit. + // + // As another little optimisation once an interactive object has been hit we can carry on through the scenegraph, but we know that there will be no more hits! So we can avoid extra hit tests + // A final optimisation is that an object is not hit test directly if a child has already been hit. + + var hit = 0, + interactiveParent = interactive = displayObject.interactive || interactive; + + + // if the displayobject has a hitArea, then it does not need to hitTest children. + if (displayObject.hitArea) { + interactiveParent = false; + } + + // it has a mask! Then lets hit test that before continuing.. + if (hitTestOrder < Infinity && displayObject._mask) { + if (!displayObject._mask.containsPoint(point)) { + hitTestOrder = Infinity; + } + } + + // it has a filterArea! Same as mask but easier, its a rectangle + if (hitTestOrder < Infinity && displayObject.filterArea) { + if (!displayObject.filterArea.contains(point.x, point.y)) { + hitTestOrder = Infinity; + } + } + + // ** FREE TIP **! If an object is not interactive or has no buttons in it (such as a game scene!) set interactiveChildren to false for that displayObject. + // This will allow pixi to completly ignore and bypass checking the displayObjects children. + if (displayObject.interactiveChildren) { + var children = displayObject.children; + + for (var i = children.length - 1; i >= 0; i--) { + + var child = children[i]; + + var hitChild = this._processInteractive(point, child, hitTestOrder, interactiveParent); + // time to get recursive.. if this function will return if something is hit.. + if (hitChild) { + hit = hitChild; + hitTestOrder = hitChild; + } + } + } + + + // no point running this if the item is not interactive or does not have an interactive parent. + if (interactive) { + // if we are hit testing (as in we have no hit any objects yet) + // We also don't need to worry about hit testing if once of the displayObjects children has already been hit! + if (hitTestOrder < displayObject.displayOrder) { + if (gameofbombs) { + //gameofbombs version + if (displayObject.hitArea && displayObject.isRaycastPossible) { + if (displayObject.containsPoint(point)) { + hit = displayObject.displayOrder; + } + } + } else { + //pixi v4 + if (displayObject.hitArea) { + displayObject.worldTransform.applyInverse(point, this._tempPoint); + if (displayObject.hitArea.contains(this._tempPoint.x, this._tempPoint.y)) { + hit = displayObject.displayOrder; + } + } + else if (displayObject.containsPoint) { + if (displayObject.containsPoint(point)) { + hit = displayObject.displayOrder; + } + } + } + } + + if (displayObject.interactive) { + this._queueAdd(displayObject, hit); + } + } + + return hit; + + }, + + /** + * This function is provides a neat way of crawling through the scene graph and running a specified function on all interactive objects it finds. + * It will also take care of hit testing the interactive objects and passes the hit across in the function. + * + * @param {PIXI.Point} point the point that is tested for collision + * @param {PIXI.Container|PIXI.Sprite|PIXI.extras.TilingSprite} displayObject the displayObject that will be hit test (recursively crawls its children) + * @param {boolean} hitTest this indicates if the objects inside should be hit test against the point + * @param {Function} func the function that will be called on each interactive object. The displayObject and hit will be passed to the function + * @private + * @return {boolean} returns true if the displayObject hit the point + */ + processInteractive: function (point, displayObject, func, hitTest) { + this._startInteractionProcess(); + this._processInteractive(point, displayObject, hitTest ? 0 : Infinity, false); + this._finishInteractionProcess(func); + }, + + _startInteractionProcess: function () { + //move it to constructor + this._eventDisplayOrder = 1; + if (!this._queue) { + //move it to constructor + this._queue = [[], []]; + } + this._queue[0].length = 0; + this._queue[1].length = 0; + }, + + _queueAdd: function (displayObject, order) { + var queue = this._queue; + if (order < this._eventDisplayOrder) { + queue[0].push(displayObject); + } else { + if (order > this._eventDisplayOrder) { + this._eventDisplayOrder = order; + var q = queue[1]; + for (var i = 0; i < q.length; i++) { + queue[0].push(q[i]); + } + queue[1].length = 0; + } + queue[1].push(displayObject); + } + }, + + /** + * + * @param {Function} func the function that will be called on each interactive object. The displayObject and hit will be passed to the function + */ + _finishInteractionProcess: function (func) { + var queue = this._queue; + var q = queue[0]; + var i; + for (i = 0; i < q.length; i++) { + func(q[i], false); + } + q = queue[1]; + for (i = 0; i < q.length; i++) { + func(q[i], true); + } + } +}; + +module.exports = InteractionManagerMixin; + +},{}],8:[function(require,module,exports){ +/** + * @mixin + */ +var SystemRendererMixin = { + /** + * @private + * @type {number} + */ + _lastDisplayOrder: 0, + + /** + * gets new display order for container/displayobject + */ + incDisplayOrder: function() { + return ++this._lastDisplayOrder; + } +}; + +module.exports = SystemRendererMixin; + +},{}],9:[function(require,module,exports){ +/** + * @mixin + */ +var WebGLRendererMixin = { + _oldRender: PIXI.WebGLRenderer.prototype.render, + render: function (displayObject, renderTexture, clear, transform, skipUpdateTransform) { + if (!renderTexture) { + this._lastDisplayOrder = 0; + } + this._oldRender(displayObject, renderTexture, clear, transform, skipUpdateTransform); + } +}; + +module.exports = WebGLRendererMixin; + +},{}],10:[function(require,module,exports){ +var plugin = { + DisplayGroup: require('./DisplayGroup'), + DisplayList: require('./DisplayList'), + Const: require('./Const'), + DisplayObjectMixin: require('./DisplayObjectMixin'), + ContainerMixin: require('./ContainerMixin'), + SystemRendererMixin: require('./SystemRendererMixin'), + WebGLRendererMixin: require('./WebGLRendererMixin'), + CanvasRendererMixin: require('./CanvasRendererMixin'), + InteractionManagerMixin: require('./InteractionManagerMixin') +}; + +var pluginMixin = { + DisplayGroup: plugin.DisplayGroup, + DisplayList: plugin.DisplayList +}; + +Object.assign(pluginMixin, plugin.Const); + +Object.assign(PIXI.DisplayObject.prototype, plugin.DisplayObjectMixin); + +Object.assign(PIXI.Container.prototype, plugin.ContainerMixin); + +Object.assign(PIXI.WebGLRenderer.prototype, plugin.SystemRendererMixin, plugin.WebGLRendererMixin); + +Object.assign(PIXI.CanvasRenderer.prototype, plugin.SystemRendererMixin, plugin.CanvasRendererMixin); + +Object.assign(PIXI.interaction.InteractionManager.prototype, plugin.InteractionManagerMixin); + +Object.assign(PIXI, pluginMixin); + +module.exports = plugin; + +},{"./CanvasRendererMixin":1,"./Const":2,"./ContainerMixin":3,"./DisplayGroup":4,"./DisplayList":5,"./DisplayObjectMixin":6,"./InteractionManagerMixin":7,"./SystemRendererMixin":8,"./WebGLRendererMixin":9}]},{},[10]) + + +//# sourceMappingURL=pixi-display.js.map diff --git a/_site/js/plugins/pixi-picture.js b/_site/js/plugins/pixi-picture.js new file mode 100644 index 0000000..d1379a7 --- /dev/null +++ b/_site/js/plugins/pixi-picture.js @@ -0,0 +1,383 @@ +(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 0.0) {\n\n Cs = target.rgb / target.a;\n\n }\n\n vec3 multiply = Cb * Cs * 2.0;\n\n vec3 Cs2 = Cs * 2.0 - 1.0;\n\n vec3 screen = Cb + Cs2 - Cb * Cs2;\n\n vec3 B;\n\n if (Cb.r <= 0.5) {\n\n B.r = multiply.r;\n\n } else {\n\n B.r = screen.r;\n\n }\n\n if (Cb.g <= 0.5) {\n\n B.g = multiply.g;\n\n } else {\n\n B.g = screen.g;\n\n }\n\n if (Cb.b <= 0.5) {\n\n B.b = multiply.b;\n\n } else {\n\n B.b = screen.b;\n\n }\n\n vec4 res;\n\n res.xyz = (1.0 - source.a) * Cs + source.a * B;\n\n res.a = source.a + target.a * (1.0-source.a);\n\n gl_FragColor = vec4(res.xyz * res.a, res.a);\n\n}\n\n" + ); + this.bind(); + this.uniforms.uSampler = [0, 1]; +} + +OverlayShader.prototype = Object.create(PIXI.Shader.prototype); +OverlayShader.prototype.constructor = OverlayShader; +module.exports = OverlayShader; + +},{}],2:[function(require,module,exports){ + + +/** + * @class + * @extends PIXI.Shader + * @memberof PIXI.tilemap + * @param gl {PIXI.Shader} The WebGL shader manager this shader works for. + */ +function OverlayShader(gl) +{ + PIXI.Shader.call(this, + gl, + "#define GLSLIFY 1\nattribute vec2 aVertexPosition;\n\nattribute vec2 aTextureCoord;\n\nattribute vec4 aColor;\n\nuniform mat3 projectionMatrix;\n\nuniform mat3 mapMatrix;\n\nvarying vec2 vTextureCoord;\n\nvarying vec2 vMapCoord;\n\nvoid main(void)\n\n{\n\n gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\n\n vMapCoord = (mapMatrix * vec3(aVertexPosition, 1.0)).xy;\n\n vTextureCoord = aTextureCoord;\n\n}\n\n", + "#define GLSLIFY 1\nvarying vec2 vTextureCoord;\n\nvarying vec2 vMapCoord;\n\nvarying vec4 vColor;\n\nuniform sampler2D uSampler[2];\n\nuniform vec4 uTextureClamp;\n\nuniform vec4 uColor;\n\nvoid main(void)\n\n{\n\n vec2 textureCoord = clamp(vTextureCoord, uTextureClamp.xy, uTextureClamp.zw);\n\n vec4 source = texture2D(uSampler[0], textureCoord);\n\n vec4 target = texture2D(uSampler[1], vMapCoord);\n\n //reverse hardlight\r\n if (source.a == 0.0) {\n\n gl_FragColor = vec4(0, 0, 0, 0);\n\n return;\n\n }\n\n //yeah, premultiplied\r\n vec3 Cb = source.rgb/source.a, Cs;\n\n if (target.a > 0.0) {\n\n Cs = target.rgb / target.a;\n\n }\n\n vec3 multiply = Cb * Cs * 2.0;\n\n vec3 Cb2 = Cb * 2.0 - 1.0;\n\n vec3 screen = Cb2 + Cs - Cb2 * Cs;\n\n vec3 B;\n\n if (Cs.r <= 0.5) {\n\n B.r = multiply.r;\n\n } else {\n\n B.r = screen.r;\n\n }\n\n if (Cs.g <= 0.5) {\n\n B.g = multiply.g;\n\n } else {\n\n B.g = screen.g;\n\n }\n\n if (Cs.b <= 0.5) {\n\n B.b = multiply.b;\n\n } else {\n\n B.b = screen.b;\n\n }\n\n vec4 res;\n\n res.xyz = (1.0 - source.a) * Cs + source.a * B;\n\n res.a = source.a + target.a * (1.0-source.a);\n\n gl_FragColor = vec4(res.xyz * res.a, res.a);\n\n}\n\n" + ); + this.bind(); + this.uniforms.uSampler = [0, 1]; +} + +OverlayShader.prototype = Object.create(PIXI.Shader.prototype); +OverlayShader.prototype.constructor = OverlayShader; +module.exports = OverlayShader; + +},{}],3:[function(require,module,exports){ +var PictureShader = require('./PictureShader'), + mapFilterBlendModesToPixi = require('./mapFilterBlendModesToPixi'), + glCore = PIXI.glCore; + +/** + * Renderer that clamps the texture so neighbour frames wont bleed on it + * immitates context2d drawImage behaviour + * + * @class + * @memberof PIXI.extras + * @extends PIXI.ObjectRenderer + * @param renderer {PIXI.WebGLRenderer} The renderer this plugin works for + */ +function PictureRenderer(renderer) { + PIXI.ObjectRenderer.call(this, renderer); +} + +PictureRenderer.prototype = Object.create(PIXI.ObjectRenderer.prototype); +PictureRenderer.prototype.constructor = PictureRenderer; + +PictureRenderer.prototype.onContextChange = function () { + var gl = this.renderer.gl; + this.quad = new PIXI.Quad(gl); + this.normalShader = new PictureShader(gl); + this.drawModes = mapFilterBlendModesToPixi(gl); + this.quad.initVao(this.normalShader); + this._tempClamp = new Float32Array(4); + this._tempColor = new Float32Array(4); + this._tempRect = new PIXI.Rectangle(); + this._tempRect2 = new PIXI.Rectangle(); + this._tempRect3 = new PIXI.Rectangle(); + this._tempMatrix = new PIXI.Matrix(); + this._bigBuf = new Uint8Array(1 << 20); + this._renderTexture = new PIXI.BaseRenderTexture(1024, 1024); +}; + +PictureRenderer.prototype.start = function () { + //noop +}; + +PictureRenderer.prototype.flush = function () { + //noop +}; + +function nextPow2(v) { + v += v === 0; + --v; + v |= v >>> 1; + v |= v >>> 2; + v |= v >>> 4; + v |= v >>> 8; + v |= v >>> 16; + return v + 1; +} + +PictureRenderer.prototype._getRenderTexture = function (minWidth, minHeight) { + if (this._renderTexture.width < minWidth || + this._renderTexture.height < minHeight) { + minHeight = nextPow2(minWidth * resolution); + minHeight = nextPow2(minHeight * resolution); + this._renderTexture.resize(minWidth, minHeight); + } + return this._renderTexture; +}; + +PictureRenderer.prototype._getBuf = function (size) { + var buf = this._bigBuf; + if (buf.length < size) { + size = nextPow2(size); + buf = new Uint8Array(size); + this._bigBuf = buf; + } + return buf; +}; + +/** + * Renders the picture object. + * + * @param sprite {PIXI.tilemap.PictureSprite} the picture to render + */ +PictureRenderer.prototype.render = function (sprite) { + if (!sprite.texture.valid) { + return; + } + var blendShader = this.drawModes[sprite.blendMode]; + if (blendShader) { + this._renderBlend(sprite, blendShader); + } else { + this._renderNormal(sprite, this.normalShader); + } +}; + +PictureRenderer.prototype._renderNormal = function (sprite, shader) { + var renderer = this.renderer; + renderer.bindShader(shader); + renderer.state.setBlendMode(sprite.blendMode); + this._renderInner(sprite, shader); +}; + +PictureRenderer.prototype._renderBlend = function (sprite, shader) { + //nothing there yet + var renderer = this.renderer; + var spriteBounds = sprite.getBounds(); + var renderTarget = renderer._activeRenderTarget; + var matrix = renderTarget.projectionMatrix; + var flipY = matrix.d < 0; + var resolution = renderTarget.resolution; + var screen = this._tempRect; + var fr = renderTarget.sourceFrame || renderTarget.destinationFrame; + screen.x = 0; + screen.y = 0; + screen.width = fr.width; + screen.height = fr.height; + + var bounds = this._tempRect2; + var fbw = fr.width * resolution, fbh = fr.height * resolution; + bounds.x = (spriteBounds.x + matrix.tx / matrix.a) * resolution + fbw / 2; + bounds.y = (spriteBounds.y + matrix.ty / matrix.d) * resolution + fbh / 2; + bounds.width = spriteBounds.width * resolution; + bounds.height = spriteBounds.height * resolution; + if (flipY) { + bounds.y = fbh - bounds.height - bounds.y; + } + + var screenBounds = this._tempRect3; + var x_1 = Math.floor(Math.max(screen.x, bounds.x)); + var x_2 = Math.ceil(Math.min(screen.x + screen.width, bounds.x + bounds.width)); + var y_1 = Math.floor(Math.max(screen.y, bounds.y)); + var y_2 = Math.ceil(Math.min(screen.y + screen.height, bounds.y + bounds.height)); + var pixelsWidth = x_2 - x_1; + var pixelsHeight = y_2 - y_1; + if (pixelsWidth <= 0 || pixelsHeight <= 0) { + //culling + return; + } + //TODO: padding + var rt = this._getRenderTexture(pixelsWidth, pixelsHeight); + renderer.bindTexture(rt, 1); + var gl = renderer.gl; + if (renderer.renderingToScreen && renderTarget.root) { + var buf = this._getBuf(pixelsWidth * pixelsHeight * 4); + gl.readPixels(x_1, y_1, pixelsWidth, pixelsHeight, gl.RGBA, gl.UNSIGNED_BYTE, this._bigBuf); + //REVERT Y? + gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, pixelsWidth, pixelsHeight, gl.RGBA, gl.UNSIGNED_BYTE, this._bigBuf); + } else { + gl.copyTexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, x_1, y_1, pixelsWidth, pixelsHeight); + } + + renderer.bindShader(shader); + renderer.state.setBlendMode(PIXI.BLEND_MODES.NORMAL); + if (shader.uniforms.mapMatrix) { + var mapMatrix = this._tempMatrix; + mapMatrix.a = bounds.width / rt.width / spriteBounds.width; + mapMatrix.tx = (bounds.x - x_1) / rt.width - spriteBounds.x * mapMatrix.a; + mapMatrix.d = bounds.height / rt.height / spriteBounds.height; + if (flipY) { + mapMatrix.d = -mapMatrix.d; + mapMatrix.ty = (bounds.y - y_1) / rt.height - (spriteBounds.y + spriteBounds.height) * mapMatrix.d; + } else { + mapMatrix.ty = (bounds.y - y_1) / rt.height - spriteBounds.y * mapMatrix.d; + } + + shader.uniforms.mapMatrix = mapMatrix.toArray(true, shader.uniforms.mapMatrix); + } + + this._renderInner(sprite, shader); +}; + + +PictureRenderer.prototype._renderInner = function (sprite, shader) { + var renderer = this.renderer; + var quad = this.quad; + var uvs = sprite.texture._uvs; + + //sprite already has calculated the vertices. lets transfer them to quad + var vertices = quad.vertices; + for (var i = 0; i < 8; i++) { + quad.vertices[i] = sprite.vertexData[i]; + } + + //SpriteRenderer works differently, with uint32 UVS + //but for our demo float uvs are just fine + quad.uvs[0] = uvs.x0; + quad.uvs[1] = uvs.y0; + quad.uvs[2] = uvs.x1; + quad.uvs[3] = uvs.y1; + quad.uvs[4] = uvs.x2; + quad.uvs[5] = uvs.y2; + quad.uvs[6] = uvs.x3; + quad.uvs[7] = uvs.y3; + + //TODO: add baricentric coords here + quad.upload(); + + var frame = sprite.texture.frame; + var base = sprite.texture.baseTexture; + var clamp = this._tempClamp; + //clamping 0.5 pixel from each side to reduce border artifact + //this is our plugin main purpose + clamp[0] = frame.x / base.width + 0.5 / base.realWidth; + clamp[1] = frame.y / base.height + 0.5 / base.realWidth; + clamp[2] = (frame.x + frame.width) / base.width - 0.5 / base.realWidth; + clamp[3] = (frame.y + frame.height) / base.height - 0.5 / base.realWidth; + //take a notice that size in pixels is realWidth,realHeight + //width and height are divided by resolution + shader.uniforms.uTextureClamp = clamp; + + var color = this._tempColor; + PIXI.utils.hex2rgb(sprite.tint, color); + var alpha = sprite.worldAlpha; + //premultiplied alpha tint + //of course we could do that in shader too + color[0] *= alpha; + color[1] *= alpha; + color[2] *= alpha; + color[3] = alpha; + shader.uniforms.uColor = color; + + //bind texture to unit 0, our default sampler unit + renderer.bindTexture(base, 0); + quad.draw(); +}; + +PIXI.WebGLRenderer.registerPlugin('picture', PictureRenderer); + +module.exports = PictureRenderer; + +},{"./PictureShader":4,"./mapFilterBlendModesToPixi":7}],4:[function(require,module,exports){ + + +/** + * @class + * @extends PIXI.Shader + * @memberof PIXI.extras + * @param gl {PIXI.Shader} The WebGL shader manager this shader works for. + */ +function PictureShader(gl) +{ + PIXI.Shader.call(this, + gl, + "#define GLSLIFY 1\nattribute vec2 aVertexPosition;\n\nattribute vec2 aTextureCoord;\n\nattribute vec4 aColor;\n\nuniform mat3 projectionMatrix;\n\nvarying vec2 vTextureCoord;\n\nvoid main(void)\n\n{\n\n gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\n\n vTextureCoord = aTextureCoord;\n\n}\n\n", + "#define GLSLIFY 1\nvarying vec2 vTextureCoord;\n\nvarying vec4 vColor;\n\nuniform sampler2D uSampler;\n\nuniform vec4 uTextureClamp;\n\nuniform vec4 uColor;\n\nvoid main(void)\n\n{\n\n vec2 textureCoord = clamp(vTextureCoord, uTextureClamp.xy, uTextureClamp.zw);\n\n vec4 sample = texture2D(uSampler, textureCoord);\n\n gl_FragColor = sample * uColor;\n\n}\n\n" + ); + //do some stuff, like default values for shader + //dont forget to bind it if you really are changing the uniforms + this.bind(); + //default tint + //Its an example, actually PictureRenderer takes care of this stuff + this.uniforms.uColor = new Float32Array(1,1,1,1); +} + +PictureShader.prototype = Object.create(PIXI.Shader.prototype); +PictureShader.prototype.constructor = PictureShader; +module.exports = PictureShader; + +},{}],5:[function(require,module,exports){ +/** + * A Sprite with reduced border artifacts + * + * @class + * @extends PIXI.Sprite + * @memberof PIXI.tilemap + * @param texture {PIXI.Texture} the texture for this sprite + */ +function PictureSprite(texture) +{ + PIXI.Sprite.call(this, texture); +} + +PictureSprite.prototype = Object.create(PIXI.Sprite.prototype); +PictureSprite.prototype.constructor = PictureSprite; +module.exports = PictureSprite; + +/** + * Renders the object using the WebGL renderer + * + * @param renderer {PIXI.WebGLRenderer} + * @private + */ +PictureSprite.prototype._renderWebGL = function (renderer) +{ + //copy of PIXI.Sprite v4 behaviour + if(this.transform.updated || this.textureDirty) + { + this.textureDirty = false; + // set the vertex data + this.calculateVertices(); + } + + //use different plugin for rendering + renderer.setObjectRenderer(renderer.plugins.picture); + renderer.plugins.picture.render(this); +}; + +},{}],6:[function(require,module,exports){ +var myPlugin = { + PictureSprite: require('./PictureSprite'), + PictureRenderer: require('./PictureRenderer') +}; + +//dump everything into extras + +Object.assign(PIXI.extras, myPlugin); + +module.exports = myPlugin; + +},{"./PictureRenderer":3,"./PictureSprite":5}],7:[function(require,module,exports){ +var CONST = PIXI, + OverlayShader = require('./OverlayShader'), + HardLightShader = require('./HardLightShader'); + +/** + * Maps gl blend combinations to WebGL + * @class + * @memberof PIXI + */ +function mapFilterBlendModesToPixi(gl, array) +{ + array = array || []; + + //TODO - premultiply alpha would be different. + //add a boolean for that! + array[CONST.BLEND_MODES.OVERLAY] = new OverlayShader(gl); + array[CONST.BLEND_MODES.HARD_LIGHT] = new HardLightShader(gl); + + return array; +} + +module.exports = mapFilterBlendModesToPixi; + +},{"./HardLightShader":1,"./OverlayShader":2}]},{},[6]) + + +//# sourceMappingURL=pixi-picture.js.map diff --git a/_site/js/vendor/eligrey/Blob.js b/_site/js/vendor/eligrey/Blob.js deleted file mode 100644 index 30ae332..0000000 --- a/_site/js/vendor/eligrey/Blob.js +++ /dev/null @@ -1,211 +0,0 @@ -/* Blob.js - * A Blob implementation. - * 2014-07-24 - * - * By Eli Grey, http://eligrey.com - * By Devin Samarin, https://github.com/dsamarin - * License: X11/MIT - * See https://github.com/eligrey/Blob.js/blob/master/LICENSE.md - */ - -/*global self, unescape */ -/*jslint bitwise: true, regexp: true, confusion: true, es5: true, vars: true, white: true, - plusplus: true */ - -/*! @source http://purl.eligrey.com/github/Blob.js/blob/master/Blob.js */ - -(function (view) { - "use strict"; - - view.URL = view.URL || view.webkitURL; - - if (view.Blob && view.URL) { - try { - new Blob; - return; - } catch (e) {} - } - - // Internally we use a BlobBuilder implementation to base Blob off of - // in order to support older browsers that only have BlobBuilder - var BlobBuilder = view.BlobBuilder || view.WebKitBlobBuilder || view.MozBlobBuilder || (function(view) { - var - get_class = function(object) { - return Object.prototype.toString.call(object).match(/^\[object\s(.*)\]$/)[1]; - } - , FakeBlobBuilder = function BlobBuilder() { - this.data = []; - } - , FakeBlob = function Blob(data, type, encoding) { - this.data = data; - this.size = data.length; - this.type = type; - this.encoding = encoding; - } - , FBB_proto = FakeBlobBuilder.prototype - , FB_proto = FakeBlob.prototype - , FileReaderSync = view.FileReaderSync - , FileException = function(type) { - this.code = this[this.name = type]; - } - , file_ex_codes = ( - "NOT_FOUND_ERR SECURITY_ERR ABORT_ERR NOT_READABLE_ERR ENCODING_ERR " - + "NO_MODIFICATION_ALLOWED_ERR INVALID_STATE_ERR SYNTAX_ERR" - ).split(" ") - , file_ex_code = file_ex_codes.length - , real_URL = view.URL || view.webkitURL || view - , real_create_object_URL = real_URL.createObjectURL - , real_revoke_object_URL = real_URL.revokeObjectURL - , URL = real_URL - , btoa = view.btoa - , atob = view.atob - - , ArrayBuffer = view.ArrayBuffer - , Uint8Array = view.Uint8Array - - , origin = /^[\w-]+:\/*\[?[\w\.:-]+\]?(?::[0-9]+)?/ - ; - FakeBlob.fake = FB_proto.fake = true; - while (file_ex_code--) { - FileException.prototype[file_ex_codes[file_ex_code]] = file_ex_code + 1; - } - // Polyfill URL - if (!real_URL.createObjectURL) { - URL = view.URL = function(uri) { - var - uri_info = document.createElementNS("http://www.w3.org/1999/xhtml", "a") - , uri_origin - ; - uri_info.href = uri; - if (!("origin" in uri_info)) { - if (uri_info.protocol.toLowerCase() === "data:") { - uri_info.origin = null; - } else { - uri_origin = uri.match(origin); - uri_info.origin = uri_origin && uri_origin[1]; - } - } - return uri_info; - }; - } - URL.createObjectURL = function(blob) { - var - type = blob.type - , data_URI_header - ; - if (type === null) { - type = "application/octet-stream"; - } - if (blob instanceof FakeBlob) { - data_URI_header = "data:" + type; - if (blob.encoding === "base64") { - return data_URI_header + ";base64," + blob.data; - } else if (blob.encoding === "URI") { - return data_URI_header + "," + decodeURIComponent(blob.data); - } if (btoa) { - return data_URI_header + ";base64," + btoa(blob.data); - } else { - return data_URI_header + "," + encodeURIComponent(blob.data); - } - } else if (real_create_object_URL) { - return real_create_object_URL.call(real_URL, blob); - } - }; - URL.revokeObjectURL = function(object_URL) { - if (object_URL.substring(0, 5) !== "data:" && real_revoke_object_URL) { - real_revoke_object_URL.call(real_URL, object_URL); - } - }; - FBB_proto.append = function(data/*, endings*/) { - var bb = this.data; - // decode data to a binary string - if (Uint8Array && (data instanceof ArrayBuffer || data instanceof Uint8Array)) { - var - str = "" - , buf = new Uint8Array(data) - , i = 0 - , buf_len = buf.length - ; - for (; i < buf_len; i++) { - str += String.fromCharCode(buf[i]); - } - bb.push(str); - } else if (get_class(data) === "Blob" || get_class(data) === "File") { - if (FileReaderSync) { - var fr = new FileReaderSync; - bb.push(fr.readAsBinaryString(data)); - } else { - // async FileReader won't work as BlobBuilder is sync - throw new FileException("NOT_READABLE_ERR"); - } - } else if (data instanceof FakeBlob) { - if (data.encoding === "base64" && atob) { - bb.push(atob(data.data)); - } else if (data.encoding === "URI") { - bb.push(decodeURIComponent(data.data)); - } else if (data.encoding === "raw") { - bb.push(data.data); - } - } else { - if (typeof data !== "string") { - data += ""; // convert unsupported types to strings - } - // decode UTF-16 to binary string - bb.push(unescape(encodeURIComponent(data))); - } - }; - FBB_proto.getBlob = function(type) { - if (!arguments.length) { - type = null; - } - return new FakeBlob(this.data.join(""), type, "raw"); - }; - FBB_proto.toString = function() { - return "[object BlobBuilder]"; - }; - FB_proto.slice = function(start, end, type) { - var args = arguments.length; - if (args < 3) { - type = null; - } - return new FakeBlob( - this.data.slice(start, args > 1 ? end : this.data.length) - , type - , this.encoding - ); - }; - FB_proto.toString = function() { - return "[object Blob]"; - }; - FB_proto.close = function() { - this.size = 0; - delete this.data; - }; - return FakeBlobBuilder; - }(view)); - - view.Blob = function(blobParts, options) { - var type = options ? (options.type || "") : ""; - var builder = new BlobBuilder(); - if (blobParts) { - for (var i = 0, len = blobParts.length; i < len; i++) { - if (Uint8Array && blobParts[i] instanceof Uint8Array) { - builder.append(blobParts[i].buffer); - } - else { - builder.append(blobParts[i]); - } - } - } - var blob = builder.getBlob(type); - if (!blob.slice && blob.webkitSlice) { - blob.slice = blob.webkitSlice; - } - return blob; - }; - - var getPrototypeOf = Object.getPrototypeOf || function(object) { - return object.__proto__; - }; - view.Blob.prototype = getPrototypeOf(new view.Blob()); -}(typeof self !== "undefined" && self || typeof window !== "undefined" && window || this.content || this)); diff --git a/_site/js/vendor/eligrey/FileSaver.js b/_site/js/vendor/eligrey/FileSaver.js deleted file mode 100644 index ee694ef..0000000 --- a/_site/js/vendor/eligrey/FileSaver.js +++ /dev/null @@ -1,248 +0,0 @@ -/* FileSaver.js - * A saveAs() FileSaver implementation. - * 2015-03-04 - * - * By Eli Grey, http://eligrey.com - * License: X11/MIT - * See https://github.com/eligrey/FileSaver.js/blob/master/LICENSE.md - */ - -/*global self */ -/*jslint bitwise: true, indent: 4, laxbreak: true, laxcomma: true, smarttabs: true, plusplus: true */ - -/*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */ - -var saveAs = saveAs - // IE 10+ (native saveAs) - || (typeof navigator !== "undefined" && - navigator.msSaveOrOpenBlob && navigator.msSaveOrOpenBlob.bind(navigator)) - // Everyone else - || (function(view) { - "use strict"; - // IE <10 is explicitly unsupported - if (typeof navigator !== "undefined" && - /MSIE [1-9]\./.test(navigator.userAgent)) { - return; - } - var - doc = view.document - // only get URL when necessary in case Blob.js hasn't overridden it yet - , get_URL = function() { - return view.URL || view.webkitURL || view; - } - , save_link = doc.createElementNS("http://www.w3.org/1999/xhtml", "a") - , can_use_save_link = "download" in save_link - , click = function(node) { - var event = doc.createEvent("MouseEvents"); - event.initMouseEvent( - "click", true, false, view, 0, 0, 0, 0, 0 - , false, false, false, false, 0, null - ); - node.dispatchEvent(event); - } - , webkit_req_fs = view.webkitRequestFileSystem - , req_fs = view.requestFileSystem || webkit_req_fs || view.mozRequestFileSystem - , throw_outside = function(ex) { - (view.setImmediate || view.setTimeout)(function() { - throw ex; - }, 0); - } - , force_saveable_type = "application/octet-stream" - , fs_min_size = 0 - // See https://code.google.com/p/chromium/issues/detail?id=375297#c7 and - // https://github.com/eligrey/FileSaver.js/commit/485930a#commitcomment-8768047 - // for the reasoning behind the timeout and revocation flow - , arbitrary_revoke_timeout = 500 // in ms - , revoke = function(file) { - var revoker = function() { - if (typeof file === "string") { // file is an object URL - get_URL().revokeObjectURL(file); - } else { // file is a File - file.remove(); - } - }; - if (view.chrome) { - revoker(); - } else { - setTimeout(revoker, arbitrary_revoke_timeout); - } - } - , dispatch = function(filesaver, event_types, event) { - event_types = [].concat(event_types); - var i = event_types.length; - while (i--) { - var listener = filesaver["on" + event_types[i]]; - if (typeof listener === "function") { - try { - listener.call(filesaver, event || filesaver); - } catch (ex) { - throw_outside(ex); - } - } - } - } - , FileSaver = function(blob, name) { - // First try a.download, then web filesystem, then object URLs - var - filesaver = this - , type = blob.type - , blob_changed = false - , object_url - , target_view - , dispatch_all = function() { - dispatch(filesaver, "writestart progress write writeend".split(" ")); - } - // on any filesys errors revert to saving with object URLs - , fs_error = function() { - // don't create more object URLs than needed - if (blob_changed || !object_url) { - object_url = get_URL().createObjectURL(blob); - } - if (target_view) { - target_view.location.href = object_url; - } else { - var new_tab = view.open(object_url, "_blank"); - if (new_tab == undefined && typeof safari !== "undefined") { - //Apple do not allow window.open, see http://bit.ly/1kZffRI - view.location.href = object_url - } - } - filesaver.readyState = filesaver.DONE; - dispatch_all(); - revoke(object_url); - } - , abortable = function(func) { - return function() { - if (filesaver.readyState !== filesaver.DONE) { - return func.apply(this, arguments); - } - }; - } - , create_if_not_found = {create: true, exclusive: false} - , slice - ; - filesaver.readyState = filesaver.INIT; - if (!name) { - name = "download"; - } - if (can_use_save_link) { - object_url = get_URL().createObjectURL(blob); - save_link.href = object_url; - save_link.download = name; - click(save_link); - filesaver.readyState = filesaver.DONE; - dispatch_all(); - revoke(object_url); - return; - } - // prepend BOM for UTF-8 XML and text/plain types - if (/^\s*(?:text\/(?:plain|xml)|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(blob.type)) { - blob = new Blob(["\ufeff", blob], {type: blob.type}); - } - // Object and web filesystem URLs have a problem saving in Google Chrome when - // viewed in a tab, so I force save with application/octet-stream - // http://code.google.com/p/chromium/issues/detail?id=91158 - // Update: Google errantly closed 91158, I submitted it again: - // https://code.google.com/p/chromium/issues/detail?id=389642 - if (view.chrome && type && type !== force_saveable_type) { - slice = blob.slice || blob.webkitSlice; - blob = slice.call(blob, 0, blob.size, force_saveable_type); - blob_changed = true; - } - // Since I can't be sure that the guessed media type will trigger a download - // in WebKit, I append .download to the filename. - // https://bugs.webkit.org/show_bug.cgi?id=65440 - if (webkit_req_fs && name !== "download") { - name += ".download"; - } - if (type === force_saveable_type || webkit_req_fs) { - target_view = view; - } - if (!req_fs) { - fs_error(); - return; - } - fs_min_size += blob.size; - req_fs(view.TEMPORARY, fs_min_size, abortable(function(fs) { - fs.root.getDirectory("saved", create_if_not_found, abortable(function(dir) { - var save = function() { - dir.getFile(name, create_if_not_found, abortable(function(file) { - file.createWriter(abortable(function(writer) { - writer.onwriteend = function(event) { - target_view.location.href = file.toURL(); - filesaver.readyState = filesaver.DONE; - dispatch(filesaver, "writeend", event); - revoke(file); - }; - writer.onerror = function() { - var error = writer.error; - if (error.code !== error.ABORT_ERR) { - fs_error(); - } - }; - "writestart progress write abort".split(" ").forEach(function(event) { - writer["on" + event] = filesaver["on" + event]; - }); - writer.write(blob); - filesaver.abort = function() { - writer.abort(); - filesaver.readyState = filesaver.DONE; - }; - filesaver.readyState = filesaver.WRITING; - }), fs_error); - }), fs_error); - }; - dir.getFile(name, {create: false}, abortable(function(file) { - // delete file if it already exists - file.remove(); - save(); - }), abortable(function(ex) { - if (ex.code === ex.NOT_FOUND_ERR) { - save(); - } else { - fs_error(); - } - })); - }), fs_error); - }), fs_error); - } - , FS_proto = FileSaver.prototype - , saveAs = function(blob, name) { - return new FileSaver(blob, name); - } - ; - FS_proto.abort = function() { - var filesaver = this; - filesaver.readyState = filesaver.DONE; - dispatch(filesaver, "abort"); - }; - FS_proto.readyState = FS_proto.INIT = 0; - FS_proto.WRITING = 1; - FS_proto.DONE = 2; - - FS_proto.error = - FS_proto.onwritestart = - FS_proto.onprogress = - FS_proto.onwrite = - FS_proto.onabort = - FS_proto.onerror = - FS_proto.onwriteend = - null; - - return saveAs; -}( - typeof self !== "undefined" && self - || typeof window !== "undefined" && window - || this.content -)); -// `self` is undefined in Firefox for Android content script context -// while `this` is nsIContentFrameMessageManager -// with an attribute `content` that corresponds to the window - -if (typeof module !== "undefined" && module.exports) { - module.exports.saveAs = saveAs; -} else if ((typeof define !== "undefined" && define !== null) && (define.amd != null)) { - define([], function() { - return saveAs; - }); -} \ No newline at end of file diff --git a/_site/js/vendor/jquery-2.1.3.min.js b/_site/js/vendor/jquery-2.1.3.min.js deleted file mode 100644 index 25714ed..0000000 --- a/_site/js/vendor/jquery-2.1.3.min.js +++ /dev/null @@ -1,4 +0,0 @@ -/*! jQuery v2.1.3 | (c) 2005, 2014 jQuery Foundation, Inc. | jquery.org/license */ -!function(a,b){"object"==typeof module&&"object"==typeof module.exports?module.exports=a.document?b(a,!0):function(a){if(!a.document)throw new Error("jQuery requires a window with a document");return b(a)}:b(a)}("undefined"!=typeof window?window:this,function(a,b){var c=[],d=c.slice,e=c.concat,f=c.push,g=c.indexOf,h={},i=h.toString,j=h.hasOwnProperty,k={},l=a.document,m="2.1.3",n=function(a,b){return new n.fn.init(a,b)},o=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,p=/^-ms-/,q=/-([\da-z])/gi,r=function(a,b){return b.toUpperCase()};n.fn=n.prototype={jquery:m,constructor:n,selector:"",length:0,toArray:function(){return d.call(this)},get:function(a){return null!=a?0>a?this[a+this.length]:this[a]:d.call(this)},pushStack:function(a){var b=n.merge(this.constructor(),a);return b.prevObject=this,b.context=this.context,b},each:function(a,b){return n.each(this,a,b)},map:function(a){return this.pushStack(n.map(this,function(b,c){return a.call(b,c,b)}))},slice:function(){return this.pushStack(d.apply(this,arguments))},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},eq:function(a){var b=this.length,c=+a+(0>a?b:0);return this.pushStack(c>=0&&b>c?[this[c]]:[])},end:function(){return this.prevObject||this.constructor(null)},push:f,sort:c.sort,splice:c.splice},n.extend=n.fn.extend=function(){var a,b,c,d,e,f,g=arguments[0]||{},h=1,i=arguments.length,j=!1;for("boolean"==typeof g&&(j=g,g=arguments[h]||{},h++),"object"==typeof g||n.isFunction(g)||(g={}),h===i&&(g=this,h--);i>h;h++)if(null!=(a=arguments[h]))for(b in a)c=g[b],d=a[b],g!==d&&(j&&d&&(n.isPlainObject(d)||(e=n.isArray(d)))?(e?(e=!1,f=c&&n.isArray(c)?c:[]):f=c&&n.isPlainObject(c)?c:{},g[b]=n.extend(j,f,d)):void 0!==d&&(g[b]=d));return g},n.extend({expando:"jQuery"+(m+Math.random()).replace(/\D/g,""),isReady:!0,error:function(a){throw new Error(a)},noop:function(){},isFunction:function(a){return"function"===n.type(a)},isArray:Array.isArray,isWindow:function(a){return null!=a&&a===a.window},isNumeric:function(a){return!n.isArray(a)&&a-parseFloat(a)+1>=0},isPlainObject:function(a){return"object"!==n.type(a)||a.nodeType||n.isWindow(a)?!1:a.constructor&&!j.call(a.constructor.prototype,"isPrototypeOf")?!1:!0},isEmptyObject:function(a){var b;for(b in a)return!1;return!0},type:function(a){return null==a?a+"":"object"==typeof a||"function"==typeof a?h[i.call(a)]||"object":typeof a},globalEval:function(a){var b,c=eval;a=n.trim(a),a&&(1===a.indexOf("use strict")?(b=l.createElement("script"),b.text=a,l.head.appendChild(b).parentNode.removeChild(b)):c(a))},camelCase:function(a){return a.replace(p,"ms-").replace(q,r)},nodeName:function(a,b){return a.nodeName&&a.nodeName.toLowerCase()===b.toLowerCase()},each:function(a,b,c){var d,e=0,f=a.length,g=s(a);if(c){if(g){for(;f>e;e++)if(d=b.apply(a[e],c),d===!1)break}else for(e in a)if(d=b.apply(a[e],c),d===!1)break}else if(g){for(;f>e;e++)if(d=b.call(a[e],e,a[e]),d===!1)break}else for(e in a)if(d=b.call(a[e],e,a[e]),d===!1)break;return a},trim:function(a){return null==a?"":(a+"").replace(o,"")},makeArray:function(a,b){var c=b||[];return null!=a&&(s(Object(a))?n.merge(c,"string"==typeof a?[a]:a):f.call(c,a)),c},inArray:function(a,b,c){return null==b?-1:g.call(b,a,c)},merge:function(a,b){for(var c=+b.length,d=0,e=a.length;c>d;d++)a[e++]=b[d];return a.length=e,a},grep:function(a,b,c){for(var d,e=[],f=0,g=a.length,h=!c;g>f;f++)d=!b(a[f],f),d!==h&&e.push(a[f]);return e},map:function(a,b,c){var d,f=0,g=a.length,h=s(a),i=[];if(h)for(;g>f;f++)d=b(a[f],f,c),null!=d&&i.push(d);else for(f in a)d=b(a[f],f,c),null!=d&&i.push(d);return e.apply([],i)},guid:1,proxy:function(a,b){var c,e,f;return"string"==typeof b&&(c=a[b],b=a,a=c),n.isFunction(a)?(e=d.call(arguments,2),f=function(){return a.apply(b||this,e.concat(d.call(arguments)))},f.guid=a.guid=a.guid||n.guid++,f):void 0},now:Date.now,support:k}),n.each("Boolean Number String Function Array Date RegExp Object Error".split(" "),function(a,b){h["[object "+b+"]"]=b.toLowerCase()});function s(a){var b=a.length,c=n.type(a);return"function"===c||n.isWindow(a)?!1:1===a.nodeType&&b?!0:"array"===c||0===b||"number"==typeof b&&b>0&&b-1 in a}var t=function(a){var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u="sizzle"+1*new Date,v=a.document,w=0,x=0,y=hb(),z=hb(),A=hb(),B=function(a,b){return a===b&&(l=!0),0},C=1<<31,D={}.hasOwnProperty,E=[],F=E.pop,G=E.push,H=E.push,I=E.slice,J=function(a,b){for(var c=0,d=a.length;d>c;c++)if(a[c]===b)return c;return-1},K="checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",L="[\\x20\\t\\r\\n\\f]",M="(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+",N=M.replace("w","w#"),O="\\["+L+"*("+M+")(?:"+L+"*([*^$|!~]?=)"+L+"*(?:'((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\"|("+N+"))|)"+L+"*\\]",P=":("+M+")(?:\\((('((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\")|((?:\\\\.|[^\\\\()[\\]]|"+O+")*)|.*)\\)|)",Q=new RegExp(L+"+","g"),R=new RegExp("^"+L+"+|((?:^|[^\\\\])(?:\\\\.)*)"+L+"+$","g"),S=new RegExp("^"+L+"*,"+L+"*"),T=new RegExp("^"+L+"*([>+~]|"+L+")"+L+"*"),U=new RegExp("="+L+"*([^\\]'\"]*?)"+L+"*\\]","g"),V=new RegExp(P),W=new RegExp("^"+N+"$"),X={ID:new RegExp("^#("+M+")"),CLASS:new RegExp("^\\.("+M+")"),TAG:new RegExp("^("+M.replace("w","w*")+")"),ATTR:new RegExp("^"+O),PSEUDO:new RegExp("^"+P),CHILD:new RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\("+L+"*(even|odd|(([+-]|)(\\d*)n|)"+L+"*(?:([+-]|)"+L+"*(\\d+)|))"+L+"*\\)|)","i"),bool:new RegExp("^(?:"+K+")$","i"),needsContext:new RegExp("^"+L+"*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\("+L+"*((?:-\\d)?\\d*)"+L+"*\\)|)(?=[^-]|$)","i")},Y=/^(?:input|select|textarea|button)$/i,Z=/^h\d$/i,$=/^[^{]+\{\s*\[native \w/,_=/^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,ab=/[+~]/,bb=/'|\\/g,cb=new RegExp("\\\\([\\da-f]{1,6}"+L+"?|("+L+")|.)","ig"),db=function(a,b,c){var d="0x"+b-65536;return d!==d||c?b:0>d?String.fromCharCode(d+65536):String.fromCharCode(d>>10|55296,1023&d|56320)},eb=function(){m()};try{H.apply(E=I.call(v.childNodes),v.childNodes),E[v.childNodes.length].nodeType}catch(fb){H={apply:E.length?function(a,b){G.apply(a,I.call(b))}:function(a,b){var c=a.length,d=0;while(a[c++]=b[d++]);a.length=c-1}}}function gb(a,b,d,e){var f,h,j,k,l,o,r,s,w,x;if((b?b.ownerDocument||b:v)!==n&&m(b),b=b||n,d=d||[],k=b.nodeType,"string"!=typeof a||!a||1!==k&&9!==k&&11!==k)return d;if(!e&&p){if(11!==k&&(f=_.exec(a)))if(j=f[1]){if(9===k){if(h=b.getElementById(j),!h||!h.parentNode)return d;if(h.id===j)return d.push(h),d}else if(b.ownerDocument&&(h=b.ownerDocument.getElementById(j))&&t(b,h)&&h.id===j)return d.push(h),d}else{if(f[2])return H.apply(d,b.getElementsByTagName(a)),d;if((j=f[3])&&c.getElementsByClassName)return H.apply(d,b.getElementsByClassName(j)),d}if(c.qsa&&(!q||!q.test(a))){if(s=r=u,w=b,x=1!==k&&a,1===k&&"object"!==b.nodeName.toLowerCase()){o=g(a),(r=b.getAttribute("id"))?s=r.replace(bb,"\\$&"):b.setAttribute("id",s),s="[id='"+s+"'] ",l=o.length;while(l--)o[l]=s+rb(o[l]);w=ab.test(a)&&pb(b.parentNode)||b,x=o.join(",")}if(x)try{return H.apply(d,w.querySelectorAll(x)),d}catch(y){}finally{r||b.removeAttribute("id")}}}return i(a.replace(R,"$1"),b,d,e)}function hb(){var a=[];function b(c,e){return a.push(c+" ")>d.cacheLength&&delete b[a.shift()],b[c+" "]=e}return b}function ib(a){return a[u]=!0,a}function jb(a){var b=n.createElement("div");try{return!!a(b)}catch(c){return!1}finally{b.parentNode&&b.parentNode.removeChild(b),b=null}}function kb(a,b){var c=a.split("|"),e=a.length;while(e--)d.attrHandle[c[e]]=b}function lb(a,b){var c=b&&a,d=c&&1===a.nodeType&&1===b.nodeType&&(~b.sourceIndex||C)-(~a.sourceIndex||C);if(d)return d;if(c)while(c=c.nextSibling)if(c===b)return-1;return a?1:-1}function mb(a){return function(b){var c=b.nodeName.toLowerCase();return"input"===c&&b.type===a}}function nb(a){return function(b){var c=b.nodeName.toLowerCase();return("input"===c||"button"===c)&&b.type===a}}function ob(a){return ib(function(b){return b=+b,ib(function(c,d){var e,f=a([],c.length,b),g=f.length;while(g--)c[e=f[g]]&&(c[e]=!(d[e]=c[e]))})})}function pb(a){return a&&"undefined"!=typeof a.getElementsByTagName&&a}c=gb.support={},f=gb.isXML=function(a){var b=a&&(a.ownerDocument||a).documentElement;return b?"HTML"!==b.nodeName:!1},m=gb.setDocument=function(a){var b,e,g=a?a.ownerDocument||a:v;return g!==n&&9===g.nodeType&&g.documentElement?(n=g,o=g.documentElement,e=g.defaultView,e&&e!==e.top&&(e.addEventListener?e.addEventListener("unload",eb,!1):e.attachEvent&&e.attachEvent("onunload",eb)),p=!f(g),c.attributes=jb(function(a){return a.className="i",!a.getAttribute("className")}),c.getElementsByTagName=jb(function(a){return a.appendChild(g.createComment("")),!a.getElementsByTagName("*").length}),c.getElementsByClassName=$.test(g.getElementsByClassName),c.getById=jb(function(a){return o.appendChild(a).id=u,!g.getElementsByName||!g.getElementsByName(u).length}),c.getById?(d.find.ID=function(a,b){if("undefined"!=typeof b.getElementById&&p){var c=b.getElementById(a);return c&&c.parentNode?[c]:[]}},d.filter.ID=function(a){var b=a.replace(cb,db);return function(a){return a.getAttribute("id")===b}}):(delete d.find.ID,d.filter.ID=function(a){var b=a.replace(cb,db);return function(a){var c="undefined"!=typeof a.getAttributeNode&&a.getAttributeNode("id");return c&&c.value===b}}),d.find.TAG=c.getElementsByTagName?function(a,b){return"undefined"!=typeof b.getElementsByTagName?b.getElementsByTagName(a):c.qsa?b.querySelectorAll(a):void 0}:function(a,b){var c,d=[],e=0,f=b.getElementsByTagName(a);if("*"===a){while(c=f[e++])1===c.nodeType&&d.push(c);return d}return f},d.find.CLASS=c.getElementsByClassName&&function(a,b){return p?b.getElementsByClassName(a):void 0},r=[],q=[],(c.qsa=$.test(g.querySelectorAll))&&(jb(function(a){o.appendChild(a).innerHTML="",a.querySelectorAll("[msallowcapture^='']").length&&q.push("[*^$]="+L+"*(?:''|\"\")"),a.querySelectorAll("[selected]").length||q.push("\\["+L+"*(?:value|"+K+")"),a.querySelectorAll("[id~="+u+"-]").length||q.push("~="),a.querySelectorAll(":checked").length||q.push(":checked"),a.querySelectorAll("a#"+u+"+*").length||q.push(".#.+[+~]")}),jb(function(a){var b=g.createElement("input");b.setAttribute("type","hidden"),a.appendChild(b).setAttribute("name","D"),a.querySelectorAll("[name=d]").length&&q.push("name"+L+"*[*^$|!~]?="),a.querySelectorAll(":enabled").length||q.push(":enabled",":disabled"),a.querySelectorAll("*,:x"),q.push(",.*:")})),(c.matchesSelector=$.test(s=o.matches||o.webkitMatchesSelector||o.mozMatchesSelector||o.oMatchesSelector||o.msMatchesSelector))&&jb(function(a){c.disconnectedMatch=s.call(a,"div"),s.call(a,"[s!='']:x"),r.push("!=",P)}),q=q.length&&new RegExp(q.join("|")),r=r.length&&new RegExp(r.join("|")),b=$.test(o.compareDocumentPosition),t=b||$.test(o.contains)?function(a,b){var c=9===a.nodeType?a.documentElement:a,d=b&&b.parentNode;return a===d||!(!d||1!==d.nodeType||!(c.contains?c.contains(d):a.compareDocumentPosition&&16&a.compareDocumentPosition(d)))}:function(a,b){if(b)while(b=b.parentNode)if(b===a)return!0;return!1},B=b?function(a,b){if(a===b)return l=!0,0;var d=!a.compareDocumentPosition-!b.compareDocumentPosition;return d?d:(d=(a.ownerDocument||a)===(b.ownerDocument||b)?a.compareDocumentPosition(b):1,1&d||!c.sortDetached&&b.compareDocumentPosition(a)===d?a===g||a.ownerDocument===v&&t(v,a)?-1:b===g||b.ownerDocument===v&&t(v,b)?1:k?J(k,a)-J(k,b):0:4&d?-1:1)}:function(a,b){if(a===b)return l=!0,0;var c,d=0,e=a.parentNode,f=b.parentNode,h=[a],i=[b];if(!e||!f)return a===g?-1:b===g?1:e?-1:f?1:k?J(k,a)-J(k,b):0;if(e===f)return lb(a,b);c=a;while(c=c.parentNode)h.unshift(c);c=b;while(c=c.parentNode)i.unshift(c);while(h[d]===i[d])d++;return d?lb(h[d],i[d]):h[d]===v?-1:i[d]===v?1:0},g):n},gb.matches=function(a,b){return gb(a,null,null,b)},gb.matchesSelector=function(a,b){if((a.ownerDocument||a)!==n&&m(a),b=b.replace(U,"='$1']"),!(!c.matchesSelector||!p||r&&r.test(b)||q&&q.test(b)))try{var d=s.call(a,b);if(d||c.disconnectedMatch||a.document&&11!==a.document.nodeType)return d}catch(e){}return gb(b,n,null,[a]).length>0},gb.contains=function(a,b){return(a.ownerDocument||a)!==n&&m(a),t(a,b)},gb.attr=function(a,b){(a.ownerDocument||a)!==n&&m(a);var e=d.attrHandle[b.toLowerCase()],f=e&&D.call(d.attrHandle,b.toLowerCase())?e(a,b,!p):void 0;return void 0!==f?f:c.attributes||!p?a.getAttribute(b):(f=a.getAttributeNode(b))&&f.specified?f.value:null},gb.error=function(a){throw new Error("Syntax error, unrecognized expression: "+a)},gb.uniqueSort=function(a){var b,d=[],e=0,f=0;if(l=!c.detectDuplicates,k=!c.sortStable&&a.slice(0),a.sort(B),l){while(b=a[f++])b===a[f]&&(e=d.push(f));while(e--)a.splice(d[e],1)}return k=null,a},e=gb.getText=function(a){var b,c="",d=0,f=a.nodeType;if(f){if(1===f||9===f||11===f){if("string"==typeof a.textContent)return a.textContent;for(a=a.firstChild;a;a=a.nextSibling)c+=e(a)}else if(3===f||4===f)return a.nodeValue}else while(b=a[d++])c+=e(b);return c},d=gb.selectors={cacheLength:50,createPseudo:ib,match:X,attrHandle:{},find:{},relative:{">":{dir:"parentNode",first:!0}," ":{dir:"parentNode"},"+":{dir:"previousSibling",first:!0},"~":{dir:"previousSibling"}},preFilter:{ATTR:function(a){return a[1]=a[1].replace(cb,db),a[3]=(a[3]||a[4]||a[5]||"").replace(cb,db),"~="===a[2]&&(a[3]=" "+a[3]+" "),a.slice(0,4)},CHILD:function(a){return a[1]=a[1].toLowerCase(),"nth"===a[1].slice(0,3)?(a[3]||gb.error(a[0]),a[4]=+(a[4]?a[5]+(a[6]||1):2*("even"===a[3]||"odd"===a[3])),a[5]=+(a[7]+a[8]||"odd"===a[3])):a[3]&&gb.error(a[0]),a},PSEUDO:function(a){var b,c=!a[6]&&a[2];return X.CHILD.test(a[0])?null:(a[3]?a[2]=a[4]||a[5]||"":c&&V.test(c)&&(b=g(c,!0))&&(b=c.indexOf(")",c.length-b)-c.length)&&(a[0]=a[0].slice(0,b),a[2]=c.slice(0,b)),a.slice(0,3))}},filter:{TAG:function(a){var b=a.replace(cb,db).toLowerCase();return"*"===a?function(){return!0}:function(a){return a.nodeName&&a.nodeName.toLowerCase()===b}},CLASS:function(a){var b=y[a+" "];return b||(b=new RegExp("(^|"+L+")"+a+"("+L+"|$)"))&&y(a,function(a){return b.test("string"==typeof a.className&&a.className||"undefined"!=typeof a.getAttribute&&a.getAttribute("class")||"")})},ATTR:function(a,b,c){return function(d){var e=gb.attr(d,a);return null==e?"!="===b:b?(e+="","="===b?e===c:"!="===b?e!==c:"^="===b?c&&0===e.indexOf(c):"*="===b?c&&e.indexOf(c)>-1:"$="===b?c&&e.slice(-c.length)===c:"~="===b?(" "+e.replace(Q," ")+" ").indexOf(c)>-1:"|="===b?e===c||e.slice(0,c.length+1)===c+"-":!1):!0}},CHILD:function(a,b,c,d,e){var f="nth"!==a.slice(0,3),g="last"!==a.slice(-4),h="of-type"===b;return 1===d&&0===e?function(a){return!!a.parentNode}:function(b,c,i){var j,k,l,m,n,o,p=f!==g?"nextSibling":"previousSibling",q=b.parentNode,r=h&&b.nodeName.toLowerCase(),s=!i&&!h;if(q){if(f){while(p){l=b;while(l=l[p])if(h?l.nodeName.toLowerCase()===r:1===l.nodeType)return!1;o=p="only"===a&&!o&&"nextSibling"}return!0}if(o=[g?q.firstChild:q.lastChild],g&&s){k=q[u]||(q[u]={}),j=k[a]||[],n=j[0]===w&&j[1],m=j[0]===w&&j[2],l=n&&q.childNodes[n];while(l=++n&&l&&l[p]||(m=n=0)||o.pop())if(1===l.nodeType&&++m&&l===b){k[a]=[w,n,m];break}}else if(s&&(j=(b[u]||(b[u]={}))[a])&&j[0]===w)m=j[1];else while(l=++n&&l&&l[p]||(m=n=0)||o.pop())if((h?l.nodeName.toLowerCase()===r:1===l.nodeType)&&++m&&(s&&((l[u]||(l[u]={}))[a]=[w,m]),l===b))break;return m-=e,m===d||m%d===0&&m/d>=0}}},PSEUDO:function(a,b){var c,e=d.pseudos[a]||d.setFilters[a.toLowerCase()]||gb.error("unsupported pseudo: "+a);return e[u]?e(b):e.length>1?(c=[a,a,"",b],d.setFilters.hasOwnProperty(a.toLowerCase())?ib(function(a,c){var d,f=e(a,b),g=f.length;while(g--)d=J(a,f[g]),a[d]=!(c[d]=f[g])}):function(a){return e(a,0,c)}):e}},pseudos:{not:ib(function(a){var b=[],c=[],d=h(a.replace(R,"$1"));return d[u]?ib(function(a,b,c,e){var f,g=d(a,null,e,[]),h=a.length;while(h--)(f=g[h])&&(a[h]=!(b[h]=f))}):function(a,e,f){return b[0]=a,d(b,null,f,c),b[0]=null,!c.pop()}}),has:ib(function(a){return function(b){return gb(a,b).length>0}}),contains:ib(function(a){return a=a.replace(cb,db),function(b){return(b.textContent||b.innerText||e(b)).indexOf(a)>-1}}),lang:ib(function(a){return W.test(a||"")||gb.error("unsupported lang: "+a),a=a.replace(cb,db).toLowerCase(),function(b){var c;do if(c=p?b.lang:b.getAttribute("xml:lang")||b.getAttribute("lang"))return c=c.toLowerCase(),c===a||0===c.indexOf(a+"-");while((b=b.parentNode)&&1===b.nodeType);return!1}}),target:function(b){var c=a.location&&a.location.hash;return c&&c.slice(1)===b.id},root:function(a){return a===o},focus:function(a){return a===n.activeElement&&(!n.hasFocus||n.hasFocus())&&!!(a.type||a.href||~a.tabIndex)},enabled:function(a){return a.disabled===!1},disabled:function(a){return a.disabled===!0},checked:function(a){var b=a.nodeName.toLowerCase();return"input"===b&&!!a.checked||"option"===b&&!!a.selected},selected:function(a){return a.parentNode&&a.parentNode.selectedIndex,a.selected===!0},empty:function(a){for(a=a.firstChild;a;a=a.nextSibling)if(a.nodeType<6)return!1;return!0},parent:function(a){return!d.pseudos.empty(a)},header:function(a){return Z.test(a.nodeName)},input:function(a){return Y.test(a.nodeName)},button:function(a){var b=a.nodeName.toLowerCase();return"input"===b&&"button"===a.type||"button"===b},text:function(a){var b;return"input"===a.nodeName.toLowerCase()&&"text"===a.type&&(null==(b=a.getAttribute("type"))||"text"===b.toLowerCase())},first:ob(function(){return[0]}),last:ob(function(a,b){return[b-1]}),eq:ob(function(a,b,c){return[0>c?c+b:c]}),even:ob(function(a,b){for(var c=0;b>c;c+=2)a.push(c);return a}),odd:ob(function(a,b){for(var c=1;b>c;c+=2)a.push(c);return a}),lt:ob(function(a,b,c){for(var d=0>c?c+b:c;--d>=0;)a.push(d);return a}),gt:ob(function(a,b,c){for(var d=0>c?c+b:c;++db;b++)d+=a[b].value;return d}function sb(a,b,c){var d=b.dir,e=c&&"parentNode"===d,f=x++;return b.first?function(b,c,f){while(b=b[d])if(1===b.nodeType||e)return a(b,c,f)}:function(b,c,g){var h,i,j=[w,f];if(g){while(b=b[d])if((1===b.nodeType||e)&&a(b,c,g))return!0}else while(b=b[d])if(1===b.nodeType||e){if(i=b[u]||(b[u]={}),(h=i[d])&&h[0]===w&&h[1]===f)return j[2]=h[2];if(i[d]=j,j[2]=a(b,c,g))return!0}}}function tb(a){return a.length>1?function(b,c,d){var e=a.length;while(e--)if(!a[e](b,c,d))return!1;return!0}:a[0]}function ub(a,b,c){for(var d=0,e=b.length;e>d;d++)gb(a,b[d],c);return c}function vb(a,b,c,d,e){for(var f,g=[],h=0,i=a.length,j=null!=b;i>h;h++)(f=a[h])&&(!c||c(f,d,e))&&(g.push(f),j&&b.push(h));return g}function wb(a,b,c,d,e,f){return d&&!d[u]&&(d=wb(d)),e&&!e[u]&&(e=wb(e,f)),ib(function(f,g,h,i){var j,k,l,m=[],n=[],o=g.length,p=f||ub(b||"*",h.nodeType?[h]:h,[]),q=!a||!f&&b?p:vb(p,m,a,h,i),r=c?e||(f?a:o||d)?[]:g:q;if(c&&c(q,r,h,i),d){j=vb(r,n),d(j,[],h,i),k=j.length;while(k--)(l=j[k])&&(r[n[k]]=!(q[n[k]]=l))}if(f){if(e||a){if(e){j=[],k=r.length;while(k--)(l=r[k])&&j.push(q[k]=l);e(null,r=[],j,i)}k=r.length;while(k--)(l=r[k])&&(j=e?J(f,l):m[k])>-1&&(f[j]=!(g[j]=l))}}else r=vb(r===g?r.splice(o,r.length):r),e?e(null,g,r,i):H.apply(g,r)})}function xb(a){for(var b,c,e,f=a.length,g=d.relative[a[0].type],h=g||d.relative[" "],i=g?1:0,k=sb(function(a){return a===b},h,!0),l=sb(function(a){return J(b,a)>-1},h,!0),m=[function(a,c,d){var e=!g&&(d||c!==j)||((b=c).nodeType?k(a,c,d):l(a,c,d));return b=null,e}];f>i;i++)if(c=d.relative[a[i].type])m=[sb(tb(m),c)];else{if(c=d.filter[a[i].type].apply(null,a[i].matches),c[u]){for(e=++i;f>e;e++)if(d.relative[a[e].type])break;return wb(i>1&&tb(m),i>1&&rb(a.slice(0,i-1).concat({value:" "===a[i-2].type?"*":""})).replace(R,"$1"),c,e>i&&xb(a.slice(i,e)),f>e&&xb(a=a.slice(e)),f>e&&rb(a))}m.push(c)}return tb(m)}function yb(a,b){var c=b.length>0,e=a.length>0,f=function(f,g,h,i,k){var l,m,o,p=0,q="0",r=f&&[],s=[],t=j,u=f||e&&d.find.TAG("*",k),v=w+=null==t?1:Math.random()||.1,x=u.length;for(k&&(j=g!==n&&g);q!==x&&null!=(l=u[q]);q++){if(e&&l){m=0;while(o=a[m++])if(o(l,g,h)){i.push(l);break}k&&(w=v)}c&&((l=!o&&l)&&p--,f&&r.push(l))}if(p+=q,c&&q!==p){m=0;while(o=b[m++])o(r,s,g,h);if(f){if(p>0)while(q--)r[q]||s[q]||(s[q]=F.call(i));s=vb(s)}H.apply(i,s),k&&!f&&s.length>0&&p+b.length>1&&gb.uniqueSort(i)}return k&&(w=v,j=t),r};return c?ib(f):f}return h=gb.compile=function(a,b){var c,d=[],e=[],f=A[a+" "];if(!f){b||(b=g(a)),c=b.length;while(c--)f=xb(b[c]),f[u]?d.push(f):e.push(f);f=A(a,yb(e,d)),f.selector=a}return f},i=gb.select=function(a,b,e,f){var i,j,k,l,m,n="function"==typeof a&&a,o=!f&&g(a=n.selector||a);if(e=e||[],1===o.length){if(j=o[0]=o[0].slice(0),j.length>2&&"ID"===(k=j[0]).type&&c.getById&&9===b.nodeType&&p&&d.relative[j[1].type]){if(b=(d.find.ID(k.matches[0].replace(cb,db),b)||[])[0],!b)return e;n&&(b=b.parentNode),a=a.slice(j.shift().value.length)}i=X.needsContext.test(a)?0:j.length;while(i--){if(k=j[i],d.relative[l=k.type])break;if((m=d.find[l])&&(f=m(k.matches[0].replace(cb,db),ab.test(j[0].type)&&pb(b.parentNode)||b))){if(j.splice(i,1),a=f.length&&rb(j),!a)return H.apply(e,f),e;break}}}return(n||h(a,o))(f,b,!p,e,ab.test(a)&&pb(b.parentNode)||b),e},c.sortStable=u.split("").sort(B).join("")===u,c.detectDuplicates=!!l,m(),c.sortDetached=jb(function(a){return 1&a.compareDocumentPosition(n.createElement("div"))}),jb(function(a){return a.innerHTML="","#"===a.firstChild.getAttribute("href")})||kb("type|href|height|width",function(a,b,c){return c?void 0:a.getAttribute(b,"type"===b.toLowerCase()?1:2)}),c.attributes&&jb(function(a){return a.innerHTML="",a.firstChild.setAttribute("value",""),""===a.firstChild.getAttribute("value")})||kb("value",function(a,b,c){return c||"input"!==a.nodeName.toLowerCase()?void 0:a.defaultValue}),jb(function(a){return null==a.getAttribute("disabled")})||kb(K,function(a,b,c){var d;return c?void 0:a[b]===!0?b.toLowerCase():(d=a.getAttributeNode(b))&&d.specified?d.value:null}),gb}(a);n.find=t,n.expr=t.selectors,n.expr[":"]=n.expr.pseudos,n.unique=t.uniqueSort,n.text=t.getText,n.isXMLDoc=t.isXML,n.contains=t.contains;var u=n.expr.match.needsContext,v=/^<(\w+)\s*\/?>(?:<\/\1>|)$/,w=/^.[^:#\[\.,]*$/;function x(a,b,c){if(n.isFunction(b))return n.grep(a,function(a,d){return!!b.call(a,d,a)!==c});if(b.nodeType)return n.grep(a,function(a){return a===b!==c});if("string"==typeof b){if(w.test(b))return n.filter(b,a,c);b=n.filter(b,a)}return n.grep(a,function(a){return g.call(b,a)>=0!==c})}n.filter=function(a,b,c){var d=b[0];return c&&(a=":not("+a+")"),1===b.length&&1===d.nodeType?n.find.matchesSelector(d,a)?[d]:[]:n.find.matches(a,n.grep(b,function(a){return 1===a.nodeType}))},n.fn.extend({find:function(a){var b,c=this.length,d=[],e=this;if("string"!=typeof a)return this.pushStack(n(a).filter(function(){for(b=0;c>b;b++)if(n.contains(e[b],this))return!0}));for(b=0;c>b;b++)n.find(a,e[b],d);return d=this.pushStack(c>1?n.unique(d):d),d.selector=this.selector?this.selector+" "+a:a,d},filter:function(a){return this.pushStack(x(this,a||[],!1))},not:function(a){return this.pushStack(x(this,a||[],!0))},is:function(a){return!!x(this,"string"==typeof a&&u.test(a)?n(a):a||[],!1).length}});var y,z=/^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,A=n.fn.init=function(a,b){var c,d;if(!a)return this;if("string"==typeof a){if(c="<"===a[0]&&">"===a[a.length-1]&&a.length>=3?[null,a,null]:z.exec(a),!c||!c[1]&&b)return!b||b.jquery?(b||y).find(a):this.constructor(b).find(a);if(c[1]){if(b=b instanceof n?b[0]:b,n.merge(this,n.parseHTML(c[1],b&&b.nodeType?b.ownerDocument||b:l,!0)),v.test(c[1])&&n.isPlainObject(b))for(c in b)n.isFunction(this[c])?this[c](b[c]):this.attr(c,b[c]);return this}return d=l.getElementById(c[2]),d&&d.parentNode&&(this.length=1,this[0]=d),this.context=l,this.selector=a,this}return a.nodeType?(this.context=this[0]=a,this.length=1,this):n.isFunction(a)?"undefined"!=typeof y.ready?y.ready(a):a(n):(void 0!==a.selector&&(this.selector=a.selector,this.context=a.context),n.makeArray(a,this))};A.prototype=n.fn,y=n(l);var B=/^(?:parents|prev(?:Until|All))/,C={children:!0,contents:!0,next:!0,prev:!0};n.extend({dir:function(a,b,c){var d=[],e=void 0!==c;while((a=a[b])&&9!==a.nodeType)if(1===a.nodeType){if(e&&n(a).is(c))break;d.push(a)}return d},sibling:function(a,b){for(var c=[];a;a=a.nextSibling)1===a.nodeType&&a!==b&&c.push(a);return c}}),n.fn.extend({has:function(a){var b=n(a,this),c=b.length;return this.filter(function(){for(var a=0;c>a;a++)if(n.contains(this,b[a]))return!0})},closest:function(a,b){for(var c,d=0,e=this.length,f=[],g=u.test(a)||"string"!=typeof a?n(a,b||this.context):0;e>d;d++)for(c=this[d];c&&c!==b;c=c.parentNode)if(c.nodeType<11&&(g?g.index(c)>-1:1===c.nodeType&&n.find.matchesSelector(c,a))){f.push(c);break}return this.pushStack(f.length>1?n.unique(f):f)},index:function(a){return a?"string"==typeof a?g.call(n(a),this[0]):g.call(this,a.jquery?a[0]:a):this[0]&&this[0].parentNode?this.first().prevAll().length:-1},add:function(a,b){return this.pushStack(n.unique(n.merge(this.get(),n(a,b))))},addBack:function(a){return this.add(null==a?this.prevObject:this.prevObject.filter(a))}});function D(a,b){while((a=a[b])&&1!==a.nodeType);return a}n.each({parent:function(a){var b=a.parentNode;return b&&11!==b.nodeType?b:null},parents:function(a){return n.dir(a,"parentNode")},parentsUntil:function(a,b,c){return n.dir(a,"parentNode",c)},next:function(a){return D(a,"nextSibling")},prev:function(a){return D(a,"previousSibling")},nextAll:function(a){return n.dir(a,"nextSibling")},prevAll:function(a){return n.dir(a,"previousSibling")},nextUntil:function(a,b,c){return n.dir(a,"nextSibling",c)},prevUntil:function(a,b,c){return n.dir(a,"previousSibling",c)},siblings:function(a){return n.sibling((a.parentNode||{}).firstChild,a)},children:function(a){return n.sibling(a.firstChild)},contents:function(a){return a.contentDocument||n.merge([],a.childNodes)}},function(a,b){n.fn[a]=function(c,d){var e=n.map(this,b,c);return"Until"!==a.slice(-5)&&(d=c),d&&"string"==typeof d&&(e=n.filter(d,e)),this.length>1&&(C[a]||n.unique(e),B.test(a)&&e.reverse()),this.pushStack(e)}});var E=/\S+/g,F={};function G(a){var b=F[a]={};return n.each(a.match(E)||[],function(a,c){b[c]=!0}),b}n.Callbacks=function(a){a="string"==typeof a?F[a]||G(a):n.extend({},a);var b,c,d,e,f,g,h=[],i=!a.once&&[],j=function(l){for(b=a.memory&&l,c=!0,g=e||0,e=0,f=h.length,d=!0;h&&f>g;g++)if(h[g].apply(l[0],l[1])===!1&&a.stopOnFalse){b=!1;break}d=!1,h&&(i?i.length&&j(i.shift()):b?h=[]:k.disable())},k={add:function(){if(h){var c=h.length;!function g(b){n.each(b,function(b,c){var d=n.type(c);"function"===d?a.unique&&k.has(c)||h.push(c):c&&c.length&&"string"!==d&&g(c)})}(arguments),d?f=h.length:b&&(e=c,j(b))}return this},remove:function(){return h&&n.each(arguments,function(a,b){var c;while((c=n.inArray(b,h,c))>-1)h.splice(c,1),d&&(f>=c&&f--,g>=c&&g--)}),this},has:function(a){return a?n.inArray(a,h)>-1:!(!h||!h.length)},empty:function(){return h=[],f=0,this},disable:function(){return h=i=b=void 0,this},disabled:function(){return!h},lock:function(){return i=void 0,b||k.disable(),this},locked:function(){return!i},fireWith:function(a,b){return!h||c&&!i||(b=b||[],b=[a,b.slice?b.slice():b],d?i.push(b):j(b)),this},fire:function(){return k.fireWith(this,arguments),this},fired:function(){return!!c}};return k},n.extend({Deferred:function(a){var b=[["resolve","done",n.Callbacks("once memory"),"resolved"],["reject","fail",n.Callbacks("once memory"),"rejected"],["notify","progress",n.Callbacks("memory")]],c="pending",d={state:function(){return c},always:function(){return e.done(arguments).fail(arguments),this},then:function(){var a=arguments;return n.Deferred(function(c){n.each(b,function(b,f){var g=n.isFunction(a[b])&&a[b];e[f[1]](function(){var a=g&&g.apply(this,arguments);a&&n.isFunction(a.promise)?a.promise().done(c.resolve).fail(c.reject).progress(c.notify):c[f[0]+"With"](this===d?c.promise():this,g?[a]:arguments)})}),a=null}).promise()},promise:function(a){return null!=a?n.extend(a,d):d}},e={};return d.pipe=d.then,n.each(b,function(a,f){var g=f[2],h=f[3];d[f[1]]=g.add,h&&g.add(function(){c=h},b[1^a][2].disable,b[2][2].lock),e[f[0]]=function(){return e[f[0]+"With"](this===e?d:this,arguments),this},e[f[0]+"With"]=g.fireWith}),d.promise(e),a&&a.call(e,e),e},when:function(a){var b=0,c=d.call(arguments),e=c.length,f=1!==e||a&&n.isFunction(a.promise)?e:0,g=1===f?a:n.Deferred(),h=function(a,b,c){return function(e){b[a]=this,c[a]=arguments.length>1?d.call(arguments):e,c===i?g.notifyWith(b,c):--f||g.resolveWith(b,c)}},i,j,k;if(e>1)for(i=new Array(e),j=new Array(e),k=new Array(e);e>b;b++)c[b]&&n.isFunction(c[b].promise)?c[b].promise().done(h(b,k,c)).fail(g.reject).progress(h(b,j,i)):--f;return f||g.resolveWith(k,c),g.promise()}});var H;n.fn.ready=function(a){return n.ready.promise().done(a),this},n.extend({isReady:!1,readyWait:1,holdReady:function(a){a?n.readyWait++:n.ready(!0)},ready:function(a){(a===!0?--n.readyWait:n.isReady)||(n.isReady=!0,a!==!0&&--n.readyWait>0||(H.resolveWith(l,[n]),n.fn.triggerHandler&&(n(l).triggerHandler("ready"),n(l).off("ready"))))}});function I(){l.removeEventListener("DOMContentLoaded",I,!1),a.removeEventListener("load",I,!1),n.ready()}n.ready.promise=function(b){return H||(H=n.Deferred(),"complete"===l.readyState?setTimeout(n.ready):(l.addEventListener("DOMContentLoaded",I,!1),a.addEventListener("load",I,!1))),H.promise(b)},n.ready.promise();var J=n.access=function(a,b,c,d,e,f,g){var h=0,i=a.length,j=null==c;if("object"===n.type(c)){e=!0;for(h in c)n.access(a,b,h,c[h],!0,f,g)}else if(void 0!==d&&(e=!0,n.isFunction(d)||(g=!0),j&&(g?(b.call(a,d),b=null):(j=b,b=function(a,b,c){return j.call(n(a),c)})),b))for(;i>h;h++)b(a[h],c,g?d:d.call(a[h],h,b(a[h],c)));return e?a:j?b.call(a):i?b(a[0],c):f};n.acceptData=function(a){return 1===a.nodeType||9===a.nodeType||!+a.nodeType};function K(){Object.defineProperty(this.cache={},0,{get:function(){return{}}}),this.expando=n.expando+K.uid++}K.uid=1,K.accepts=n.acceptData,K.prototype={key:function(a){if(!K.accepts(a))return 0;var b={},c=a[this.expando];if(!c){c=K.uid++;try{b[this.expando]={value:c},Object.defineProperties(a,b)}catch(d){b[this.expando]=c,n.extend(a,b)}}return this.cache[c]||(this.cache[c]={}),c},set:function(a,b,c){var d,e=this.key(a),f=this.cache[e];if("string"==typeof b)f[b]=c;else if(n.isEmptyObject(f))n.extend(this.cache[e],b);else for(d in b)f[d]=b[d];return f},get:function(a,b){var c=this.cache[this.key(a)];return void 0===b?c:c[b]},access:function(a,b,c){var d;return void 0===b||b&&"string"==typeof b&&void 0===c?(d=this.get(a,b),void 0!==d?d:this.get(a,n.camelCase(b))):(this.set(a,b,c),void 0!==c?c:b)},remove:function(a,b){var c,d,e,f=this.key(a),g=this.cache[f];if(void 0===b)this.cache[f]={};else{n.isArray(b)?d=b.concat(b.map(n.camelCase)):(e=n.camelCase(b),b in g?d=[b,e]:(d=e,d=d in g?[d]:d.match(E)||[])),c=d.length;while(c--)delete g[d[c]]}},hasData:function(a){return!n.isEmptyObject(this.cache[a[this.expando]]||{})},discard:function(a){a[this.expando]&&delete this.cache[a[this.expando]]}};var L=new K,M=new K,N=/^(?:\{[\w\W]*\}|\[[\w\W]*\])$/,O=/([A-Z])/g;function P(a,b,c){var d;if(void 0===c&&1===a.nodeType)if(d="data-"+b.replace(O,"-$1").toLowerCase(),c=a.getAttribute(d),"string"==typeof c){try{c="true"===c?!0:"false"===c?!1:"null"===c?null:+c+""===c?+c:N.test(c)?n.parseJSON(c):c}catch(e){}M.set(a,b,c)}else c=void 0;return c}n.extend({hasData:function(a){return M.hasData(a)||L.hasData(a)},data:function(a,b,c){return M.access(a,b,c) -},removeData:function(a,b){M.remove(a,b)},_data:function(a,b,c){return L.access(a,b,c)},_removeData:function(a,b){L.remove(a,b)}}),n.fn.extend({data:function(a,b){var c,d,e,f=this[0],g=f&&f.attributes;if(void 0===a){if(this.length&&(e=M.get(f),1===f.nodeType&&!L.get(f,"hasDataAttrs"))){c=g.length;while(c--)g[c]&&(d=g[c].name,0===d.indexOf("data-")&&(d=n.camelCase(d.slice(5)),P(f,d,e[d])));L.set(f,"hasDataAttrs",!0)}return e}return"object"==typeof a?this.each(function(){M.set(this,a)}):J(this,function(b){var c,d=n.camelCase(a);if(f&&void 0===b){if(c=M.get(f,a),void 0!==c)return c;if(c=M.get(f,d),void 0!==c)return c;if(c=P(f,d,void 0),void 0!==c)return c}else this.each(function(){var c=M.get(this,d);M.set(this,d,b),-1!==a.indexOf("-")&&void 0!==c&&M.set(this,a,b)})},null,b,arguments.length>1,null,!0)},removeData:function(a){return this.each(function(){M.remove(this,a)})}}),n.extend({queue:function(a,b,c){var d;return a?(b=(b||"fx")+"queue",d=L.get(a,b),c&&(!d||n.isArray(c)?d=L.access(a,b,n.makeArray(c)):d.push(c)),d||[]):void 0},dequeue:function(a,b){b=b||"fx";var c=n.queue(a,b),d=c.length,e=c.shift(),f=n._queueHooks(a,b),g=function(){n.dequeue(a,b)};"inprogress"===e&&(e=c.shift(),d--),e&&("fx"===b&&c.unshift("inprogress"),delete f.stop,e.call(a,g,f)),!d&&f&&f.empty.fire()},_queueHooks:function(a,b){var c=b+"queueHooks";return L.get(a,c)||L.access(a,c,{empty:n.Callbacks("once memory").add(function(){L.remove(a,[b+"queue",c])})})}}),n.fn.extend({queue:function(a,b){var c=2;return"string"!=typeof a&&(b=a,a="fx",c--),arguments.lengthx",k.noCloneChecked=!!b.cloneNode(!0).lastChild.defaultValue}();var U="undefined";k.focusinBubbles="onfocusin"in a;var V=/^key/,W=/^(?:mouse|pointer|contextmenu)|click/,X=/^(?:focusinfocus|focusoutblur)$/,Y=/^([^.]*)(?:\.(.+)|)$/;function Z(){return!0}function $(){return!1}function _(){try{return l.activeElement}catch(a){}}n.event={global:{},add:function(a,b,c,d,e){var f,g,h,i,j,k,l,m,o,p,q,r=L.get(a);if(r){c.handler&&(f=c,c=f.handler,e=f.selector),c.guid||(c.guid=n.guid++),(i=r.events)||(i=r.events={}),(g=r.handle)||(g=r.handle=function(b){return typeof n!==U&&n.event.triggered!==b.type?n.event.dispatch.apply(a,arguments):void 0}),b=(b||"").match(E)||[""],j=b.length;while(j--)h=Y.exec(b[j])||[],o=q=h[1],p=(h[2]||"").split(".").sort(),o&&(l=n.event.special[o]||{},o=(e?l.delegateType:l.bindType)||o,l=n.event.special[o]||{},k=n.extend({type:o,origType:q,data:d,handler:c,guid:c.guid,selector:e,needsContext:e&&n.expr.match.needsContext.test(e),namespace:p.join(".")},f),(m=i[o])||(m=i[o]=[],m.delegateCount=0,l.setup&&l.setup.call(a,d,p,g)!==!1||a.addEventListener&&a.addEventListener(o,g,!1)),l.add&&(l.add.call(a,k),k.handler.guid||(k.handler.guid=c.guid)),e?m.splice(m.delegateCount++,0,k):m.push(k),n.event.global[o]=!0)}},remove:function(a,b,c,d,e){var f,g,h,i,j,k,l,m,o,p,q,r=L.hasData(a)&&L.get(a);if(r&&(i=r.events)){b=(b||"").match(E)||[""],j=b.length;while(j--)if(h=Y.exec(b[j])||[],o=q=h[1],p=(h[2]||"").split(".").sort(),o){l=n.event.special[o]||{},o=(d?l.delegateType:l.bindType)||o,m=i[o]||[],h=h[2]&&new RegExp("(^|\\.)"+p.join("\\.(?:.*\\.|)")+"(\\.|$)"),g=f=m.length;while(f--)k=m[f],!e&&q!==k.origType||c&&c.guid!==k.guid||h&&!h.test(k.namespace)||d&&d!==k.selector&&("**"!==d||!k.selector)||(m.splice(f,1),k.selector&&m.delegateCount--,l.remove&&l.remove.call(a,k));g&&!m.length&&(l.teardown&&l.teardown.call(a,p,r.handle)!==!1||n.removeEvent(a,o,r.handle),delete i[o])}else for(o in i)n.event.remove(a,o+b[j],c,d,!0);n.isEmptyObject(i)&&(delete r.handle,L.remove(a,"events"))}},trigger:function(b,c,d,e){var f,g,h,i,k,m,o,p=[d||l],q=j.call(b,"type")?b.type:b,r=j.call(b,"namespace")?b.namespace.split("."):[];if(g=h=d=d||l,3!==d.nodeType&&8!==d.nodeType&&!X.test(q+n.event.triggered)&&(q.indexOf(".")>=0&&(r=q.split("."),q=r.shift(),r.sort()),k=q.indexOf(":")<0&&"on"+q,b=b[n.expando]?b:new n.Event(q,"object"==typeof b&&b),b.isTrigger=e?2:3,b.namespace=r.join("."),b.namespace_re=b.namespace?new RegExp("(^|\\.)"+r.join("\\.(?:.*\\.|)")+"(\\.|$)"):null,b.result=void 0,b.target||(b.target=d),c=null==c?[b]:n.makeArray(c,[b]),o=n.event.special[q]||{},e||!o.trigger||o.trigger.apply(d,c)!==!1)){if(!e&&!o.noBubble&&!n.isWindow(d)){for(i=o.delegateType||q,X.test(i+q)||(g=g.parentNode);g;g=g.parentNode)p.push(g),h=g;h===(d.ownerDocument||l)&&p.push(h.defaultView||h.parentWindow||a)}f=0;while((g=p[f++])&&!b.isPropagationStopped())b.type=f>1?i:o.bindType||q,m=(L.get(g,"events")||{})[b.type]&&L.get(g,"handle"),m&&m.apply(g,c),m=k&&g[k],m&&m.apply&&n.acceptData(g)&&(b.result=m.apply(g,c),b.result===!1&&b.preventDefault());return b.type=q,e||b.isDefaultPrevented()||o._default&&o._default.apply(p.pop(),c)!==!1||!n.acceptData(d)||k&&n.isFunction(d[q])&&!n.isWindow(d)&&(h=d[k],h&&(d[k]=null),n.event.triggered=q,d[q](),n.event.triggered=void 0,h&&(d[k]=h)),b.result}},dispatch:function(a){a=n.event.fix(a);var b,c,e,f,g,h=[],i=d.call(arguments),j=(L.get(this,"events")||{})[a.type]||[],k=n.event.special[a.type]||{};if(i[0]=a,a.delegateTarget=this,!k.preDispatch||k.preDispatch.call(this,a)!==!1){h=n.event.handlers.call(this,a,j),b=0;while((f=h[b++])&&!a.isPropagationStopped()){a.currentTarget=f.elem,c=0;while((g=f.handlers[c++])&&!a.isImmediatePropagationStopped())(!a.namespace_re||a.namespace_re.test(g.namespace))&&(a.handleObj=g,a.data=g.data,e=((n.event.special[g.origType]||{}).handle||g.handler).apply(f.elem,i),void 0!==e&&(a.result=e)===!1&&(a.preventDefault(),a.stopPropagation()))}return k.postDispatch&&k.postDispatch.call(this,a),a.result}},handlers:function(a,b){var c,d,e,f,g=[],h=b.delegateCount,i=a.target;if(h&&i.nodeType&&(!a.button||"click"!==a.type))for(;i!==this;i=i.parentNode||this)if(i.disabled!==!0||"click"!==a.type){for(d=[],c=0;h>c;c++)f=b[c],e=f.selector+" ",void 0===d[e]&&(d[e]=f.needsContext?n(e,this).index(i)>=0:n.find(e,this,null,[i]).length),d[e]&&d.push(f);d.length&&g.push({elem:i,handlers:d})}return h]*)\/>/gi,bb=/<([\w:]+)/,cb=/<|&#?\w+;/,db=/<(?:script|style|link)/i,eb=/checked\s*(?:[^=]|=\s*.checked.)/i,fb=/^$|\/(?:java|ecma)script/i,gb=/^true\/(.*)/,hb=/^\s*\s*$/g,ib={option:[1,""],thead:[1,"","
"],col:[2,"","
"],tr:[2,"","
"],td:[3,"","
"],_default:[0,"",""]};ib.optgroup=ib.option,ib.tbody=ib.tfoot=ib.colgroup=ib.caption=ib.thead,ib.th=ib.td;function jb(a,b){return n.nodeName(a,"table")&&n.nodeName(11!==b.nodeType?b:b.firstChild,"tr")?a.getElementsByTagName("tbody")[0]||a.appendChild(a.ownerDocument.createElement("tbody")):a}function kb(a){return a.type=(null!==a.getAttribute("type"))+"/"+a.type,a}function lb(a){var b=gb.exec(a.type);return b?a.type=b[1]:a.removeAttribute("type"),a}function mb(a,b){for(var c=0,d=a.length;d>c;c++)L.set(a[c],"globalEval",!b||L.get(b[c],"globalEval"))}function nb(a,b){var c,d,e,f,g,h,i,j;if(1===b.nodeType){if(L.hasData(a)&&(f=L.access(a),g=L.set(b,f),j=f.events)){delete g.handle,g.events={};for(e in j)for(c=0,d=j[e].length;d>c;c++)n.event.add(b,e,j[e][c])}M.hasData(a)&&(h=M.access(a),i=n.extend({},h),M.set(b,i))}}function ob(a,b){var c=a.getElementsByTagName?a.getElementsByTagName(b||"*"):a.querySelectorAll?a.querySelectorAll(b||"*"):[];return void 0===b||b&&n.nodeName(a,b)?n.merge([a],c):c}function pb(a,b){var c=b.nodeName.toLowerCase();"input"===c&&T.test(a.type)?b.checked=a.checked:("input"===c||"textarea"===c)&&(b.defaultValue=a.defaultValue)}n.extend({clone:function(a,b,c){var d,e,f,g,h=a.cloneNode(!0),i=n.contains(a.ownerDocument,a);if(!(k.noCloneChecked||1!==a.nodeType&&11!==a.nodeType||n.isXMLDoc(a)))for(g=ob(h),f=ob(a),d=0,e=f.length;e>d;d++)pb(f[d],g[d]);if(b)if(c)for(f=f||ob(a),g=g||ob(h),d=0,e=f.length;e>d;d++)nb(f[d],g[d]);else nb(a,h);return g=ob(h,"script"),g.length>0&&mb(g,!i&&ob(a,"script")),h},buildFragment:function(a,b,c,d){for(var e,f,g,h,i,j,k=b.createDocumentFragment(),l=[],m=0,o=a.length;o>m;m++)if(e=a[m],e||0===e)if("object"===n.type(e))n.merge(l,e.nodeType?[e]:e);else if(cb.test(e)){f=f||k.appendChild(b.createElement("div")),g=(bb.exec(e)||["",""])[1].toLowerCase(),h=ib[g]||ib._default,f.innerHTML=h[1]+e.replace(ab,"<$1>")+h[2],j=h[0];while(j--)f=f.lastChild;n.merge(l,f.childNodes),f=k.firstChild,f.textContent=""}else l.push(b.createTextNode(e));k.textContent="",m=0;while(e=l[m++])if((!d||-1===n.inArray(e,d))&&(i=n.contains(e.ownerDocument,e),f=ob(k.appendChild(e),"script"),i&&mb(f),c)){j=0;while(e=f[j++])fb.test(e.type||"")&&c.push(e)}return k},cleanData:function(a){for(var b,c,d,e,f=n.event.special,g=0;void 0!==(c=a[g]);g++){if(n.acceptData(c)&&(e=c[L.expando],e&&(b=L.cache[e]))){if(b.events)for(d in b.events)f[d]?n.event.remove(c,d):n.removeEvent(c,d,b.handle);L.cache[e]&&delete L.cache[e]}delete M.cache[c[M.expando]]}}}),n.fn.extend({text:function(a){return J(this,function(a){return void 0===a?n.text(this):this.empty().each(function(){(1===this.nodeType||11===this.nodeType||9===this.nodeType)&&(this.textContent=a)})},null,a,arguments.length)},append:function(){return this.domManip(arguments,function(a){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var b=jb(this,a);b.appendChild(a)}})},prepend:function(){return this.domManip(arguments,function(a){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var b=jb(this,a);b.insertBefore(a,b.firstChild)}})},before:function(){return this.domManip(arguments,function(a){this.parentNode&&this.parentNode.insertBefore(a,this)})},after:function(){return this.domManip(arguments,function(a){this.parentNode&&this.parentNode.insertBefore(a,this.nextSibling)})},remove:function(a,b){for(var c,d=a?n.filter(a,this):this,e=0;null!=(c=d[e]);e++)b||1!==c.nodeType||n.cleanData(ob(c)),c.parentNode&&(b&&n.contains(c.ownerDocument,c)&&mb(ob(c,"script")),c.parentNode.removeChild(c));return this},empty:function(){for(var a,b=0;null!=(a=this[b]);b++)1===a.nodeType&&(n.cleanData(ob(a,!1)),a.textContent="");return this},clone:function(a,b){return a=null==a?!1:a,b=null==b?a:b,this.map(function(){return n.clone(this,a,b)})},html:function(a){return J(this,function(a){var b=this[0]||{},c=0,d=this.length;if(void 0===a&&1===b.nodeType)return b.innerHTML;if("string"==typeof a&&!db.test(a)&&!ib[(bb.exec(a)||["",""])[1].toLowerCase()]){a=a.replace(ab,"<$1>");try{for(;d>c;c++)b=this[c]||{},1===b.nodeType&&(n.cleanData(ob(b,!1)),b.innerHTML=a);b=0}catch(e){}}b&&this.empty().append(a)},null,a,arguments.length)},replaceWith:function(){var a=arguments[0];return this.domManip(arguments,function(b){a=this.parentNode,n.cleanData(ob(this)),a&&a.replaceChild(b,this)}),a&&(a.length||a.nodeType)?this:this.remove()},detach:function(a){return this.remove(a,!0)},domManip:function(a,b){a=e.apply([],a);var c,d,f,g,h,i,j=0,l=this.length,m=this,o=l-1,p=a[0],q=n.isFunction(p);if(q||l>1&&"string"==typeof p&&!k.checkClone&&eb.test(p))return this.each(function(c){var d=m.eq(c);q&&(a[0]=p.call(this,c,d.html())),d.domManip(a,b)});if(l&&(c=n.buildFragment(a,this[0].ownerDocument,!1,this),d=c.firstChild,1===c.childNodes.length&&(c=d),d)){for(f=n.map(ob(c,"script"),kb),g=f.length;l>j;j++)h=c,j!==o&&(h=n.clone(h,!0,!0),g&&n.merge(f,ob(h,"script"))),b.call(this[j],h,j);if(g)for(i=f[f.length-1].ownerDocument,n.map(f,lb),j=0;g>j;j++)h=f[j],fb.test(h.type||"")&&!L.access(h,"globalEval")&&n.contains(i,h)&&(h.src?n._evalUrl&&n._evalUrl(h.src):n.globalEval(h.textContent.replace(hb,"")))}return this}}),n.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(a,b){n.fn[a]=function(a){for(var c,d=[],e=n(a),g=e.length-1,h=0;g>=h;h++)c=h===g?this:this.clone(!0),n(e[h])[b](c),f.apply(d,c.get());return this.pushStack(d)}});var qb,rb={};function sb(b,c){var d,e=n(c.createElement(b)).appendTo(c.body),f=a.getDefaultComputedStyle&&(d=a.getDefaultComputedStyle(e[0]))?d.display:n.css(e[0],"display");return e.detach(),f}function tb(a){var b=l,c=rb[a];return c||(c=sb(a,b),"none"!==c&&c||(qb=(qb||n(" + +
+ + + +
+ +
+

Example Code

+ + +
+

Would you like to create a new example? Head over to the examples repo on GitHub.

+ + + + + + + + + +======= @@ -21,7 +106,6 @@ - @@ -76,8 +160,8 @@

- Download the example code @@ -140,3 +224,4 @@

+>>>>>>> origin/master diff --git a/js/jquery.mobile.custom.min.js b/js/jquery.mobile.custom.min.js new file mode 100755 index 0000000..058c345 --- /dev/null +++ b/js/jquery.mobile.custom.min.js @@ -0,0 +1,3 @@ +/*! jQuery Mobile v1.4.5 | Copyright 2010, 2014 jQuery Foundation, Inc. | jquery.org/license */ + +(function(e,t,n){typeof define=="function"&&define.amd?define(["jquery"],function(r){return n(r,e,t),r.mobile}):n(e.jQuery,e,t)})(this,document,function(e,t,n,r){(function(e,t,n,r){function T(e){while(e&&typeof e.originalEvent!="undefined")e=e.originalEvent;return e}function N(t,n){var i=t.type,s,o,a,l,c,h,p,d,v;t=e.Event(t),t.type=n,s=t.originalEvent,o=e.event.props,i.search(/^(mouse|click)/)>-1&&(o=f);if(s)for(p=o.length,l;p;)l=o[--p],t[l]=s[l];i.search(/mouse(down|up)|click/)>-1&&!t.which&&(t.which=1);if(i.search(/^touch/)!==-1){a=T(s),i=a.touches,c=a.changedTouches,h=i&&i.length?i[0]:c&&c.length?c[0]:r;if(h)for(d=0,v=u.length;di||Math.abs(n.pageY-p)>i,d&&!r&&P("vmousecancel",t,s),P("vmousemove",t,s),_()}function I(e){if(g)return;A();var t=C(e.target),n,r;P("vmouseup",e,t),d||(n=P("vclick",e,t),n&&n.isDefaultPrevented()&&(r=T(e).changedTouches[0],v.push({touchID:E,x:r.clientX,y:r.clientY}),m=!0)),P("vmouseout",e,t),d=!1,_()}function q(t){var n=e.data(t,i),r;if(n)for(r in n)if(n[r])return!0;return!1}function R(){}function U(t){var n=t.substr(1);return{setup:function(){q(this)||e.data(this,i,{});var r=e.data(this,i);r[t]=!0,l[t]=(l[t]||0)+1,l[t]===1&&b.bind(n,H),e(this).bind(n,R),y&&(l.touchstart=(l.touchstart||0)+1,l.touchstart===1&&b.bind("touchstart",B).bind("touchend",I).bind("touchmove",F).bind("scroll",j))},teardown:function(){--l[t],l[t]||b.unbind(n,H),y&&(--l.touchstart,l.touchstart||b.unbind("touchstart",B).unbind("touchmove",F).unbind("touchend",I).unbind("scroll",j));var r=e(this),s=e.data(this,i);s&&(s[t]=!1),r.unbind(n,R),q(this)||r.removeData(i)}}}var i="virtualMouseBindings",s="virtualTouchID",o="vmouseover vmousedown vmousemove vmouseup vclick vmouseout vmousecancel".split(" "),u="clientX clientY pageX pageY screenX screenY".split(" "),a=e.event.mouseHooks?e.event.mouseHooks.props:[],f=e.event.props.concat(a),l={},c=0,h=0,p=0,d=!1,v=[],m=!1,g=!1,y="addEventListener"in n,b=e(n),w=1,E=0,S,x;e.vmouse={moveDistanceThreshold:10,clickDistanceThreshold:10,resetTimerDuration:1500};for(x=0;xMath.floor(e.pageY)||e.pageX===0&&Math.floor(i)>Math.floor(e.pageX))i-=n,s-=r;else if(se.event.special.swipe.horizontalDistanceThreshold&&Math.abs(t.coords[1]-n.coords[1])n.coords[0]?"swipeleft":"swiperight";return l(r,"swipe",e.Event("swipe",{target:i,swipestart:t,swipestop:n}),!0),l(r,s,e.Event(s,{target:i,swipestart:t,swipestop:n}),!0),!0}return!1},eventInProgress:!1,setup:function(){var t,n=this,r=e(n),s={};t=e.data(this,"mobile-events"),t||(t={length:0},e.data(this,"mobile-events",t)),t.length++,t.swipe=s,s.start=function(t){if(e.event.special.swipe.eventInProgress)return;e.event.special.swipe.eventInProgress=!0;var r,o=e.event.special.swipe.start(t),u=t.target,l=!1;s.move=function(t){if(!o||t.isDefaultPrevented())return;r=e.event.special.swipe.stop(t),l||(l=e.event.special.swipe.handleSwipe(o,r,n,u),l&&(e.event.special.swipe.eventInProgress=!1)),Math.abs(o.coords[0]-r.coords[0])>e.event.special.swipe.scrollSupressionThreshold&&t.preventDefault()},s.stop=function(){l=!0,e.event.special.swipe.eventInProgress=!1,i.off(f,s.move),s.move=null},i.on(f,s.move).one(a,s.stop)},r.on(u,s.start)},teardown:function(){var t,n;t=e.data(this,"mobile-events"),t&&(n=t.swipe,delete t.swipe,t.length--,t.length===0&&e.removeData(this,"mobile-events")),n&&(n.start&&e(this).off(u,n.start),n.move&&i.off(f,n.move),n.stop&&i.off(a,n.stop))}},e.each({scrollstop:"scrollstart",taphold:"tap",swipeleft:"swipe.left",swiperight:"swipe.right"},function(t,n){e.event.special[t]={setup:function(){e(this).bind(n,e.noop)},teardown:function(){e(this).unbind(n)}}})}(e,this)}); \ No newline at end of file diff --git a/js/modernizr.custom.min.js b/js/modernizr.custom.min.js new file mode 100755 index 0000000..99420e5 --- /dev/null +++ b/js/modernizr.custom.min.js @@ -0,0 +1,3 @@ +/*! modernizr 3.3.1 (Custom Build) | MIT * + * http://modernizr.com/download/?-canvas-touchevents-setclasses !*/ +!function(e,n,t){function o(e,n){return typeof e===n}function s(){var e,n,t,s,a,i,r;for(var l in c)if(c.hasOwnProperty(l)){if(e=[],n=c[l],n.name&&(e.push(n.name.toLowerCase()),n.options&&n.options.aliases&&n.options.aliases.length))for(t=0;t'+sections[i]+'
    ', + items = data[sections[i]]; + + for (var j=0; j'+items[j].title+''; + } + html += '
'; + + $('.main-menu').append(html); + } + + bpc.initNav(); + }); + + $.getJSON('https://api.github.com/repos/pixijs/pixi.js/git/refs/tags', function (data) { + // filters the tags to only include v3 and above + data = data.filter(function (tag) { + return tag.ref.indexOf('refs/tags/v3.0.11') === 0 || + tag.ref.indexOf('refs/tags/v4') === 0; + }).map(function (tag) { + return tag.ref.replace('refs/tags/', ''); + }); + + for (var i = 0; i < data.length; i++) { + $('.select-group .select ul').append('
  • '+data[i]+'
  • '); + } + }); + }; + + bpc.openMobileNav = function() { + TweenMax.to('#line1', 0.2, {y: 0, ease: Linear.easeNone}); + TweenMax.to('#line2', 0, {alpha: 0, ease: Linear.easeNone, delay: 0.2}); + TweenMax.to('#line3', 0.2, {y: 0, ease: Linear.easeNone}); + + TweenMax.to('#line1', 0.2, {rotation: 45, ease: Quart.easeOut, delay: 0.2}); + TweenMax.to('#line3', 0.2, {rotation: -45, ease: Quart.easeOut, delay: 0.2}); + + $('.main-nav').addClass('mobile-open'); + }; + + bpc.closeMobileNav = function() { + TweenMax.to('#line1', 0.2, {rotation: 0, ease: Linear.easeNone, delay: 0}); + TweenMax.to('#line3', 0.2, {rotation: 0, ease: Linear.easeNone, delay: 0}); + + TweenMax.to('#line2', 0, {alpha: 1, ease: Quart.easeOut, delay: 0.2}); + TweenMax.to('#line1', 0.2, {y: -8, ease: Quart.easeOut, delay: 0.2}); + TweenMax.to('#line3', 0.2, {y: 8, ease: Quart.easeOut, delay: 0.2}); + + $('.main-nav').removeClass('mobile-open'); + }; + + /*bpc.drawLines = function(elem) { + var divHeight = parseInt(elem.height()); + var lineHeight = parseInt(elem.css('line-height')); + var lines = divHeight / lineHeight; + $('.main-content .code-editor .line-numbers').html(''); + for (var i = 1; i <= lines; i++) { + $('.main-content .code-editor .line-numbers').append(i+'
    '); + } + };*/ + + bpc.initNav = function() { + //var Prism = require('prismjs'); + $('.main-menu .section').on(bpc.clickType, function() { + $(this).next('ul').slideToggle(350); + $(this).toggleClass('open'); + }); + $('.main-menu li').on(bpc.clickType, function() { + if (!$(this).hasClass('selected')) { + $('.main-menu li.selected').removeClass('selected'); + $(this).addClass('selected'); + // load data + bpc.closeMobileNav(); + $('.main-content h1').text($(this).text()); + window.location.hash = '/'+$(this).parent().attr('data-section')+'/'+$(this).attr('data-src'); + + document.title = $(this).text() + ' - PixiJS Examples'; + + bpc.currentSource = 'required/examples/'+$(this).parent().attr('data-section')+'/'+$(this).attr('data-src'); + bpc.currentFilename = $(this).attr('data-src'); + bpc.plugins = $(this).attr('data-plugins'); + + $.ajax({ + url : 'required/examples/'+$(this).parent().attr('data-section')+'/'+$(this).attr('data-src'), + dataType: "text", + success : function(data) { + bpc.jsSource = data; + //var html = Prism.highlight(data, Prism.languages.javascript); + var html = data; + $('.CodeMirror').remove(); + $('.main-content #code').html(html); + + var editorOptions = { + mode: 'javascript', + lineNumbers: true, + styleActiveLine: true, + matchBrackets: true, + viewportMargin: Infinity, + lineWrapping: true + }; + + bpc.editor = CodeMirror.fromTextArea(document.getElementById('code'), editorOptions); + + //bpc.drawLines($('.main-content .code-editor #code')); + + bpc.generateIFrameContent(); + } + }); + + //$('#preview').attr('src', 'iframe.html?src='+bpc.currentSource+'&v='+bpc.version+'&plugins='+bpc.plugins); + } + }); + $('.main-header .hamburger').on(bpc.clickType, function(e) { + e.preventDefault(); + if ($('.main-nav').hasClass('mobile-open')) { + bpc.closeMobileNav(); + } else { + bpc.openMobileNav(); + } + return false; + }); + + // Deep link + if (window.location.hash !== '') { + var hash = window.location.hash.replace('#/', ''); + var arr = hash.split('/'); + if (arr.length > 1) { + if ($('.main-menu .section[data-section="'+arr[0]+'"]').length > 0) { + $('.main-menu .section[data-section="'+arr[0]+'"]').trigger(bpc.clickType); + if ($('.main-menu .section[data-section="'+arr[0]+'"]').next().find('li[data-src="'+arr[1]+'"]').length > 0) { + $('.main-menu .section[data-section="'+arr[0]+'"]').next().find('li[data-src="'+arr[1]+'"]').trigger(bpc.clickType); + } + } + } + } else { + $('.main-menu .section').eq(0).trigger(bpc.clickType); + $('.main-menu li').eq(0).trigger(bpc.clickType); + } + + // Version control + $('.select-group').on(bpc.clickType, function() { + if ($(this).find('.select').hasClass('open')) { + $(this).find('.select').removeClass('open'); + $(this).find('ul').slideUp(250); + } else { + $(this).find('.select').addClass('open'); + $(this).find('ul').slideDown(250); + } + }); + /*$('.select-group .current').on(bpc.clickType, function() { + if ($(this).parent().hasClass('open')) { + $(this).parent().removeClass('open'); + $(this).parent().find('ul').slideUp(250); + } else { + $(this).parent().addClass('open'); + $(this).parent().find('ul').slideDown(250); + } + });*/ + $('.select-group .select').on(bpc.clickType, 'li', function() { + if (!$(this).hasClass('selected')) { + $('.select-group .select li.selected').removeClass('selected'); + $(this).addClass('selected'); + $('.select-group .select .current').text($(this).text()); + + bpc.version = $(this).attr('data-val'); + //$('#preview').attr('src', 'iframe.html?src='+bpc.currentSource+'&v='+bpc.version+'&plugins='+bpc.plugins); + bpc.generateIFrameContent(); + $('.main-content').animate({scrollTop: 0}, 300); + } + }); + + // Download + $('.footer .download').on(bpc.clickType, function() { + bpc.SaveToDisk(bpc.currentSource, bpc.currentFilename); + }); + + // Refresh Button + $('.reload').on(bpc.clickType, function() { + bpc.jsSource = bpc.editor.getValue(); + bpc.generateIFrameContent(); + }); + }; + + bpc.generateIFrameContent = function() { + // Remove all iFrames and content + var iframes = document.querySelectorAll('iframe'); + for (var i = 0; i < iframes.length; i++) { + iframes[i].parentNode.removeChild(iframes[i]); + } + $('#example').html(''); + // Generate HTML and insert into iFrame + var js = bpc.jsSource; + var html = ''; + html += ''; + html += ''; + + var plugins = bpc.plugins === '' ? [] : bpc.plugins.split(','); + for (i=0; i < plugins.length; i++) { + html += ''; + } + + html += ''; + + var iframe = document.getElementById('preview'); + var frameDoc = iframe.contentDocument || iframe.contentWindow.document; + + frameDoc.open(); + frameDoc.write(html); + frameDoc.close(); + }; + + bpc.SaveToDisk = function(fileURL, fileName) { + // for non-IE + if (!window.ActiveXObject) { + var save = document.createElement('a'); + save.href = fileURL; + save.target = '_blank'; + save.download = fileName || 'unknown'; + + var evt = new MouseEvent('click', { + 'view': window, + 'bubbles': true, + 'cancelable': false + }); + save.dispatchEvent(evt); + + (window.URL || window.webkitURL).revokeObjectURL(save.href); + } + + // for IE < 11 + else if (!! window.ActiveXObject && document.execCommand) { + var _window = window.open(fileURL, '_blank'); + _window.document.close(); + _window.document.execCommand('SaveAs', true, fileName || fileURL); + _window.close(); + } + }; + + bpc.init = function() { + if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) bpc.clickType = 'click'; + $(window).resize(bpc.resize); + + bpc.loadScriptsAsync(); + }; + + bpc.init(); +}); \ No newline at end of file diff --git a/js/pixi.min.js b/js/pixi.min.js new file mode 100644 index 0000000..1f87eec --- /dev/null +++ b/js/pixi.min.js @@ -0,0 +1,2 @@ +jQuery(document).ready(function($){var e=e||{};e.aniIn=.2,e.aniOut=.3,e.currentSource="",e.currentFilename="",e.version="dev",e.plugins="",e.clickType=Modernizr.touchevents?"tap":"click",e.resize=function(){},e.scriptsToLoad=["http://cdnjs.cloudflare.com/ajax/libs/gsap/latest/TweenMax.min.js"],e.scriptsLoaded=0,"tap"===e.clickType&&e.scriptsToLoad.push("js/jquery.mobile.custom.min.js"),e.loadScriptsAsync=function(){for(var t=0;t'+n[a]+'
      ',s=t[n[a]],o=0;o'+s[o].title+""}i+="
    ",$(".main-menu").append(i)}e.initNav()}),$.getJSON("https://api.github.com/repos/pixijs/pixi.js/git/refs/tags",function(e){e=e.filter(function(e){return 0===e.ref.indexOf("refs/tags/v3.0.11")||0===e.ref.indexOf("refs/tags/v4")}).map(function(e){return e.ref.replace("refs/tags/","")});for(var t=0;t'+e[t]+"")})},e.openMobileNav=function(){TweenMax.to("#line1",.2,{y:0,ease:Linear.easeNone}),TweenMax.to("#line2",0,{alpha:0,ease:Linear.easeNone,delay:.2}),TweenMax.to("#line3",.2,{y:0,ease:Linear.easeNone}),TweenMax.to("#line1",.2,{rotation:45,ease:Quart.easeOut,delay:.2}),TweenMax.to("#line3",.2,{rotation:-45,ease:Quart.easeOut,delay:.2}),$(".main-nav").addClass("mobile-open")},e.closeMobileNav=function(){TweenMax.to("#line1",.2,{rotation:0,ease:Linear.easeNone,delay:0}),TweenMax.to("#line3",.2,{rotation:0,ease:Linear.easeNone,delay:0}),TweenMax.to("#line2",0,{alpha:1,ease:Quart.easeOut,delay:.2}),TweenMax.to("#line1",.2,{y:-8,ease:Quart.easeOut,delay:.2}),TweenMax.to("#line3",.2,{y:8,ease:Quart.easeOut,delay:.2}),$(".main-nav").removeClass("mobile-open")},e.initNav=function(){if($(".main-menu .section").on(e.clickType,function(){$(this).next("ul").slideToggle(350),$(this).toggleClass("open")}),$(".main-menu li").on(e.clickType,function(){$(this).hasClass("selected")||($(".main-menu li.selected").removeClass("selected"),$(this).addClass("selected"),e.closeMobileNav(),$(".main-content h1").text($(this).text()),window.location.hash="/"+$(this).parent().attr("data-section")+"/"+$(this).attr("data-src"),document.title=$(this).text()+" - PixiJS Examples",e.currentSource="required/examples/"+$(this).parent().attr("data-section")+"/"+$(this).attr("data-src"),e.currentFilename=$(this).attr("data-src"),e.plugins=$(this).attr("data-plugins"),$.ajax({url:"required/examples/"+$(this).parent().attr("data-section")+"/"+$(this).attr("data-src"),dataType:"text",success:function(t){e.jsSource=t;var n=t;$(".CodeMirror").remove(),$(".main-content #code").html(n);var a={mode:"javascript",lineNumbers:!0,styleActiveLine:!0,matchBrackets:!0,viewportMargin:1/0,lineWrapping:!0};e.editor=CodeMirror.fromTextArea(document.getElementById("code"),a),e.generateIFrameContent()}}))}),$(".main-header .hamburger").on(e.clickType,function(t){return t.preventDefault(),$(".main-nav").hasClass("mobile-open")?e.closeMobileNav():e.openMobileNav(),!1}),""!==window.location.hash){var t=window.location.hash.replace("#/",""),n=t.split("/");n.length>1&&$('.main-menu .section[data-section="'+n[0]+'"]').length>0&&($('.main-menu .section[data-section="'+n[0]+'"]').trigger(e.clickType),$('.main-menu .section[data-section="'+n[0]+'"]').next().find('li[data-src="'+n[1]+'"]').length>0&&$('.main-menu .section[data-section="'+n[0]+'"]').next().find('li[data-src="'+n[1]+'"]').trigger(e.clickType))}else $(".main-menu .section").eq(0).trigger(e.clickType),$(".main-menu li").eq(0).trigger(e.clickType);$(".select-group").on(e.clickType,function(){$(this).find(".select").hasClass("open")?($(this).find(".select").removeClass("open"),$(this).find("ul").slideUp(250)):($(this).find(".select").addClass("open"),$(this).find("ul").slideDown(250))}),$(".select-group .select").on(e.clickType,"li",function(){$(this).hasClass("selected")||($(".select-group .select li.selected").removeClass("selected"),$(this).addClass("selected"),$(".select-group .select .current").text($(this).text()),e.version=$(this).attr("data-val"),e.generateIFrameContent(),$(".main-content").animate({scrollTop:0},300))}),$(".footer .download").on(e.clickType,function(){e.SaveToDisk(e.currentSource,e.currentFilename)}),$(".reload").on(e.clickType,function(){e.jsSource=e.editor.getValue(),e.generateIFrameContent()})},e.generateIFrameContent=function(){for(var t=document.querySelectorAll("iframe"),n=0;n');var a=e.jsSource,i="";i+='',i+='';var s=""===e.plugins?[]:e.plugins.split(",");for(n=0;n';i+="";var o=document.getElementById("preview"),r=o.contentDocument||o.contentWindow.document;r.open(),r.write(i),r.close()},e.SaveToDisk=function(e,t){if(window.ActiveXObject){if(window.ActiveXObject&&document.execCommand){var n=window.open(e,"_blank");n.document.close(),n.document.execCommand("SaveAs",!0,t||e),n.close()}}else{var a=document.createElement("a");a.href=e,a.target="_blank",a.download=t||"unknown";var i=new MouseEvent("click",{view:window,bubbles:!0,cancelable:!1});a.dispatchEvent(i),(window.URL||window.webkitURL).revokeObjectURL(a.href)}},e.init=function(){/MSIE (\d+\.\d+);/.test(navigator.userAgent)&&(e.clickType="click"),$(window).resize(e.resize),e.loadScriptsAsync()},e.init()}); +//# sourceMappingURL=./pixi.min.js.map \ No newline at end of file diff --git a/js/pixi.min.js.map b/js/pixi.min.js.map new file mode 100644 index 0000000..23d08e7 --- /dev/null +++ b/js/pixi.min.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["pixi.js"],"names":["jQuery","document","ready","$","bpc","aniIn","aniOut","currentSource","currentFilename","version","plugins","clickType","Modernizr","touchevents","resize","scriptsToLoad","scriptsLoaded","push","loadScriptsAsync","i","length","ajax","url","dataType","cache","async","success","fileLoaded","loadComplete","getJSON","data","sections","Object","keys","html","items","j","join","entry","title","append","initNav","filter","tag","ref","indexOf","map","replace","openMobileNav","TweenMax","to","y","ease","Linear","easeNone","alpha","delay","rotation","Quart","easeOut","addClass","closeMobileNav","removeClass","on","this","next","slideToggle","toggleClass","hasClass","text","window","location","hash","parent","attr","jsSource","remove","editorOptions","mode","lineNumbers","styleActiveLine","matchBrackets","viewportMargin","Infinity","lineWrapping","editor","CodeMirror","fromTextArea","getElementById","generateIFrameContent","e","preventDefault","arr","split","trigger","find","eq","slideUp","slideDown","animate","scrollTop","SaveToDisk","getValue","iframes","querySelectorAll","parentNode","removeChild","js","iframe","frameDoc","contentDocument","contentWindow","open","write","close","fileURL","fileName","ActiveXObject","execCommand","_window","save","createElement","href","target","download","evt","MouseEvent","view","bubbles","cancelable","dispatchEvent","URL","webkitURL","revokeObjectURL","init","test","navigator","userAgent"],"mappings":"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","file":"pixi.min.js"} \ No newline at end of file diff --git a/jspm_packages/.dependencies.json b/jspm_packages/.dependencies.json new file mode 100644 index 0000000..c665d83 --- /dev/null +++ b/jspm_packages/.dependencies.json @@ -0,0 +1,39 @@ +{ + "npm:whatwg-fetch@0.7.0": {}, + "npm:signals@1.0.0": {}, + "npm:babel-runtime@5.8.35": { + "process": "github:jspm/nodelibs-process@^0.1.0" + }, + "npm:babel-core@5.8.35": {}, + "github:systemjs/plugin-text@0.0.2": {}, + "github:components/handlebars.js@3.0.0": {}, + "npm:core-js@0.9.18": { + "systemjs-json": "github:systemjs/plugin-json@^0.1.0", + "process": "github:jspm/nodelibs-process@^0.1.0", + "fs": "github:jspm/nodelibs-fs@^0.1.0" + }, + "npm:process@0.11.2": { + "assert": "github:jspm/nodelibs-assert@^0.1.0" + }, + "github:jspm/nodelibs-process@0.1.2": { + "process": "npm:process@^0.11.0" + }, + "npm:assert@1.3.0": { + "util": "npm:util@0.10.3" + }, + "npm:util@0.10.3": { + "inherits": "npm:inherits@2.0.1", + "process": "github:jspm/nodelibs-process@^0.1.0" + }, + "npm:inherits@2.0.1": { + "util": "github:jspm/nodelibs-util@^0.1.0" + }, + "github:systemjs/plugin-json@0.1.0": {}, + "github:jspm/nodelibs-fs@0.1.2": {}, + "github:jspm/nodelibs-assert@0.1.0": { + "assert": "npm:assert@^1.3.0" + }, + "github:jspm/nodelibs-util@0.1.0": { + "util": "npm:util@^0.10.3" + } +} \ No newline at end of file diff --git a/jspm_packages/.loaderversions b/jspm_packages/.loaderversions new file mode 100644 index 0000000..584f514 --- /dev/null +++ b/jspm_packages/.loaderversions @@ -0,0 +1 @@ +0.19.24 \ No newline at end of file diff --git a/jspm_packages/github/components/handlebars.js@3.0.0.js b/jspm_packages/github/components/handlebars.js@3.0.0.js new file mode 100644 index 0000000..dc8f3c2 --- /dev/null +++ b/jspm_packages/github/components/handlebars.js@3.0.0.js @@ -0,0 +1 @@ +module.exports = require("github:components/handlebars.js@3.0.0/handlebars"); \ No newline at end of file diff --git a/jspm_packages/github/components/handlebars.js@3.0.0/.jspm-hash b/jspm_packages/github/components/handlebars.js@3.0.0/.jspm-hash new file mode 100644 index 0000000..74d9ecc --- /dev/null +++ b/jspm_packages/github/components/handlebars.js@3.0.0/.jspm-hash @@ -0,0 +1 @@ +cd9d40b3ea6431204cc291d20e335e28337eea6399914b932bd37a50b983c5e7c90ae93bjspm-github@0.13.10.16.1 \ No newline at end of file diff --git a/jspm_packages/github/components/handlebars.js@3.0.0/handlebars.js b/jspm_packages/github/components/handlebars.js@3.0.0/handlebars.js new file mode 100644 index 0000000..b7e7601 --- /dev/null +++ b/jspm_packages/github/components/handlebars.js@3.0.0/handlebars.js @@ -0,0 +1,3749 @@ +/* */ +"format global"; +"exports Handlebars"; +/*! + + handlebars v3.0.0 + +Copyright (C) 2011-2014 by Yehuda Katz + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +@license +*/ +/* exported Handlebars */ +(function (root, factory) { + if (typeof define === 'function' && define.amd) { + define([], factory); + } else if (typeof exports === 'object') { + module.exports = factory(); + } else { + root.Handlebars = factory(); + } +}(this, function () { +// handlebars/utils.js +var __module3__ = (function() { + "use strict"; + var __exports__ = {}; + /*jshint -W004 */ + var escape = { + "&": "&", + "<": "<", + ">": ">", + '"': """, + "'": "'", + "`": "`" + }; + + var badChars = /[&<>"'`]/g; + var possible = /[&<>"'`]/; + + function escapeChar(chr) { + return escape[chr]; + } + + function extend(obj /* , ...source */) { + for (var i = 1; i < arguments.length; i++) { + for (var key in arguments[i]) { + if (Object.prototype.hasOwnProperty.call(arguments[i], key)) { + obj[key] = arguments[i][key]; + } + } + } + + return obj; + } + + __exports__.extend = extend;var toString = Object.prototype.toString; + __exports__.toString = toString; + // Sourced from lodash + // https://github.com/bestiejs/lodash/blob/master/LICENSE.txt + var isFunction = function(value) { + return typeof value === 'function'; + }; + // fallback for older versions of Chrome and Safari + /* istanbul ignore next */ + if (isFunction(/x/)) { + isFunction = function(value) { + return typeof value === 'function' && toString.call(value) === '[object Function]'; + }; + } + var isFunction; + __exports__.isFunction = isFunction; + /* istanbul ignore next */ + var isArray = Array.isArray || function(value) { + return (value && typeof value === 'object') ? toString.call(value) === '[object Array]' : false; + }; + __exports__.isArray = isArray; + // Older IE versions do not directly support indexOf so we must implement our own, sadly. + function indexOf(array, value) { + for (var i = 0, len = array.length; i < len; i++) { + if (array[i] === value) { + return i; + } + } + return -1; + } + + __exports__.indexOf = indexOf; + function escapeExpression(string) { + // don't escape SafeStrings, since they're already safe + if (string && string.toHTML) { + return string.toHTML(); + } else if (string == null) { + return ""; + } else if (!string) { + return string + ''; + } + + // Force a string conversion as this will be done by the append regardless and + // the regex test will do this transparently behind the scenes, causing issues if + // an object's to string has escaped characters in it. + string = "" + string; + + if(!possible.test(string)) { return string; } + return string.replace(badChars, escapeChar); + } + + __exports__.escapeExpression = escapeExpression;function isEmpty(value) { + if (!value && value !== 0) { + return true; + } else if (isArray(value) && value.length === 0) { + return true; + } else { + return false; + } + } + + __exports__.isEmpty = isEmpty;function blockParams(params, ids) { + params.path = ids; + return params; + } + + __exports__.blockParams = blockParams;function appendContextPath(contextPath, id) { + return (contextPath ? contextPath + '.' : '') + id; + } + + __exports__.appendContextPath = appendContextPath; + return __exports__; +})(); + +// handlebars/exception.js +var __module4__ = (function() { + "use strict"; + var __exports__; + + var errorProps = ['description', 'fileName', 'lineNumber', 'message', 'name', 'number', 'stack']; + + function Exception(message, node) { + var loc = node && node.loc, + line, + column; + if (loc) { + line = loc.start.line; + column = loc.start.column; + + message += ' - ' + line + ':' + column; + } + + var tmp = Error.prototype.constructor.call(this, message); + + // Unfortunately errors are not enumerable in Chrome (at least), so `for prop in tmp` doesn't work. + for (var idx = 0; idx < errorProps.length; idx++) { + this[errorProps[idx]] = tmp[errorProps[idx]]; + } + + if (loc) { + this.lineNumber = line; + this.column = column; + } + } + + Exception.prototype = new Error(); + + __exports__ = Exception; + return __exports__; +})(); + +// handlebars/base.js +var __module2__ = (function(__dependency1__, __dependency2__) { + "use strict"; + var __exports__ = {}; + var Utils = __dependency1__; + var Exception = __dependency2__; + + var VERSION = "3.0.0"; + __exports__.VERSION = VERSION;var COMPILER_REVISION = 6; + __exports__.COMPILER_REVISION = COMPILER_REVISION; + var REVISION_CHANGES = { + 1: '<= 1.0.rc.2', // 1.0.rc.2 is actually rev2 but doesn't report it + 2: '== 1.0.0-rc.3', + 3: '== 1.0.0-rc.4', + 4: '== 1.x.x', + 5: '== 2.0.0-alpha.x', + 6: '>= 2.0.0-beta.1' + }; + __exports__.REVISION_CHANGES = REVISION_CHANGES; + var isArray = Utils.isArray, + isFunction = Utils.isFunction, + toString = Utils.toString, + objectType = '[object Object]'; + + function HandlebarsEnvironment(helpers, partials) { + this.helpers = helpers || {}; + this.partials = partials || {}; + + registerDefaultHelpers(this); + } + + __exports__.HandlebarsEnvironment = HandlebarsEnvironment;HandlebarsEnvironment.prototype = { + constructor: HandlebarsEnvironment, + + logger: logger, + log: log, + + registerHelper: function(name, fn) { + if (toString.call(name) === objectType) { + if (fn) { throw new Exception('Arg not supported with multiple helpers'); } + Utils.extend(this.helpers, name); + } else { + this.helpers[name] = fn; + } + }, + unregisterHelper: function(name) { + delete this.helpers[name]; + }, + + registerPartial: function(name, partial) { + if (toString.call(name) === objectType) { + Utils.extend(this.partials, name); + } else { + if (typeof partial === 'undefined') { + throw new Exception('Attempting to register a partial as undefined'); + } + this.partials[name] = partial; + } + }, + unregisterPartial: function(name) { + delete this.partials[name]; + } + }; + + function registerDefaultHelpers(instance) { + instance.registerHelper('helperMissing', function(/* [args, ]options */) { + if(arguments.length === 1) { + // A missing field in a {{foo}} constuct. + return undefined; + } else { + // Someone is actually trying to call something, blow up. + throw new Exception("Missing helper: '" + arguments[arguments.length-1].name + "'"); + } + }); + + instance.registerHelper('blockHelperMissing', function(context, options) { + var inverse = options.inverse, + fn = options.fn; + + if(context === true) { + return fn(this); + } else if(context === false || context == null) { + return inverse(this); + } else if (isArray(context)) { + if(context.length > 0) { + if (options.ids) { + options.ids = [options.name]; + } + + return instance.helpers.each(context, options); + } else { + return inverse(this); + } + } else { + if (options.data && options.ids) { + var data = createFrame(options.data); + data.contextPath = Utils.appendContextPath(options.data.contextPath, options.name); + options = {data: data}; + } + + return fn(context, options); + } + }); + + instance.registerHelper('each', function(context, options) { + if (!options) { + throw new Exception('Must pass iterator to #each'); + } + + var fn = options.fn, inverse = options.inverse; + var i = 0, ret = "", data; + + var contextPath; + if (options.data && options.ids) { + contextPath = Utils.appendContextPath(options.data.contextPath, options.ids[0]) + '.'; + } + + if (isFunction(context)) { context = context.call(this); } + + if (options.data) { + data = createFrame(options.data); + } + + function execIteration(key, i, last) { + if (data) { + data.key = key; + data.index = i; + data.first = i === 0; + data.last = !!last; + + if (contextPath) { + data.contextPath = contextPath + key; + } + } + + ret = ret + fn(context[key], { + data: data, + blockParams: Utils.blockParams([context[key], key], [contextPath + key, null]) + }); + } + + if(context && typeof context === 'object') { + if (isArray(context)) { + for(var j = context.length; i 2) { + expected.push("'" + this.terminals_[p] + "'"); + } + if (this.lexer.showPosition) { + errStr = "Parse error on line " + (yylineno + 1) + ":\n" + this.lexer.showPosition() + "\nExpecting " + expected.join(", ") + ", got '" + (this.terminals_[symbol] || symbol) + "'"; + } else { + errStr = "Parse error on line " + (yylineno + 1) + ": Unexpected " + (symbol == 1?"end of input":"'" + (this.terminals_[symbol] || symbol) + "'"); + } + this.parseError(errStr, {text: this.lexer.match, token: this.terminals_[symbol] || symbol, line: this.lexer.yylineno, loc: yyloc, expected: expected}); + } + } + if (action[0] instanceof Array && action.length > 1) { + throw new Error("Parse Error: multiple actions possible at state: " + state + ", token: " + symbol); + } + switch (action[0]) { + case 1: + stack.push(symbol); + vstack.push(this.lexer.yytext); + lstack.push(this.lexer.yylloc); + stack.push(action[1]); + symbol = null; + if (!preErrorSymbol) { + yyleng = this.lexer.yyleng; + yytext = this.lexer.yytext; + yylineno = this.lexer.yylineno; + yyloc = this.lexer.yylloc; + if (recovering > 0) + recovering--; + } else { + symbol = preErrorSymbol; + preErrorSymbol = null; + } + break; + case 2: + len = this.productions_[action[1]][1]; + yyval.$ = vstack[vstack.length - len]; + yyval._$ = {first_line: lstack[lstack.length - (len || 1)].first_line, last_line: lstack[lstack.length - 1].last_line, first_column: lstack[lstack.length - (len || 1)].first_column, last_column: lstack[lstack.length - 1].last_column}; + if (ranges) { + yyval._$.range = [lstack[lstack.length - (len || 1)].range[0], lstack[lstack.length - 1].range[1]]; + } + r = this.performAction.call(yyval, yytext, yyleng, yylineno, this.yy, action[1], vstack, lstack); + if (typeof r !== "undefined") { + return r; + } + if (len) { + stack = stack.slice(0, -1 * len * 2); + vstack = vstack.slice(0, -1 * len); + lstack = lstack.slice(0, -1 * len); + } + stack.push(this.productions_[action[1]][0]); + vstack.push(yyval.$); + lstack.push(yyval._$); + newState = table[stack[stack.length - 2]][stack[stack.length - 1]]; + stack.push(newState); + break; + case 3: + return true; + } + } + return true; + } + }; + /* Jison generated lexer */ + var lexer = (function(){ + var lexer = ({EOF:1, + parseError:function parseError(str, hash) { + if (this.yy.parser) { + this.yy.parser.parseError(str, hash); + } else { + throw new Error(str); + } + }, + setInput:function (input) { + this._input = input; + this._more = this._less = this.done = false; + this.yylineno = this.yyleng = 0; + this.yytext = this.matched = this.match = ''; + this.conditionStack = ['INITIAL']; + this.yylloc = {first_line:1,first_column:0,last_line:1,last_column:0}; + if (this.options.ranges) this.yylloc.range = [0,0]; + this.offset = 0; + return this; + }, + input:function () { + var ch = this._input[0]; + this.yytext += ch; + this.yyleng++; + this.offset++; + this.match += ch; + this.matched += ch; + var lines = ch.match(/(?:\r\n?|\n).*/g); + if (lines) { + this.yylineno++; + this.yylloc.last_line++; + } else { + this.yylloc.last_column++; + } + if (this.options.ranges) this.yylloc.range[1]++; + + this._input = this._input.slice(1); + return ch; + }, + unput:function (ch) { + var len = ch.length; + var lines = ch.split(/(?:\r\n?|\n)/g); + + this._input = ch + this._input; + this.yytext = this.yytext.substr(0, this.yytext.length-len-1); + //this.yyleng -= len; + this.offset -= len; + var oldLines = this.match.split(/(?:\r\n?|\n)/g); + this.match = this.match.substr(0, this.match.length-1); + this.matched = this.matched.substr(0, this.matched.length-1); + + if (lines.length-1) this.yylineno -= lines.length-1; + var r = this.yylloc.range; + + this.yylloc = {first_line: this.yylloc.first_line, + last_line: this.yylineno+1, + first_column: this.yylloc.first_column, + last_column: lines ? + (lines.length === oldLines.length ? this.yylloc.first_column : 0) + oldLines[oldLines.length - lines.length].length - lines[0].length: + this.yylloc.first_column - len + }; + + if (this.options.ranges) { + this.yylloc.range = [r[0], r[0] + this.yyleng - len]; + } + return this; + }, + more:function () { + this._more = true; + return this; + }, + less:function (n) { + this.unput(this.match.slice(n)); + }, + pastInput:function () { + var past = this.matched.substr(0, this.matched.length - this.match.length); + return (past.length > 20 ? '...':'') + past.substr(-20).replace(/\n/g, ""); + }, + upcomingInput:function () { + var next = this.match; + if (next.length < 20) { + next += this._input.substr(0, 20-next.length); + } + return (next.substr(0,20)+(next.length > 20 ? '...':'')).replace(/\n/g, ""); + }, + showPosition:function () { + var pre = this.pastInput(); + var c = new Array(pre.length + 1).join("-"); + return pre + this.upcomingInput() + "\n" + c+"^"; + }, + next:function () { + if (this.done) { + return this.EOF; + } + if (!this._input) this.done = true; + + var token, + match, + tempMatch, + index, + col, + lines; + if (!this._more) { + this.yytext = ''; + this.match = ''; + } + var rules = this._currentRules(); + for (var i=0;i < rules.length; i++) { + tempMatch = this._input.match(this.rules[rules[i]]); + if (tempMatch && (!match || tempMatch[0].length > match[0].length)) { + match = tempMatch; + index = i; + if (!this.options.flex) break; + } + } + if (match) { + lines = match[0].match(/(?:\r\n?|\n).*/g); + if (lines) this.yylineno += lines.length; + this.yylloc = {first_line: this.yylloc.last_line, + last_line: this.yylineno+1, + first_column: this.yylloc.last_column, + last_column: lines ? lines[lines.length-1].length-lines[lines.length-1].match(/\r?\n?/)[0].length : this.yylloc.last_column + match[0].length}; + this.yytext += match[0]; + this.match += match[0]; + this.matches = match; + this.yyleng = this.yytext.length; + if (this.options.ranges) { + this.yylloc.range = [this.offset, this.offset += this.yyleng]; + } + this._more = false; + this._input = this._input.slice(match[0].length); + this.matched += match[0]; + token = this.performAction.call(this, this.yy, this, rules[index],this.conditionStack[this.conditionStack.length-1]); + if (this.done && this._input) this.done = false; + if (token) return token; + else return; + } + if (this._input === "") { + return this.EOF; + } else { + return this.parseError('Lexical error on line '+(this.yylineno+1)+'. Unrecognized text.\n'+this.showPosition(), + {text: "", token: null, line: this.yylineno}); + } + }, + lex:function lex() { + var r = this.next(); + if (typeof r !== 'undefined') { + return r; + } else { + return this.lex(); + } + }, + begin:function begin(condition) { + this.conditionStack.push(condition); + }, + popState:function popState() { + return this.conditionStack.pop(); + }, + _currentRules:function _currentRules() { + return this.conditions[this.conditionStack[this.conditionStack.length-1]].rules; + }, + topState:function () { + return this.conditionStack[this.conditionStack.length-2]; + }, + pushState:function begin(condition) { + this.begin(condition); + }}); + lexer.options = {}; + lexer.performAction = function anonymous(yy,yy_,$avoiding_name_collisions,YY_START) { + + + function strip(start, end) { + return yy_.yytext = yy_.yytext.substr(start, yy_.yyleng-end); + } + + + var YYSTATE=YY_START + switch($avoiding_name_collisions) { + case 0: + if(yy_.yytext.slice(-2) === "\\\\") { + strip(0,1); + this.begin("mu"); + } else if(yy_.yytext.slice(-1) === "\\") { + strip(0,1); + this.begin("emu"); + } else { + this.begin("mu"); + } + if(yy_.yytext) return 14; + + break; + case 1:return 14; + break; + case 2: + this.popState(); + return 14; + + break; + case 3: + yy_.yytext = yy_.yytext.substr(5, yy_.yyleng-9); + this.popState(); + return 16; + + break; + case 4: return 14; + break; + case 5: + this.popState(); + return 13; + + break; + case 6:return 59; + break; + case 7:return 62; + break; + case 8: return 17; + break; + case 9: + this.popState(); + this.begin('raw'); + return 21; + + break; + case 10:return 53; + break; + case 11:return 27; + break; + case 12:return 45; + break; + case 13:this.popState(); return 42; + break; + case 14:this.popState(); return 42; + break; + case 15:return 32; + break; + case 16:return 37; + break; + case 17:return 49; + break; + case 18:return 46; + break; + case 19: + this.unput(yy_.yytext); + this.popState(); + this.begin('com'); + + break; + case 20: + this.popState(); + return 13; + + break; + case 21:return 46; + break; + case 22:return 67; + break; + case 23:return 66; + break; + case 24:return 66; + break; + case 25:return 79; + break; + case 26:// ignore whitespace + break; + case 27:this.popState(); return 52; + break; + case 28:this.popState(); return 31; + break; + case 29:yy_.yytext = strip(1,2).replace(/\\"/g,'"'); return 74; + break; + case 30:yy_.yytext = strip(1,2).replace(/\\'/g,"'"); return 74; + break; + case 31:return 77; + break; + case 32:return 76; + break; + case 33:return 76; + break; + case 34:return 75; + break; + case 35:return 69; + break; + case 36:return 71; + break; + case 37:return 66; + break; + case 38:yy_.yytext = strip(1,2); return 66; + break; + case 39:return 'INVALID'; + break; + case 40:return 5; + break; + } + }; + lexer.rules = [/^(?:[^\x00]*?(?=(\{\{)))/,/^(?:[^\x00]+)/,/^(?:[^\x00]{2,}?(?=(\{\{|\\\{\{|\\\\\{\{|$)))/,/^(?:\{\{\{\{\/[^\s!"#%-,\.\/;->@\[-\^`\{-~]+(?=[=}\s\/.])\}\}\}\})/,/^(?:[^\x00]*?(?=(\{\{\{\{\/)))/,/^(?:[\s\S]*?--(~)?\}\})/,/^(?:\()/,/^(?:\))/,/^(?:\{\{\{\{)/,/^(?:\}\}\}\})/,/^(?:\{\{(~)?>)/,/^(?:\{\{(~)?#)/,/^(?:\{\{(~)?\/)/,/^(?:\{\{(~)?\^\s*(~)?\}\})/,/^(?:\{\{(~)?\s*else\s*(~)?\}\})/,/^(?:\{\{(~)?\^)/,/^(?:\{\{(~)?\s*else\b)/,/^(?:\{\{(~)?\{)/,/^(?:\{\{(~)?&)/,/^(?:\{\{(~)?!--)/,/^(?:\{\{(~)?![\s\S]*?\}\})/,/^(?:\{\{(~)?)/,/^(?:=)/,/^(?:\.\.)/,/^(?:\.(?=([=~}\s\/.)|])))/,/^(?:[\/.])/,/^(?:\s+)/,/^(?:\}(~)?\}\})/,/^(?:(~)?\}\})/,/^(?:"(\\["]|[^"])*")/,/^(?:'(\\[']|[^'])*')/,/^(?:@)/,/^(?:true(?=([~}\s)])))/,/^(?:false(?=([~}\s)])))/,/^(?:-?[0-9]+(?:\.[0-9]+)?(?=([~}\s)])))/,/^(?:as\s+\|)/,/^(?:\|)/,/^(?:([^\s!"#%-,\.\/;->@\[-\^`\{-~]+(?=([=~}\s\/.)|]))))/,/^(?:\[[^\]]*\])/,/^(?:.)/,/^(?:$)/]; + lexer.conditions = {"mu":{"rules":[6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40],"inclusive":false},"emu":{"rules":[2],"inclusive":false},"com":{"rules":[5],"inclusive":false},"raw":{"rules":[3,4],"inclusive":false},"INITIAL":{"rules":[0,1,40],"inclusive":true}}; + return lexer;})() + parser.lexer = lexer; + function Parser () { this.yy = {}; }Parser.prototype = parser;parser.Parser = Parser; + return new Parser; + })();__exports__ = handlebars; + /* jshint ignore:end */ + return __exports__; +})(); + +// handlebars/compiler/visitor.js +var __module11__ = (function(__dependency1__, __dependency2__) { + "use strict"; + var __exports__; + var Exception = __dependency1__; + var AST = __dependency2__; + + function Visitor() { + this.parents = []; + } + + Visitor.prototype = { + constructor: Visitor, + mutating: false, + + // Visits a given value. If mutating, will replace the value if necessary. + acceptKey: function(node, name) { + var value = this.accept(node[name]); + if (this.mutating) { + // Hacky sanity check: + if (value && (!value.type || !AST[value.type])) { + throw new Exception('Unexpected node type "' + value.type + '" found when accepting ' + name + ' on ' + node.type); + } + node[name] = value; + } + }, + + // Performs an accept operation with added sanity check to ensure + // required keys are not removed. + acceptRequired: function(node, name) { + this.acceptKey(node, name); + + if (!node[name]) { + throw new Exception(node.type + ' requires ' + name); + } + }, + + // Traverses a given array. If mutating, empty respnses will be removed + // for child elements. + acceptArray: function(array) { + for (var i = 0, l = array.length; i < l; i++) { + this.acceptKey(array, i); + + if (!array[i]) { + array.splice(i, 1); + i--; + l--; + } + } + }, + + accept: function(object) { + if (!object) { + return; + } + + if (this.current) { + this.parents.unshift(this.current); + } + this.current = object; + + var ret = this[object.type](object); + + this.current = this.parents.shift(); + + if (!this.mutating || ret) { + return ret; + } else if (ret !== false) { + return object; + } + }, + + Program: function(program) { + this.acceptArray(program.body); + }, + + MustacheStatement: function(mustache) { + this.acceptRequired(mustache, 'path'); + this.acceptArray(mustache.params); + this.acceptKey(mustache, 'hash'); + }, + + BlockStatement: function(block) { + this.acceptRequired(block, 'path'); + this.acceptArray(block.params); + this.acceptKey(block, 'hash'); + + this.acceptKey(block, 'program'); + this.acceptKey(block, 'inverse'); + }, + + PartialStatement: function(partial) { + this.acceptRequired(partial, 'name'); + this.acceptArray(partial.params); + this.acceptKey(partial, 'hash'); + }, + + ContentStatement: function(/* content */) {}, + CommentStatement: function(/* comment */) {}, + + SubExpression: function(sexpr) { + this.acceptRequired(sexpr, 'path'); + this.acceptArray(sexpr.params); + this.acceptKey(sexpr, 'hash'); + }, + PartialExpression: function(partial) { + this.acceptRequired(partial, 'name'); + this.acceptArray(partial.params); + this.acceptKey(partial, 'hash'); + }, + + PathExpression: function(/* path */) {}, + + StringLiteral: function(/* string */) {}, + NumberLiteral: function(/* number */) {}, + BooleanLiteral: function(/* bool */) {}, + + Hash: function(hash) { + this.acceptArray(hash.pairs); + }, + HashPair: function(pair) { + this.acceptRequired(pair, 'value'); + } + }; + + __exports__ = Visitor; + return __exports__; +})(__module4__, __module7__); + +// handlebars/compiler/whitespace-control.js +var __module10__ = (function(__dependency1__) { + "use strict"; + var __exports__; + var Visitor = __dependency1__; + + function WhitespaceControl() { + } + WhitespaceControl.prototype = new Visitor(); + + WhitespaceControl.prototype.Program = function(program) { + var isRoot = !this.isRootSeen; + this.isRootSeen = true; + + var body = program.body; + for (var i = 0, l = body.length; i < l; i++) { + var current = body[i], + strip = this.accept(current); + + if (!strip) { + continue; + } + + var _isPrevWhitespace = isPrevWhitespace(body, i, isRoot), + _isNextWhitespace = isNextWhitespace(body, i, isRoot), + + openStandalone = strip.openStandalone && _isPrevWhitespace, + closeStandalone = strip.closeStandalone && _isNextWhitespace, + inlineStandalone = strip.inlineStandalone && _isPrevWhitespace && _isNextWhitespace; + + if (strip.close) { + omitRight(body, i, true); + } + if (strip.open) { + omitLeft(body, i, true); + } + + if (inlineStandalone) { + omitRight(body, i); + + if (omitLeft(body, i)) { + // If we are on a standalone node, save the indent info for partials + if (current.type === 'PartialStatement') { + // Pull out the whitespace from the final line + current.indent = (/([ \t]+$)/).exec(body[i-1].original)[1]; + } + } + } + if (openStandalone) { + omitRight((current.program || current.inverse).body); + + // Strip out the previous content node if it's whitespace only + omitLeft(body, i); + } + if (closeStandalone) { + // Always strip the next node + omitRight(body, i); + + omitLeft((current.inverse || current.program).body); + } + } + + return program; + }; + WhitespaceControl.prototype.BlockStatement = function(block) { + this.accept(block.program); + this.accept(block.inverse); + + // Find the inverse program that is involed with whitespace stripping. + var program = block.program || block.inverse, + inverse = block.program && block.inverse, + firstInverse = inverse, + lastInverse = inverse; + + if (inverse && inverse.chained) { + firstInverse = inverse.body[0].program; + + // Walk the inverse chain to find the last inverse that is actually in the chain. + while (lastInverse.chained) { + lastInverse = lastInverse.body[lastInverse.body.length-1].program; + } + } + + var strip = { + open: block.openStrip.open, + close: block.closeStrip.close, + + // Determine the standalone candiacy. Basically flag our content as being possibly standalone + // so our parent can determine if we actually are standalone + openStandalone: isNextWhitespace(program.body), + closeStandalone: isPrevWhitespace((firstInverse || program).body) + }; + + if (block.openStrip.close) { + omitRight(program.body, null, true); + } + + if (inverse) { + var inverseStrip = block.inverseStrip; + + if (inverseStrip.open) { + omitLeft(program.body, null, true); + } + + if (inverseStrip.close) { + omitRight(firstInverse.body, null, true); + } + if (block.closeStrip.open) { + omitLeft(lastInverse.body, null, true); + } + + // Find standalone else statments + if (isPrevWhitespace(program.body) + && isNextWhitespace(firstInverse.body)) { + + omitLeft(program.body); + omitRight(firstInverse.body); + } + } else { + if (block.closeStrip.open) { + omitLeft(program.body, null, true); + } + } + + return strip; + }; + + WhitespaceControl.prototype.MustacheStatement = function(mustache) { + return mustache.strip; + }; + + WhitespaceControl.prototype.PartialStatement = + WhitespaceControl.prototype.CommentStatement = function(node) { + /* istanbul ignore next */ + var strip = node.strip || {}; + return { + inlineStandalone: true, + open: strip.open, + close: strip.close + }; + }; + + + function isPrevWhitespace(body, i, isRoot) { + if (i === undefined) { + i = body.length; + } + + // Nodes that end with newlines are considered whitespace (but are special + // cased for strip operations) + var prev = body[i-1], + sibling = body[i-2]; + if (!prev) { + return isRoot; + } + + if (prev.type === 'ContentStatement') { + return (sibling || !isRoot ? (/\r?\n\s*?$/) : (/(^|\r?\n)\s*?$/)).test(prev.original); + } + } + function isNextWhitespace(body, i, isRoot) { + if (i === undefined) { + i = -1; + } + + var next = body[i+1], + sibling = body[i+2]; + if (!next) { + return isRoot; + } + + if (next.type === 'ContentStatement') { + return (sibling || !isRoot ? (/^\s*?\r?\n/) : (/^\s*?(\r?\n|$)/)).test(next.original); + } + } + + // Marks the node to the right of the position as omitted. + // I.e. {{foo}}' ' will mark the ' ' node as omitted. + // + // If i is undefined, then the first child will be marked as such. + // + // If mulitple is truthy then all whitespace will be stripped out until non-whitespace + // content is met. + function omitRight(body, i, multiple) { + var current = body[i == null ? 0 : i + 1]; + if (!current || current.type !== 'ContentStatement' || (!multiple && current.rightStripped)) { + return; + } + + var original = current.value; + current.value = current.value.replace(multiple ? (/^\s+/) : (/^[ \t]*\r?\n?/), ''); + current.rightStripped = current.value !== original; + } + + // Marks the node to the left of the position as omitted. + // I.e. ' '{{foo}} will mark the ' ' node as omitted. + // + // If i is undefined then the last child will be marked as such. + // + // If mulitple is truthy then all whitespace will be stripped out until non-whitespace + // content is met. + function omitLeft(body, i, multiple) { + var current = body[i == null ? body.length - 1 : i - 1]; + if (!current || current.type !== 'ContentStatement' || (!multiple && current.leftStripped)) { + return; + } + + // We omit the last node if it's whitespace only and not preceeded by a non-content node. + var original = current.value; + current.value = current.value.replace(multiple ? (/\s+$/) : (/[ \t]+$/), ''); + current.leftStripped = current.value !== original; + return current.leftStripped; + } + + __exports__ = WhitespaceControl; + return __exports__; +})(__module11__); + +// handlebars/compiler/helpers.js +var __module12__ = (function(__dependency1__) { + "use strict"; + var __exports__ = {}; + var Exception = __dependency1__; + + function SourceLocation(source, locInfo) { + this.source = source; + this.start = { + line: locInfo.first_line, + column: locInfo.first_column + }; + this.end = { + line: locInfo.last_line, + column: locInfo.last_column + }; + } + + __exports__.SourceLocation = SourceLocation;function stripFlags(open, close) { + return { + open: open.charAt(2) === '~', + close: close.charAt(close.length-3) === '~' + }; + } + + __exports__.stripFlags = stripFlags;function stripComment(comment) { + return comment.replace(/^\{\{~?\!-?-?/, '') + .replace(/-?-?~?\}\}$/, ''); + } + + __exports__.stripComment = stripComment;function preparePath(data, parts, locInfo) { + /*jshint -W040 */ + locInfo = this.locInfo(locInfo); + + var original = data ? '@' : '', + dig = [], + depth = 0, + depthString = ''; + + for(var i=0,l=parts.length; i 0) { + throw new Exception('Invalid path: ' + original, {loc: locInfo}); + } else if (part === '..') { + depth++; + depthString += '../'; + } + } else { + dig.push(part); + } + } + + return new this.PathExpression(data, depth, dig, original, locInfo); + } + + __exports__.preparePath = preparePath;function prepareMustache(path, params, hash, open, strip, locInfo) { + /*jshint -W040 */ + // Must use charAt to support IE pre-10 + var escapeFlag = open.charAt(3) || open.charAt(2), + escaped = escapeFlag !== '{' && escapeFlag !== '&'; + + return new this.MustacheStatement(path, params, hash, escaped, strip, this.locInfo(locInfo)); + } + + __exports__.prepareMustache = prepareMustache;function prepareRawBlock(openRawBlock, content, close, locInfo) { + /*jshint -W040 */ + if (openRawBlock.path.original !== close) { + var errorNode = {loc: openRawBlock.path.loc}; + + throw new Exception(openRawBlock.path.original + " doesn't match " + close, errorNode); + } + + locInfo = this.locInfo(locInfo); + var program = new this.Program([content], null, {}, locInfo); + + return new this.BlockStatement( + openRawBlock.path, openRawBlock.params, openRawBlock.hash, + program, undefined, + {}, {}, {}, + locInfo); + } + + __exports__.prepareRawBlock = prepareRawBlock;function prepareBlock(openBlock, program, inverseAndProgram, close, inverted, locInfo) { + /*jshint -W040 */ + // When we are chaining inverse calls, we will not have a close path + if (close && close.path && openBlock.path.original !== close.path.original) { + var errorNode = {loc: openBlock.path.loc}; + + throw new Exception(openBlock.path.original + ' doesn\'t match ' + close.path.original, errorNode); + } + + program.blockParams = openBlock.blockParams; + + var inverse, + inverseStrip; + + if (inverseAndProgram) { + if (inverseAndProgram.chain) { + inverseAndProgram.program.body[0].closeStrip = close.strip; + } + + inverseStrip = inverseAndProgram.strip; + inverse = inverseAndProgram.program; + } + + if (inverted) { + inverted = inverse; + inverse = program; + program = inverted; + } + + return new this.BlockStatement( + openBlock.path, openBlock.params, openBlock.hash, + program, inverse, + openBlock.strip, inverseStrip, close && close.strip, + this.locInfo(locInfo)); + } + + __exports__.prepareBlock = prepareBlock; + return __exports__; +})(__module4__); + +// handlebars/compiler/base.js +var __module8__ = (function(__dependency1__, __dependency2__, __dependency3__, __dependency4__, __dependency5__) { + "use strict"; + var __exports__ = {}; + var parser = __dependency1__; + var AST = __dependency2__; + var WhitespaceControl = __dependency3__; + var Helpers = __dependency4__; + var extend = __dependency5__.extend; + + __exports__.parser = parser; + + var yy = {}; + extend(yy, Helpers, AST); + + function parse(input, options) { + // Just return if an already-compiled AST was passed in. + if (input.type === 'Program') { return input; } + + parser.yy = yy; + + // Altering the shared object here, but this is ok as parser is a sync operation + yy.locInfo = function(locInfo) { + return new yy.SourceLocation(options && options.srcName, locInfo); + }; + + var strip = new WhitespaceControl(); + return strip.accept(parser.parse(input)); + } + + __exports__.parse = parse; + return __exports__; +})(__module9__, __module7__, __module10__, __module12__, __module3__); + +// handlebars/compiler/compiler.js +var __module13__ = (function(__dependency1__, __dependency2__, __dependency3__) { + "use strict"; + var __exports__ = {}; + var Exception = __dependency1__; + var isArray = __dependency2__.isArray; + var indexOf = __dependency2__.indexOf; + var AST = __dependency3__; + + var slice = [].slice; + + + function Compiler() {} + + __exports__.Compiler = Compiler;// the foundHelper register will disambiguate helper lookup from finding a + // function in a context. This is necessary for mustache compatibility, which + // requires that context functions in blocks are evaluated by blockHelperMissing, + // and then proceed as if the resulting value was provided to blockHelperMissing. + + Compiler.prototype = { + compiler: Compiler, + + equals: function(other) { + var len = this.opcodes.length; + if (other.opcodes.length !== len) { + return false; + } + + for (var i = 0; i < len; i++) { + var opcode = this.opcodes[i], + otherOpcode = other.opcodes[i]; + if (opcode.opcode !== otherOpcode.opcode || !argEquals(opcode.args, otherOpcode.args)) { + return false; + } + } + + // We know that length is the same between the two arrays because they are directly tied + // to the opcode behavior above. + len = this.children.length; + for (i = 0; i < len; i++) { + if (!this.children[i].equals(other.children[i])) { + return false; + } + } + + return true; + }, + + guid: 0, + + compile: function(program, options) { + this.sourceNode = []; + this.opcodes = []; + this.children = []; + this.options = options; + this.stringParams = options.stringParams; + this.trackIds = options.trackIds; + + options.blockParams = options.blockParams || []; + + // These changes will propagate to the other compiler components + var knownHelpers = options.knownHelpers; + options.knownHelpers = { + 'helperMissing': true, + 'blockHelperMissing': true, + 'each': true, + 'if': true, + 'unless': true, + 'with': true, + 'log': true, + 'lookup': true + }; + if (knownHelpers) { + for (var name in knownHelpers) { + options.knownHelpers[name] = knownHelpers[name]; + } + } + + return this.accept(program); + }, + + compileProgram: function(program) { + var result = new this.compiler().compile(program, this.options); + var guid = this.guid++; + + this.usePartial = this.usePartial || result.usePartial; + + this.children[guid] = result; + this.useDepths = this.useDepths || result.useDepths; + + return guid; + }, + + accept: function(node) { + this.sourceNode.unshift(node); + var ret = this[node.type](node); + this.sourceNode.shift(); + return ret; + }, + + Program: function(program) { + this.options.blockParams.unshift(program.blockParams); + + var body = program.body; + for(var i=0, l=body.length; i 1) { + throw new Exception('Unsupported number of partial arguments: ' + params.length, partial); + } else if (!params.length) { + params.push({type: 'PathExpression', parts: [], depth: 0}); + } + + var partialName = partial.name.original, + isDynamic = partial.name.type === 'SubExpression'; + if (isDynamic) { + this.accept(partial.name); + } + + this.setupFullMustacheParams(partial, undefined, undefined, true); + + var indent = partial.indent || ''; + if (this.options.preventIndent && indent) { + this.opcode('appendContent', indent); + indent = ''; + } + + this.opcode('invokePartial', isDynamic, partialName, indent); + this.opcode('append'); + }, + + MustacheStatement: function(mustache) { + this.SubExpression(mustache); + + if(mustache.escaped && !this.options.noEscape) { + this.opcode('appendEscaped'); + } else { + this.opcode('append'); + } + }, + + ContentStatement: function(content) { + if (content.value) { + this.opcode('appendContent', content.value); + } + }, + + CommentStatement: function() {}, + + SubExpression: function(sexpr) { + transformLiteralToPath(sexpr); + var type = this.classifySexpr(sexpr); + + if (type === 'simple') { + this.simpleSexpr(sexpr); + } else if (type === 'helper') { + this.helperSexpr(sexpr); + } else { + this.ambiguousSexpr(sexpr); + } + }, + ambiguousSexpr: function(sexpr, program, inverse) { + var path = sexpr.path, + name = path.parts[0], + isBlock = program != null || inverse != null; + + this.opcode('getContext', path.depth); + + this.opcode('pushProgram', program); + this.opcode('pushProgram', inverse); + + this.accept(path); + + this.opcode('invokeAmbiguous', name, isBlock); + }, + + simpleSexpr: function(sexpr) { + this.accept(sexpr.path); + this.opcode('resolvePossibleLambda'); + }, + + helperSexpr: function(sexpr, program, inverse) { + var params = this.setupFullMustacheParams(sexpr, program, inverse), + path = sexpr.path, + name = path.parts[0]; + + if (this.options.knownHelpers[name]) { + this.opcode('invokeKnownHelper', params.length, name); + } else if (this.options.knownHelpersOnly) { + throw new Exception("You specified knownHelpersOnly, but used the unknown helper " + name, sexpr); + } else { + path.falsy = true; + + this.accept(path); + this.opcode('invokeHelper', params.length, path.original, AST.helpers.simpleId(path)); + } + }, + + PathExpression: function(path) { + this.addDepth(path.depth); + this.opcode('getContext', path.depth); + + var name = path.parts[0], + scoped = AST.helpers.scopedId(path), + blockParamId = !path.depth && !scoped && this.blockParamIndex(name); + + if (blockParamId) { + this.opcode('lookupBlockParam', blockParamId, path.parts); + } else if (!name) { + // Context reference, i.e. `{{foo .}}` or `{{foo ..}}` + this.opcode('pushContext'); + } else if (path.data) { + this.options.data = true; + this.opcode('lookupData', path.depth, path.parts); + } else { + this.opcode('lookupOnContext', path.parts, path.falsy, scoped); + } + }, + + StringLiteral: function(string) { + this.opcode('pushString', string.value); + }, + + NumberLiteral: function(number) { + this.opcode('pushLiteral', number.value); + }, + + BooleanLiteral: function(bool) { + this.opcode('pushLiteral', bool.value); + }, + + Hash: function(hash) { + var pairs = hash.pairs, i, l; + + this.opcode('pushHash'); + + for (i=0, l=pairs.length; i= 0) { + return [depth, param]; + } + } + } + }; + + function precompile(input, options, env) { + if (input == null || (typeof input !== 'string' && input.type !== 'Program')) { + throw new Exception("You must pass a string or Handlebars AST to Handlebars.precompile. You passed " + input); + } + + options = options || {}; + if (!('data' in options)) { + options.data = true; + } + if (options.compat) { + options.useDepths = true; + } + + var ast = env.parse(input, options); + var environment = new env.Compiler().compile(ast, options); + return new env.JavaScriptCompiler().compile(environment, options); + } + + __exports__.precompile = precompile;function compile(input, options, env) { + if (input == null || (typeof input !== 'string' && input.type !== 'Program')) { + throw new Exception("You must pass a string or Handlebars AST to Handlebars.compile. You passed " + input); + } + + options = options || {}; + + if (!('data' in options)) { + options.data = true; + } + if (options.compat) { + options.useDepths = true; + } + + var compiled; + + function compileInput() { + var ast = env.parse(input, options); + var environment = new env.Compiler().compile(ast, options); + var templateSpec = new env.JavaScriptCompiler().compile(environment, options, undefined, true); + return env.template(templateSpec); + } + + // Template is only compiled on first use and cached after that point. + var ret = function(context, options) { + if (!compiled) { + compiled = compileInput(); + } + return compiled.call(this, context, options); + }; + ret._setup = function(options) { + if (!compiled) { + compiled = compileInput(); + } + return compiled._setup(options); + }; + ret._child = function(i, data, blockParams, depths) { + if (!compiled) { + compiled = compileInput(); + } + return compiled._child(i, data, blockParams, depths); + }; + return ret; + } + + __exports__.compile = compile;function argEquals(a, b) { + if (a === b) { + return true; + } + + if (isArray(a) && isArray(b) && a.length === b.length) { + for (var i = 0; i < a.length; i++) { + if (!argEquals(a[i], b[i])) { + return false; + } + } + return true; + } + } + + function transformLiteralToPath(sexpr) { + if (!sexpr.path.parts) { + var literal = sexpr.path; + // Casting to string here to make false and 0 literal values play nicely with the rest + // of the system. + sexpr.path = new AST.PathExpression(false, 0, [literal.original+''], literal.original+'', literal.log); + } + } + return __exports__; +})(__module4__, __module3__, __module7__); + +// handlebars/compiler/code-gen.js +var __module15__ = (function(__dependency1__) { + "use strict"; + var __exports__; + var isArray = __dependency1__.isArray; + + try { + var SourceMap = require('source-map'), + SourceNode = SourceMap.SourceNode; + } catch (err) { + /* istanbul ignore next: tested but not covered in istanbul due to dist build */ + SourceNode = function(line, column, srcFile, chunks) { + this.src = ''; + if (chunks) { + this.add(chunks); + } + }; + /* istanbul ignore next */ + SourceNode.prototype = { + add: function(chunks) { + if (isArray(chunks)) { + chunks = chunks.join(''); + } + this.src += chunks; + }, + prepend: function(chunks) { + if (isArray(chunks)) { + chunks = chunks.join(''); + } + this.src = chunks + this.src; + }, + toStringWithSourceMap: function() { + return {code: this.toString()}; + }, + toString: function() { + return this.src; + } + }; + } + + + function castChunk(chunk, codeGen, loc) { + if (isArray(chunk)) { + var ret = []; + + for (var i = 0, len = chunk.length; i < len; i++) { + ret.push(codeGen.wrap(chunk[i], loc)); + } + return ret; + } else if (typeof chunk === 'boolean' || typeof chunk === 'number') { + // Handle primitives that the SourceNode will throw up on + return chunk+''; + } + return chunk; + } + + + function CodeGen(srcFile) { + this.srcFile = srcFile; + this.source = []; + } + + CodeGen.prototype = { + prepend: function(source, loc) { + this.source.unshift(this.wrap(source, loc)); + }, + push: function(source, loc) { + this.source.push(this.wrap(source, loc)); + }, + + merge: function() { + var source = this.empty(); + this.each(function(line) { + source.add([' ', line, '\n']); + }); + return source; + }, + + each: function(iter) { + for (var i = 0, len = this.source.length; i < len; i++) { + iter(this.source[i]); + } + }, + + empty: function(loc) { + loc = loc || this.currentLocation || {start:{}}; + return new SourceNode(loc.start.line, loc.start.column, this.srcFile); + }, + wrap: function(chunk, loc) { + if (chunk instanceof SourceNode) { + return chunk; + } + + loc = loc || this.currentLocation || {start:{}}; + chunk = castChunk(chunk, this, loc); + + return new SourceNode(loc.start.line, loc.start.column, this.srcFile, chunk); + }, + + functionCall: function(fn, type, params) { + params = this.generateList(params); + return this.wrap([fn, type ? '.' + type + '(' : '(', params, ')']); + }, + + quotedString: function(str) { + return '"' + (str + '') + .replace(/\\/g, '\\\\') + .replace(/"/g, '\\"') + .replace(/\n/g, '\\n') + .replace(/\r/g, '\\r') + .replace(/\u2028/g, '\\u2028') // Per Ecma-262 7.3 + 7.8.4 + .replace(/\u2029/g, '\\u2029') + '"'; + }, + + objectLiteral: function(obj) { + var pairs = []; + + for (var key in obj) { + if (obj.hasOwnProperty(key)) { + var value = castChunk(obj[key], this); + if (value !== 'undefined') { + pairs.push([this.quotedString(key), ':', value]); + } + } + } + + var ret = this.generateList(pairs); + ret.prepend('{'); + ret.add('}'); + return ret; + }, + + + generateList: function(entries, loc) { + var ret = this.empty(loc); + + for (var i = 0, len = entries.length; i < len; i++) { + if (i) { + ret.add(','); + } + + ret.add(castChunk(entries[i], this, loc)); + } + + return ret; + }, + + generateArray: function(entries, loc) { + var ret = this.generateList(entries, loc); + ret.prepend('['); + ret.add(']'); + + return ret; + } + }; + + __exports__ = CodeGen; + return __exports__; +})(__module3__); + +// handlebars/compiler/javascript-compiler.js +var __module14__ = (function(__dependency1__, __dependency2__, __dependency3__, __dependency4__) { + "use strict"; + var __exports__; + var COMPILER_REVISION = __dependency1__.COMPILER_REVISION; + var REVISION_CHANGES = __dependency1__.REVISION_CHANGES; + var Exception = __dependency2__; + var isArray = __dependency3__.isArray; + var CodeGen = __dependency4__; + + function Literal(value) { + this.value = value; + } + + function JavaScriptCompiler() {} + + JavaScriptCompiler.prototype = { + // PUBLIC API: You can override these methods in a subclass to provide + // alternative compiled forms for name lookup and buffering semantics + nameLookup: function(parent, name /* , type*/) { + if (JavaScriptCompiler.isValidJavaScriptVariableName(name)) { + return [parent, ".", name]; + } else { + return [parent, "['", name, "']"]; + } + }, + depthedLookup: function(name) { + return [this.aliasable('this.lookup'), '(depths, "', name, '")']; + }, + + compilerInfo: function() { + var revision = COMPILER_REVISION, + versions = REVISION_CHANGES[revision]; + return [revision, versions]; + }, + + appendToBuffer: function(source, location, explicit) { + // Force a source as this simplifies the merge logic. + if (!isArray(source)) { + source = [source]; + } + source = this.source.wrap(source, location); + + if (this.environment.isSimple) { + return ['return ', source, ';']; + } else if (explicit) { + // This is a case where the buffer operation occurs as a child of another + // construct, generally braces. We have to explicitly output these buffer + // operations to ensure that the emitted code goes in the correct location. + return ['buffer += ', source, ';']; + } else { + source.appendToBuffer = true; + return source; + } + }, + + initializeBuffer: function() { + return this.quotedString(""); + }, + // END PUBLIC API + + compile: function(environment, options, context, asObject) { + this.environment = environment; + this.options = options; + this.stringParams = this.options.stringParams; + this.trackIds = this.options.trackIds; + this.precompile = !asObject; + + this.name = this.environment.name; + this.isChild = !!context; + this.context = context || { + programs: [], + environments: [] + }; + + this.preamble(); + + this.stackSlot = 0; + this.stackVars = []; + this.aliases = {}; + this.registers = { list: [] }; + this.hashes = []; + this.compileStack = []; + this.inlineStack = []; + this.blockParams = []; + + this.compileChildren(environment, options); + + this.useDepths = this.useDepths || environment.useDepths || this.options.compat; + this.useBlockParams = this.useBlockParams || environment.useBlockParams; + + var opcodes = environment.opcodes, + opcode, + firstLoc, + i, + l; + + for (i = 0, l = opcodes.length; i < l; i++) { + opcode = opcodes[i]; + + this.source.currentLocation = opcode.loc; + firstLoc = firstLoc || opcode.loc; + this[opcode.opcode].apply(this, opcode.args); + } + + // Flush any trailing content that might be pending. + this.source.currentLocation = firstLoc; + this.pushSource(''); + + /* istanbul ignore next */ + if (this.stackSlot || this.inlineStack.length || this.compileStack.length) { + throw new Exception('Compile completed with content left on stack'); + } + + var fn = this.createFunctionContext(asObject); + if (!this.isChild) { + var ret = { + compiler: this.compilerInfo(), + main: fn + }; + var programs = this.context.programs; + for (i = 0, l = programs.length; i < l; i++) { + if (programs[i]) { + ret[i] = programs[i]; + } + } + + if (this.environment.usePartial) { + ret.usePartial = true; + } + if (this.options.data) { + ret.useData = true; + } + if (this.useDepths) { + ret.useDepths = true; + } + if (this.useBlockParams) { + ret.useBlockParams = true; + } + if (this.options.compat) { + ret.compat = true; + } + + if (!asObject) { + ret.compiler = JSON.stringify(ret.compiler); + + this.source.currentLocation = {start: {line: 1, column: 0}}; + ret = this.objectLiteral(ret); + + if (options.srcName) { + ret = ret.toStringWithSourceMap({file: options.destName}); + ret.map = ret.map && ret.map.toString(); + } else { + ret = ret.toString(); + } + } else { + ret.compilerOptions = this.options; + } + + return ret; + } else { + return fn; + } + }, + + preamble: function() { + // track the last context pushed into place to allow skipping the + // getContext opcode when it would be a noop + this.lastContext = 0; + this.source = new CodeGen(this.options.srcName); + }, + + createFunctionContext: function(asObject) { + var varDeclarations = ''; + + var locals = this.stackVars.concat(this.registers.list); + if(locals.length > 0) { + varDeclarations += ", " + locals.join(", "); + } + + // Generate minimizer alias mappings + // + // When using true SourceNodes, this will update all references to the given alias + // as the source nodes are reused in situ. For the non-source node compilation mode, + // aliases will not be used, but this case is already being run on the client and + // we aren't concern about minimizing the template size. + var aliasCount = 0; + for (var alias in this.aliases) { + var node = this.aliases[alias]; + + if (this.aliases.hasOwnProperty(alias) && node.children && node.referenceCount > 1) { + varDeclarations += ', alias' + (++aliasCount) + '=' + alias; + node.children[0] = 'alias' + aliasCount; + } + } + + var params = ["depth0", "helpers", "partials", "data"]; + + if (this.useBlockParams || this.useDepths) { + params.push('blockParams'); + } + if (this.useDepths) { + params.push('depths'); + } + + // Perform a second pass over the output to merge content when possible + var source = this.mergeSource(varDeclarations); + + if (asObject) { + params.push(source); + + return Function.apply(this, params); + } else { + return this.source.wrap(['function(', params.join(','), ') {\n ', source, '}']); + } + }, + mergeSource: function(varDeclarations) { + var isSimple = this.environment.isSimple, + appendOnly = !this.forceBuffer, + appendFirst, + + sourceSeen, + bufferStart, + bufferEnd; + this.source.each(function(line) { + if (line.appendToBuffer) { + if (bufferStart) { + line.prepend(' + '); + } else { + bufferStart = line; + } + bufferEnd = line; + } else { + if (bufferStart) { + if (!sourceSeen) { + appendFirst = true; + } else { + bufferStart.prepend('buffer += '); + } + bufferEnd.add(';'); + bufferStart = bufferEnd = undefined; + } + + sourceSeen = true; + if (!isSimple) { + appendOnly = false; + } + } + }); + + + if (appendOnly) { + if (bufferStart) { + bufferStart.prepend('return '); + bufferEnd.add(';'); + } else if (!sourceSeen) { + this.source.push('return "";'); + } + } else { + varDeclarations += ", buffer = " + (appendFirst ? '' : this.initializeBuffer()); + + if (bufferStart) { + bufferStart.prepend('return buffer + '); + bufferEnd.add(';'); + } else { + this.source.push('return buffer;'); + } + } + + if (varDeclarations) { + this.source.prepend('var ' + varDeclarations.substring(2) + (appendFirst ? '' : ';\n')); + } + + return this.source.merge(); + }, + + // [blockValue] + // + // On stack, before: hash, inverse, program, value + // On stack, after: return value of blockHelperMissing + // + // The purpose of this opcode is to take a block of the form + // `{{#this.foo}}...{{/this.foo}}`, resolve the value of `foo`, and + // replace it on the stack with the result of properly + // invoking blockHelperMissing. + blockValue: function(name) { + var blockHelperMissing = this.aliasable('helpers.blockHelperMissing'), + params = [this.contextName(0)]; + this.setupHelperArgs(name, 0, params); + + var blockName = this.popStack(); + params.splice(1, 0, blockName); + + this.push(this.source.functionCall(blockHelperMissing, 'call', params)); + }, + + // [ambiguousBlockValue] + // + // On stack, before: hash, inverse, program, value + // Compiler value, before: lastHelper=value of last found helper, if any + // On stack, after, if no lastHelper: same as [blockValue] + // On stack, after, if lastHelper: value + ambiguousBlockValue: function() { + // We're being a bit cheeky and reusing the options value from the prior exec + var blockHelperMissing = this.aliasable('helpers.blockHelperMissing'), + params = [this.contextName(0)]; + this.setupHelperArgs('', 0, params, true); + + this.flushInline(); + + var current = this.topStack(); + params.splice(1, 0, current); + + this.pushSource([ + 'if (!', this.lastHelper, ') { ', + current, ' = ', this.source.functionCall(blockHelperMissing, 'call', params), + '}']); + }, + + // [appendContent] + // + // On stack, before: ... + // On stack, after: ... + // + // Appends the string value of `content` to the current buffer + appendContent: function(content) { + if (this.pendingContent) { + content = this.pendingContent + content; + } else { + this.pendingLocation = this.source.currentLocation; + } + + this.pendingContent = content; + }, + + // [append] + // + // On stack, before: value, ... + // On stack, after: ... + // + // Coerces `value` to a String and appends it to the current buffer. + // + // If `value` is truthy, or 0, it is coerced into a string and appended + // Otherwise, the empty string is appended + append: function() { + if (this.isInline()) { + this.replaceStack(function(current) { + return [' != null ? ', current, ' : ""']; + }); + + this.pushSource(this.appendToBuffer(this.popStack())); + } else { + var local = this.popStack(); + this.pushSource(['if (', local, ' != null) { ', this.appendToBuffer(local, undefined, true), ' }']); + if (this.environment.isSimple) { + this.pushSource(['else { ', this.appendToBuffer("''", undefined, true), ' }']); + } + } + }, + + // [appendEscaped] + // + // On stack, before: value, ... + // On stack, after: ... + // + // Escape `value` and append it to the buffer + appendEscaped: function() { + this.pushSource(this.appendToBuffer( + [this.aliasable('this.escapeExpression'), '(', this.popStack(), ')'])); + }, + + // [getContext] + // + // On stack, before: ... + // On stack, after: ... + // Compiler value, after: lastContext=depth + // + // Set the value of the `lastContext` compiler value to the depth + getContext: function(depth) { + this.lastContext = depth; + }, + + // [pushContext] + // + // On stack, before: ... + // On stack, after: currentContext, ... + // + // Pushes the value of the current context onto the stack. + pushContext: function() { + this.pushStackLiteral(this.contextName(this.lastContext)); + }, + + // [lookupOnContext] + // + // On stack, before: ... + // On stack, after: currentContext[name], ... + // + // Looks up the value of `name` on the current context and pushes + // it onto the stack. + lookupOnContext: function(parts, falsy, scoped) { + var i = 0; + + if (!scoped && this.options.compat && !this.lastContext) { + // The depthed query is expected to handle the undefined logic for the root level that + // is implemented below, so we evaluate that directly in compat mode + this.push(this.depthedLookup(parts[i++])); + } else { + this.pushContext(); + } + + this.resolvePath('context', parts, i, falsy); + }, + + // [lookupBlockParam] + // + // On stack, before: ... + // On stack, after: blockParam[name], ... + // + // Looks up the value of `parts` on the given block param and pushes + // it onto the stack. + lookupBlockParam: function(blockParamId, parts) { + this.useBlockParams = true; + + this.push(['blockParams[', blockParamId[0], '][', blockParamId[1], ']']); + this.resolvePath('context', parts, 1); + }, + + // [lookupData] + // + // On stack, before: ... + // On stack, after: data, ... + // + // Push the data lookup operator + lookupData: function(depth, parts) { + /*jshint -W083 */ + if (!depth) { + this.pushStackLiteral('data'); + } else { + this.pushStackLiteral('this.data(data, ' + depth + ')'); + } + + this.resolvePath('data', parts, 0, true); + }, + + resolvePath: function(type, parts, i, falsy) { + /*jshint -W083 */ + if (this.options.strict || this.options.assumeObjects) { + this.push(strictLookup(this.options.strict, this, parts, type)); + return; + } + + var len = parts.length; + for (; i < len; i++) { + this.replaceStack(function(current) { + var lookup = this.nameLookup(current, parts[i], type); + // We want to ensure that zero and false are handled properly if the context (falsy flag) + // needs to have the special handling for these values. + if (!falsy) { + return [' != null ? ', lookup, ' : ', current]; + } else { + // Otherwise we can use generic falsy handling + return [' && ', lookup]; + } + }); + } + }, + + // [resolvePossibleLambda] + // + // On stack, before: value, ... + // On stack, after: resolved value, ... + // + // If the `value` is a lambda, replace it on the stack by + // the return value of the lambda + resolvePossibleLambda: function() { + this.push([this.aliasable('this.lambda'), '(', this.popStack(), ', ', this.contextName(0), ')']); + }, + + // [pushStringParam] + // + // On stack, before: ... + // On stack, after: string, currentContext, ... + // + // This opcode is designed for use in string mode, which + // provides the string value of a parameter along with its + // depth rather than resolving it immediately. + pushStringParam: function(string, type) { + this.pushContext(); + this.pushString(type); + + // If it's a subexpression, the string result + // will be pushed after this opcode. + if (type !== 'SubExpression') { + if (typeof string === 'string') { + this.pushString(string); + } else { + this.pushStackLiteral(string); + } + } + }, + + emptyHash: function(omitEmpty) { + if (this.trackIds) { + this.push('{}'); // hashIds + } + if (this.stringParams) { + this.push('{}'); // hashContexts + this.push('{}'); // hashTypes + } + this.pushStackLiteral(omitEmpty ? 'undefined' : '{}'); + }, + pushHash: function() { + if (this.hash) { + this.hashes.push(this.hash); + } + this.hash = {values: [], types: [], contexts: [], ids: []}; + }, + popHash: function() { + var hash = this.hash; + this.hash = this.hashes.pop(); + + if (this.trackIds) { + this.push(this.objectLiteral(hash.ids)); + } + if (this.stringParams) { + this.push(this.objectLiteral(hash.contexts)); + this.push(this.objectLiteral(hash.types)); + } + + this.push(this.objectLiteral(hash.values)); + }, + + // [pushString] + // + // On stack, before: ... + // On stack, after: quotedString(string), ... + // + // Push a quoted version of `string` onto the stack + pushString: function(string) { + this.pushStackLiteral(this.quotedString(string)); + }, + + // [pushLiteral] + // + // On stack, before: ... + // On stack, after: value, ... + // + // Pushes a value onto the stack. This operation prevents + // the compiler from creating a temporary variable to hold + // it. + pushLiteral: function(value) { + this.pushStackLiteral(value); + }, + + // [pushProgram] + // + // On stack, before: ... + // On stack, after: program(guid), ... + // + // Push a program expression onto the stack. This takes + // a compile-time guid and converts it into a runtime-accessible + // expression. + pushProgram: function(guid) { + if (guid != null) { + this.pushStackLiteral(this.programExpression(guid)); + } else { + this.pushStackLiteral(null); + } + }, + + // [invokeHelper] + // + // On stack, before: hash, inverse, program, params..., ... + // On stack, after: result of helper invocation + // + // Pops off the helper's parameters, invokes the helper, + // and pushes the helper's return value onto the stack. + // + // If the helper is not found, `helperMissing` is called. + invokeHelper: function(paramSize, name, isSimple) { + var nonHelper = this.popStack(); + var helper = this.setupHelper(paramSize, name); + var simple = isSimple ? [helper.name, ' || '] : ''; + + var lookup = ['('].concat(simple, nonHelper); + if (!this.options.strict) { + lookup.push(' || ', this.aliasable('helpers.helperMissing')); + } + lookup.push(')'); + + this.push(this.source.functionCall(lookup, 'call', helper.callParams)); + }, + + // [invokeKnownHelper] + // + // On stack, before: hash, inverse, program, params..., ... + // On stack, after: result of helper invocation + // + // This operation is used when the helper is known to exist, + // so a `helperMissing` fallback is not required. + invokeKnownHelper: function(paramSize, name) { + var helper = this.setupHelper(paramSize, name); + this.push(this.source.functionCall(helper.name, 'call', helper.callParams)); + }, + + // [invokeAmbiguous] + // + // On stack, before: hash, inverse, program, params..., ... + // On stack, after: result of disambiguation + // + // This operation is used when an expression like `{{foo}}` + // is provided, but we don't know at compile-time whether it + // is a helper or a path. + // + // This operation emits more code than the other options, + // and can be avoided by passing the `knownHelpers` and + // `knownHelpersOnly` flags at compile-time. + invokeAmbiguous: function(name, helperCall) { + this.useRegister('helper'); + + var nonHelper = this.popStack(); + + this.emptyHash(); + var helper = this.setupHelper(0, name, helperCall); + + var helperName = this.lastHelper = this.nameLookup('helpers', name, 'helper'); + + var lookup = ['(', '(helper = ', helperName, ' || ', nonHelper, ')']; + if (!this.options.strict) { + lookup[0] = '(helper = '; + lookup.push( + ' != null ? helper : ', + this.aliasable('helpers.helperMissing') + ); + } + + this.push([ + '(', lookup, + (helper.paramsInit ? ['),(', helper.paramsInit] : []), '),', + '(typeof helper === ', this.aliasable('"function"'), ' ? ', + this.source.functionCall('helper','call', helper.callParams), ' : helper))' + ]); + }, + + // [invokePartial] + // + // On stack, before: context, ... + // On stack after: result of partial invocation + // + // This operation pops off a context, invokes a partial with that context, + // and pushes the result of the invocation back. + invokePartial: function(isDynamic, name, indent) { + var params = [], + options = this.setupParams(name, 1, params, false); + + if (isDynamic) { + name = this.popStack(); + delete options.name; + } + + if (indent) { + options.indent = JSON.stringify(indent); + } + options.helpers = 'helpers'; + options.partials = 'partials'; + + if (!isDynamic) { + params.unshift(this.nameLookup('partials', name, 'partial')); + } else { + params.unshift(name); + } + + if (this.options.compat) { + options.depths = 'depths'; + } + options = this.objectLiteral(options); + params.push(options); + + this.push(this.source.functionCall('this.invokePartial', '', params)); + }, + + // [assignToHash] + // + // On stack, before: value, ..., hash, ... + // On stack, after: ..., hash, ... + // + // Pops a value off the stack and assigns it to the current hash + assignToHash: function(key) { + var value = this.popStack(), + context, + type, + id; + + if (this.trackIds) { + id = this.popStack(); + } + if (this.stringParams) { + type = this.popStack(); + context = this.popStack(); + } + + var hash = this.hash; + if (context) { + hash.contexts[key] = context; + } + if (type) { + hash.types[key] = type; + } + if (id) { + hash.ids[key] = id; + } + hash.values[key] = value; + }, + + pushId: function(type, name, child) { + if (type === 'BlockParam') { + this.pushStackLiteral( + 'blockParams[' + name[0] + '].path[' + name[1] + ']' + + (child ? ' + ' + JSON.stringify('.' + child) : '')); + } else if (type === 'PathExpression') { + this.pushString(name); + } else if (type === 'SubExpression') { + this.pushStackLiteral('true'); + } else { + this.pushStackLiteral('null'); + } + }, + + // HELPERS + + compiler: JavaScriptCompiler, + + compileChildren: function(environment, options) { + var children = environment.children, child, compiler; + + for(var i=0, l=children.length; i this.stackVars.length) { this.stackVars.push("stack" + this.stackSlot); } + return this.topStackName(); + }, + topStackName: function() { + return "stack" + this.stackSlot; + }, + flushInline: function() { + var inlineStack = this.inlineStack; + this.inlineStack = []; + for (var i = 0, len = inlineStack.length; i < len; i++) { + var entry = inlineStack[i]; + /* istanbul ignore if */ + if (entry instanceof Literal) { + this.compileStack.push(entry); + } else { + var stack = this.incrStack(); + this.pushSource([stack, ' = ', entry, ';']); + this.compileStack.push(stack); + } + } + }, + isInline: function() { + return this.inlineStack.length; + }, + + popStack: function(wrapped) { + var inline = this.isInline(), + item = (inline ? this.inlineStack : this.compileStack).pop(); + + if (!wrapped && (item instanceof Literal)) { + return item.value; + } else { + if (!inline) { + /* istanbul ignore next */ + if (!this.stackSlot) { + throw new Exception('Invalid stack pop'); + } + this.stackSlot--; + } + return item; + } + }, + + topStack: function() { + var stack = (this.isInline() ? this.inlineStack : this.compileStack), + item = stack[stack.length - 1]; + + /* istanbul ignore if */ + if (item instanceof Literal) { + return item.value; + } else { + return item; + } + }, + + contextName: function(context) { + if (this.useDepths && context) { + return 'depths[' + context + ']'; + } else { + return 'depth' + context; + } + }, + + quotedString: function(str) { + return this.source.quotedString(str); + }, + + objectLiteral: function(obj) { + return this.source.objectLiteral(obj); + }, + + aliasable: function(name) { + var ret = this.aliases[name]; + if (ret) { + ret.referenceCount++; + return ret; + } + + ret = this.aliases[name] = this.source.wrap(name); + ret.aliasable = true; + ret.referenceCount = 1; + + return ret; + }, + + setupHelper: function(paramSize, name, blockHelper) { + var params = [], + paramsInit = this.setupHelperArgs(name, paramSize, params, blockHelper); + var foundHelper = this.nameLookup('helpers', name, 'helper'); + + return { + params: params, + paramsInit: paramsInit, + name: foundHelper, + callParams: [this.contextName(0)].concat(params) + }; + }, + + setupParams: function(helper, paramSize, params) { + var options = {}, contexts = [], types = [], ids = [], param; + + options.name = this.quotedString(helper); + options.hash = this.popStack(); + + if (this.trackIds) { + options.hashIds = this.popStack(); + } + if (this.stringParams) { + options.hashTypes = this.popStack(); + options.hashContexts = this.popStack(); + } + + var inverse = this.popStack(), + program = this.popStack(); + + // Avoid setting fn and inverse if neither are set. This allows + // helpers to do a check for `if (options.fn)` + if (program || inverse) { + options.fn = program || 'this.noop'; + options.inverse = inverse || 'this.noop'; + } + + // The parameters go on to the stack in order (making sure that they are evaluated in order) + // so we need to pop them off the stack in reverse order + var i = paramSize; + while (i--) { + param = this.popStack(); + params[i] = param; + + if (this.trackIds) { + ids[i] = this.popStack(); + } + if (this.stringParams) { + types[i] = this.popStack(); + contexts[i] = this.popStack(); + } + } + + if (this.trackIds) { + options.ids = this.source.generateArray(ids); + } + if (this.stringParams) { + options.types = this.source.generateArray(types); + options.contexts = this.source.generateArray(contexts); + } + + if (this.options.data) { + options.data = 'data'; + } + if (this.useBlockParams) { + options.blockParams = 'blockParams'; + } + return options; + }, + + setupHelperArgs: function(helper, paramSize, params, useRegister) { + var options = this.setupParams(helper, paramSize, params, true); + options = this.objectLiteral(options); + if (useRegister) { + this.useRegister('options'); + params.push('options'); + return ['options=', options]; + } else { + params.push(options); + return ''; + } + } + }; + + + var reservedWords = ( + "break else new var" + + " case finally return void" + + " catch for switch while" + + " continue function this with" + + " default if throw" + + " delete in try" + + " do instanceof typeof" + + " abstract enum int short" + + " boolean export interface static" + + " byte extends long super" + + " char final native synchronized" + + " class float package throws" + + " const goto private transient" + + " debugger implements protected volatile" + + " double import public let yield await" + + " null true false" + ).split(" "); + + var compilerWords = JavaScriptCompiler.RESERVED_WORDS = {}; + + for(var i=0, l=reservedWords.length; i + + + handlebars.js + 3.0.0 + handlebars.js Authors + https://github.com/wycats/handlebars.js/blob/master/LICENSE + https://github.com/wycats/handlebars.js/ + false + Extension of the Mustache logicless template language + + handlebars mustache template html + + + + + diff --git a/jspm_packages/github/jspm/nodelibs-assert@0.1.0.js b/jspm_packages/github/jspm/nodelibs-assert@0.1.0.js new file mode 100644 index 0000000..93fa283 --- /dev/null +++ b/jspm_packages/github/jspm/nodelibs-assert@0.1.0.js @@ -0,0 +1 @@ +module.exports = require("github:jspm/nodelibs-assert@0.1.0/index"); \ No newline at end of file diff --git a/jspm_packages/github/jspm/nodelibs-assert@0.1.0/.jspm-hash b/jspm_packages/github/jspm/nodelibs-assert@0.1.0/.jspm-hash new file mode 100644 index 0000000..615c0e7 --- /dev/null +++ b/jspm_packages/github/jspm/nodelibs-assert@0.1.0/.jspm-hash @@ -0,0 +1 @@ +3df1642a7cf401eacbb46a1d8bfe246ab79b57c299914b932bd37a50b983c5e7c90ae93bjspm-github@0.13.10.16.1 \ No newline at end of file diff --git a/jspm_packages/github/jspm/nodelibs-assert@0.1.0/index.js b/jspm_packages/github/jspm/nodelibs-assert@0.1.0/index.js new file mode 100644 index 0000000..b8a2f1a --- /dev/null +++ b/jspm_packages/github/jspm/nodelibs-assert@0.1.0/index.js @@ -0,0 +1,2 @@ +/* */ +module.exports = System._nodeRequire ? System._nodeRequire('assert') : require('assert'); \ No newline at end of file diff --git a/jspm_packages/github/jspm/nodelibs-assert@0.1.0/package.json b/jspm_packages/github/jspm/nodelibs-assert@0.1.0/package.json new file mode 100644 index 0000000..61d704a --- /dev/null +++ b/jspm_packages/github/jspm/nodelibs-assert@0.1.0/package.json @@ -0,0 +1,6 @@ +{ + "registry": "npm", + "dependencies": { + "assert": "^1.3.0" + } +} \ No newline at end of file diff --git a/jspm_packages/github/jspm/nodelibs-fs@0.1.2.js b/jspm_packages/github/jspm/nodelibs-fs@0.1.2.js new file mode 100644 index 0000000..d6649f6 --- /dev/null +++ b/jspm_packages/github/jspm/nodelibs-fs@0.1.2.js @@ -0,0 +1 @@ +module.exports = require("github:jspm/nodelibs-fs@0.1.2/index"); \ No newline at end of file diff --git a/jspm_packages/github/jspm/nodelibs-fs@0.1.2/.jspm-hash b/jspm_packages/github/jspm/nodelibs-fs@0.1.2/.jspm-hash new file mode 100644 index 0000000..fb5d342 --- /dev/null +++ b/jspm_packages/github/jspm/nodelibs-fs@0.1.2/.jspm-hash @@ -0,0 +1 @@ +e295454174ed9e95b9383f8184859d76c610d19c99914b932bd37a50b983c5e7c90ae93bjspm-github@0.13.10.16.1 \ No newline at end of file diff --git a/jspm_packages/github/jspm/nodelibs-fs@0.1.2/index.js b/jspm_packages/github/jspm/nodelibs-fs@0.1.2/index.js new file mode 100644 index 0000000..3894a05 --- /dev/null +++ b/jspm_packages/github/jspm/nodelibs-fs@0.1.2/index.js @@ -0,0 +1,25 @@ +/* */ +if (System._nodeRequire) { + module.exports = System._nodeRequire('fs'); +} +else { + + exports.readFileSync = function(address) { + var output; + var xhr = new XMLHttpRequest(); + xhr.open('GET', address, false); + xhr.onreadystatechange = function(e) { + if (xhr.readyState == 4) { + var status = xhr.status; + if ((status > 399 && status < 600) || status == 400) { + throw 'File read error on ' + address; + } + else + output = xhr.responseText; + } + } + xhr.send(null); + return output; + }; + +} diff --git a/jspm_packages/github/jspm/nodelibs-fs@0.1.2/package.json b/jspm_packages/github/jspm/nodelibs-fs@0.1.2/package.json new file mode 100644 index 0000000..c514fda --- /dev/null +++ b/jspm_packages/github/jspm/nodelibs-fs@0.1.2/package.json @@ -0,0 +1,3 @@ +{ + "registry": "npm" +} diff --git a/jspm_packages/github/jspm/nodelibs-process@0.1.2.js b/jspm_packages/github/jspm/nodelibs-process@0.1.2.js new file mode 100644 index 0000000..6b37edd --- /dev/null +++ b/jspm_packages/github/jspm/nodelibs-process@0.1.2.js @@ -0,0 +1 @@ +module.exports = require("github:jspm/nodelibs-process@0.1.2/index"); \ No newline at end of file diff --git a/jspm_packages/github/jspm/nodelibs-process@0.1.2/.jspm-hash b/jspm_packages/github/jspm/nodelibs-process@0.1.2/.jspm-hash new file mode 100644 index 0000000..ef88f25 --- /dev/null +++ b/jspm_packages/github/jspm/nodelibs-process@0.1.2/.jspm-hash @@ -0,0 +1 @@ +32790c950d3f375e4beff9c8bdbc3b3837c355e699914b932bd37a50b983c5e7c90ae93bjspm-github@0.13.10.16.1 \ No newline at end of file diff --git a/jspm_packages/github/jspm/nodelibs-process@0.1.2/index.js b/jspm_packages/github/jspm/nodelibs-process@0.1.2/index.js new file mode 100644 index 0000000..448b6e7 --- /dev/null +++ b/jspm_packages/github/jspm/nodelibs-process@0.1.2/index.js @@ -0,0 +1 @@ +module.exports = System._nodeRequire ? process : require('process'); \ No newline at end of file diff --git a/jspm_packages/github/jspm/nodelibs-process@0.1.2/package.json b/jspm_packages/github/jspm/nodelibs-process@0.1.2/package.json new file mode 100644 index 0000000..2cc5be8 --- /dev/null +++ b/jspm_packages/github/jspm/nodelibs-process@0.1.2/package.json @@ -0,0 +1,6 @@ +{ + "registry": "jspm", + "dependencies": { + "process": "npm:process@^0.11.0" + } +} diff --git a/jspm_packages/github/jspm/nodelibs-util@0.1.0.js b/jspm_packages/github/jspm/nodelibs-util@0.1.0.js new file mode 100644 index 0000000..1811521 --- /dev/null +++ b/jspm_packages/github/jspm/nodelibs-util@0.1.0.js @@ -0,0 +1 @@ +module.exports = require("github:jspm/nodelibs-util@0.1.0/index"); \ No newline at end of file diff --git a/jspm_packages/github/jspm/nodelibs-util@0.1.0/.jspm-hash b/jspm_packages/github/jspm/nodelibs-util@0.1.0/.jspm-hash new file mode 100644 index 0000000..ba8bfe8 --- /dev/null +++ b/jspm_packages/github/jspm/nodelibs-util@0.1.0/.jspm-hash @@ -0,0 +1 @@ +108d15fdf020621a254a7f09bdc94001e5a8dbcb99914b932bd37a50b983c5e7c90ae93bjspm-github@0.13.10.16.1 \ No newline at end of file diff --git a/jspm_packages/github/jspm/nodelibs-util@0.1.0/index.js b/jspm_packages/github/jspm/nodelibs-util@0.1.0/index.js new file mode 100644 index 0000000..e670e97 --- /dev/null +++ b/jspm_packages/github/jspm/nodelibs-util@0.1.0/index.js @@ -0,0 +1,2 @@ +/* */ +module.exports = System._nodeRequire ? System._nodeRequire('util') : require('util'); \ No newline at end of file diff --git a/jspm_packages/github/jspm/nodelibs-util@0.1.0/package.json b/jspm_packages/github/jspm/nodelibs-util@0.1.0/package.json new file mode 100644 index 0000000..9bdeecd --- /dev/null +++ b/jspm_packages/github/jspm/nodelibs-util@0.1.0/package.json @@ -0,0 +1,6 @@ +{ + "registry": "npm", + "dependencies": { + "util": "^0.10.3" + } +} \ No newline at end of file diff --git a/jspm_packages/github/systemjs/plugin-json@0.1.0.js b/jspm_packages/github/systemjs/plugin-json@0.1.0.js new file mode 100644 index 0000000..ae0baf9 --- /dev/null +++ b/jspm_packages/github/systemjs/plugin-json@0.1.0.js @@ -0,0 +1 @@ +module.exports = require("github:systemjs/plugin-json@0.1.0/json"); \ No newline at end of file diff --git a/jspm_packages/github/systemjs/plugin-json@0.1.0/.jspm-hash b/jspm_packages/github/systemjs/plugin-json@0.1.0/.jspm-hash new file mode 100644 index 0000000..071f987 --- /dev/null +++ b/jspm_packages/github/systemjs/plugin-json@0.1.0/.jspm-hash @@ -0,0 +1 @@ +476c01034237dfec4dec8c94a59e3bd0750bdf0399914b932bd37a50b983c5e7c90ae93bjspm-github@0.13.10.16.1 \ No newline at end of file diff --git a/jspm_packages/github/systemjs/plugin-json@0.1.0/LICENSE b/jspm_packages/github/systemjs/plugin-json@0.1.0/LICENSE new file mode 100644 index 0000000..7167772 --- /dev/null +++ b/jspm_packages/github/systemjs/plugin-json@0.1.0/LICENSE @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright (c) 2013 jspm + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/jspm_packages/github/systemjs/plugin-json@0.1.0/README.md b/jspm_packages/github/systemjs/plugin-json@0.1.0/README.md new file mode 100644 index 0000000..03658df --- /dev/null +++ b/jspm_packages/github/systemjs/plugin-json@0.1.0/README.md @@ -0,0 +1,4 @@ +plugin-json +=========== + +JSON loader plugin diff --git a/jspm_packages/github/systemjs/plugin-json@0.1.0/json.js b/jspm_packages/github/systemjs/plugin-json@0.1.0/json.js new file mode 100644 index 0000000..7b71f59 --- /dev/null +++ b/jspm_packages/github/systemjs/plugin-json@0.1.0/json.js @@ -0,0 +1,6 @@ +/* + JSON plugin +*/ +exports.translate = function(load) { + return 'module.exports = ' + load.source; +} \ No newline at end of file diff --git a/jspm_packages/github/systemjs/plugin-json@0.1.0/json.json b/jspm_packages/github/systemjs/plugin-json@0.1.0/json.json new file mode 100644 index 0000000..0294a88 --- /dev/null +++ b/jspm_packages/github/systemjs/plugin-json@0.1.0/json.json @@ -0,0 +1,3 @@ +{ + "some": "json" +} \ No newline at end of file diff --git a/jspm_packages/github/systemjs/plugin-json@0.1.0/package.json b/jspm_packages/github/systemjs/plugin-json@0.1.0/package.json new file mode 100644 index 0000000..0848e62 --- /dev/null +++ b/jspm_packages/github/systemjs/plugin-json@0.1.0/package.json @@ -0,0 +1,3 @@ +{ + "main": "json" +} diff --git a/jspm_packages/github/systemjs/plugin-json@0.1.0/test.html b/jspm_packages/github/systemjs/plugin-json@0.1.0/test.html new file mode 100644 index 0000000..3cb5a3e --- /dev/null +++ b/jspm_packages/github/systemjs/plugin-json@0.1.0/test.html @@ -0,0 +1,5 @@ + + + \ No newline at end of file diff --git a/jspm_packages/github/systemjs/plugin-text@0.0.2.js b/jspm_packages/github/systemjs/plugin-text@0.0.2.js new file mode 100644 index 0000000..d41794b --- /dev/null +++ b/jspm_packages/github/systemjs/plugin-text@0.0.2.js @@ -0,0 +1 @@ +module.exports = require("github:systemjs/plugin-text@0.0.2/text"); \ No newline at end of file diff --git a/jspm_packages/github/systemjs/plugin-text@0.0.2/.jspm-hash b/jspm_packages/github/systemjs/plugin-text@0.0.2/.jspm-hash new file mode 100644 index 0000000..a78abf0 --- /dev/null +++ b/jspm_packages/github/systemjs/plugin-text@0.0.2/.jspm-hash @@ -0,0 +1 @@ +3f05122b725d091a193b679946efbac23effebf499914b932bd37a50b983c5e7c90ae93bjspm-github@0.13.10.16.1 \ No newline at end of file diff --git a/jspm_packages/github/systemjs/plugin-text@0.0.2/LICENSE b/jspm_packages/github/systemjs/plugin-text@0.0.2/LICENSE new file mode 100644 index 0000000..7167772 --- /dev/null +++ b/jspm_packages/github/systemjs/plugin-text@0.0.2/LICENSE @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright (c) 2013 jspm + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/jspm_packages/github/systemjs/plugin-text@0.0.2/README.md b/jspm_packages/github/systemjs/plugin-text@0.0.2/README.md new file mode 100644 index 0000000..3c8c0cb --- /dev/null +++ b/jspm_packages/github/systemjs/plugin-text@0.0.2/README.md @@ -0,0 +1,4 @@ +plugin-text +=========== + +Text plugin diff --git a/jspm_packages/github/systemjs/plugin-text@0.0.2/package.json b/jspm_packages/github/systemjs/plugin-text@0.0.2/package.json new file mode 100644 index 0000000..b85fce2 --- /dev/null +++ b/jspm_packages/github/systemjs/plugin-text@0.0.2/package.json @@ -0,0 +1,3 @@ +{ + "main": "text" +} diff --git a/jspm_packages/github/systemjs/plugin-text@0.0.2/test.html b/jspm_packages/github/systemjs/plugin-text@0.0.2/test.html new file mode 100644 index 0000000..044e2a0 --- /dev/null +++ b/jspm_packages/github/systemjs/plugin-text@0.0.2/test.html @@ -0,0 +1,5 @@ + + + \ No newline at end of file diff --git a/jspm_packages/github/systemjs/plugin-text@0.0.2/text.js b/jspm_packages/github/systemjs/plugin-text@0.0.2/text.js new file mode 100644 index 0000000..bb14aa3 --- /dev/null +++ b/jspm_packages/github/systemjs/plugin-text@0.0.2/text.js @@ -0,0 +1,15 @@ +/* + Text plugin +*/ +exports.translate = function(load) { + return 'module.exports = "' + load.source + .replace(/(["\\])/g, '\\$1') + .replace(/[\f]/g, "\\f") + .replace(/[\b]/g, "\\b") + .replace(/[\n]/g, "\\n") + .replace(/[\t]/g, "\\t") + .replace(/[\r]/g, "\\r") + .replace(/[\u2028]/g, "\\u2028") + .replace(/[\u2029]/g, "\\u2029") + + '";'; +} \ No newline at end of file diff --git a/jspm_packages/github/systemjs/plugin-text@0.0.2/text.txt b/jspm_packages/github/systemjs/plugin-text@0.0.2/text.txt new file mode 100644 index 0000000..446b259 --- /dev/null +++ b/jspm_packages/github/systemjs/plugin-text@0.0.2/text.txt @@ -0,0 +1,4 @@ +This is +Some text + +"yay" \ No newline at end of file diff --git a/jspm_packages/npm/assert@1.3.0.js b/jspm_packages/npm/assert@1.3.0.js new file mode 100644 index 0000000..c572921 --- /dev/null +++ b/jspm_packages/npm/assert@1.3.0.js @@ -0,0 +1 @@ +module.exports = require("npm:assert@1.3.0/assert.js"); \ No newline at end of file diff --git a/jspm_packages/npm/assert@1.3.0/.jspm-hash b/jspm_packages/npm/assert@1.3.0/.jspm-hash new file mode 100644 index 0000000..30c389c --- /dev/null +++ b/jspm_packages/npm/assert@1.3.0/.jspm-hash @@ -0,0 +1 @@ +03939a622582a812cc202320a0b9a56c9b81584999914b932bd37a50b983c5e7c90ae93bjspm-npm@0.260.16.1 \ No newline at end of file diff --git a/jspm_packages/npm/assert@1.3.0/.npmignore b/jspm_packages/npm/assert@1.3.0/.npmignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/jspm_packages/npm/assert@1.3.0/.npmignore @@ -0,0 +1 @@ +node_modules diff --git a/jspm_packages/npm/assert@1.3.0/.travis.yml b/jspm_packages/npm/assert@1.3.0/.travis.yml new file mode 100644 index 0000000..b5f7f83 --- /dev/null +++ b/jspm_packages/npm/assert@1.3.0/.travis.yml @@ -0,0 +1,7 @@ +language: node_js +node_js: +- '0.10' +env: + global: + - secure: qThuKBZQtkooAvzaYldECGNqvKGPRTnXx62IVyhSbFlsCY1VCmjhLldhyPDiZQ3JqL1XvSkK8OMDupiHqZnNE0nGijoO4M/kaEdjBB+jpjg3f8I6te2SNU935SbkfY9KHAaFXMZwdcq7Fk932AxWEu+FMSDM+080wNKpEATXDe4= + - secure: O/scKjHLRcPN5ILV5qsSkksQ7qcZQdHWEUUPItmj/4+vmCc28bHpicoUxXG5A96iHvkBbdmky/nGCg464ZaNLk68m6hfEMDAR3J6mhM2Pf5C4QI/LlFlR1fob9sQ8lztwSGOItwdK8Rfrgb30RRVV71f6FxnaJ6PKMuMNT5S1AQ= diff --git a/jspm_packages/npm/assert@1.3.0/.zuul.yml b/jspm_packages/npm/assert@1.3.0/.zuul.yml new file mode 100644 index 0000000..eeb1386 --- /dev/null +++ b/jspm_packages/npm/assert@1.3.0/.zuul.yml @@ -0,0 +1,10 @@ +ui: mocha-qunit +browsers: + - name: chrome + version: latest + - name: firefox + version: latest + - name: safari + version: latest + - name: ie + version: 9..latest diff --git a/jspm_packages/npm/assert@1.3.0/LICENSE b/jspm_packages/npm/assert@1.3.0/LICENSE new file mode 100644 index 0000000..e3d4e69 --- /dev/null +++ b/jspm_packages/npm/assert@1.3.0/LICENSE @@ -0,0 +1,18 @@ +Copyright Joyent, Inc. and other Node contributors. All rights reserved. +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to +deal in the Software without restriction, including without limitation the +rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +IN THE SOFTWARE. diff --git a/jspm_packages/npm/assert@1.3.0/README.md b/jspm_packages/npm/assert@1.3.0/README.md new file mode 100644 index 0000000..6d252ab --- /dev/null +++ b/jspm_packages/npm/assert@1.3.0/README.md @@ -0,0 +1,64 @@ +# assert + +[![Build Status](https://travis-ci.org/defunctzombie/commonjs-assert.svg?branch=master)](https://travis-ci.org/defunctzombie/commonjs-assert) + +This module is used for writing unit tests for your applications, you can access it with require('assert'). + +The API is derived from the [commonjs 1.0 unit testing](http://wiki.commonjs.org/wiki/Unit_Testing/1.0) spec and the [node.js assert module](http://nodejs.org/api/assert.html) + +## assert.fail(actual, expected, message, operator) +Throws an exception that displays the values for actual and expected separated by the provided operator. + +## assert(value, message), assert.ok(value, [message]) +Tests if value is truthy, it is equivalent to assert.equal(true, !!value, message); + +## assert.equal(actual, expected, [message]) +Tests shallow, coercive equality with the equal comparison operator ( == ). + +## assert.notEqual(actual, expected, [message]) +Tests shallow, coercive non-equality with the not equal comparison operator ( != ). + +## assert.deepEqual(actual, expected, [message]) +Tests for deep equality. + +## assert.notDeepEqual(actual, expected, [message]) +Tests for any deep inequality. + +## assert.strictEqual(actual, expected, [message]) +Tests strict equality, as determined by the strict equality operator ( === ) + +## assert.notStrictEqual(actual, expected, [message]) +Tests strict non-equality, as determined by the strict not equal operator ( !== ) + +## assert.throws(block, [error], [message]) +Expects block to throw an error. error can be constructor, regexp or validation function. + +Validate instanceof using constructor: + +```javascript +assert.throws(function() { throw new Error("Wrong value"); }, Error); +``` + +Validate error message using RegExp: + +```javascript +assert.throws(function() { throw new Error("Wrong value"); }, /value/); +``` + +Custom error validation: + +```javascript +assert.throws(function() { + throw new Error("Wrong value"); +}, function(err) { + if ( (err instanceof Error) && /value/.test(err) ) { + return true; + } +}, "unexpected error"); +``` + +## assert.doesNotThrow(block, [message]) +Expects block not to throw an error, see assert.throws for details. + +## assert.ifError(value) +Tests if value is not a false value, throws if it is a true value. Useful when testing the first argument, error in callbacks. diff --git a/jspm_packages/npm/assert@1.3.0/assert.js b/jspm_packages/npm/assert@1.3.0/assert.js new file mode 100644 index 0000000..59d8985 --- /dev/null +++ b/jspm_packages/npm/assert@1.3.0/assert.js @@ -0,0 +1,359 @@ +// http://wiki.commonjs.org/wiki/Unit_Testing/1.0 +// +// THIS IS NOT TESTED NOR LIKELY TO WORK OUTSIDE V8! +// +// Originally from narwhal.js (http://narwhaljs.org) +// Copyright (c) 2009 Thomas Robinson <280north.com> +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the 'Software'), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +// when used in node, this will actually load the util module we depend on +// versus loading the builtin util module as happens otherwise +// this is a bug in node module loading as far as I am concerned +var util = require('util/'); + +var pSlice = Array.prototype.slice; +var hasOwn = Object.prototype.hasOwnProperty; + +// 1. The assert module provides functions that throw +// AssertionError's when particular conditions are not met. The +// assert module must conform to the following interface. + +var assert = module.exports = ok; + +// 2. The AssertionError is defined in assert. +// new assert.AssertionError({ message: message, +// actual: actual, +// expected: expected }) + +assert.AssertionError = function AssertionError(options) { + this.name = 'AssertionError'; + this.actual = options.actual; + this.expected = options.expected; + this.operator = options.operator; + if (options.message) { + this.message = options.message; + this.generatedMessage = false; + } else { + this.message = getMessage(this); + this.generatedMessage = true; + } + var stackStartFunction = options.stackStartFunction || fail; + + if (Error.captureStackTrace) { + Error.captureStackTrace(this, stackStartFunction); + } + else { + // non v8 browsers so we can have a stacktrace + var err = new Error(); + if (err.stack) { + var out = err.stack; + + // try to strip useless frames + var fn_name = stackStartFunction.name; + var idx = out.indexOf('\n' + fn_name); + if (idx >= 0) { + // once we have located the function frame + // we need to strip out everything before it (and its line) + var next_line = out.indexOf('\n', idx + 1); + out = out.substring(next_line + 1); + } + + this.stack = out; + } + } +}; + +// assert.AssertionError instanceof Error +util.inherits(assert.AssertionError, Error); + +function replacer(key, value) { + if (util.isUndefined(value)) { + return '' + value; + } + if (util.isNumber(value) && !isFinite(value)) { + return value.toString(); + } + if (util.isFunction(value) || util.isRegExp(value)) { + return value.toString(); + } + return value; +} + +function truncate(s, n) { + if (util.isString(s)) { + return s.length < n ? s : s.slice(0, n); + } else { + return s; + } +} + +function getMessage(self) { + return truncate(JSON.stringify(self.actual, replacer), 128) + ' ' + + self.operator + ' ' + + truncate(JSON.stringify(self.expected, replacer), 128); +} + +// At present only the three keys mentioned above are used and +// understood by the spec. Implementations or sub modules can pass +// other keys to the AssertionError's constructor - they will be +// ignored. + +// 3. All of the following functions must throw an AssertionError +// when a corresponding condition is not met, with a message that +// may be undefined if not provided. All assertion methods provide +// both the actual and expected values to the assertion error for +// display purposes. + +function fail(actual, expected, message, operator, stackStartFunction) { + throw new assert.AssertionError({ + message: message, + actual: actual, + expected: expected, + operator: operator, + stackStartFunction: stackStartFunction + }); +} + +// EXTENSION! allows for well behaved errors defined elsewhere. +assert.fail = fail; + +// 4. Pure assertion tests whether a value is truthy, as determined +// by !!guard. +// assert.ok(guard, message_opt); +// This statement is equivalent to assert.equal(true, !!guard, +// message_opt);. To test strictly for the value true, use +// assert.strictEqual(true, guard, message_opt);. + +function ok(value, message) { + if (!value) fail(value, true, message, '==', assert.ok); +} +assert.ok = ok; + +// 5. The equality assertion tests shallow, coercive equality with +// ==. +// assert.equal(actual, expected, message_opt); + +assert.equal = function equal(actual, expected, message) { + if (actual != expected) fail(actual, expected, message, '==', assert.equal); +}; + +// 6. The non-equality assertion tests for whether two objects are not equal +// with != assert.notEqual(actual, expected, message_opt); + +assert.notEqual = function notEqual(actual, expected, message) { + if (actual == expected) { + fail(actual, expected, message, '!=', assert.notEqual); + } +}; + +// 7. The equivalence assertion tests a deep equality relation. +// assert.deepEqual(actual, expected, message_opt); + +assert.deepEqual = function deepEqual(actual, expected, message) { + if (!_deepEqual(actual, expected)) { + fail(actual, expected, message, 'deepEqual', assert.deepEqual); + } +}; + +function _deepEqual(actual, expected) { + // 7.1. All identical values are equivalent, as determined by ===. + if (actual === expected) { + return true; + + } else if (util.isBuffer(actual) && util.isBuffer(expected)) { + if (actual.length != expected.length) return false; + + for (var i = 0; i < actual.length; i++) { + if (actual[i] !== expected[i]) return false; + } + + return true; + + // 7.2. If the expected value is a Date object, the actual value is + // equivalent if it is also a Date object that refers to the same time. + } else if (util.isDate(actual) && util.isDate(expected)) { + return actual.getTime() === expected.getTime(); + + // 7.3 If the expected value is a RegExp object, the actual value is + // equivalent if it is also a RegExp object with the same source and + // properties (`global`, `multiline`, `lastIndex`, `ignoreCase`). + } else if (util.isRegExp(actual) && util.isRegExp(expected)) { + return actual.source === expected.source && + actual.global === expected.global && + actual.multiline === expected.multiline && + actual.lastIndex === expected.lastIndex && + actual.ignoreCase === expected.ignoreCase; + + // 7.4. Other pairs that do not both pass typeof value == 'object', + // equivalence is determined by ==. + } else if (!util.isObject(actual) && !util.isObject(expected)) { + return actual == expected; + + // 7.5 For all other Object pairs, including Array objects, equivalence is + // determined by having the same number of owned properties (as verified + // with Object.prototype.hasOwnProperty.call), the same set of keys + // (although not necessarily the same order), equivalent values for every + // corresponding key, and an identical 'prototype' property. Note: this + // accounts for both named and indexed properties on Arrays. + } else { + return objEquiv(actual, expected); + } +} + +function isArguments(object) { + return Object.prototype.toString.call(object) == '[object Arguments]'; +} + +function objEquiv(a, b) { + if (util.isNullOrUndefined(a) || util.isNullOrUndefined(b)) + return false; + // an identical 'prototype' property. + if (a.prototype !== b.prototype) return false; + // if one is a primitive, the other must be same + if (util.isPrimitive(a) || util.isPrimitive(b)) { + return a === b; + } + var aIsArgs = isArguments(a), + bIsArgs = isArguments(b); + if ((aIsArgs && !bIsArgs) || (!aIsArgs && bIsArgs)) + return false; + if (aIsArgs) { + a = pSlice.call(a); + b = pSlice.call(b); + return _deepEqual(a, b); + } + var ka = objectKeys(a), + kb = objectKeys(b), + key, i; + // having the same number of owned properties (keys incorporates + // hasOwnProperty) + if (ka.length != kb.length) + return false; + //the same set of keys (although not necessarily the same order), + ka.sort(); + kb.sort(); + //~~~cheap key test + for (i = ka.length - 1; i >= 0; i--) { + if (ka[i] != kb[i]) + return false; + } + //equivalent values for every corresponding key, and + //~~~possibly expensive deep test + for (i = ka.length - 1; i >= 0; i--) { + key = ka[i]; + if (!_deepEqual(a[key], b[key])) return false; + } + return true; +} + +// 8. The non-equivalence assertion tests for any deep inequality. +// assert.notDeepEqual(actual, expected, message_opt); + +assert.notDeepEqual = function notDeepEqual(actual, expected, message) { + if (_deepEqual(actual, expected)) { + fail(actual, expected, message, 'notDeepEqual', assert.notDeepEqual); + } +}; + +// 9. The strict equality assertion tests strict equality, as determined by ===. +// assert.strictEqual(actual, expected, message_opt); + +assert.strictEqual = function strictEqual(actual, expected, message) { + if (actual !== expected) { + fail(actual, expected, message, '===', assert.strictEqual); + } +}; + +// 10. The strict non-equality assertion tests for strict inequality, as +// determined by !==. assert.notStrictEqual(actual, expected, message_opt); + +assert.notStrictEqual = function notStrictEqual(actual, expected, message) { + if (actual === expected) { + fail(actual, expected, message, '!==', assert.notStrictEqual); + } +}; + +function expectedException(actual, expected) { + if (!actual || !expected) { + return false; + } + + if (Object.prototype.toString.call(expected) == '[object RegExp]') { + return expected.test(actual); + } else if (actual instanceof expected) { + return true; + } else if (expected.call({}, actual) === true) { + return true; + } + + return false; +} + +function _throws(shouldThrow, block, expected, message) { + var actual; + + if (util.isString(expected)) { + message = expected; + expected = null; + } + + try { + block(); + } catch (e) { + actual = e; + } + + message = (expected && expected.name ? ' (' + expected.name + ').' : '.') + + (message ? ' ' + message : '.'); + + if (shouldThrow && !actual) { + fail(actual, expected, 'Missing expected exception' + message); + } + + if (!shouldThrow && expectedException(actual, expected)) { + fail(actual, expected, 'Got unwanted exception' + message); + } + + if ((shouldThrow && actual && expected && + !expectedException(actual, expected)) || (!shouldThrow && actual)) { + throw actual; + } +} + +// 11. Expected to throw an error: +// assert.throws(block, Error_opt, message_opt); + +assert.throws = function(block, /*optional*/error, /*optional*/message) { + _throws.apply(this, [true].concat(pSlice.call(arguments))); +}; + +// EXTENSION! This is annoying to write outside this module. +assert.doesNotThrow = function(block, /*optional*/message) { + _throws.apply(this, [false].concat(pSlice.call(arguments))); +}; + +assert.ifError = function(err) { if (err) {throw err;}}; + +var objectKeys = Object.keys || function (obj) { + var keys = []; + for (var key in obj) { + if (hasOwn.call(obj, key)) keys.push(key); + } + return keys; +}; diff --git a/jspm_packages/npm/assert@1.3.0/package.json b/jspm_packages/npm/assert@1.3.0/package.json new file mode 100644 index 0000000..96f0584 --- /dev/null +++ b/jspm_packages/npm/assert@1.3.0/package.json @@ -0,0 +1,25 @@ +{ + "name": "assert", + "description": "commonjs assert - node.js api compatible", + "keywords": [ + "assert" + ], + "version": "1.3.0", + "homepage": "https://github.com/defunctzombie/commonjs-assert", + "repository": { + "type": "git", + "url": "git://github.com/defunctzombie/commonjs-assert.git" + }, + "main": "./assert.js", + "dependencies": { + "util": "0.10.3" + }, + "devDependencies": { + "zuul": "~1.10.2", + "mocha": "~1.21.4" + }, + "license": "MIT", + "scripts": { + "test": "mocha --ui qunit test.js && zuul -- test.js" + } +} diff --git a/jspm_packages/npm/assert@1.3.0/test.js b/jspm_packages/npm/assert@1.3.0/test.js new file mode 100644 index 0000000..875842d --- /dev/null +++ b/jspm_packages/npm/assert@1.3.0/test.js @@ -0,0 +1,269 @@ +/* */ +var assert = require('./assert'); +var keys = Object.keys; +function makeBlock(f) { + var args = Array.prototype.slice.call(arguments, 1); + return function() { + return f.apply(this, args); + }; +} +test('assert.ok', function() { + assert.throws(makeBlock(assert, false), assert.AssertionError, 'ok(false)'); + assert.doesNotThrow(makeBlock(assert, true), assert.AssertionError, 'ok(true)'); + assert.doesNotThrow(makeBlock(assert, 'test', 'ok(\'test\')')); + assert.throws(makeBlock(assert.ok, false), assert.AssertionError, 'ok(false)'); + assert.doesNotThrow(makeBlock(assert.ok, true), assert.AssertionError, 'ok(true)'); + assert.doesNotThrow(makeBlock(assert.ok, 'test'), 'ok(\'test\')'); +}); +test('assert.equal', function() { + assert.throws(makeBlock(assert.equal, true, false), assert.AssertionError, 'equal'); + assert.doesNotThrow(makeBlock(assert.equal, null, null), 'equal'); + assert.doesNotThrow(makeBlock(assert.equal, undefined, undefined), 'equal'); + assert.doesNotThrow(makeBlock(assert.equal, null, undefined), 'equal'); + assert.doesNotThrow(makeBlock(assert.equal, true, true), 'equal'); + assert.doesNotThrow(makeBlock(assert.equal, 2, '2'), 'equal'); + assert.doesNotThrow(makeBlock(assert.notEqual, true, false), 'notEqual'); + assert.throws(makeBlock(assert.notEqual, true, true), assert.AssertionError, 'notEqual'); +}); +test('assert.strictEqual', function() { + assert.throws(makeBlock(assert.strictEqual, 2, '2'), assert.AssertionError, 'strictEqual'); + assert.throws(makeBlock(assert.strictEqual, null, undefined), assert.AssertionError, 'strictEqual'); + assert.doesNotThrow(makeBlock(assert.notStrictEqual, 2, '2'), 'notStrictEqual'); +}); +test('assert.deepEqual - 7.2', function() { + assert.doesNotThrow(makeBlock(assert.deepEqual, new Date(2000, 3, 14), new Date(2000, 3, 14)), 'deepEqual date'); + assert.throws(makeBlock(assert.deepEqual, new Date(), new Date(2000, 3, 14)), assert.AssertionError, 'deepEqual date'); +}); +test('assert.deepEqual - 7.3', function() { + assert.doesNotThrow(makeBlock(assert.deepEqual, /a/, /a/)); + assert.doesNotThrow(makeBlock(assert.deepEqual, /a/g, /a/g)); + assert.doesNotThrow(makeBlock(assert.deepEqual, /a/i, /a/i)); + assert.doesNotThrow(makeBlock(assert.deepEqual, /a/m, /a/m)); + assert.doesNotThrow(makeBlock(assert.deepEqual, /a/igm, /a/igm)); + assert.throws(makeBlock(assert.deepEqual, /ab/, /a/)); + assert.throws(makeBlock(assert.deepEqual, /a/g, /a/)); + assert.throws(makeBlock(assert.deepEqual, /a/i, /a/)); + assert.throws(makeBlock(assert.deepEqual, /a/m, /a/)); + assert.throws(makeBlock(assert.deepEqual, /a/igm, /a/im)); + var re1 = /a/; + re1.lastIndex = 3; + assert.throws(makeBlock(assert.deepEqual, re1, /a/)); +}); +test('assert.deepEqual - 7.4', function() { + assert.doesNotThrow(makeBlock(assert.deepEqual, 4, '4'), 'deepEqual == check'); + assert.doesNotThrow(makeBlock(assert.deepEqual, true, 1), 'deepEqual == check'); + assert.throws(makeBlock(assert.deepEqual, 4, '5'), assert.AssertionError, 'deepEqual == check'); +}); +test('assert.deepEqual - 7.5', function() { + assert.doesNotThrow(makeBlock(assert.deepEqual, {a: 4}, {a: 4})); + assert.doesNotThrow(makeBlock(assert.deepEqual, { + a: 4, + b: '2' + }, { + a: 4, + b: '2' + })); + assert.doesNotThrow(makeBlock(assert.deepEqual, [4], ['4'])); + assert.throws(makeBlock(assert.deepEqual, {a: 4}, { + a: 4, + b: true + }), assert.AssertionError); + assert.doesNotThrow(makeBlock(assert.deepEqual, ['a'], {0: 'a'})); + assert.doesNotThrow(makeBlock(assert.deepEqual, { + a: 4, + b: '1' + }, { + b: '1', + a: 4 + })); + var a1 = [1, 2, 3]; + var a2 = [1, 2, 3]; + a1.a = 'test'; + a1.b = true; + a2.b = true; + a2.a = 'test'; + assert.throws(makeBlock(assert.deepEqual, keys(a1), keys(a2)), assert.AssertionError); + assert.doesNotThrow(makeBlock(assert.deepEqual, a1, a2)); +}); +test('assert.deepEqual - instances', function() { + var nbRoot = {toString: function() { + return this.first + ' ' + this.last; + }}; + function nameBuilder(first, last) { + this.first = first; + this.last = last; + return this; + } + nameBuilder.prototype = nbRoot; + function nameBuilder2(first, last) { + this.first = first; + this.last = last; + return this; + } + nameBuilder2.prototype = nbRoot; + var nb1 = new nameBuilder('Ryan', 'Dahl'); + var nb2 = new nameBuilder2('Ryan', 'Dahl'); + assert.doesNotThrow(makeBlock(assert.deepEqual, nb1, nb2)); + nameBuilder2.prototype = Object; + nb2 = new nameBuilder2('Ryan', 'Dahl'); + assert.throws(makeBlock(assert.deepEqual, nb1, nb2), assert.AssertionError); +}); +test('assert.deepEqual - ES6 primitives', function() { + assert.throws(makeBlock(assert.deepEqual, null, {}), assert.AssertionError); + assert.throws(makeBlock(assert.deepEqual, undefined, {}), assert.AssertionError); + assert.throws(makeBlock(assert.deepEqual, 'a', ['a']), assert.AssertionError); + assert.throws(makeBlock(assert.deepEqual, 'a', {0: 'a'}), assert.AssertionError); + assert.throws(makeBlock(assert.deepEqual, 1, {}), assert.AssertionError); + assert.throws(makeBlock(assert.deepEqual, true, {}), assert.AssertionError); + if (typeof Symbol === 'symbol') { + assert.throws(makeBlock(assert.deepEqual, Symbol(), {}), assert.AssertionError); + } +}); +test('assert.deepEqual - object wrappers', function() { + assert.doesNotThrow(makeBlock(assert.deepEqual, new String('a'), ['a'])); + assert.doesNotThrow(makeBlock(assert.deepEqual, new String('a'), {0: 'a'})); + assert.doesNotThrow(makeBlock(assert.deepEqual, new Number(1), {})); + assert.doesNotThrow(makeBlock(assert.deepEqual, new Boolean(true), {})); +}); +function thrower(errorConstructor) { + throw new errorConstructor('test'); +} +test('assert - Testing the throwing', function() { + var aethrow = makeBlock(thrower, assert.AssertionError); + aethrow = makeBlock(thrower, assert.AssertionError); + assert.throws(makeBlock(thrower, assert.AssertionError), assert.AssertionError, 'message'); + assert.throws(makeBlock(thrower, assert.AssertionError), assert.AssertionError); + assert.throws(makeBlock(thrower, assert.AssertionError)); + assert.throws(makeBlock(thrower, TypeError)); + var threw = false; + try { + assert.throws(makeBlock(thrower, TypeError), assert.AssertionError); + } catch (e) { + threw = true; + assert.ok(e instanceof TypeError, 'type'); + } + assert.equal(true, threw, 'a.throws with an explicit error is eating extra errors', assert.AssertionError); + threw = false; + try { + assert.doesNotThrow(makeBlock(thrower, TypeError), assert.AssertionError); + } catch (e) { + threw = true; + assert.ok(e instanceof TypeError); + } + assert.equal(true, threw, 'a.doesNotThrow with an explicit error is eating extra errors'); + try { + assert.doesNotThrow(makeBlock(thrower, TypeError), TypeError); + } catch (e) { + threw = true; + assert.ok(e instanceof assert.AssertionError); + } + assert.equal(true, threw, 'a.doesNotThrow is not catching type matching errors'); +}); +test('assert.ifError', function() { + assert.throws(function() { + assert.ifError(new Error('test error')); + }); + assert.doesNotThrow(function() { + assert.ifError(null); + }); + assert.doesNotThrow(function() { + assert.ifError(); + }); +}); +test('assert - make sure that validating using constructor really works', function() { + var threw = false; + try { + assert.throws(function() { + throw ({}); + }, Array); + } catch (e) { + threw = true; + } + assert.ok(threw, 'wrong constructor validation'); +}); +test('assert - use a RegExp to validate error message', function() { + assert.throws(makeBlock(thrower, TypeError), /test/); +}); +test('assert - se a fn to validate error object', function() { + assert.throws(makeBlock(thrower, TypeError), function(err) { + if ((err instanceof TypeError) && /test/.test(err)) { + return true; + } + }); +}); +test('assert - Make sure deepEqual doesn\'t loop forever on circular refs', function() { + var b = {}; + b.b = b; + var c = {}; + c.b = c; + var gotError = false; + try { + assert.deepEqual(b, c); + } catch (e) { + gotError = true; + } + assert.ok(gotError); +}); +test('assert - Ensure reflexivity of deepEqual with `arguments` objects', function() { + var args = (function() { + return arguments; + })(); + assert.throws(makeBlock(assert.deepEqual, [], args), assert.AssertionError); + assert.throws(makeBlock(assert.deepEqual, args, []), assert.AssertionError); +}); +test('assert - test assertion message', function() { + function testAssertionMessage(actual, expected) { + try { + assert.equal(actual, ''); + } catch (e) { + assert.equal(e.toString(), ['AssertionError:', expected, '==', '""'].join(' ')); + } + } + testAssertionMessage(undefined, '"undefined"'); + testAssertionMessage(null, 'null'); + testAssertionMessage(true, 'true'); + testAssertionMessage(false, 'false'); + testAssertionMessage(0, '0'); + testAssertionMessage(100, '100'); + testAssertionMessage(NaN, '"NaN"'); + testAssertionMessage(Infinity, '"Infinity"'); + testAssertionMessage(-Infinity, '"-Infinity"'); + testAssertionMessage('', '""'); + testAssertionMessage('foo', '"foo"'); + testAssertionMessage([], '[]'); + testAssertionMessage([1, 2, 3], '[1,2,3]'); + testAssertionMessage(/a/, '"/a/"'); + testAssertionMessage(function f() {}, '"function f() {}"'); + testAssertionMessage({}, '{}'); + testAssertionMessage({ + a: undefined, + b: null + }, '{"a":"undefined","b":null}'); + testAssertionMessage({ + a: NaN, + b: Infinity, + c: -Infinity + }, '{"a":"NaN","b":"Infinity","c":"-Infinity"}'); +}); +test('assert - regressions from node.js testcase', function() { + var threw = false; + try { + assert.throws(function() { + assert.ifError(null); + }); + } catch (e) { + threw = true; + assert.equal(e.message, 'Missing expected exception..'); + } + assert.ok(threw); + try { + assert.equal(1, 2); + } catch (e) { + assert.equal(e.toString().split('\n')[0], 'AssertionError: 1 == 2'); + } + try { + assert.equal(1, 2, 'oh no'); + } catch (e) { + assert.equal(e.toString().split('\n')[0], 'AssertionError: oh no'); + } +}); diff --git a/jspm_packages/npm/babel-core@5.8.35.js b/jspm_packages/npm/babel-core@5.8.35.js new file mode 100644 index 0000000..9dea74c --- /dev/null +++ b/jspm_packages/npm/babel-core@5.8.35.js @@ -0,0 +1 @@ +module.exports = require("npm:babel-core@5.8.35/browser.js"); \ No newline at end of file diff --git a/jspm_packages/npm/babel-core@5.8.35/.jspm-hash b/jspm_packages/npm/babel-core@5.8.35/.jspm-hash new file mode 100644 index 0000000..f4c6b1d --- /dev/null +++ b/jspm_packages/npm/babel-core@5.8.35/.jspm-hash @@ -0,0 +1 @@ +9d27c5f7199a400cc426ce1f6fac149065ea14bf2615f3cffc60555b3aeaacf1dd14b06ejspm-npm@0.260.16.1 \ No newline at end of file diff --git a/jspm_packages/npm/babel-core@5.8.35/browser-polyfill.js b/jspm_packages/npm/babel-core@5.8.35/browser-polyfill.js new file mode 100644 index 0000000..99919b6 --- /dev/null +++ b/jspm_packages/npm/babel-core@5.8.35/browser-polyfill.js @@ -0,0 +1,4414 @@ +/* */ +"format cjs"; +(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 2 ? $$[2] : undefined + , count = Math.min((end === undefined ? len : toIndex(end, len)) - from, len - to) + , inc = 1; + if(from < to && to < from + count){ + inc = -1; + from += count - 1; + to += count - 1; + } + while(count-- > 0){ + if(from in O)O[to] = O[from]; + else delete O[to]; + to += inc; + from += inc; + } return O; +}; +},{"76":76,"79":79,"80":80}],6:[function(_dereq_,module,exports){ +// 22.1.3.6 Array.prototype.fill(value, start = 0, end = this.length) +'use strict'; +var toObject = _dereq_(80) + , toIndex = _dereq_(76) + , toLength = _dereq_(79); +module.exports = [].fill || function fill(value /*, start = 0, end = @length */){ + var O = toObject(this) + , length = toLength(O.length) + , $$ = arguments + , $$len = $$.length + , index = toIndex($$len > 1 ? $$[1] : undefined, length) + , end = $$len > 2 ? $$[2] : undefined + , endPos = end === undefined ? length : toIndex(end, length); + while(endPos > index)O[index++] = value; + return O; +}; +},{"76":76,"79":79,"80":80}],7:[function(_dereq_,module,exports){ +// false -> Array#indexOf +// true -> Array#includes +var toIObject = _dereq_(78) + , toLength = _dereq_(79) + , toIndex = _dereq_(76); +module.exports = function(IS_INCLUDES){ + return function($this, el, fromIndex){ + var O = toIObject($this) + , length = toLength(O.length) + , index = toIndex(fromIndex, length) + , value; + // Array#includes uses SameValueZero equality algorithm + if(IS_INCLUDES && el != el)while(length > index){ + value = O[index++]; + if(value != value)return true; + // Array#toIndex ignores holes, Array#includes - not + } else for(;length > index; index++)if(IS_INCLUDES || index in O){ + if(O[index] === el)return IS_INCLUDES || index; + } return !IS_INCLUDES && -1; + }; +}; +},{"76":76,"78":78,"79":79}],8:[function(_dereq_,module,exports){ +// 0 -> Array#forEach +// 1 -> Array#map +// 2 -> Array#filter +// 3 -> Array#some +// 4 -> Array#every +// 5 -> Array#find +// 6 -> Array#findIndex +var ctx = _dereq_(17) + , IObject = _dereq_(34) + , toObject = _dereq_(80) + , toLength = _dereq_(79) + , asc = _dereq_(9); +module.exports = function(TYPE){ + var IS_MAP = TYPE == 1 + , IS_FILTER = TYPE == 2 + , IS_SOME = TYPE == 3 + , IS_EVERY = TYPE == 4 + , IS_FIND_INDEX = TYPE == 6 + , NO_HOLES = TYPE == 5 || IS_FIND_INDEX; + return function($this, callbackfn, that){ + var O = toObject($this) + , self = IObject(O) + , f = ctx(callbackfn, that, 3) + , length = toLength(self.length) + , index = 0 + , result = IS_MAP ? asc($this, length) : IS_FILTER ? asc($this, 0) : undefined + , val, res; + for(;length > index; index++)if(NO_HOLES || index in self){ + val = self[index]; + res = f(val, index, O); + if(TYPE){ + if(IS_MAP)result[index] = res; // map + else if(res)switch(TYPE){ + case 3: return true; // some + case 5: return val; // find + case 6: return index; // findIndex + case 2: result.push(val); // filter + } else if(IS_EVERY)return false; // every + } + } + return IS_FIND_INDEX ? -1 : IS_SOME || IS_EVERY ? IS_EVERY : result; + }; +}; +},{"17":17,"34":34,"79":79,"80":80,"9":9}],9:[function(_dereq_,module,exports){ +// 9.4.2.3 ArraySpeciesCreate(originalArray, length) +var isObject = _dereq_(38) + , isArray = _dereq_(36) + , SPECIES = _dereq_(83)('species'); +module.exports = function(original, length){ + var C; + if(isArray(original)){ + C = original.constructor; + // cross-realm fallback + if(typeof C == 'function' && (C === Array || isArray(C.prototype)))C = undefined; + if(isObject(C)){ + C = C[SPECIES]; + if(C === null)C = undefined; + } + } return new (C === undefined ? Array : C)(length); +}; +},{"36":36,"38":38,"83":83}],10:[function(_dereq_,module,exports){ +// getting tag from 19.1.3.6 Object.prototype.toString() +var cof = _dereq_(11) + , TAG = _dereq_(83)('toStringTag') + // ES3 wrong here + , ARG = cof(function(){ return arguments; }()) == 'Arguments'; + +module.exports = function(it){ + var O, T, B; + return it === undefined ? 'Undefined' : it === null ? 'Null' + // @@toStringTag case + : typeof (T = (O = Object(it))[TAG]) == 'string' ? T + // builtinTag case + : ARG ? cof(O) + // ES3 arguments fallback + : (B = cof(O)) == 'Object' && typeof O.callee == 'function' ? 'Arguments' : B; +}; +},{"11":11,"83":83}],11:[function(_dereq_,module,exports){ +var toString = {}.toString; + +module.exports = function(it){ + return toString.call(it).slice(8, -1); +}; +},{}],12:[function(_dereq_,module,exports){ +'use strict'; +var $ = _dereq_(46) + , hide = _dereq_(31) + , redefineAll = _dereq_(60) + , ctx = _dereq_(17) + , strictNew = _dereq_(69) + , defined = _dereq_(18) + , forOf = _dereq_(27) + , $iterDefine = _dereq_(42) + , step = _dereq_(44) + , ID = _dereq_(82)('id') + , $has = _dereq_(30) + , isObject = _dereq_(38) + , setSpecies = _dereq_(65) + , DESCRIPTORS = _dereq_(19) + , isExtensible = Object.isExtensible || isObject + , SIZE = DESCRIPTORS ? '_s' : 'size' + , id = 0; + +var fastKey = function(it, create){ + // return primitive with prefix + if(!isObject(it))return typeof it == 'symbol' ? it : (typeof it == 'string' ? 'S' : 'P') + it; + if(!$has(it, ID)){ + // can't set id to frozen object + if(!isExtensible(it))return 'F'; + // not necessary to add id + if(!create)return 'E'; + // add missing object id + hide(it, ID, ++id); + // return object id with prefix + } return 'O' + it[ID]; +}; + +var getEntry = function(that, key){ + // fast case + var index = fastKey(key), entry; + if(index !== 'F')return that._i[index]; + // frozen object case + for(entry = that._f; entry; entry = entry.n){ + if(entry.k == key)return entry; + } +}; + +module.exports = { + getConstructor: function(wrapper, NAME, IS_MAP, ADDER){ + var C = wrapper(function(that, iterable){ + strictNew(that, C, NAME); + that._i = $.create(null); // index + that._f = undefined; // first entry + that._l = undefined; // last entry + that[SIZE] = 0; // size + if(iterable != undefined)forOf(iterable, IS_MAP, that[ADDER], that); + }); + redefineAll(C.prototype, { + // 23.1.3.1 Map.prototype.clear() + // 23.2.3.2 Set.prototype.clear() + clear: function clear(){ + for(var that = this, data = that._i, entry = that._f; entry; entry = entry.n){ + entry.r = true; + if(entry.p)entry.p = entry.p.n = undefined; + delete data[entry.i]; + } + that._f = that._l = undefined; + that[SIZE] = 0; + }, + // 23.1.3.3 Map.prototype.delete(key) + // 23.2.3.4 Set.prototype.delete(value) + 'delete': function(key){ + var that = this + , entry = getEntry(that, key); + if(entry){ + var next = entry.n + , prev = entry.p; + delete that._i[entry.i]; + entry.r = true; + if(prev)prev.n = next; + if(next)next.p = prev; + if(that._f == entry)that._f = next; + if(that._l == entry)that._l = prev; + that[SIZE]--; + } return !!entry; + }, + // 23.2.3.6 Set.prototype.forEach(callbackfn, thisArg = undefined) + // 23.1.3.5 Map.prototype.forEach(callbackfn, thisArg = undefined) + forEach: function forEach(callbackfn /*, that = undefined */){ + var f = ctx(callbackfn, arguments.length > 1 ? arguments[1] : undefined, 3) + , entry; + while(entry = entry ? entry.n : this._f){ + f(entry.v, entry.k, this); + // revert to the last existing entry + while(entry && entry.r)entry = entry.p; + } + }, + // 23.1.3.7 Map.prototype.has(key) + // 23.2.3.7 Set.prototype.has(value) + has: function has(key){ + return !!getEntry(this, key); + } + }); + if(DESCRIPTORS)$.setDesc(C.prototype, 'size', { + get: function(){ + return defined(this[SIZE]); + } + }); + return C; + }, + def: function(that, key, value){ + var entry = getEntry(that, key) + , prev, index; + // change existing entry + if(entry){ + entry.v = value; + // create new entry + } else { + that._l = entry = { + i: index = fastKey(key, true), // <- index + k: key, // <- key + v: value, // <- value + p: prev = that._l, // <- previous entry + n: undefined, // <- next entry + r: false // <- removed + }; + if(!that._f)that._f = entry; + if(prev)prev.n = entry; + that[SIZE]++; + // add to index + if(index !== 'F')that._i[index] = entry; + } return that; + }, + getEntry: getEntry, + setStrong: function(C, NAME, IS_MAP){ + // add .keys, .values, .entries, [@@iterator] + // 23.1.3.4, 23.1.3.8, 23.1.3.11, 23.1.3.12, 23.2.3.5, 23.2.3.8, 23.2.3.10, 23.2.3.11 + $iterDefine(C, NAME, function(iterated, kind){ + this._t = iterated; // target + this._k = kind; // kind + this._l = undefined; // previous + }, function(){ + var that = this + , kind = that._k + , entry = that._l; + // revert to the last existing entry + while(entry && entry.r)entry = entry.p; + // get next entry + if(!that._t || !(that._l = entry = entry ? entry.n : that._t._f)){ + // or finish the iteration + that._t = undefined; + return step(1); + } + // return step by kind + if(kind == 'keys' )return step(0, entry.k); + if(kind == 'values')return step(0, entry.v); + return step(0, [entry.k, entry.v]); + }, IS_MAP ? 'entries' : 'values' , !IS_MAP, true); + + // add [@@species], 23.1.2.2, 23.2.2.2 + setSpecies(NAME); + } +}; +},{"17":17,"18":18,"19":19,"27":27,"30":30,"31":31,"38":38,"42":42,"44":44,"46":46,"60":60,"65":65,"69":69,"82":82}],13:[function(_dereq_,module,exports){ +// https://github.com/DavidBruant/Map-Set.prototype.toJSON +var forOf = _dereq_(27) + , classof = _dereq_(10); +module.exports = function(NAME){ + return function toJSON(){ + if(classof(this) != NAME)throw TypeError(NAME + "#toJSON isn't generic"); + var arr = []; + forOf(this, false, arr.push, arr); + return arr; + }; +}; +},{"10":10,"27":27}],14:[function(_dereq_,module,exports){ +'use strict'; +var hide = _dereq_(31) + , redefineAll = _dereq_(60) + , anObject = _dereq_(4) + , isObject = _dereq_(38) + , strictNew = _dereq_(69) + , forOf = _dereq_(27) + , createArrayMethod = _dereq_(8) + , $has = _dereq_(30) + , WEAK = _dereq_(82)('weak') + , isExtensible = Object.isExtensible || isObject + , arrayFind = createArrayMethod(5) + , arrayFindIndex = createArrayMethod(6) + , id = 0; + +// fallback for frozen keys +var frozenStore = function(that){ + return that._l || (that._l = new FrozenStore); +}; +var FrozenStore = function(){ + this.a = []; +}; +var findFrozen = function(store, key){ + return arrayFind(store.a, function(it){ + return it[0] === key; + }); +}; +FrozenStore.prototype = { + get: function(key){ + var entry = findFrozen(this, key); + if(entry)return entry[1]; + }, + has: function(key){ + return !!findFrozen(this, key); + }, + set: function(key, value){ + var entry = findFrozen(this, key); + if(entry)entry[1] = value; + else this.a.push([key, value]); + }, + 'delete': function(key){ + var index = arrayFindIndex(this.a, function(it){ + return it[0] === key; + }); + if(~index)this.a.splice(index, 1); + return !!~index; + } +}; + +module.exports = { + getConstructor: function(wrapper, NAME, IS_MAP, ADDER){ + var C = wrapper(function(that, iterable){ + strictNew(that, C, NAME); + that._i = id++; // collection id + that._l = undefined; // leak store for frozen objects + if(iterable != undefined)forOf(iterable, IS_MAP, that[ADDER], that); + }); + redefineAll(C.prototype, { + // 23.3.3.2 WeakMap.prototype.delete(key) + // 23.4.3.3 WeakSet.prototype.delete(value) + 'delete': function(key){ + if(!isObject(key))return false; + if(!isExtensible(key))return frozenStore(this)['delete'](key); + return $has(key, WEAK) && $has(key[WEAK], this._i) && delete key[WEAK][this._i]; + }, + // 23.3.3.4 WeakMap.prototype.has(key) + // 23.4.3.4 WeakSet.prototype.has(value) + has: function has(key){ + if(!isObject(key))return false; + if(!isExtensible(key))return frozenStore(this).has(key); + return $has(key, WEAK) && $has(key[WEAK], this._i); + } + }); + return C; + }, + def: function(that, key, value){ + if(!isExtensible(anObject(key))){ + frozenStore(that).set(key, value); + } else { + $has(key, WEAK) || hide(key, WEAK, {}); + key[WEAK][that._i] = value; + } return that; + }, + frozenStore: frozenStore, + WEAK: WEAK +}; +},{"27":27,"30":30,"31":31,"38":38,"4":4,"60":60,"69":69,"8":8,"82":82}],15:[function(_dereq_,module,exports){ +'use strict'; +var global = _dereq_(29) + , $export = _dereq_(22) + , redefine = _dereq_(61) + , redefineAll = _dereq_(60) + , forOf = _dereq_(27) + , strictNew = _dereq_(69) + , isObject = _dereq_(38) + , fails = _dereq_(24) + , $iterDetect = _dereq_(43) + , setToStringTag = _dereq_(66); + +module.exports = function(NAME, wrapper, methods, common, IS_MAP, IS_WEAK){ + var Base = global[NAME] + , C = Base + , ADDER = IS_MAP ? 'set' : 'add' + , proto = C && C.prototype + , O = {}; + var fixMethod = function(KEY){ + var fn = proto[KEY]; + redefine(proto, KEY, + KEY == 'delete' ? function(a){ + return IS_WEAK && !isObject(a) ? false : fn.call(this, a === 0 ? 0 : a); + } : KEY == 'has' ? function has(a){ + return IS_WEAK && !isObject(a) ? false : fn.call(this, a === 0 ? 0 : a); + } : KEY == 'get' ? function get(a){ + return IS_WEAK && !isObject(a) ? undefined : fn.call(this, a === 0 ? 0 : a); + } : KEY == 'add' ? function add(a){ fn.call(this, a === 0 ? 0 : a); return this; } + : function set(a, b){ fn.call(this, a === 0 ? 0 : a, b); return this; } + ); + }; + if(typeof C != 'function' || !(IS_WEAK || proto.forEach && !fails(function(){ + new C().entries().next(); + }))){ + // create collection constructor + C = common.getConstructor(wrapper, NAME, IS_MAP, ADDER); + redefineAll(C.prototype, methods); + } else { + var instance = new C + // early implementations not supports chaining + , HASNT_CHAINING = instance[ADDER](IS_WEAK ? {} : -0, 1) != instance + // V8 ~ Chromium 40- weak-collections throws on primitives, but should return false + , THROWS_ON_PRIMITIVES = fails(function(){ instance.has(1); }) + // most early implementations doesn't supports iterables, most modern - not close it correctly + , ACCEPT_ITERABLES = $iterDetect(function(iter){ new C(iter); }) // eslint-disable-line no-new + // for early implementations -0 and +0 not the same + , BUGGY_ZERO; + if(!ACCEPT_ITERABLES){ + C = wrapper(function(target, iterable){ + strictNew(target, C, NAME); + var that = new Base; + if(iterable != undefined)forOf(iterable, IS_MAP, that[ADDER], that); + return that; + }); + C.prototype = proto; + proto.constructor = C; + } + IS_WEAK || instance.forEach(function(val, key){ + BUGGY_ZERO = 1 / key === -Infinity; + }); + if(THROWS_ON_PRIMITIVES || BUGGY_ZERO){ + fixMethod('delete'); + fixMethod('has'); + IS_MAP && fixMethod('get'); + } + if(BUGGY_ZERO || HASNT_CHAINING)fixMethod(ADDER); + // weak collections should not contains .clear method + if(IS_WEAK && proto.clear)delete proto.clear; + } + + setToStringTag(C, NAME); + + O[NAME] = C; + $export($export.G + $export.W + $export.F * (C != Base), O); + + if(!IS_WEAK)common.setStrong(C, NAME, IS_MAP); + + return C; +}; +},{"22":22,"24":24,"27":27,"29":29,"38":38,"43":43,"60":60,"61":61,"66":66,"69":69}],16:[function(_dereq_,module,exports){ +var core = module.exports = {version: '1.2.6'}; +if(typeof __e == 'number')__e = core; // eslint-disable-line no-undef +},{}],17:[function(_dereq_,module,exports){ +// optional / simple context binding +var aFunction = _dereq_(2); +module.exports = function(fn, that, length){ + aFunction(fn); + if(that === undefined)return fn; + switch(length){ + case 1: return function(a){ + return fn.call(that, a); + }; + case 2: return function(a, b){ + return fn.call(that, a, b); + }; + case 3: return function(a, b, c){ + return fn.call(that, a, b, c); + }; + } + return function(/* ...args */){ + return fn.apply(that, arguments); + }; +}; +},{"2":2}],18:[function(_dereq_,module,exports){ +// 7.2.1 RequireObjectCoercible(argument) +module.exports = function(it){ + if(it == undefined)throw TypeError("Can't call method on " + it); + return it; +}; +},{}],19:[function(_dereq_,module,exports){ +// Thank's IE8 for his funny defineProperty +module.exports = !_dereq_(24)(function(){ + return Object.defineProperty({}, 'a', {get: function(){ return 7; }}).a != 7; +}); +},{"24":24}],20:[function(_dereq_,module,exports){ +var isObject = _dereq_(38) + , document = _dereq_(29).document + // in old IE typeof document.createElement is 'object' + , is = isObject(document) && isObject(document.createElement); +module.exports = function(it){ + return is ? document.createElement(it) : {}; +}; +},{"29":29,"38":38}],21:[function(_dereq_,module,exports){ +// all enumerable object keys, includes symbols +var $ = _dereq_(46); +module.exports = function(it){ + var keys = $.getKeys(it) + , getSymbols = $.getSymbols; + if(getSymbols){ + var symbols = getSymbols(it) + , isEnum = $.isEnum + , i = 0 + , key; + while(symbols.length > i)if(isEnum.call(it, key = symbols[i++]))keys.push(key); + } + return keys; +}; +},{"46":46}],22:[function(_dereq_,module,exports){ +var global = _dereq_(29) + , core = _dereq_(16) + , hide = _dereq_(31) + , redefine = _dereq_(61) + , ctx = _dereq_(17) + , PROTOTYPE = 'prototype'; + +var $export = function(type, name, source){ + var IS_FORCED = type & $export.F + , IS_GLOBAL = type & $export.G + , IS_STATIC = type & $export.S + , IS_PROTO = type & $export.P + , IS_BIND = type & $export.B + , target = IS_GLOBAL ? global : IS_STATIC ? global[name] || (global[name] = {}) : (global[name] || {})[PROTOTYPE] + , exports = IS_GLOBAL ? core : core[name] || (core[name] = {}) + , expProto = exports[PROTOTYPE] || (exports[PROTOTYPE] = {}) + , key, own, out, exp; + if(IS_GLOBAL)source = name; + for(key in source){ + // contains in native + own = !IS_FORCED && target && key in target; + // export native or passed + out = (own ? target : source)[key]; + // bind timers to global for call from export context + exp = IS_BIND && own ? ctx(out, global) : IS_PROTO && typeof out == 'function' ? ctx(Function.call, out) : out; + // extend global + if(target && !own)redefine(target, key, out); + // export + if(exports[key] != out)hide(exports, key, exp); + if(IS_PROTO && expProto[key] != out)expProto[key] = out; + } +}; +global.core = core; +// type bitmap +$export.F = 1; // forced +$export.G = 2; // global +$export.S = 4; // static +$export.P = 8; // proto +$export.B = 16; // bind +$export.W = 32; // wrap +module.exports = $export; +},{"16":16,"17":17,"29":29,"31":31,"61":61}],23:[function(_dereq_,module,exports){ +var MATCH = _dereq_(83)('match'); +module.exports = function(KEY){ + var re = /./; + try { + '/./'[KEY](re); + } catch(e){ + try { + re[MATCH] = false; + return !'/./'[KEY](re); + } catch(f){ /* empty */ } + } return true; +}; +},{"83":83}],24:[function(_dereq_,module,exports){ +module.exports = function(exec){ + try { + return !!exec(); + } catch(e){ + return true; + } +}; +},{}],25:[function(_dereq_,module,exports){ +'use strict'; +var hide = _dereq_(31) + , redefine = _dereq_(61) + , fails = _dereq_(24) + , defined = _dereq_(18) + , wks = _dereq_(83); + +module.exports = function(KEY, length, exec){ + var SYMBOL = wks(KEY) + , original = ''[KEY]; + if(fails(function(){ + var O = {}; + O[SYMBOL] = function(){ return 7; }; + return ''[KEY](O) != 7; + })){ + redefine(String.prototype, KEY, exec(defined, SYMBOL, original)); + hide(RegExp.prototype, SYMBOL, length == 2 + // 21.2.5.8 RegExp.prototype[@@replace](string, replaceValue) + // 21.2.5.11 RegExp.prototype[@@split](string, limit) + ? function(string, arg){ return original.call(string, this, arg); } + // 21.2.5.6 RegExp.prototype[@@match](string) + // 21.2.5.9 RegExp.prototype[@@search](string) + : function(string){ return original.call(string, this); } + ); + } +}; +},{"18":18,"24":24,"31":31,"61":61,"83":83}],26:[function(_dereq_,module,exports){ +'use strict'; +// 21.2.5.3 get RegExp.prototype.flags +var anObject = _dereq_(4); +module.exports = function(){ + var that = anObject(this) + , result = ''; + if(that.global) result += 'g'; + if(that.ignoreCase) result += 'i'; + if(that.multiline) result += 'm'; + if(that.unicode) result += 'u'; + if(that.sticky) result += 'y'; + return result; +}; +},{"4":4}],27:[function(_dereq_,module,exports){ +var ctx = _dereq_(17) + , call = _dereq_(40) + , isArrayIter = _dereq_(35) + , anObject = _dereq_(4) + , toLength = _dereq_(79) + , getIterFn = _dereq_(84); +module.exports = function(iterable, entries, fn, that){ + var iterFn = getIterFn(iterable) + , f = ctx(fn, that, entries ? 2 : 1) + , index = 0 + , length, step, iterator; + if(typeof iterFn != 'function')throw TypeError(iterable + ' is not iterable!'); + // fast case for arrays with default iterator + if(isArrayIter(iterFn))for(length = toLength(iterable.length); length > index; index++){ + entries ? f(anObject(step = iterable[index])[0], step[1]) : f(iterable[index]); + } else for(iterator = iterFn.call(iterable); !(step = iterator.next()).done; ){ + call(iterator, f, step.value, entries); + } +}; +},{"17":17,"35":35,"4":4,"40":40,"79":79,"84":84}],28:[function(_dereq_,module,exports){ +// fallback for IE11 buggy Object.getOwnPropertyNames with iframe and window +var toIObject = _dereq_(78) + , getNames = _dereq_(46).getNames + , toString = {}.toString; + +var windowNames = typeof window == 'object' && Object.getOwnPropertyNames + ? Object.getOwnPropertyNames(window) : []; + +var getWindowNames = function(it){ + try { + return getNames(it); + } catch(e){ + return windowNames.slice(); + } +}; + +module.exports.get = function getOwnPropertyNames(it){ + if(windowNames && toString.call(it) == '[object Window]')return getWindowNames(it); + return getNames(toIObject(it)); +}; +},{"46":46,"78":78}],29:[function(_dereq_,module,exports){ +// https://github.com/zloirock/core-js/issues/86#issuecomment-115759028 +var global = module.exports = typeof window != 'undefined' && window.Math == Math + ? window : typeof self != 'undefined' && self.Math == Math ? self : Function('return this')(); +if(typeof __g == 'number')__g = global; // eslint-disable-line no-undef +},{}],30:[function(_dereq_,module,exports){ +var hasOwnProperty = {}.hasOwnProperty; +module.exports = function(it, key){ + return hasOwnProperty.call(it, key); +}; +},{}],31:[function(_dereq_,module,exports){ +var $ = _dereq_(46) + , createDesc = _dereq_(59); +module.exports = _dereq_(19) ? function(object, key, value){ + return $.setDesc(object, key, createDesc(1, value)); +} : function(object, key, value){ + object[key] = value; + return object; +}; +},{"19":19,"46":46,"59":59}],32:[function(_dereq_,module,exports){ +module.exports = _dereq_(29).document && document.documentElement; +},{"29":29}],33:[function(_dereq_,module,exports){ +// fast apply, http://jsperf.lnkit.com/fast-apply/5 +module.exports = function(fn, args, that){ + var un = that === undefined; + switch(args.length){ + case 0: return un ? fn() + : fn.call(that); + case 1: return un ? fn(args[0]) + : fn.call(that, args[0]); + case 2: return un ? fn(args[0], args[1]) + : fn.call(that, args[0], args[1]); + case 3: return un ? fn(args[0], args[1], args[2]) + : fn.call(that, args[0], args[1], args[2]); + case 4: return un ? fn(args[0], args[1], args[2], args[3]) + : fn.call(that, args[0], args[1], args[2], args[3]); + } return fn.apply(that, args); +}; +},{}],34:[function(_dereq_,module,exports){ +// fallback for non-array-like ES3 and non-enumerable old V8 strings +var cof = _dereq_(11); +module.exports = Object('z').propertyIsEnumerable(0) ? Object : function(it){ + return cof(it) == 'String' ? it.split('') : Object(it); +}; +},{"11":11}],35:[function(_dereq_,module,exports){ +// check on default Array iterator +var Iterators = _dereq_(45) + , ITERATOR = _dereq_(83)('iterator') + , ArrayProto = Array.prototype; + +module.exports = function(it){ + return it !== undefined && (Iterators.Array === it || ArrayProto[ITERATOR] === it); +}; +},{"45":45,"83":83}],36:[function(_dereq_,module,exports){ +// 7.2.2 IsArray(argument) +var cof = _dereq_(11); +module.exports = Array.isArray || function(arg){ + return cof(arg) == 'Array'; +}; +},{"11":11}],37:[function(_dereq_,module,exports){ +// 20.1.2.3 Number.isInteger(number) +var isObject = _dereq_(38) + , floor = Math.floor; +module.exports = function isInteger(it){ + return !isObject(it) && isFinite(it) && floor(it) === it; +}; +},{"38":38}],38:[function(_dereq_,module,exports){ +module.exports = function(it){ + return typeof it === 'object' ? it !== null : typeof it === 'function'; +}; +},{}],39:[function(_dereq_,module,exports){ +// 7.2.8 IsRegExp(argument) +var isObject = _dereq_(38) + , cof = _dereq_(11) + , MATCH = _dereq_(83)('match'); +module.exports = function(it){ + var isRegExp; + return isObject(it) && ((isRegExp = it[MATCH]) !== undefined ? !!isRegExp : cof(it) == 'RegExp'); +}; +},{"11":11,"38":38,"83":83}],40:[function(_dereq_,module,exports){ +// call something on iterator step with safe closing on error +var anObject = _dereq_(4); +module.exports = function(iterator, fn, value, entries){ + try { + return entries ? fn(anObject(value)[0], value[1]) : fn(value); + // 7.4.6 IteratorClose(iterator, completion) + } catch(e){ + var ret = iterator['return']; + if(ret !== undefined)anObject(ret.call(iterator)); + throw e; + } +}; +},{"4":4}],41:[function(_dereq_,module,exports){ +'use strict'; +var $ = _dereq_(46) + , descriptor = _dereq_(59) + , setToStringTag = _dereq_(66) + , IteratorPrototype = {}; + +// 25.1.2.1.1 %IteratorPrototype%[@@iterator]() +_dereq_(31)(IteratorPrototype, _dereq_(83)('iterator'), function(){ return this; }); + +module.exports = function(Constructor, NAME, next){ + Constructor.prototype = $.create(IteratorPrototype, {next: descriptor(1, next)}); + setToStringTag(Constructor, NAME + ' Iterator'); +}; +},{"31":31,"46":46,"59":59,"66":66,"83":83}],42:[function(_dereq_,module,exports){ +'use strict'; +var LIBRARY = _dereq_(48) + , $export = _dereq_(22) + , redefine = _dereq_(61) + , hide = _dereq_(31) + , has = _dereq_(30) + , Iterators = _dereq_(45) + , $iterCreate = _dereq_(41) + , setToStringTag = _dereq_(66) + , getProto = _dereq_(46).getProto + , ITERATOR = _dereq_(83)('iterator') + , BUGGY = !([].keys && 'next' in [].keys()) // Safari has buggy iterators w/o `next` + , FF_ITERATOR = '@@iterator' + , KEYS = 'keys' + , VALUES = 'values'; + +var returnThis = function(){ return this; }; + +module.exports = function(Base, NAME, Constructor, next, DEFAULT, IS_SET, FORCED){ + $iterCreate(Constructor, NAME, next); + var getMethod = function(kind){ + if(!BUGGY && kind in proto)return proto[kind]; + switch(kind){ + case KEYS: return function keys(){ return new Constructor(this, kind); }; + case VALUES: return function values(){ return new Constructor(this, kind); }; + } return function entries(){ return new Constructor(this, kind); }; + }; + var TAG = NAME + ' Iterator' + , DEF_VALUES = DEFAULT == VALUES + , VALUES_BUG = false + , proto = Base.prototype + , $native = proto[ITERATOR] || proto[FF_ITERATOR] || DEFAULT && proto[DEFAULT] + , $default = $native || getMethod(DEFAULT) + , methods, key; + // Fix native + if($native){ + var IteratorPrototype = getProto($default.call(new Base)); + // Set @@toStringTag to native iterators + setToStringTag(IteratorPrototype, TAG, true); + // FF fix + if(!LIBRARY && has(proto, FF_ITERATOR))hide(IteratorPrototype, ITERATOR, returnThis); + // fix Array#{values, @@iterator}.name in V8 / FF + if(DEF_VALUES && $native.name !== VALUES){ + VALUES_BUG = true; + $default = function values(){ return $native.call(this); }; + } + } + // Define iterator + if((!LIBRARY || FORCED) && (BUGGY || VALUES_BUG || !proto[ITERATOR])){ + hide(proto, ITERATOR, $default); + } + // Plug for library + Iterators[NAME] = $default; + Iterators[TAG] = returnThis; + if(DEFAULT){ + methods = { + values: DEF_VALUES ? $default : getMethod(VALUES), + keys: IS_SET ? $default : getMethod(KEYS), + entries: !DEF_VALUES ? $default : getMethod('entries') + }; + if(FORCED)for(key in methods){ + if(!(key in proto))redefine(proto, key, methods[key]); + } else $export($export.P + $export.F * (BUGGY || VALUES_BUG), NAME, methods); + } + return methods; +}; +},{"22":22,"30":30,"31":31,"41":41,"45":45,"46":46,"48":48,"61":61,"66":66,"83":83}],43:[function(_dereq_,module,exports){ +var ITERATOR = _dereq_(83)('iterator') + , SAFE_CLOSING = false; + +try { + var riter = [7][ITERATOR](); + riter['return'] = function(){ SAFE_CLOSING = true; }; + Array.from(riter, function(){ throw 2; }); +} catch(e){ /* empty */ } + +module.exports = function(exec, skipClosing){ + if(!skipClosing && !SAFE_CLOSING)return false; + var safe = false; + try { + var arr = [7] + , iter = arr[ITERATOR](); + iter.next = function(){ safe = true; }; + arr[ITERATOR] = function(){ return iter; }; + exec(arr); + } catch(e){ /* empty */ } + return safe; +}; +},{"83":83}],44:[function(_dereq_,module,exports){ +module.exports = function(done, value){ + return {value: value, done: !!done}; +}; +},{}],45:[function(_dereq_,module,exports){ +module.exports = {}; +},{}],46:[function(_dereq_,module,exports){ +var $Object = Object; +module.exports = { + create: $Object.create, + getProto: $Object.getPrototypeOf, + isEnum: {}.propertyIsEnumerable, + getDesc: $Object.getOwnPropertyDescriptor, + setDesc: $Object.defineProperty, + setDescs: $Object.defineProperties, + getKeys: $Object.keys, + getNames: $Object.getOwnPropertyNames, + getSymbols: $Object.getOwnPropertySymbols, + each: [].forEach +}; +},{}],47:[function(_dereq_,module,exports){ +var $ = _dereq_(46) + , toIObject = _dereq_(78); +module.exports = function(object, el){ + var O = toIObject(object) + , keys = $.getKeys(O) + , length = keys.length + , index = 0 + , key; + while(length > index)if(O[key = keys[index++]] === el)return key; +}; +},{"46":46,"78":78}],48:[function(_dereq_,module,exports){ +module.exports = false; +},{}],49:[function(_dereq_,module,exports){ +// 20.2.2.14 Math.expm1(x) +module.exports = Math.expm1 || function expm1(x){ + return (x = +x) == 0 ? x : x > -1e-6 && x < 1e-6 ? x + x * x / 2 : Math.exp(x) - 1; +}; +},{}],50:[function(_dereq_,module,exports){ +// 20.2.2.20 Math.log1p(x) +module.exports = Math.log1p || function log1p(x){ + return (x = +x) > -1e-8 && x < 1e-8 ? x - x * x / 2 : Math.log(1 + x); +}; +},{}],51:[function(_dereq_,module,exports){ +// 20.2.2.28 Math.sign(x) +module.exports = Math.sign || function sign(x){ + return (x = +x) == 0 || x != x ? x : x < 0 ? -1 : 1; +}; +},{}],52:[function(_dereq_,module,exports){ +var global = _dereq_(29) + , macrotask = _dereq_(75).set + , Observer = global.MutationObserver || global.WebKitMutationObserver + , process = global.process + , Promise = global.Promise + , isNode = _dereq_(11)(process) == 'process' + , head, last, notify; + +var flush = function(){ + var parent, domain, fn; + if(isNode && (parent = process.domain)){ + process.domain = null; + parent.exit(); + } + while(head){ + domain = head.domain; + fn = head.fn; + if(domain)domain.enter(); + fn(); // <- currently we use it only for Promise - try / catch not required + if(domain)domain.exit(); + head = head.next; + } last = undefined; + if(parent)parent.enter(); +}; + +// Node.js +if(isNode){ + notify = function(){ + process.nextTick(flush); + }; +// browsers with MutationObserver +} else if(Observer){ + var toggle = 1 + , node = document.createTextNode(''); + new Observer(flush).observe(node, {characterData: true}); // eslint-disable-line no-new + notify = function(){ + node.data = toggle = -toggle; + }; +// environments with maybe non-completely correct, but existent Promise +} else if(Promise && Promise.resolve){ + notify = function(){ + Promise.resolve().then(flush); + }; +// for other environments - macrotask based on: +// - setImmediate +// - MessageChannel +// - window.postMessag +// - onreadystatechange +// - setTimeout +} else { + notify = function(){ + // strange IE + webpack dev server bug - use .call(global) + macrotask.call(global, flush); + }; +} + +module.exports = function asap(fn){ + var task = {fn: fn, next: undefined, domain: isNode && process.domain}; + if(last)last.next = task; + if(!head){ + head = task; + notify(); + } last = task; +}; +},{"11":11,"29":29,"75":75}],53:[function(_dereq_,module,exports){ +// 19.1.2.1 Object.assign(target, source, ...) +var $ = _dereq_(46) + , toObject = _dereq_(80) + , IObject = _dereq_(34); + +// should work with symbols and should have deterministic property order (V8 bug) +module.exports = _dereq_(24)(function(){ + var a = Object.assign + , A = {} + , B = {} + , S = Symbol() + , K = 'abcdefghijklmnopqrst'; + A[S] = 7; + K.split('').forEach(function(k){ B[k] = k; }); + return a({}, A)[S] != 7 || Object.keys(a({}, B)).join('') != K; +}) ? function assign(target, source){ // eslint-disable-line no-unused-vars + var T = toObject(target) + , $$ = arguments + , $$len = $$.length + , index = 1 + , getKeys = $.getKeys + , getSymbols = $.getSymbols + , isEnum = $.isEnum; + while($$len > index){ + var S = IObject($$[index++]) + , keys = getSymbols ? getKeys(S).concat(getSymbols(S)) : getKeys(S) + , length = keys.length + , j = 0 + , key; + while(length > j)if(isEnum.call(S, key = keys[j++]))T[key] = S[key]; + } + return T; +} : Object.assign; +},{"24":24,"34":34,"46":46,"80":80}],54:[function(_dereq_,module,exports){ +// most Object methods by ES6 should accept primitives +var $export = _dereq_(22) + , core = _dereq_(16) + , fails = _dereq_(24); +module.exports = function(KEY, exec){ + var fn = (core.Object || {})[KEY] || Object[KEY] + , exp = {}; + exp[KEY] = exec(fn); + $export($export.S + $export.F * fails(function(){ fn(1); }), 'Object', exp); +}; +},{"16":16,"22":22,"24":24}],55:[function(_dereq_,module,exports){ +var $ = _dereq_(46) + , toIObject = _dereq_(78) + , isEnum = $.isEnum; +module.exports = function(isEntries){ + return function(it){ + var O = toIObject(it) + , keys = $.getKeys(O) + , length = keys.length + , i = 0 + , result = [] + , key; + while(length > i)if(isEnum.call(O, key = keys[i++])){ + result.push(isEntries ? [key, O[key]] : O[key]); + } return result; + }; +}; +},{"46":46,"78":78}],56:[function(_dereq_,module,exports){ +// all object keys, includes non-enumerable and symbols +var $ = _dereq_(46) + , anObject = _dereq_(4) + , Reflect = _dereq_(29).Reflect; +module.exports = Reflect && Reflect.ownKeys || function ownKeys(it){ + var keys = $.getNames(anObject(it)) + , getSymbols = $.getSymbols; + return getSymbols ? keys.concat(getSymbols(it)) : keys; +}; +},{"29":29,"4":4,"46":46}],57:[function(_dereq_,module,exports){ +'use strict'; +var path = _dereq_(58) + , invoke = _dereq_(33) + , aFunction = _dereq_(2); +module.exports = function(/* ...pargs */){ + var fn = aFunction(this) + , length = arguments.length + , pargs = Array(length) + , i = 0 + , _ = path._ + , holder = false; + while(length > i)if((pargs[i] = arguments[i++]) === _)holder = true; + return function(/* ...args */){ + var that = this + , $$ = arguments + , $$len = $$.length + , j = 0, k = 0, args; + if(!holder && !$$len)return invoke(fn, pargs, that); + args = pargs.slice(); + if(holder)for(;length > j; j++)if(args[j] === _)args[j] = $$[k++]; + while($$len > k)args.push($$[k++]); + return invoke(fn, args, that); + }; +}; +},{"2":2,"33":33,"58":58}],58:[function(_dereq_,module,exports){ +module.exports = _dereq_(29); +},{"29":29}],59:[function(_dereq_,module,exports){ +module.exports = function(bitmap, value){ + return { + enumerable : !(bitmap & 1), + configurable: !(bitmap & 2), + writable : !(bitmap & 4), + value : value + }; +}; +},{}],60:[function(_dereq_,module,exports){ +var redefine = _dereq_(61); +module.exports = function(target, src){ + for(var key in src)redefine(target, key, src[key]); + return target; +}; +},{"61":61}],61:[function(_dereq_,module,exports){ +// add fake Function#toString +// for correct work wrapped methods / constructors with methods like LoDash isNative +var global = _dereq_(29) + , hide = _dereq_(31) + , SRC = _dereq_(82)('src') + , TO_STRING = 'toString' + , $toString = Function[TO_STRING] + , TPL = ('' + $toString).split(TO_STRING); + +_dereq_(16).inspectSource = function(it){ + return $toString.call(it); +}; + +(module.exports = function(O, key, val, safe){ + if(typeof val == 'function'){ + val.hasOwnProperty(SRC) || hide(val, SRC, O[key] ? '' + O[key] : TPL.join(String(key))); + val.hasOwnProperty('name') || hide(val, 'name', key); + } + if(O === global){ + O[key] = val; + } else { + if(!safe)delete O[key]; + hide(O, key, val); + } +})(Function.prototype, TO_STRING, function toString(){ + return typeof this == 'function' && this[SRC] || $toString.call(this); +}); +},{"16":16,"29":29,"31":31,"82":82}],62:[function(_dereq_,module,exports){ +module.exports = function(regExp, replace){ + var replacer = replace === Object(replace) ? function(part){ + return replace[part]; + } : replace; + return function(it){ + return String(it).replace(regExp, replacer); + }; +}; +},{}],63:[function(_dereq_,module,exports){ +// 7.2.9 SameValue(x, y) +module.exports = Object.is || function is(x, y){ + return x === y ? x !== 0 || 1 / x === 1 / y : x != x && y != y; +}; +},{}],64:[function(_dereq_,module,exports){ +// Works with __proto__ only. Old v8 can't work with null proto objects. +/* eslint-disable no-proto */ +var getDesc = _dereq_(46).getDesc + , isObject = _dereq_(38) + , anObject = _dereq_(4); +var check = function(O, proto){ + anObject(O); + if(!isObject(proto) && proto !== null)throw TypeError(proto + ": can't set as prototype!"); +}; +module.exports = { + set: Object.setPrototypeOf || ('__proto__' in {} ? // eslint-disable-line + function(test, buggy, set){ + try { + set = _dereq_(17)(Function.call, getDesc(Object.prototype, '__proto__').set, 2); + set(test, []); + buggy = !(test instanceof Array); + } catch(e){ buggy = true; } + return function setPrototypeOf(O, proto){ + check(O, proto); + if(buggy)O.__proto__ = proto; + else set(O, proto); + return O; + }; + }({}, false) : undefined), + check: check +}; +},{"17":17,"38":38,"4":4,"46":46}],65:[function(_dereq_,module,exports){ +'use strict'; +var global = _dereq_(29) + , $ = _dereq_(46) + , DESCRIPTORS = _dereq_(19) + , SPECIES = _dereq_(83)('species'); + +module.exports = function(KEY){ + var C = global[KEY]; + if(DESCRIPTORS && C && !C[SPECIES])$.setDesc(C, SPECIES, { + configurable: true, + get: function(){ return this; } + }); +}; +},{"19":19,"29":29,"46":46,"83":83}],66:[function(_dereq_,module,exports){ +var def = _dereq_(46).setDesc + , has = _dereq_(30) + , TAG = _dereq_(83)('toStringTag'); + +module.exports = function(it, tag, stat){ + if(it && !has(it = stat ? it : it.prototype, TAG))def(it, TAG, {configurable: true, value: tag}); +}; +},{"30":30,"46":46,"83":83}],67:[function(_dereq_,module,exports){ +var global = _dereq_(29) + , SHARED = '__core-js_shared__' + , store = global[SHARED] || (global[SHARED] = {}); +module.exports = function(key){ + return store[key] || (store[key] = {}); +}; +},{"29":29}],68:[function(_dereq_,module,exports){ +// 7.3.20 SpeciesConstructor(O, defaultConstructor) +var anObject = _dereq_(4) + , aFunction = _dereq_(2) + , SPECIES = _dereq_(83)('species'); +module.exports = function(O, D){ + var C = anObject(O).constructor, S; + return C === undefined || (S = anObject(C)[SPECIES]) == undefined ? D : aFunction(S); +}; +},{"2":2,"4":4,"83":83}],69:[function(_dereq_,module,exports){ +module.exports = function(it, Constructor, name){ + if(!(it instanceof Constructor))throw TypeError(name + ": use the 'new' operator!"); + return it; +}; +},{}],70:[function(_dereq_,module,exports){ +var toInteger = _dereq_(77) + , defined = _dereq_(18); +// true -> String#at +// false -> String#codePointAt +module.exports = function(TO_STRING){ + return function(that, pos){ + var s = String(defined(that)) + , i = toInteger(pos) + , l = s.length + , a, b; + if(i < 0 || i >= l)return TO_STRING ? '' : undefined; + a = s.charCodeAt(i); + return a < 0xd800 || a > 0xdbff || i + 1 === l || (b = s.charCodeAt(i + 1)) < 0xdc00 || b > 0xdfff + ? TO_STRING ? s.charAt(i) : a + : TO_STRING ? s.slice(i, i + 2) : (a - 0xd800 << 10) + (b - 0xdc00) + 0x10000; + }; +}; +},{"18":18,"77":77}],71:[function(_dereq_,module,exports){ +// helper for String#{startsWith, endsWith, includes} +var isRegExp = _dereq_(39) + , defined = _dereq_(18); + +module.exports = function(that, searchString, NAME){ + if(isRegExp(searchString))throw TypeError('String#' + NAME + " doesn't accept regex!"); + return String(defined(that)); +}; +},{"18":18,"39":39}],72:[function(_dereq_,module,exports){ +// https://github.com/ljharb/proposal-string-pad-left-right +var toLength = _dereq_(79) + , repeat = _dereq_(73) + , defined = _dereq_(18); + +module.exports = function(that, maxLength, fillString, left){ + var S = String(defined(that)) + , stringLength = S.length + , fillStr = fillString === undefined ? ' ' : String(fillString) + , intMaxLength = toLength(maxLength); + if(intMaxLength <= stringLength)return S; + if(fillStr == '')fillStr = ' '; + var fillLen = intMaxLength - stringLength + , stringFiller = repeat.call(fillStr, Math.ceil(fillLen / fillStr.length)); + if(stringFiller.length > fillLen)stringFiller = stringFiller.slice(0, fillLen); + return left ? stringFiller + S : S + stringFiller; +}; +},{"18":18,"73":73,"79":79}],73:[function(_dereq_,module,exports){ +'use strict'; +var toInteger = _dereq_(77) + , defined = _dereq_(18); + +module.exports = function repeat(count){ + var str = String(defined(this)) + , res = '' + , n = toInteger(count); + if(n < 0 || n == Infinity)throw RangeError("Count can't be negative"); + for(;n > 0; (n >>>= 1) && (str += str))if(n & 1)res += str; + return res; +}; +},{"18":18,"77":77}],74:[function(_dereq_,module,exports){ +var $export = _dereq_(22) + , defined = _dereq_(18) + , fails = _dereq_(24) + , spaces = '\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003' + + '\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF' + , space = '[' + spaces + ']' + , non = '\u200b\u0085' + , ltrim = RegExp('^' + space + space + '*') + , rtrim = RegExp(space + space + '*$'); + +var exporter = function(KEY, exec){ + var exp = {}; + exp[KEY] = exec(trim); + $export($export.P + $export.F * fails(function(){ + return !!spaces[KEY]() || non[KEY]() != non; + }), 'String', exp); +}; + +// 1 -> String#trimLeft +// 2 -> String#trimRight +// 3 -> String#trim +var trim = exporter.trim = function(string, TYPE){ + string = String(defined(string)); + if(TYPE & 1)string = string.replace(ltrim, ''); + if(TYPE & 2)string = string.replace(rtrim, ''); + return string; +}; + +module.exports = exporter; +},{"18":18,"22":22,"24":24}],75:[function(_dereq_,module,exports){ +var ctx = _dereq_(17) + , invoke = _dereq_(33) + , html = _dereq_(32) + , cel = _dereq_(20) + , global = _dereq_(29) + , process = global.process + , setTask = global.setImmediate + , clearTask = global.clearImmediate + , MessageChannel = global.MessageChannel + , counter = 0 + , queue = {} + , ONREADYSTATECHANGE = 'onreadystatechange' + , defer, channel, port; +var run = function(){ + var id = +this; + if(queue.hasOwnProperty(id)){ + var fn = queue[id]; + delete queue[id]; + fn(); + } +}; +var listner = function(event){ + run.call(event.data); +}; +// Node.js 0.9+ & IE10+ has setImmediate, otherwise: +if(!setTask || !clearTask){ + setTask = function setImmediate(fn){ + var args = [], i = 1; + while(arguments.length > i)args.push(arguments[i++]); + queue[++counter] = function(){ + invoke(typeof fn == 'function' ? fn : Function(fn), args); + }; + defer(counter); + return counter; + }; + clearTask = function clearImmediate(id){ + delete queue[id]; + }; + // Node.js 0.8- + if(_dereq_(11)(process) == 'process'){ + defer = function(id){ + process.nextTick(ctx(run, id, 1)); + }; + // Browsers with MessageChannel, includes WebWorkers + } else if(MessageChannel){ + channel = new MessageChannel; + port = channel.port2; + channel.port1.onmessage = listner; + defer = ctx(port.postMessage, port, 1); + // Browsers with postMessage, skip WebWorkers + // IE8 has postMessage, but it's sync & typeof its postMessage is 'object' + } else if(global.addEventListener && typeof postMessage == 'function' && !global.importScripts){ + defer = function(id){ + global.postMessage(id + '', '*'); + }; + global.addEventListener('message', listner, false); + // IE8- + } else if(ONREADYSTATECHANGE in cel('script')){ + defer = function(id){ + html.appendChild(cel('script'))[ONREADYSTATECHANGE] = function(){ + html.removeChild(this); + run.call(id); + }; + }; + // Rest old browsers + } else { + defer = function(id){ + setTimeout(ctx(run, id, 1), 0); + }; + } +} +module.exports = { + set: setTask, + clear: clearTask +}; +},{"11":11,"17":17,"20":20,"29":29,"32":32,"33":33}],76:[function(_dereq_,module,exports){ +var toInteger = _dereq_(77) + , max = Math.max + , min = Math.min; +module.exports = function(index, length){ + index = toInteger(index); + return index < 0 ? max(index + length, 0) : min(index, length); +}; +},{"77":77}],77:[function(_dereq_,module,exports){ +// 7.1.4 ToInteger +var ceil = Math.ceil + , floor = Math.floor; +module.exports = function(it){ + return isNaN(it = +it) ? 0 : (it > 0 ? floor : ceil)(it); +}; +},{}],78:[function(_dereq_,module,exports){ +// to indexed object, toObject with fallback for non-array-like ES3 strings +var IObject = _dereq_(34) + , defined = _dereq_(18); +module.exports = function(it){ + return IObject(defined(it)); +}; +},{"18":18,"34":34}],79:[function(_dereq_,module,exports){ +// 7.1.15 ToLength +var toInteger = _dereq_(77) + , min = Math.min; +module.exports = function(it){ + return it > 0 ? min(toInteger(it), 0x1fffffffffffff) : 0; // pow(2, 53) - 1 == 9007199254740991 +}; +},{"77":77}],80:[function(_dereq_,module,exports){ +// 7.1.13 ToObject(argument) +var defined = _dereq_(18); +module.exports = function(it){ + return Object(defined(it)); +}; +},{"18":18}],81:[function(_dereq_,module,exports){ +// 7.1.1 ToPrimitive(input [, PreferredType]) +var isObject = _dereq_(38); +// instead of the ES6 spec version, we didn't implement @@toPrimitive case +// and the second argument - flag - preferred type is a string +module.exports = function(it, S){ + if(!isObject(it))return it; + var fn, val; + if(S && typeof (fn = it.toString) == 'function' && !isObject(val = fn.call(it)))return val; + if(typeof (fn = it.valueOf) == 'function' && !isObject(val = fn.call(it)))return val; + if(!S && typeof (fn = it.toString) == 'function' && !isObject(val = fn.call(it)))return val; + throw TypeError("Can't convert object to primitive value"); +}; +},{"38":38}],82:[function(_dereq_,module,exports){ +var id = 0 + , px = Math.random(); +module.exports = function(key){ + return 'Symbol('.concat(key === undefined ? '' : key, ')_', (++id + px).toString(36)); +}; +},{}],83:[function(_dereq_,module,exports){ +var store = _dereq_(67)('wks') + , uid = _dereq_(82) + , Symbol = _dereq_(29).Symbol; +module.exports = function(name){ + return store[name] || (store[name] = + Symbol && Symbol[name] || (Symbol || uid)('Symbol.' + name)); +}; +},{"29":29,"67":67,"82":82}],84:[function(_dereq_,module,exports){ +var classof = _dereq_(10) + , ITERATOR = _dereq_(83)('iterator') + , Iterators = _dereq_(45); +module.exports = _dereq_(16).getIteratorMethod = function(it){ + if(it != undefined)return it[ITERATOR] + || it['@@iterator'] + || Iterators[classof(it)]; +}; +},{"10":10,"16":16,"45":45,"83":83}],85:[function(_dereq_,module,exports){ +'use strict'; +var $ = _dereq_(46) + , $export = _dereq_(22) + , DESCRIPTORS = _dereq_(19) + , createDesc = _dereq_(59) + , html = _dereq_(32) + , cel = _dereq_(20) + , has = _dereq_(30) + , cof = _dereq_(11) + , invoke = _dereq_(33) + , fails = _dereq_(24) + , anObject = _dereq_(4) + , aFunction = _dereq_(2) + , isObject = _dereq_(38) + , toObject = _dereq_(80) + , toIObject = _dereq_(78) + , toInteger = _dereq_(77) + , toIndex = _dereq_(76) + , toLength = _dereq_(79) + , IObject = _dereq_(34) + , IE_PROTO = _dereq_(82)('__proto__') + , createArrayMethod = _dereq_(8) + , arrayIndexOf = _dereq_(7)(false) + , ObjectProto = Object.prototype + , ArrayProto = Array.prototype + , arraySlice = ArrayProto.slice + , arrayJoin = ArrayProto.join + , defineProperty = $.setDesc + , getOwnDescriptor = $.getDesc + , defineProperties = $.setDescs + , factories = {} + , IE8_DOM_DEFINE; + +if(!DESCRIPTORS){ + IE8_DOM_DEFINE = !fails(function(){ + return defineProperty(cel('div'), 'a', {get: function(){ return 7; }}).a != 7; + }); + $.setDesc = function(O, P, Attributes){ + if(IE8_DOM_DEFINE)try { + return defineProperty(O, P, Attributes); + } catch(e){ /* empty */ } + if('get' in Attributes || 'set' in Attributes)throw TypeError('Accessors not supported!'); + if('value' in Attributes)anObject(O)[P] = Attributes.value; + return O; + }; + $.getDesc = function(O, P){ + if(IE8_DOM_DEFINE)try { + return getOwnDescriptor(O, P); + } catch(e){ /* empty */ } + if(has(O, P))return createDesc(!ObjectProto.propertyIsEnumerable.call(O, P), O[P]); + }; + $.setDescs = defineProperties = function(O, Properties){ + anObject(O); + var keys = $.getKeys(Properties) + , length = keys.length + , i = 0 + , P; + while(length > i)$.setDesc(O, P = keys[i++], Properties[P]); + return O; + }; +} +$export($export.S + $export.F * !DESCRIPTORS, 'Object', { + // 19.1.2.6 / 15.2.3.3 Object.getOwnPropertyDescriptor(O, P) + getOwnPropertyDescriptor: $.getDesc, + // 19.1.2.4 / 15.2.3.6 Object.defineProperty(O, P, Attributes) + defineProperty: $.setDesc, + // 19.1.2.3 / 15.2.3.7 Object.defineProperties(O, Properties) + defineProperties: defineProperties +}); + + // IE 8- don't enum bug keys +var keys1 = ('constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,' + + 'toLocaleString,toString,valueOf').split(',') + // Additional keys for getOwnPropertyNames + , keys2 = keys1.concat('length', 'prototype') + , keysLen1 = keys1.length; + +// Create object with `null` prototype: use iframe Object with cleared prototype +var createDict = function(){ + // Thrash, waste and sodomy: IE GC bug + var iframe = cel('iframe') + , i = keysLen1 + , gt = '>' + , iframeDocument; + iframe.style.display = 'none'; + html.appendChild(iframe); + iframe.src = 'javascript:'; // eslint-disable-line no-script-url + // createDict = iframe.contentWindow.Object; + // html.removeChild(iframe); + iframeDocument = iframe.contentWindow.document; + iframeDocument.open(); + iframeDocument.write(' + */ + +var runScripts = function runScripts() { + var scripts = []; + var types = ["text/ecmascript-6", "text/6to5", "text/babel", "module"]; + var index = 0; + + /** + * Transform and execute script. Ensures correct load order. + */ + + var exec = function exec() { + var param = scripts[index]; + if (param instanceof Array) { + transform.run.apply(transform, param); + index++; + exec(); + } + }; + + /** + * Load, transform, and execute all scripts. + */ + + var run = function run(script, i) { + var opts = {}; + + if (script.src) { + transform.load(script.src, function (param) { + scripts[i] = param; + exec(); + }, opts, true); + } else { + opts.filename = "embedded"; + scripts[i] = [script.innerHTML, opts]; + } + }; + + // Collect scripts with Babel `types`. + + var _scripts = global.document.getElementsByTagName("script"); + + for (var i = 0; i < _scripts.length; ++i) { + var _script = _scripts[i]; + if (types.indexOf(_script.type) >= 0) scripts.push(_script); + } + + for (i in scripts) { + run(scripts[i], i); + } + + exec(); +}; + +/** + * Register load event to transform and execute scripts. + */ + +if (global.addEventListener) { + global.addEventListener("DOMContentLoaded", runScripts, false); +} else if (global.attachEvent) { + global.attachEvent("onload", runScripts); +} +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"15":15,"49":49,"611":611,"66":66}],15:[function(_dereq_,module,exports){ +"use strict"; + +exports.__esModule = true; +exports.register = register; +exports.polyfill = polyfill; +exports.transformFile = transformFile; +exports.transformFileSync = transformFileSync; +exports.parse = parse; +// istanbul ignore next + +function _interopRequire(obj) { return obj && obj.__esModule ? obj["default"] : obj; } + +// istanbul ignore next + +function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } + +// istanbul ignore next + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } + +var _lodashLangIsFunction = _dereq_(508); + +var _lodashLangIsFunction2 = _interopRequireDefault(_lodashLangIsFunction); + +var _transformation = _dereq_(66); + +var _transformation2 = _interopRequireDefault(_transformation); + +var _babylon = _dereq_(613); + +var babylon = _interopRequireWildcard(_babylon); + +var _util = _dereq_(182); + +var util = _interopRequireWildcard(_util); + +var _fs = _dereq_(3); + +var _fs2 = _interopRequireDefault(_fs); + +var _types = _dereq_(179); + +var t = _interopRequireWildcard(_types); + +exports.util = util; +exports.acorn = babylon; +exports.transform = _transformation2["default"]; +exports.pipeline = _transformation.pipeline; +exports.canCompile = _util.canCompile; + +var _transformationFile = _dereq_(46); + +exports.File = _interopRequire(_transformationFile); + +var _transformationFileOptionsConfig = _dereq_(48); + +exports.options = _interopRequire(_transformationFileOptionsConfig); + +var _transformationPlugin = _dereq_(82); + +exports.Plugin = _interopRequire(_transformationPlugin); + +var _transformationTransformer = _dereq_(83); + +exports.Transformer = _interopRequire(_transformationTransformer); + +var _transformationPipeline = _dereq_(80); + +exports.Pipeline = _interopRequire(_transformationPipeline); + +var _traversal = _dereq_(148); + +exports.traverse = _interopRequire(_traversal); + +var _toolsBuildExternalHelpers = _dereq_(45); + +exports.buildExternalHelpers = _interopRequire(_toolsBuildExternalHelpers); + +var _package = _dereq_(611); + +exports.version = _package.version; +exports.types = t; + +/** + * Register Babel and polyfill globally. + */ + +function register(opts) { + var callback = _dereq_(17); + if (opts != null) callback(opts); + return callback; +} + +/** + * Register polyfill globally. + */ + +function polyfill() { + _dereq_(44); +} + +/** + * Asynchronously transform `filename` with optional `opts`, calls `callback` when complete. + */ + +function transformFile(filename, opts, callback) { + if (_lodashLangIsFunction2["default"](opts)) { + callback = opts; + opts = {}; + } + + opts.filename = filename; + + _fs2["default"].readFile(filename, function (err, code) { + if (err) return callback(err); + + var result; + + try { + result = _transformation2["default"](code, opts); + } catch (err) { + return callback(err); + } + + callback(null, result); + }); +} + +/** + * Synchronous form of `transformFile`. + */ + +function transformFileSync(filename) { + var opts = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; + + opts.filename = filename; + return _transformation2["default"](_fs2["default"].readFileSync(filename, "utf8"), opts); +} + +/** + * Parse script with Babel's parser. + */ + +function parse(code) { + var opts = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; + + opts.allowHashBang = true; + opts.sourceType = "module"; + opts.ecmaVersion = Infinity; + opts.plugins = { + jsx: true, + flow: true + }; + opts.features = {}; + + for (var key in _transformation2["default"].pipeline.transformers) { + opts.features[key] = true; + } + + var ast = babylon.parse(code, opts); + + if (opts.onToken) { + // istanbul ignore next + + var _opts$onToken; + + (_opts$onToken = opts.onToken).push.apply(_opts$onToken, ast.tokens); + } + + if (opts.onComment) { + // istanbul ignore next + + var _opts$onComment; + + (_opts$onComment = opts.onComment).push.apply(_opts$onComment, ast.comments); + } + + return ast.program; +} +},{"148":148,"17":17,"179":179,"182":182,"3":3,"44":44,"45":45,"46":46,"48":48,"508":508,"611":611,"613":613,"66":66,"80":80,"82":82,"83":83}],16:[function(_dereq_,module,exports){ +// required to safely use babel/register within a browserify codebase + +"use strict"; + +exports.__esModule = true; + +_dereq_(44); + +exports["default"] = function () {}; + +module.exports = exports["default"]; +},{"44":44}],17:[function(_dereq_,module,exports){ +"use strict"; + +exports.__esModule = true; +// istanbul ignore next + +function _interopRequire(obj) { return obj && obj.__esModule ? obj["default"] : obj; } + +_dereq_(44); + +var _node = _dereq_(16); + +exports["default"] = _interopRequire(_node); +module.exports = exports["default"]; +},{"16":16,"44":44}],18:[function(_dereq_,module,exports){ +"use strict"; + +exports.__esModule = true; +// istanbul ignore next + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } + +// istanbul ignore next + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var _repeating = _dereq_(592); + +var _repeating2 = _interopRequireDefault(_repeating); + +var _trimRight = _dereq_(609); + +var _trimRight2 = _interopRequireDefault(_trimRight); + +var _lodashLangIsBoolean = _dereq_(506); + +var _lodashLangIsBoolean2 = _interopRequireDefault(_lodashLangIsBoolean); + +var _lodashCollectionIncludes = _dereq_(421); + +var _lodashCollectionIncludes2 = _interopRequireDefault(_lodashCollectionIncludes); + +var _lodashLangIsNumber = _dereq_(510); + +var _lodashLangIsNumber2 = _interopRequireDefault(_lodashLangIsNumber); + +/** + * Buffer for collecting generated output. + */ + +var Buffer = (function () { + function Buffer(position, format) { + _classCallCheck(this, Buffer); + + this.parenPushNewlineState = null; + + this.position = position; + this._indent = format.indent.base; + this.format = format; + this.buf = ""; + } + + /** + * Get the current trimmed buffer. + */ + + Buffer.prototype.get = function get() { + return _trimRight2["default"](this.buf); + }; + + /** + * Get the current indent. + */ + + Buffer.prototype.getIndent = function getIndent() { + if (this.format.compact || this.format.concise) { + return ""; + } else { + return _repeating2["default"](this.format.indent.style, this._indent); + } + }; + + /** + * Get the current indent size. + */ + + Buffer.prototype.indentSize = function indentSize() { + return this.getIndent().length; + }; + + /** + * Increment indent size. + */ + + Buffer.prototype.indent = function indent() { + this._indent++; + }; + + /** + * Decrement indent size. + */ + + Buffer.prototype.dedent = function dedent() { + this._indent--; + }; + + /** + * Add a semicolon to the buffer. + */ + + Buffer.prototype.semicolon = function semicolon() { + this.push(";"); + }; + + /** + * Ensure last character is a semicolon. + */ + + Buffer.prototype.ensureSemicolon = function ensureSemicolon() { + if (!this.isLast(";")) this.semicolon(); + }; + + /** + * Add a right brace to the buffer. + */ + + Buffer.prototype.rightBrace = function rightBrace() { + this.newline(true); + //if (this.format.compact) this._removeLast(";"); + this.push("}"); + }; + + /** + * Add a keyword to the buffer. + */ + + Buffer.prototype.keyword = function keyword(name) { + this.push(name); + this.space(); + }; + + /** + * Add a space to the buffer unless it is compact (override with force). + */ + + Buffer.prototype.space = function space(force) { + if (!force && this.format.compact) return; + + if (force || this.buf && !this.isLast(" ") && !this.isLast("\n")) { + this.push(" "); + } + }; + + /** + * Remove the last character. + */ + + Buffer.prototype.removeLast = function removeLast(cha) { + if (this.format.compact) return; + return this._removeLast(cha); + }; + + Buffer.prototype._removeLast = function _removeLast(cha) { + if (!this._isLast(cha)) return; + this.buf = this.buf.substr(0, this.buf.length - 1); + this.position.unshift(cha); + }; + + /** + * Set some state that will be modified if a newline has been inserted before any + * non-space characters. + * + * This is to prevent breaking semantics for terminatorless separator nodes. eg: + * + * return foo; + * + * returns `foo`. But if we do: + * + * return + * foo; + * + * `undefined` will be returned and not `foo` due to the terminator. + */ + + Buffer.prototype.startTerminatorless = function startTerminatorless() { + return this.parenPushNewlineState = { + printed: false + }; + }; + + /** + * Print an ending parentheses if a starting one has been printed. + */ + + Buffer.prototype.endTerminatorless = function endTerminatorless(state) { + if (state.printed) { + this.dedent(); + this.newline(); + this.push(")"); + } + }; + + /** + * Add a newline (or many newlines), maintaining formatting. + * Strips multiple newlines if removeLast is true. + */ + + Buffer.prototype.newline = function newline(i, removeLast) { + if (this.format.compact || this.format.retainLines) return; + + if (this.format.concise) { + this.space(); + return; + } + + removeLast = removeLast || false; + + if (_lodashLangIsNumber2["default"](i)) { + i = Math.min(2, i); + + if (this.endsWith("{\n") || this.endsWith(":\n")) i--; + if (i <= 0) return; + + while (i > 0) { + this._newline(removeLast); + i--; + } + return; + } + + if (_lodashLangIsBoolean2["default"](i)) { + removeLast = i; + } + + this._newline(removeLast); + }; + + /** + * Adds a newline unless there is already two previous newlines. + */ + + Buffer.prototype._newline = function _newline(removeLast) { + // never allow more than two lines + if (this.endsWith("\n\n")) return; + + // remove the last newline + if (removeLast && this.isLast("\n")) this.removeLast("\n"); + + this.removeLast(" "); + this._removeSpacesAfterLastNewline(); + this._push("\n"); + }; + + /** + * If buffer ends with a newline and some spaces after it, trim those spaces. + */ + + Buffer.prototype._removeSpacesAfterLastNewline = function _removeSpacesAfterLastNewline() { + var lastNewlineIndex = this.buf.lastIndexOf("\n"); + if (lastNewlineIndex === -1) { + return; + } + + var index = this.buf.length - 1; + while (index > lastNewlineIndex) { + if (this.buf[index] !== " ") { + break; + } + + index--; + } + + if (index === lastNewlineIndex) { + this.buf = this.buf.substring(0, index + 1); + } + }; + + /** + * Push a string to the buffer, maintaining indentation and newlines. + */ + + Buffer.prototype.push = function push(str, noIndent) { + if (!this.format.compact && this._indent && !noIndent && str !== "\n") { + // we have an indent level and we aren't pushing a newline + var indent = this.getIndent(); + + // replace all newlines with newlines with the indentation + str = str.replace(/\n/g, "\n" + indent); + + // we've got a newline before us so prepend on the indentation + if (this.isLast("\n")) this._push(indent); + } + + this._push(str); + }; + + /** + * Push a string to the buffer. + */ + + Buffer.prototype._push = function _push(str) { + // see startTerminatorless() instance method + var parenPushNewlineState = this.parenPushNewlineState; + if (parenPushNewlineState) { + for (var i = 0; i < str.length; i++) { + var cha = str[i]; + + // we can ignore spaces since they wont interupt a terminatorless separator + if (cha === " ") continue; + + this.parenPushNewlineState = null; + + if (cha === "\n" || cha === "/") { + // we're going to break this terminator expression so we need to add a parentheses + this._push("("); + this.indent(); + parenPushNewlineState.printed = true; + } + + break; + } + } + + // + this.position.push(str); + this.buf += str; + }; + + /** + * Test if the buffer ends with a string. + */ + + Buffer.prototype.endsWith = function endsWith(str) { + var buf = arguments.length <= 1 || arguments[1] === undefined ? this.buf : arguments[1]; + + if (str.length === 1) { + return buf[buf.length - 1] === str; + } else { + return buf.slice(-str.length) === str; + } + }; + + /** + * Test if a character is last in the buffer. + */ + + Buffer.prototype.isLast = function isLast(cha) { + if (this.format.compact) return false; + return this._isLast(cha); + }; + + Buffer.prototype._isLast = function _isLast(cha) { + var buf = this.buf; + var last = buf[buf.length - 1]; + + if (Array.isArray(cha)) { + return _lodashCollectionIncludes2["default"](cha, last); + } else { + return cha === last; + } + }; + + return Buffer; +})(); + +exports["default"] = Buffer; +module.exports = exports["default"]; +},{"421":421,"506":506,"510":510,"592":592,"609":609}],19:[function(_dereq_,module,exports){ +/** + * Print File.program + */ + +"use strict"; + +exports.__esModule = true; +exports.File = File; +exports.Program = Program; +exports.BlockStatement = BlockStatement; +exports.Noop = Noop; + +function File(node, print) { + print.plain(node.program); +} + +/** + * Print all nodes in a Program.body. + */ + +function Program(node, print) { + print.sequence(node.body); +} + +/** + * Print BlockStatement, collapses empty blocks, prints body. + */ + +function BlockStatement(node, print) { + this.push("{"); + if (node.body.length) { + this.newline(); + print.sequence(node.body, { indent: true }); + if (!this.format.retainLines) this.removeLast("\n"); + this.rightBrace(); + } else { + print.printInnerComments(); + this.push("}"); + } +} + +/** + * What is my purpose? + * Why am I here? + * Why are any of us here? + * Does any of this really matter? + */ + +function Noop() {} +},{}],20:[function(_dereq_,module,exports){ +/** + * Print ClassDeclaration, prints decorators, typeParameters, extends, implements, and body. + */ + +"use strict"; + +exports.__esModule = true; +exports.ClassDeclaration = ClassDeclaration; +exports.ClassBody = ClassBody; +exports.ClassProperty = ClassProperty; +exports.MethodDefinition = MethodDefinition; + +function ClassDeclaration(node, print) { + print.list(node.decorators, { separator: "" }); + this.push("class"); + + if (node.id) { + this.push(" "); + print.plain(node.id); + } + + print.plain(node.typeParameters); + + if (node.superClass) { + this.push(" extends "); + print.plain(node.superClass); + print.plain(node.superTypeParameters); + } + + if (node["implements"]) { + this.push(" implements "); + print.join(node["implements"], { separator: ", " }); + } + + this.space(); + print.plain(node.body); +} + +/** + * Alias ClassDeclaration printer as ClassExpression. + */ + +exports.ClassExpression = ClassDeclaration; + +/** + * Print ClassBody, collapses empty blocks, prints body. + */ + +function ClassBody(node, print) { + this.push("{"); + if (node.body.length === 0) { + print.printInnerComments(); + this.push("}"); + } else { + this.newline(); + + this.indent(); + print.sequence(node.body); + this.dedent(); + + this.rightBrace(); + } +} + +/** + * Print ClassProperty, prints decorators, static, key, typeAnnotation, and value. + * Also: semicolons, deal with it. + */ + +function ClassProperty(node, print) { + print.list(node.decorators, { separator: "" }); + + if (node["static"]) this.push("static "); + print.plain(node.key); + print.plain(node.typeAnnotation); + if (node.value) { + this.space(); + this.push("="); + this.space(); + print.plain(node.value); + } + this.semicolon(); +} + +/** + * Print MethodDefinition, prints decorations, static, and method. + */ + +function MethodDefinition(node, print) { + print.list(node.decorators, { separator: "" }); + + if (node["static"]) { + this.push("static "); + } + + this._method(node, print); +} +},{}],21:[function(_dereq_,module,exports){ +/** + * Prints ComprehensionBlock, prints left and right. + */ + +"use strict"; + +exports.__esModule = true; +exports.ComprehensionBlock = ComprehensionBlock; +exports.ComprehensionExpression = ComprehensionExpression; + +function ComprehensionBlock(node, print) { + this.keyword("for"); + this.push("("); + print.plain(node.left); + this.push(" of "); + print.plain(node.right); + this.push(")"); +} + +/** + * Prints ComprehensionExpression, prints blocks, filter, and body. Handles generators. + */ + +function ComprehensionExpression(node, print) { + this.push(node.generator ? "(" : "["); + + print.join(node.blocks, { separator: " " }); + this.space(); + + if (node.filter) { + this.keyword("if"); + this.push("("); + print.plain(node.filter); + this.push(")"); + this.space(); + } + + print.plain(node.body); + + this.push(node.generator ? ")" : "]"); +} +},{}],22:[function(_dereq_,module,exports){ +"use strict"; + +exports.__esModule = true; +exports.UnaryExpression = UnaryExpression; +exports.DoExpression = DoExpression; +exports.ParenthesizedExpression = ParenthesizedExpression; +exports.UpdateExpression = UpdateExpression; +exports.ConditionalExpression = ConditionalExpression; +exports.NewExpression = NewExpression; +exports.SequenceExpression = SequenceExpression; +exports.ThisExpression = ThisExpression; +exports.Super = Super; +exports.Decorator = Decorator; +exports.CallExpression = CallExpression; +exports.EmptyStatement = EmptyStatement; +exports.ExpressionStatement = ExpressionStatement; +exports.AssignmentPattern = AssignmentPattern; +exports.AssignmentExpression = AssignmentExpression; +exports.BindExpression = BindExpression; +exports.MemberExpression = MemberExpression; +exports.MetaProperty = MetaProperty; +// istanbul ignore next + +function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } } + +// istanbul ignore next + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } + +var _isInteger = _dereq_(406); + +var _isInteger2 = _interopRequireDefault(_isInteger); + +var _lodashLangIsNumber = _dereq_(510); + +var _lodashLangIsNumber2 = _interopRequireDefault(_lodashLangIsNumber); + +var _node = _dereq_(31); + +var _node2 = _interopRequireDefault(_node); + +var _types = _dereq_(179); + +var t = _interopRequireWildcard(_types); + +/** + * RegExp for testing scientific notation in literals. + */ + +var SCIENTIFIC_NOTATION = /e/i; +var ZERO_DECIMAL_INTEGER = /\.0+$/; + +/** + * RegExp for testing if a numeric literal is + * a BinaryIntegerLiteral, OctalIntegerLiteral or HexIntegerLiteral. + */ + +var NON_DECIMAL_NUMERIC_LITERAL = /^0(b|o|x)/i; + +/** + * Prints UnaryExpression, prints operator and argument. + */ + +function UnaryExpression(node, print) { + var needsSpace = /[a-z]$/.test(node.operator); + var arg = node.argument; + + if (t.isUpdateExpression(arg) || t.isUnaryExpression(arg)) { + needsSpace = true; + } + + if (t.isUnaryExpression(arg) && arg.operator === "!") { + needsSpace = false; + } + + this.push(node.operator); + if (needsSpace) this.push(" "); + print.plain(node.argument); +} + +/** + * Prints DoExpression, prints body. + */ + +function DoExpression(node, print) { + this.push("do"); + this.space(); + print.plain(node.body); +} + +/** + * Prints ParenthesizedExpression, prints expression. + */ + +function ParenthesizedExpression(node, print) { + this.push("("); + print.plain(node.expression); + this.push(")"); +} + +/** + * Prints UpdateExpression, prints operator and argument. + */ + +function UpdateExpression(node, print) { + if (node.prefix) { + this.push(node.operator); + print.plain(node.argument); + } else { + print.plain(node.argument); + this.push(node.operator); + } +} + +/** + * Prints ConditionalExpression, prints test, consequent, and alternate. + */ + +function ConditionalExpression(node, print) { + print.plain(node.test); + this.space(); + this.push("?"); + this.space(); + print.plain(node.consequent); + this.space(); + this.push(":"); + this.space(); + print.plain(node.alternate); +} + +/** + * Prints NewExpression, prints callee and arguments. + */ + +function NewExpression(node, print) { + this.push("new "); + print.plain(node.callee); + this.push("("); + print.list(node.arguments); + this.push(")"); +} + +/** + * Prints SequenceExpression.expressions. + */ + +function SequenceExpression(node, print) { + print.list(node.expressions); +} + +/** + * Prints ThisExpression. + */ + +function ThisExpression() { + this.push("this"); +} + +/** + * Prints Super. + */ + +function Super() { + this.push("super"); +} + +/** + * Prints Decorator, prints expression. + */ + +function Decorator(node, print) { + this.push("@"); + print.plain(node.expression); + this.newline(); +} + +/** + * Prints CallExpression, prints callee and arguments. + */ + +function CallExpression(node, print) { + print.plain(node.callee); + + this.push("("); + + var isPrettyCall = node._prettyCall && !this.format.retainLines && !this.format.compact; + + var separator; + if (isPrettyCall) { + separator = ",\n"; + this.newline(); + this.indent(); + } + + print.list(node.arguments, { separator: separator }); + + if (isPrettyCall) { + this.newline(); + this.dedent(); + } + + this.push(")"); +} + +/** + * Builds yield or await expression printer. + * Prints delegate, all, and argument. + */ + +var buildYieldAwait = function buildYieldAwait(keyword) { + return function (node, print) { + this.push(keyword); + + if (node.delegate || node.all) { + this.push("*"); + } + + if (node.argument) { + this.push(" "); + var terminatorState = this.startTerminatorless(); + print.plain(node.argument); + this.endTerminatorless(terminatorState); + } + }; +}; + +/** + * Create YieldExpression and AwaitExpression printers. + */ + +var YieldExpression = buildYieldAwait("yield"); +exports.YieldExpression = YieldExpression; +var AwaitExpression = buildYieldAwait("await"); + +exports.AwaitExpression = AwaitExpression; +/** + * Prints EmptyStatement. + */ + +function EmptyStatement() { + this.semicolon(); +} + +/** + * Prints ExpressionStatement, prints expression. + */ + +function ExpressionStatement(node, print) { + print.plain(node.expression); + this.semicolon(); +} + +/** + * Prints AssignmentPattern, prints left and right. + */ + +function AssignmentPattern(node, print) { + print.plain(node.left); + this.push(" = "); + print.plain(node.right); +} + +/** + * Prints AssignmentExpression, prints left, operator, and right. + */ + +function AssignmentExpression(node, print, parent) { + // Somewhere inside a for statement `init` node but doesn't usually + // needs a paren except for `in` expressions: `for (a in b ? a : b;;)` + var parens = this._inForStatementInit && node.operator === "in" && !_node2["default"].needsParens(node, parent); + + if (parens) { + this.push("("); + } + + // todo: add cases where the spaces can be dropped when in compact mode + print.plain(node.left); + + var spaces = node.operator === "in" || node.operator === "instanceof"; + spaces = true; // todo: https://github.com/babel/babel/issues/1835 + this.space(spaces); + + this.push(node.operator); + + if (!spaces) { + // space is mandatory to avoid outputting regexps + set = set.map(function (s, si, set) { + return s.map(this.parse, this) + }, this) + + this.debug(this.pattern, set) + + // filter out everything that didn't compile properly. + set = set.filter(function (s) { + return s.indexOf(false) === -1 + }) + + this.debug(this.pattern, set) + + this.set = set +} + +Minimatch.prototype.parseNegate = parseNegate +function parseNegate () { + var pattern = this.pattern + var negate = false + var options = this.options + var negateOffset = 0 + + if (options.nonegate) return + + for (var i = 0, l = pattern.length + ; i < l && pattern.charAt(i) === '!' + ; i++) { + negate = !negate + negateOffset++ + } + + if (negateOffset) this.pattern = pattern.substr(negateOffset) + this.negate = negate +} + +// Brace expansion: +// a{b,c}d -> abd acd +// a{b,}c -> abc ac +// a{0..3}d -> a0d a1d a2d a3d +// a{b,c{d,e}f}g -> abg acdfg acefg +// a{b,c}d{e,f}g -> abdeg acdeg abdeg abdfg +// +// Invalid sets are not expanded. +// a{2..}b -> a{2..}b +// a{b}c -> a{b}c +minimatch.braceExpand = function (pattern, options) { + return braceExpand(pattern, options) +} + +Minimatch.prototype.braceExpand = braceExpand + +function braceExpand (pattern, options) { + if (!options) { + if (this instanceof Minimatch) { + options = this.options + } else { + options = {} + } + } + + pattern = typeof pattern === 'undefined' + ? this.pattern : pattern + + if (typeof pattern === 'undefined') { + throw new Error('undefined pattern') + } + + if (options.nobrace || + !pattern.match(/\{.*\}/)) { + // shortcut. no need to expand. + return [pattern] + } + + return expand(pattern) +} + +// parse a component of the expanded set. +// At this point, no pattern may contain "/" in it +// so we're going to return a 2d array, where each entry is the full +// pattern, split on '/', and then turned into a regular expression. +// A regexp is made at the end which joins each array with an +// escaped /, and another full one which joins each regexp with |. +// +// Following the lead of Bash 4.1, note that "**" only has special meaning +// when it is the *only* thing in a path portion. Otherwise, any series +// of * is equivalent to a single *. Globstar behavior is enabled by +// default, and can be disabled by setting options.noglobstar. +Minimatch.prototype.parse = parse +var SUBPARSE = {} +function parse (pattern, isSub) { + var options = this.options + + // shortcuts + if (!options.noglobstar && pattern === '**') return GLOBSTAR + if (pattern === '') return '' + + var re = '' + var hasMagic = !!options.nocase + var escaping = false + // ? => one single character + var patternListStack = [] + var negativeLists = [] + var plType + var stateChar + var inClass = false + var reClassStart = -1 + var classStart = -1 + // . and .. never match anything that doesn't start with ., + // even when options.dot is set. + var patternStart = pattern.charAt(0) === '.' ? '' // anything + // not (start or / followed by . or .. followed by / or end) + : options.dot ? '(?!(?:^|\\\/)\\.{1,2}(?:$|\\\/))' + : '(?!\\.)' + var self = this + + function clearStateChar () { + if (stateChar) { + // we had some state-tracking character + // that wasn't consumed by this pass. + switch (stateChar) { + case '*': + re += star + hasMagic = true + break + case '?': + re += qmark + hasMagic = true + break + default: + re += '\\' + stateChar + break + } + self.debug('clearStateChar %j %j', stateChar, re) + stateChar = false + } + } + + for (var i = 0, len = pattern.length, c + ; (i < len) && (c = pattern.charAt(i)) + ; i++) { + this.debug('%s\t%s %s %j', pattern, i, re, c) + + // skip over any that are escaped. + if (escaping && reSpecials[c]) { + re += '\\' + c + escaping = false + continue + } + + switch (c) { + case '/': + // completely not allowed, even escaped. + // Should already be path-split by now. + return false + + case '\\': + clearStateChar() + escaping = true + continue + + // the various stateChar values + // for the "extglob" stuff. + case '?': + case '*': + case '+': + case '@': + case '!': + this.debug('%s\t%s %s %j <-- stateChar', pattern, i, re, c) + + // all of those are literals inside a class, except that + // the glob [!a] means [^a] in regexp + if (inClass) { + this.debug(' in class') + if (c === '!' && i === classStart + 1) c = '^' + re += c + continue + } + + // if we already have a stateChar, then it means + // that there was something like ** or +? in there. + // Handle the stateChar, then proceed with this one. + self.debug('call clearStateChar %j', stateChar) + clearStateChar() + stateChar = c + // if extglob is disabled, then +(asdf|foo) isn't a thing. + // just clear the statechar *now*, rather than even diving into + // the patternList stuff. + if (options.noext) clearStateChar() + continue + + case '(': + if (inClass) { + re += '(' + continue + } + + if (!stateChar) { + re += '\\(' + continue + } + + plType = stateChar + patternListStack.push({ + type: plType, + start: i - 1, + reStart: re.length + }) + // negation is (?:(?!js)[^/]*) + re += stateChar === '!' ? '(?:(?!(?:' : '(?:' + this.debug('plType %j %j', stateChar, re) + stateChar = false + continue + + case ')': + if (inClass || !patternListStack.length) { + re += '\\)' + continue + } + + clearStateChar() + hasMagic = true + re += ')' + var pl = patternListStack.pop() + plType = pl.type + // negation is (?:(?!js)[^/]*) + // The others are (?:) + switch (plType) { + case '!': + negativeLists.push(pl) + re += ')[^/]*?)' + pl.reEnd = re.length + break + case '?': + case '+': + case '*': + re += plType + break + case '@': break // the default anyway + } + continue + + case '|': + if (inClass || !patternListStack.length || escaping) { + re += '\\|' + escaping = false + continue + } + + clearStateChar() + re += '|' + continue + + // these are mostly the same in regexp and glob + case '[': + // swallow any state-tracking char before the [ + clearStateChar() + + if (inClass) { + re += '\\' + c + continue + } + + inClass = true + classStart = i + reClassStart = re.length + re += c + continue + + case ']': + // a right bracket shall lose its special + // meaning and represent itself in + // a bracket expression if it occurs + // first in the list. -- POSIX.2 2.8.3.2 + if (i === classStart + 1 || !inClass) { + re += '\\' + c + escaping = false + continue + } + + // handle the case where we left a class open. + // "[z-a]" is valid, equivalent to "\[z-a\]" + if (inClass) { + // split where the last [ was, make sure we don't have + // an invalid re. if so, re-walk the contents of the + // would-be class to re-translate any characters that + // were passed through as-is + // TODO: It would probably be faster to determine this + // without a try/catch and a new RegExp, but it's tricky + // to do safely. For now, this is safe and works. + var cs = pattern.substring(classStart + 1, i) + try { + RegExp('[' + cs + ']') + } catch (er) { + // not a valid class! + var sp = this.parse(cs, SUBPARSE) + re = re.substr(0, reClassStart) + '\\[' + sp[0] + '\\]' + hasMagic = hasMagic || sp[1] + inClass = false + continue + } + } + + // finish up the class. + hasMagic = true + inClass = false + re += c + continue + + default: + // swallow any state char that wasn't consumed + clearStateChar() + + if (escaping) { + // no need + escaping = false + } else if (reSpecials[c] + && !(c === '^' && inClass)) { + re += '\\' + } + + re += c + + } // switch + } // for + + // handle the case where we left a class open. + // "[abc" is valid, equivalent to "\[abc" + if (inClass) { + // split where the last [ was, and escape it + // this is a huge pita. We now have to re-walk + // the contents of the would-be class to re-translate + // any characters that were passed through as-is + cs = pattern.substr(classStart + 1) + sp = this.parse(cs, SUBPARSE) + re = re.substr(0, reClassStart) + '\\[' + sp[0] + hasMagic = hasMagic || sp[1] + } + + // handle the case where we had a +( thing at the *end* + // of the pattern. + // each pattern list stack adds 3 chars, and we need to go through + // and escape any | chars that were passed through as-is for the regexp. + // Go through and escape them, taking care not to double-escape any + // | chars that were already escaped. + for (pl = patternListStack.pop(); pl; pl = patternListStack.pop()) { + var tail = re.slice(pl.reStart + 3) + // maybe some even number of \, then maybe 1 \, followed by a | + tail = tail.replace(/((?:\\{2})*)(\\?)\|/g, function (_, $1, $2) { + if (!$2) { + // the | isn't already escaped, so escape it. + $2 = '\\' + } + + // need to escape all those slashes *again*, without escaping the + // one that we need for escaping the | character. As it works out, + // escaping an even number of slashes can be done by simply repeating + // it exactly after itself. That's why this trick works. + // + // I am sorry that you have to see this. + return $1 + $1 + $2 + '|' + }) + + this.debug('tail=%j\n %s', tail, tail) + var t = pl.type === '*' ? star + : pl.type === '?' ? qmark + : '\\' + pl.type + + hasMagic = true + re = re.slice(0, pl.reStart) + t + '\\(' + tail + } + + // handle trailing things that only matter at the very end. + clearStateChar() + if (escaping) { + // trailing \\ + re += '\\\\' + } + + // only need to apply the nodot start if the re starts with + // something that could conceivably capture a dot + var addPatternStart = false + switch (re.charAt(0)) { + case '.': + case '[': + case '(': addPatternStart = true + } + + // Hack to work around lack of negative lookbehind in JS + // A pattern like: *.!(x).!(y|z) needs to ensure that a name + // like 'a.xyz.yz' doesn't match. So, the first negative + // lookahead, has to look ALL the way ahead, to the end of + // the pattern. + for (var n = negativeLists.length - 1; n > -1; n--) { + var nl = negativeLists[n] + + var nlBefore = re.slice(0, nl.reStart) + var nlFirst = re.slice(nl.reStart, nl.reEnd - 8) + var nlLast = re.slice(nl.reEnd - 8, nl.reEnd) + var nlAfter = re.slice(nl.reEnd) + + nlLast += nlAfter + + // Handle nested stuff like *(*.js|!(*.json)), where open parens + // mean that we should *not* include the ) in the bit that is considered + // "after" the negated section. + var openParensBefore = nlBefore.split('(').length - 1 + var cleanAfter = nlAfter + for (i = 0; i < openParensBefore; i++) { + cleanAfter = cleanAfter.replace(/\)[+*?]?/, '') + } + nlAfter = cleanAfter + + var dollar = '' + if (nlAfter === '' && isSub !== SUBPARSE) { + dollar = '$' + } + var newRe = nlBefore + nlFirst + nlAfter + dollar + nlLast + re = newRe + } + + // if the re is not "" at this point, then we need to make sure + // it doesn't match against an empty path part. + // Otherwise a/* will match a/, which it should not. + if (re !== '' && hasMagic) { + re = '(?=.)' + re + } + + if (addPatternStart) { + re = patternStart + re + } + + // parsing just a piece of a larger pattern. + if (isSub === SUBPARSE) { + return [re, hasMagic] + } + + // skip the regexp for non-magical patterns + // unescape anything in it, though, so that it'll be + // an exact match against a file etc. + if (!hasMagic) { + return globUnescape(pattern) + } + + var flags = options.nocase ? 'i' : '' + var regExp = new RegExp('^' + re + '$', flags) + + regExp._glob = pattern + regExp._src = re + + return regExp +} + +minimatch.makeRe = function (pattern, options) { + return new Minimatch(pattern, options || {}).makeRe() +} + +Minimatch.prototype.makeRe = makeRe +function makeRe () { + if (this.regexp || this.regexp === false) return this.regexp + + // at this point, this.set is a 2d array of partial + // pattern strings, or "**". + // + // It's better to use .match(). This function shouldn't + // be used, really, but it's pretty convenient sometimes, + // when you just want to work with a regex. + var set = this.set + + if (!set.length) { + this.regexp = false + return this.regexp + } + var options = this.options + + var twoStar = options.noglobstar ? star + : options.dot ? twoStarDot + : twoStarNoDot + var flags = options.nocase ? 'i' : '' + + var re = set.map(function (pattern) { + return pattern.map(function (p) { + return (p === GLOBSTAR) ? twoStar + : (typeof p === 'string') ? regExpEscape(p) + : p._src + }).join('\\\/') + }).join('|') + + // must match entire pattern + // ending in a * or ** will make it less strict. + re = '^(?:' + re + ')$' + + // can match anything, as long as it's not this. + if (this.negate) re = '^(?!' + re + ').*$' + + try { + this.regexp = new RegExp(re, flags) + } catch (ex) { + this.regexp = false + } + return this.regexp +} + +minimatch.match = function (list, pattern, options) { + options = options || {} + var mm = new Minimatch(pattern, options) + list = list.filter(function (f) { + return mm.match(f) + }) + if (mm.options.nonull && !list.length) { + list.push(pattern) + } + return list +} + +Minimatch.prototype.match = match +function match (f, partial) { + this.debug('match', f, this.pattern) + // short-circuit in the case of busted things. + // comments, etc. + if (this.comment) return false + if (this.empty) return f === '' + + if (f === '/' && partial) return true + + var options = this.options + + // windows: need to use /, not \ + if (path.sep !== '/') { + f = f.split(path.sep).join('/') + } + + // treat the test path as a set of pathparts. + f = f.split(slashSplit) + this.debug(this.pattern, 'split', f) + + // just ONE of the pattern sets in this.set needs to match + // in order for it to be valid. If negating, then just one + // match means that we have failed. + // Either way, return on the first hit. + + var set = this.set + this.debug(this.pattern, 'set', set) + + // Find the basename of the path by looking for the last non-empty segment + var filename + var i + for (i = f.length - 1; i >= 0; i--) { + filename = f[i] + if (filename) break + } + + for (i = 0; i < set.length; i++) { + var pattern = set[i] + var file = f + if (options.matchBase && pattern.length === 1) { + file = [filename] + } + var hit = this.matchOne(file, pattern, partial) + if (hit) { + if (options.flipNegate) return true + return !this.negate + } + } + + // didn't get any hits. this is success if it's a negative + // pattern, failure otherwise. + if (options.flipNegate) return false + return this.negate +} + +// set partial to true to test if, for example, +// "/a/b" matches the start of "/*/b/*/d" +// Partial means, if you run out of file before you run +// out of pattern, then that's fine, as long as all +// the parts match. +Minimatch.prototype.matchOne = function (file, pattern, partial) { + var options = this.options + + this.debug('matchOne', + { 'this': this, file: file, pattern: pattern }) + + this.debug('matchOne', file.length, pattern.length) + + for (var fi = 0, + pi = 0, + fl = file.length, + pl = pattern.length + ; (fi < fl) && (pi < pl) + ; fi++, pi++) { + this.debug('matchOne loop') + var p = pattern[pi] + var f = file[fi] + + this.debug(pattern, p, f) + + // should be impossible. + // some invalid regexp stuff in the set. + if (p === false) return false + + if (p === GLOBSTAR) { + this.debug('GLOBSTAR', [pattern, p, f]) + + // "**" + // a/**/b/**/c would match the following: + // a/b/x/y/z/c + // a/x/y/z/b/c + // a/b/x/b/x/c + // a/b/c + // To do this, take the rest of the pattern after + // the **, and see if it would match the file remainder. + // If so, return success. + // If not, the ** "swallows" a segment, and try again. + // This is recursively awful. + // + // a/**/b/**/c matching a/b/x/y/z/c + // - a matches a + // - doublestar + // - matchOne(b/x/y/z/c, b/**/c) + // - b matches b + // - doublestar + // - matchOne(x/y/z/c, c) -> no + // - matchOne(y/z/c, c) -> no + // - matchOne(z/c, c) -> no + // - matchOne(c, c) yes, hit + var fr = fi + var pr = pi + 1 + if (pr === pl) { + this.debug('** at the end') + // a ** at the end will just swallow the rest. + // We have found a match. + // however, it will not swallow /.x, unless + // options.dot is set. + // . and .. are *never* matched by **, for explosively + // exponential reasons. + for (; fi < fl; fi++) { + if (file[fi] === '.' || file[fi] === '..' || + (!options.dot && file[fi].charAt(0) === '.')) return false + } + return true + } + + // ok, let's see if we can swallow whatever we can. + while (fr < fl) { + var swallowee = file[fr] + + this.debug('\nglobstar while', file, fr, pattern, pr, swallowee) + + // XXX remove this slice. Just pass the start index. + if (this.matchOne(file.slice(fr), pattern.slice(pr), partial)) { + this.debug('globstar found match!', fr, fl, swallowee) + // found a match. + return true + } else { + // can't swallow "." or ".." ever. + // can only swallow ".foo" when explicitly asked. + if (swallowee === '.' || swallowee === '..' || + (!options.dot && swallowee.charAt(0) === '.')) { + this.debug('dot detected!', file, fr, pattern, pr) + break + } + + // ** swallows a segment, and continue. + this.debug('globstar swallow a segment, and continue') + fr++ + } + } + + // no match was found. + // However, in partial mode, we can't say this is necessarily over. + // If there's more *pattern* left, then + if (partial) { + // ran out of file + this.debug('\n>>> no match, partial?', file, fr, pattern, pr) + if (fr === fl) return true + } + return false + } + + // something other than ** + // non-magic patterns just have to match exactly + // patterns with magic have been turned into regexps. + var hit + if (typeof p === 'string') { + if (options.nocase) { + hit = f.toLowerCase() === p.toLowerCase() + } else { + hit = f === p + } + this.debug('string match', p, f, hit) + } else { + hit = f.match(p) + this.debug('pattern match', p, f, hit) + } + + if (!hit) return false + } + + // Note: ending in / means that we'll get a final "" + // at the end of the pattern. This can only match a + // corresponding "" at the end of the file. + // If the file ends in /, then it can only match a + // a pattern that ends in /, unless the pattern just + // doesn't have any more for it. But, a/b/ should *not* + // match "a/b/*", even though "" matches against the + // [^/]*? pattern, except in partial mode, where it might + // simply not be reached yet. + // However, a/b/ should still satisfy a/* + + // now either we fell off the end of the pattern, or we're done. + if (fi === fl && pi === pl) { + // ran out of pattern and filename at the same time. + // an exact hit! + return true + } else if (fi === fl) { + // ran out of file, but still had pattern left. + // this is ok if we're doing the match as part of + // a glob fs traversal. + return partial + } else if (pi === pl) { + // ran out of pattern, still have file left. + // this is only acceptable if we're on the very last + // empty segment of a file with a trailing slash. + // a/* should match a/b/ + var emptyFileEnd = (fi === fl - 1) && (file[fi] === '') + return emptyFileEnd + } + + // should be unreachable. + throw new Error('wtf?') +} + +// replace stuff like \* with * +function globUnescape (s) { + return s.replace(/\\(.)/g, '$1') +} + +function regExpEscape (s) { + return s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&') +} + +},{"531":531,"9":9}],531:[function(_dereq_,module,exports){ +var concatMap = _dereq_(533); +var balanced = _dereq_(532); + +module.exports = expandTop; + +var escSlash = '\0SLASH'+Math.random()+'\0'; +var escOpen = '\0OPEN'+Math.random()+'\0'; +var escClose = '\0CLOSE'+Math.random()+'\0'; +var escComma = '\0COMMA'+Math.random()+'\0'; +var escPeriod = '\0PERIOD'+Math.random()+'\0'; + +function numeric(str) { + return parseInt(str, 10) == str + ? parseInt(str, 10) + : str.charCodeAt(0); +} + +function escapeBraces(str) { + return str.split('\\\\').join(escSlash) + .split('\\{').join(escOpen) + .split('\\}').join(escClose) + .split('\\,').join(escComma) + .split('\\.').join(escPeriod); +} + +function unescapeBraces(str) { + return str.split(escSlash).join('\\') + .split(escOpen).join('{') + .split(escClose).join('}') + .split(escComma).join(',') + .split(escPeriod).join('.'); +} + + +// Basically just str.split(","), but handling cases +// where we have nested braced sections, which should be +// treated as individual members, like {a,{b,c},d} +function parseCommaParts(str) { + if (!str) + return ['']; + + var parts = []; + var m = balanced('{', '}', str); + + if (!m) + return str.split(','); + + var pre = m.pre; + var body = m.body; + var post = m.post; + var p = pre.split(','); + + p[p.length-1] += '{' + body + '}'; + var postParts = parseCommaParts(post); + if (post.length) { + p[p.length-1] += postParts.shift(); + p.push.apply(p, postParts); + } + + parts.push.apply(parts, p); + + return parts; +} + +function expandTop(str) { + if (!str) + return []; + + return expand(escapeBraces(str), true).map(unescapeBraces); +} + +function identity(e) { + return e; +} + +function embrace(str) { + return '{' + str + '}'; +} +function isPadded(el) { + return /^-?0\d/.test(el); +} + +function lte(i, y) { + return i <= y; +} +function gte(i, y) { + return i >= y; +} + +function expand(str, isTop) { + var expansions = []; + + var m = balanced('{', '}', str); + if (!m || /\$$/.test(m.pre)) return [str]; + + var isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body); + var isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body); + var isSequence = isNumericSequence || isAlphaSequence; + var isOptions = /^(.*,)+(.+)?$/.test(m.body); + if (!isSequence && !isOptions) { + // {a},b} + if (m.post.match(/,.*}/)) { + str = m.pre + '{' + m.body + escClose + m.post; + return expand(str); + } + return [str]; + } + + var n; + if (isSequence) { + n = m.body.split(/\.\./); + } else { + n = parseCommaParts(m.body); + if (n.length === 1) { + // x{{a,b}}y ==> x{a}y x{b}y + n = expand(n[0], false).map(embrace); + if (n.length === 1) { + var post = m.post.length + ? expand(m.post, false) + : ['']; + return post.map(function(p) { + return m.pre + n[0] + p; + }); + } + } + } + + // at this point, n is the parts, and we know it's not a comma set + // with a single entry. + + // no need to expand pre, since it is guaranteed to be free of brace-sets + var pre = m.pre; + var post = m.post.length + ? expand(m.post, false) + : ['']; + + var N; + + if (isSequence) { + var x = numeric(n[0]); + var y = numeric(n[1]); + var width = Math.max(n[0].length, n[1].length) + var incr = n.length == 3 + ? Math.abs(numeric(n[2])) + : 1; + var test = lte; + var reverse = y < x; + if (reverse) { + incr *= -1; + test = gte; + } + var pad = n.some(isPadded); + + N = []; + + for (var i = x; test(i, y); i += incr) { + var c; + if (isAlphaSequence) { + c = String.fromCharCode(i); + if (c === '\\') + c = ''; + } else { + c = String(i); + if (pad) { + var need = width - c.length; + if (need > 0) { + var z = new Array(need + 1).join('0'); + if (i < 0) + c = '-' + z + c.slice(1); + else + c = z + c; + } + } + } + N.push(c); + } + } else { + N = concatMap(n, function(el) { return expand(el, false) }); + } + + for (var j = 0; j < N.length; j++) { + for (var k = 0; k < post.length; k++) { + var expansion = pre + N[j] + post[k]; + if (!isTop || isSequence || expansion) + expansions.push(expansion); + } + } + + return expansions; +} + + +},{"532":532,"533":533}],532:[function(_dereq_,module,exports){ +module.exports = balanced; +function balanced(a, b, str) { + var r = range(a, b, str); + + return r && { + start: r[0], + end: r[1], + pre: str.slice(0, r[0]), + body: str.slice(r[0] + a.length, r[1]), + post: str.slice(r[1] + b.length) + }; +} + +balanced.range = range; +function range(a, b, str) { + var begs, beg, left, right, result; + var ai = str.indexOf(a); + var bi = str.indexOf(b, ai + 1); + var i = ai; + + if (ai >= 0 && bi > 0) { + begs = []; + left = str.length; + + while (i < str.length && i >= 0 && ! result) { + if (i == ai) { + begs.push(i); + ai = str.indexOf(a, i + 1); + } else if (begs.length == 1) { + result = [ begs.pop(), bi ]; + } else { + beg = begs.pop(); + if (beg < left) { + left = beg; + right = bi; + } + + bi = str.indexOf(b, i + 1); + } + + i = ai < bi && ai >= 0 ? ai : bi; + } + + if (begs.length) { + result = [ left, right ]; + } + } + + return result; +} + +},{}],533:[function(_dereq_,module,exports){ +module.exports = function (xs, fn) { + var res = []; + for (var i = 0; i < xs.length; i++) { + var x = fn(xs[i], i); + if (isArray(x)) res.push.apply(res, x); + else res.push(x); + } + return res; +}; + +var isArray = Array.isArray || function (xs) { + return Object.prototype.toString.call(xs) === '[object Array]'; +}; + +},{}],534:[function(_dereq_,module,exports){ +'use strict'; +var fs = _dereq_(3) + +module.exports = function (pth, cb) { + var fn = typeof fs.access === 'function' ? fs.access : fs.stat; + + fn(pth, function (err) { + cb(null, !err); + }); +}; + +module.exports.sync = function (pth) { + var fn = typeof fs.accessSync === 'function' ? fs.accessSync : fs.statSync; + + try { + fn(pth); + return true; + } catch (err) { + return false; + } +}; + +},{"3":3}],535:[function(_dereq_,module,exports){ +(function (process){ +'use strict'; + +function posix(path) { + return path.charAt(0) === '/'; +}; + +function win32(path) { + // https://github.com/joyent/node/blob/b3fcc245fb25539909ef1d5eaa01dbf92e168633/lib/path.js#L56 + var splitDeviceRe = /^([a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/]+[^\\\/]+)?([\\\/])?([\s\S]*?)$/; + var result = splitDeviceRe.exec(path); + var device = result[1] || ''; + var isUnc = !!device && device.charAt(1) !== ':'; + + // UNC paths are always absolute + return !!result[2] || isUnc; +}; + +module.exports = process.platform === 'win32' ? win32 : posix; +module.exports.posix = posix; +module.exports.win32 = win32; + +}).call(this,_dereq_(10)) +},{"10":10}],536:[function(_dereq_,module,exports){ +"use strict"; + +var originalObject = Object; +var originalDefProp = Object.defineProperty; +var originalCreate = Object.create; + +function defProp(obj, name, value) { + if (originalDefProp) try { + originalDefProp.call(originalObject, obj, name, { value: value }); + } catch (definePropertyIsBrokenInIE8) { + obj[name] = value; + } else { + obj[name] = value; + } +} + +// For functions that will be invoked using .call or .apply, we need to +// define those methods on the function objects themselves, rather than +// inheriting them from Function.prototype, so that a malicious or clumsy +// third party cannot interfere with the functionality of this module by +// redefining Function.prototype.call or .apply. +function makeSafeToCall(fun) { + if (fun) { + defProp(fun, "call", fun.call); + defProp(fun, "apply", fun.apply); + } + return fun; +} + +makeSafeToCall(originalDefProp); +makeSafeToCall(originalCreate); + +var hasOwn = makeSafeToCall(Object.prototype.hasOwnProperty); +var numToStr = makeSafeToCall(Number.prototype.toString); +var strSlice = makeSafeToCall(String.prototype.slice); + +var cloner = function(){}; +function create(prototype) { + if (originalCreate) { + return originalCreate.call(originalObject, prototype); + } + cloner.prototype = prototype || null; + return new cloner; +} + +var rand = Math.random; +var uniqueKeys = create(null); + +function makeUniqueKey() { + // Collisions are highly unlikely, but this module is in the business of + // making guarantees rather than safe bets. + do var uniqueKey = internString(strSlice.call(numToStr.call(rand(), 36), 2)); + while (hasOwn.call(uniqueKeys, uniqueKey)); + return uniqueKeys[uniqueKey] = uniqueKey; +} + +function internString(str) { + var obj = {}; + obj[str] = true; + return Object.keys(obj)[0]; +} + +// External users might find this function useful, but it is not necessary +// for the typical use of this module. +defProp(exports, "makeUniqueKey", makeUniqueKey); + +// Object.getOwnPropertyNames is the only way to enumerate non-enumerable +// properties, so if we wrap it to ignore our secret keys, there should be +// no way (except guessing) to access those properties. +var originalGetOPNs = Object.getOwnPropertyNames; +Object.getOwnPropertyNames = function getOwnPropertyNames(object) { + for (var names = originalGetOPNs(object), + src = 0, + dst = 0, + len = names.length; + src < len; + ++src) { + if (!hasOwn.call(uniqueKeys, names[src])) { + if (src > dst) { + names[dst] = names[src]; + } + ++dst; + } + } + names.length = dst; + return names; +}; + +function defaultCreatorFn(object) { + return create(null); +} + +function makeAccessor(secretCreatorFn) { + var brand = makeUniqueKey(); + var passkey = create(null); + + secretCreatorFn = secretCreatorFn || defaultCreatorFn; + + function register(object) { + var secret; // Created lazily. + + function vault(key, forget) { + // Only code that has access to the passkey can retrieve (or forget) + // the secret object. + if (key === passkey) { + return forget + ? secret = null + : secret || (secret = secretCreatorFn(object)); + } + } + + defProp(object, brand, vault); + } + + function accessor(object) { + if (!hasOwn.call(object, brand)) + register(object); + return object[brand](passkey); + } + + accessor.forget = function(object) { + if (hasOwn.call(object, brand)) + object[brand](passkey, true); + }; + + return accessor; +} + +defProp(exports, "makeAccessor", makeAccessor); + +},{}],537:[function(_dereq_,module,exports){ +/** + * Copyright (c) 2014, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * https://raw.github.com/facebook/regenerator/master/LICENSE file. An + * additional grant of patent rights can be found in the PATENTS file in + * the same directory. + */ + +var assert = _dereq_(1); +var types = _dereq_(568).types; +var isArray = types.builtInTypes.array; +var b = types.builders; +var n = types.namedTypes; +var leap = _dereq_(539); +var meta = _dereq_(540); +var util = _dereq_(541); +var runtimeProperty = util.runtimeProperty; +var hasOwn = Object.prototype.hasOwnProperty; + +function Emitter(contextId) { + assert.ok(this instanceof Emitter); + n.Identifier.assert(contextId); + + // Used to generate unique temporary names. + this.nextTempId = 0; + + Object.defineProperties(this, { + // In order to make sure the context object does not collide with + // anything in the local scope, we might have to rename it, so we + // refer to it symbolically instead of just assuming that it will be + // called "context". + contextId: { value: contextId }, + + // An append-only list of Statements that grows each time this.emit is + // called. + listing: { value: [] }, + + // A sparse array whose keys correspond to locations in this.listing + // that have been marked as branch/jump targets. + marked: { value: [true] }, + + // The last location will be marked when this.getDispatchLoop is + // called. + finalLoc: { value: loc() }, + + // A list of all leap.TryEntry statements emitted. + tryEntries: { value: [] } + }); + + // The .leapManager property needs to be defined by a separate + // defineProperties call so that .finalLoc will be visible to the + // leap.LeapManager constructor. + Object.defineProperties(this, { + // Each time we evaluate the body of a loop, we tell this.leapManager + // to enter a nested loop context that determines the meaning of break + // and continue statements therein. + leapManager: { value: new leap.LeapManager(this) } + }); +} + +var Ep = Emitter.prototype; +exports.Emitter = Emitter; + +// Offsets into this.listing that could be used as targets for branches or +// jumps are represented as numeric Literal nodes. This representation has +// the amazingly convenient benefit of allowing the exact value of the +// location to be determined at any time, even after generating code that +// refers to the location. +function loc() { + return b.literal(-1); +} + +// Sets the exact value of the given location to the offset of the next +// Statement emitted. +Ep.mark = function(loc) { + n.Literal.assert(loc); + var index = this.listing.length; + if (loc.value === -1) { + loc.value = index; + } else { + // Locations can be marked redundantly, but their values cannot change + // once set the first time. + assert.strictEqual(loc.value, index); + } + this.marked[index] = true; + return loc; +}; + +Ep.emit = function(node) { + if (n.Expression.check(node)) + node = b.expressionStatement(node); + n.Statement.assert(node); + this.listing.push(node); +}; + +// Shorthand for emitting assignment statements. This will come in handy +// for assignments to temporary variables. +Ep.emitAssign = function(lhs, rhs) { + this.emit(this.assign(lhs, rhs)); + return lhs; +}; + +// Shorthand for an assignment statement. +Ep.assign = function(lhs, rhs) { + return b.expressionStatement( + b.assignmentExpression("=", lhs, rhs)); +}; + +// Convenience function for generating expressions like context.next, +// context.sent, and context.rval. +Ep.contextProperty = function(name, computed) { + return b.memberExpression( + this.contextId, + computed ? b.literal(name) : b.identifier(name), + !!computed + ); +}; + +// Shorthand for setting context.rval and jumping to `context.stop()`. +Ep.stop = function(rval) { + if (rval) { + this.setReturnValue(rval); + } + + this.jump(this.finalLoc); +}; + +Ep.setReturnValue = function(valuePath) { + n.Expression.assert(valuePath.value); + + this.emitAssign( + this.contextProperty("rval"), + this.explodeExpression(valuePath) + ); +}; + +Ep.clearPendingException = function(tryLoc, assignee) { + n.Literal.assert(tryLoc); + + var catchCall = b.callExpression( + this.contextProperty("catch", true), + [tryLoc] + ); + + if (assignee) { + this.emitAssign(assignee, catchCall); + } else { + this.emit(catchCall); + } +}; + +// Emits code for an unconditional jump to the given location, even if the +// exact value of the location is not yet known. +Ep.jump = function(toLoc) { + this.emitAssign(this.contextProperty("next"), toLoc); + this.emit(b.breakStatement()); +}; + +// Conditional jump. +Ep.jumpIf = function(test, toLoc) { + n.Expression.assert(test); + n.Literal.assert(toLoc); + + this.emit(b.ifStatement( + test, + b.blockStatement([ + this.assign(this.contextProperty("next"), toLoc), + b.breakStatement() + ]) + )); +}; + +// Conditional jump, with the condition negated. +Ep.jumpIfNot = function(test, toLoc) { + n.Expression.assert(test); + n.Literal.assert(toLoc); + + var negatedTest; + if (n.UnaryExpression.check(test) && + test.operator === "!") { + // Avoid double negation. + negatedTest = test.argument; + } else { + negatedTest = b.unaryExpression("!", test); + } + + this.emit(b.ifStatement( + negatedTest, + b.blockStatement([ + this.assign(this.contextProperty("next"), toLoc), + b.breakStatement() + ]) + )); +}; + +// Returns a unique MemberExpression that can be used to store and +// retrieve temporary values. Since the object of the member expression is +// the context object, which is presumed to coexist peacefully with all +// other local variables, and since we just increment `nextTempId` +// monotonically, uniqueness is assured. +Ep.makeTempVar = function() { + return this.contextProperty("t" + this.nextTempId++); +}; + +Ep.getContextFunction = function(id) { + return b.functionExpression( + id || null/*Anonymous*/, + [this.contextId], + b.blockStatement([this.getDispatchLoop()]), + false, // Not a generator anymore! + false // Nor an expression. + ); +}; + +// Turns this.listing into a loop of the form +// +// while (1) switch (context.next) { +// case 0: +// ... +// case n: +// return context.stop(); +// } +// +// Each marked location in this.listing will correspond to one generated +// case statement. +Ep.getDispatchLoop = function() { + var self = this; + var cases = []; + var current; + + // If we encounter a break, continue, or return statement in a switch + // case, we can skip the rest of the statements until the next case. + var alreadyEnded = false; + + self.listing.forEach(function(stmt, i) { + if (self.marked.hasOwnProperty(i)) { + cases.push(b.switchCase( + b.literal(i), + current = [])); + alreadyEnded = false; + } + + if (!alreadyEnded) { + current.push(stmt); + if (isSwitchCaseEnder(stmt)) + alreadyEnded = true; + } + }); + + // Now that we know how many statements there will be in this.listing, + // we can finally resolve this.finalLoc.value. + this.finalLoc.value = this.listing.length; + + cases.push( + b.switchCase(this.finalLoc, [ + // Intentionally fall through to the "end" case... + ]), + + // So that the runtime can jump to the final location without having + // to know its offset, we provide the "end" case as a synonym. + b.switchCase(b.literal("end"), [ + // This will check/clear both context.thrown and context.rval. + b.returnStatement( + b.callExpression(this.contextProperty("stop"), []) + ) + ]) + ); + + return b.whileStatement( + b.literal(1), + b.switchStatement( + b.assignmentExpression( + "=", + this.contextProperty("prev"), + this.contextProperty("next") + ), + cases + ) + ); +}; + +// See comment above re: alreadyEnded. +function isSwitchCaseEnder(stmt) { + return n.BreakStatement.check(stmt) + || n.ContinueStatement.check(stmt) + || n.ReturnStatement.check(stmt) + || n.ThrowStatement.check(stmt); +} + +Ep.getTryLocsList = function() { + if (this.tryEntries.length === 0) { + // To avoid adding a needless [] to the majority of runtime.wrap + // argument lists, force the caller to handle this case specially. + return null; + } + + var lastLocValue = 0; + + return b.arrayExpression( + this.tryEntries.map(function(tryEntry) { + var thisLocValue = tryEntry.firstLoc.value; + assert.ok(thisLocValue >= lastLocValue, "try entries out of order"); + lastLocValue = thisLocValue; + + var ce = tryEntry.catchEntry; + var fe = tryEntry.finallyEntry; + + var locs = [ + tryEntry.firstLoc, + // The null here makes a hole in the array. + ce ? ce.firstLoc : null + ]; + + if (fe) { + locs[2] = fe.firstLoc; + locs[3] = fe.afterLoc; + } + + return b.arrayExpression(locs); + }) + ); +}; + +// All side effects must be realized in order. + +// If any subexpression harbors a leap, all subexpressions must be +// neutered of side effects. + +// No destructive modification of AST nodes. + +Ep.explode = function(path, ignoreResult) { + assert.ok(path instanceof types.NodePath); + + var node = path.value; + var self = this; + + n.Node.assert(node); + + if (n.Statement.check(node)) + return self.explodeStatement(path); + + if (n.Expression.check(node)) + return self.explodeExpression(path, ignoreResult); + + if (n.Declaration.check(node)) + throw getDeclError(node); + + switch (node.type) { + case "Program": + return path.get("body").map( + self.explodeStatement, + self + ); + + case "VariableDeclarator": + throw getDeclError(node); + + // These node types should be handled by their parent nodes + // (ObjectExpression, SwitchStatement, and TryStatement, respectively). + case "Property": + case "SwitchCase": + case "CatchClause": + throw new Error( + node.type + " nodes should be handled by their parents"); + + default: + throw new Error( + "unknown Node of type " + + JSON.stringify(node.type)); + } +}; + +function getDeclError(node) { + return new Error( + "all declarations should have been transformed into " + + "assignments before the Exploder began its work: " + + JSON.stringify(node)); +} + +Ep.explodeStatement = function(path, labelId) { + assert.ok(path instanceof types.NodePath); + + var stmt = path.value; + var self = this; + + n.Statement.assert(stmt); + + if (labelId) { + n.Identifier.assert(labelId); + } else { + labelId = null; + } + + // Explode BlockStatement nodes even if they do not contain a yield, + // because we don't want or need the curly braces. + if (n.BlockStatement.check(stmt)) { + return path.get("body").each( + self.explodeStatement, + self + ); + } + + if (!meta.containsLeap(stmt)) { + // Technically we should be able to avoid emitting the statement + // altogether if !meta.hasSideEffects(stmt), but that leads to + // confusing generated code (for instance, `while (true) {}` just + // disappears) and is probably a more appropriate job for a dedicated + // dead code elimination pass. + self.emit(stmt); + return; + } + + switch (stmt.type) { + case "ExpressionStatement": + self.explodeExpression(path.get("expression"), true); + break; + + case "LabeledStatement": + var after = loc(); + + // Did you know you can break from any labeled block statement or + // control structure? Well, you can! Note: when a labeled loop is + // encountered, the leap.LabeledEntry created here will immediately + // enclose a leap.LoopEntry on the leap manager's stack, and both + // entries will have the same label. Though this works just fine, it + // may seem a bit redundant. In theory, we could check here to + // determine if stmt knows how to handle its own label; for example, + // stmt happens to be a WhileStatement and so we know it's going to + // establish its own LoopEntry when we explode it (below). Then this + // LabeledEntry would be unnecessary. Alternatively, we might be + // tempted not to pass stmt.label down into self.explodeStatement, + // because we've handled the label here, but that's a mistake because + // labeled loops may contain labeled continue statements, which is not + // something we can handle in this generic case. All in all, I think a + // little redundancy greatly simplifies the logic of this case, since + // it's clear that we handle all possible LabeledStatements correctly + // here, regardless of whether they interact with the leap manager + // themselves. Also remember that labels and break/continue-to-label + // statements are rare, and all of this logic happens at transform + // time, so it has no additional runtime cost. + self.leapManager.withEntry( + new leap.LabeledEntry(after, stmt.label), + function() { + self.explodeStatement(path.get("body"), stmt.label); + } + ); + + self.mark(after); + + break; + + case "WhileStatement": + var before = loc(); + var after = loc(); + + self.mark(before); + self.jumpIfNot(self.explodeExpression(path.get("test")), after); + self.leapManager.withEntry( + new leap.LoopEntry(after, before, labelId), + function() { self.explodeStatement(path.get("body")); } + ); + self.jump(before); + self.mark(after); + + break; + + case "DoWhileStatement": + var first = loc(); + var test = loc(); + var after = loc(); + + self.mark(first); + self.leapManager.withEntry( + new leap.LoopEntry(after, test, labelId), + function() { self.explode(path.get("body")); } + ); + self.mark(test); + self.jumpIf(self.explodeExpression(path.get("test")), first); + self.mark(after); + + break; + + case "ForStatement": + var head = loc(); + var update = loc(); + var after = loc(); + + if (stmt.init) { + // We pass true here to indicate that if stmt.init is an expression + // then we do not care about its result. + self.explode(path.get("init"), true); + } + + self.mark(head); + + if (stmt.test) { + self.jumpIfNot(self.explodeExpression(path.get("test")), after); + } else { + // No test means continue unconditionally. + } + + self.leapManager.withEntry( + new leap.LoopEntry(after, update, labelId), + function() { self.explodeStatement(path.get("body")); } + ); + + self.mark(update); + + if (stmt.update) { + // We pass true here to indicate that if stmt.update is an + // expression then we do not care about its result. + self.explode(path.get("update"), true); + } + + self.jump(head); + + self.mark(after); + + break; + + case "ForInStatement": + var head = loc(); + var after = loc(); + + var keyIterNextFn = self.makeTempVar(); + self.emitAssign( + keyIterNextFn, + b.callExpression( + runtimeProperty("keys"), + [self.explodeExpression(path.get("right"))] + ) + ); + + self.mark(head); + + var keyInfoTmpVar = self.makeTempVar(); + self.jumpIf( + b.memberExpression( + b.assignmentExpression( + "=", + keyInfoTmpVar, + b.callExpression(keyIterNextFn, []) + ), + b.identifier("done"), + false + ), + after + ); + + self.emitAssign( + stmt.left, + b.memberExpression( + keyInfoTmpVar, + b.identifier("value"), + false + ) + ); + + self.leapManager.withEntry( + new leap.LoopEntry(after, head, labelId), + function() { self.explodeStatement(path.get("body")); } + ); + + self.jump(head); + + self.mark(after); + + break; + + case "BreakStatement": + self.emitAbruptCompletion({ + type: "break", + target: self.leapManager.getBreakLoc(stmt.label) + }); + + break; + + case "ContinueStatement": + self.emitAbruptCompletion({ + type: "continue", + target: self.leapManager.getContinueLoc(stmt.label) + }); + + break; + + case "SwitchStatement": + // Always save the discriminant into a temporary variable in case the + // test expressions overwrite values like context.sent. + var disc = self.emitAssign( + self.makeTempVar(), + self.explodeExpression(path.get("discriminant")) + ); + + var after = loc(); + var defaultLoc = loc(); + var condition = defaultLoc; + var caseLocs = []; + + // If there are no cases, .cases might be undefined. + var cases = stmt.cases || []; + + for (var i = cases.length - 1; i >= 0; --i) { + var c = cases[i]; + n.SwitchCase.assert(c); + + if (c.test) { + condition = b.conditionalExpression( + b.binaryExpression("===", disc, c.test), + caseLocs[i] = loc(), + condition + ); + } else { + caseLocs[i] = defaultLoc; + } + } + + self.jump(self.explodeExpression( + new types.NodePath(condition, path, "discriminant") + )); + + self.leapManager.withEntry( + new leap.SwitchEntry(after), + function() { + path.get("cases").each(function(casePath) { + var c = casePath.value; + var i = casePath.name; + + self.mark(caseLocs[i]); + + casePath.get("consequent").each( + self.explodeStatement, + self + ); + }); + } + ); + + self.mark(after); + if (defaultLoc.value === -1) { + self.mark(defaultLoc); + assert.strictEqual(after.value, defaultLoc.value); + } + + break; + + case "IfStatement": + var elseLoc = stmt.alternate && loc(); + var after = loc(); + + self.jumpIfNot( + self.explodeExpression(path.get("test")), + elseLoc || after + ); + + self.explodeStatement(path.get("consequent")); + + if (elseLoc) { + self.jump(after); + self.mark(elseLoc); + self.explodeStatement(path.get("alternate")); + } + + self.mark(after); + + break; + + case "ReturnStatement": + self.emitAbruptCompletion({ + type: "return", + value: self.explodeExpression(path.get("argument")) + }); + + break; + + case "WithStatement": + throw new Error( + node.type + " not supported in generator functions."); + + case "TryStatement": + var after = loc(); + + var handler = stmt.handler; + if (!handler && stmt.handlers) { + handler = stmt.handlers[0] || null; + } + + var catchLoc = handler && loc(); + var catchEntry = catchLoc && new leap.CatchEntry( + catchLoc, + handler.param + ); + + var finallyLoc = stmt.finalizer && loc(); + var finallyEntry = finallyLoc && + new leap.FinallyEntry(finallyLoc, after); + + var tryEntry = new leap.TryEntry( + self.getUnmarkedCurrentLoc(), + catchEntry, + finallyEntry + ); + + self.tryEntries.push(tryEntry); + self.updateContextPrevLoc(tryEntry.firstLoc); + + self.leapManager.withEntry(tryEntry, function() { + self.explodeStatement(path.get("block")); + + if (catchLoc) { + if (finallyLoc) { + // If we have both a catch block and a finally block, then + // because we emit the catch block first, we need to jump over + // it to the finally block. + self.jump(finallyLoc); + + } else { + // If there is no finally block, then we need to jump over the + // catch block to the fall-through location. + self.jump(after); + } + + self.updateContextPrevLoc(self.mark(catchLoc)); + + var bodyPath = path.get("handler", "body"); + var safeParam = self.makeTempVar(); + self.clearPendingException(tryEntry.firstLoc, safeParam); + + var catchScope = bodyPath.scope; + var catchParamName = handler.param.name; + n.CatchClause.assert(catchScope.node); + assert.strictEqual(catchScope.lookup(catchParamName), catchScope); + + types.visit(bodyPath, { + visitIdentifier: function(path) { + if (util.isReference(path, catchParamName) && + path.scope.lookup(catchParamName) === catchScope) { + return safeParam; + } + + this.traverse(path); + }, + + visitFunction: function(path) { + if (path.scope.declares(catchParamName)) { + // Don't descend into nested scopes that shadow the catch + // parameter with their own declarations. This isn't + // logically necessary because of the path.scope.lookup we + // do in visitIdentifier, but it saves time. + return false; + } + + this.traverse(path); + } + }); + + self.leapManager.withEntry(catchEntry, function() { + self.explodeStatement(bodyPath); + }); + } + + if (finallyLoc) { + self.updateContextPrevLoc(self.mark(finallyLoc)); + + self.leapManager.withEntry(finallyEntry, function() { + self.explodeStatement(path.get("finalizer")); + }); + + self.emit(b.returnStatement(b.callExpression( + self.contextProperty("finish"), + [finallyEntry.firstLoc] + ))); + } + }); + + self.mark(after); + + break; + + case "ThrowStatement": + self.emit(b.throwStatement( + self.explodeExpression(path.get("argument")) + )); + + break; + + default: + throw new Error( + "unknown Statement of type " + + JSON.stringify(stmt.type)); + } +}; + +Ep.emitAbruptCompletion = function(record) { + if (!isValidCompletion(record)) { + assert.ok( + false, + "invalid completion record: " + + JSON.stringify(record) + ); + } + + assert.notStrictEqual( + record.type, "normal", + "normal completions are not abrupt" + ); + + var abruptArgs = [b.literal(record.type)]; + + if (record.type === "break" || + record.type === "continue") { + n.Literal.assert(record.target); + abruptArgs[1] = record.target; + } else if (record.type === "return" || + record.type === "throw") { + if (record.value) { + n.Expression.assert(record.value); + abruptArgs[1] = record.value; + } + } + + this.emit( + b.returnStatement( + b.callExpression( + this.contextProperty("abrupt"), + abruptArgs + ) + ) + ); +}; + +function isValidCompletion(record) { + var type = record.type; + + if (type === "normal") { + return !hasOwn.call(record, "target"); + } + + if (type === "break" || + type === "continue") { + return !hasOwn.call(record, "value") + && n.Literal.check(record.target); + } + + if (type === "return" || + type === "throw") { + return hasOwn.call(record, "value") + && !hasOwn.call(record, "target"); + } + + return false; +} + + +// Not all offsets into emitter.listing are potential jump targets. For +// example, execution typically falls into the beginning of a try block +// without jumping directly there. This method returns the current offset +// without marking it, so that a switch case will not necessarily be +// generated for this offset (I say "not necessarily" because the same +// location might end up being marked in the process of emitting other +// statements). There's no logical harm in marking such locations as jump +// targets, but minimizing the number of switch cases keeps the generated +// code shorter. +Ep.getUnmarkedCurrentLoc = function() { + return b.literal(this.listing.length); +}; + +// The context.prev property takes the value of context.next whenever we +// evaluate the switch statement discriminant, which is generally good +// enough for tracking the last location we jumped to, but sometimes +// context.prev needs to be more precise, such as when we fall +// successfully out of a try block and into a finally block without +// jumping. This method exists to update context.prev to the freshest +// available location. If we were implementing a full interpreter, we +// would know the location of the current instruction with complete +// precision at all times, but we don't have that luxury here, as it would +// be costly and verbose to set context.prev before every statement. +Ep.updateContextPrevLoc = function(loc) { + if (loc) { + n.Literal.assert(loc); + + if (loc.value === -1) { + // If an uninitialized location literal was passed in, set its value + // to the current this.listing.length. + loc.value = this.listing.length; + } else { + // Otherwise assert that the location matches the current offset. + assert.strictEqual(loc.value, this.listing.length); + } + + } else { + loc = this.getUnmarkedCurrentLoc(); + } + + // Make sure context.prev is up to date in case we fell into this try + // statement without jumping to it. TODO Consider avoiding this + // assignment when we know control must have jumped here. + this.emitAssign(this.contextProperty("prev"), loc); +}; + +Ep.explodeExpression = function(path, ignoreResult) { + assert.ok(path instanceof types.NodePath); + + var expr = path.value; + if (expr) { + n.Expression.assert(expr); + } else { + return expr; + } + + var self = this; + var result; // Used optionally by several cases below. + + function finish(expr) { + n.Expression.assert(expr); + if (ignoreResult) { + self.emit(expr); + } else { + return expr; + } + } + + // If the expression does not contain a leap, then we either emit the + // expression as a standalone statement or return it whole. + if (!meta.containsLeap(expr)) { + return finish(expr); + } + + // If any child contains a leap (such as a yield or labeled continue or + // break statement), then any sibling subexpressions will almost + // certainly have to be exploded in order to maintain the order of their + // side effects relative to the leaping child(ren). + var hasLeapingChildren = meta.containsLeap.onlyChildren(expr); + + // In order to save the rest of explodeExpression from a combinatorial + // trainwreck of special cases, explodeViaTempVar is responsible for + // deciding when a subexpression needs to be "exploded," which is my + // very technical term for emitting the subexpression as an assignment + // to a temporary variable and the substituting the temporary variable + // for the original subexpression. Think of exploded view diagrams, not + // Michael Bay movies. The point of exploding subexpressions is to + // control the precise order in which the generated code realizes the + // side effects of those subexpressions. + function explodeViaTempVar(tempVar, childPath, ignoreChildResult) { + assert.ok(childPath instanceof types.NodePath); + + assert.ok( + !ignoreChildResult || !tempVar, + "Ignoring the result of a child expression but forcing it to " + + "be assigned to a temporary variable?" + ); + + var result = self.explodeExpression(childPath, ignoreChildResult); + + if (ignoreChildResult) { + // Side effects already emitted above. + + } else if (tempVar || (hasLeapingChildren && + !n.Literal.check(result))) { + // If tempVar was provided, then the result will always be assigned + // to it, even if the result does not otherwise need to be assigned + // to a temporary variable. When no tempVar is provided, we have + // the flexibility to decide whether a temporary variable is really + // necessary. Unfortunately, in general, a temporary variable is + // required whenever any child contains a yield expression, since it + // is difficult to prove (at all, let alone efficiently) whether + // this result would evaluate to the same value before and after the + // yield (see #206). One narrow case where we can prove it doesn't + // matter (and thus we do not need a temporary variable) is when the + // result in question is a Literal value. + result = self.emitAssign( + tempVar || self.makeTempVar(), + result + ); + } + return result; + } + + // If ignoreResult is true, then we must take full responsibility for + // emitting the expression with all its side effects, and we should not + // return a result. + + switch (expr.type) { + case "MemberExpression": + return finish(b.memberExpression( + self.explodeExpression(path.get("object")), + expr.computed + ? explodeViaTempVar(null, path.get("property")) + : expr.property, + expr.computed + )); + + case "CallExpression": + var calleePath = path.get("callee"); + var argsPath = path.get("arguments"); + + var newCallee; + var newArgs = []; + + var hasLeapingArgs = false; + argsPath.each(function(argPath) { + hasLeapingArgs = hasLeapingArgs || + meta.containsLeap(argPath.value); + }); + + if (n.MemberExpression.check(calleePath.value)) { + if (hasLeapingArgs) { + // If the arguments of the CallExpression contained any yield + // expressions, then we need to be sure to evaluate the callee + // before evaluating the arguments, but if the callee was a member + // expression, then we must be careful that the object of the + // member expression still gets bound to `this` for the call. + + var newObject = explodeViaTempVar( + // Assign the exploded callee.object expression to a temporary + // variable so that we can use it twice without reevaluating it. + self.makeTempVar(), + calleePath.get("object") + ); + + var newProperty = calleePath.value.computed + ? explodeViaTempVar(null, calleePath.get("property")) + : calleePath.value.property; + + newArgs.unshift(newObject); + + newCallee = b.memberExpression( + b.memberExpression( + newObject, + newProperty, + calleePath.value.computed + ), + b.identifier("call"), + false + ); + + } else { + newCallee = self.explodeExpression(calleePath); + } + + } else { + newCallee = self.explodeExpression(calleePath); + + if (n.MemberExpression.check(newCallee)) { + // If the callee was not previously a MemberExpression, then the + // CallExpression was "unqualified," meaning its `this` object + // should be the global object. If the exploded expression has + // become a MemberExpression (e.g. a context property, probably a + // temporary variable), then we need to force it to be unqualified + // by using the (0, object.property)(...) trick; otherwise, it + // will receive the object of the MemberExpression as its `this` + // object. + newCallee = b.sequenceExpression([ + b.literal(0), + newCallee + ]); + } + } + + argsPath.each(function(argPath) { + newArgs.push(explodeViaTempVar(null, argPath)); + }); + + return finish(b.callExpression( + newCallee, + newArgs + )); + + case "NewExpression": + return finish(b.newExpression( + explodeViaTempVar(null, path.get("callee")), + path.get("arguments").map(function(argPath) { + return explodeViaTempVar(null, argPath); + }) + )); + + case "ObjectExpression": + return finish(b.objectExpression( + path.get("properties").map(function(propPath) { + return b.property( + propPath.value.kind, + propPath.value.key, + explodeViaTempVar(null, propPath.get("value")) + ); + }) + )); + + case "ArrayExpression": + return finish(b.arrayExpression( + path.get("elements").map(function(elemPath) { + return explodeViaTempVar(null, elemPath); + }) + )); + + case "SequenceExpression": + var lastIndex = expr.expressions.length - 1; + + path.get("expressions").each(function(exprPath) { + if (exprPath.name === lastIndex) { + result = self.explodeExpression(exprPath, ignoreResult); + } else { + self.explodeExpression(exprPath, true); + } + }); + + return result; + + case "LogicalExpression": + var after = loc(); + + if (!ignoreResult) { + result = self.makeTempVar(); + } + + var left = explodeViaTempVar(result, path.get("left")); + + if (expr.operator === "&&") { + self.jumpIfNot(left, after); + } else { + assert.strictEqual(expr.operator, "||"); + self.jumpIf(left, after); + } + + explodeViaTempVar(result, path.get("right"), ignoreResult); + + self.mark(after); + + return result; + + case "ConditionalExpression": + var elseLoc = loc(); + var after = loc(); + var test = self.explodeExpression(path.get("test")); + + self.jumpIfNot(test, elseLoc); + + if (!ignoreResult) { + result = self.makeTempVar(); + } + + explodeViaTempVar(result, path.get("consequent"), ignoreResult); + self.jump(after); + + self.mark(elseLoc); + explodeViaTempVar(result, path.get("alternate"), ignoreResult); + + self.mark(after); + + return result; + + case "UnaryExpression": + return finish(b.unaryExpression( + expr.operator, + // Can't (and don't need to) break up the syntax of the argument. + // Think about delete a[b]. + self.explodeExpression(path.get("argument")), + !!expr.prefix + )); + + case "BinaryExpression": + return finish(b.binaryExpression( + expr.operator, + explodeViaTempVar(null, path.get("left")), + explodeViaTempVar(null, path.get("right")) + )); + + case "AssignmentExpression": + return finish(b.assignmentExpression( + expr.operator, + self.explodeExpression(path.get("left")), + self.explodeExpression(path.get("right")) + )); + + case "UpdateExpression": + return finish(b.updateExpression( + expr.operator, + self.explodeExpression(path.get("argument")), + expr.prefix + )); + + case "YieldExpression": + var after = loc(); + var arg = expr.argument && self.explodeExpression(path.get("argument")); + + if (arg && expr.delegate) { + var result = self.makeTempVar(); + + self.emit(b.returnStatement(b.callExpression( + self.contextProperty("delegateYield"), [ + arg, + b.literal(result.property.name), + after + ] + ))); + + self.mark(after); + + return result; + } + + self.emitAssign(self.contextProperty("next"), after); + self.emit(b.returnStatement(arg || null)); + self.mark(after); + + return self.contextProperty("sent"); + + default: + throw new Error( + "unknown Expression of type " + + JSON.stringify(expr.type)); + } +}; + +},{"1":1,"539":539,"540":540,"541":541,"568":568}],538:[function(_dereq_,module,exports){ +/** + * Copyright (c) 2014, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * https://raw.github.com/facebook/regenerator/master/LICENSE file. An + * additional grant of patent rights can be found in the PATENTS file in + * the same directory. + */ + +var assert = _dereq_(1); +var types = _dereq_(568).types; +var n = types.namedTypes; +var b = types.builders; +var hasOwn = Object.prototype.hasOwnProperty; + +// The hoist function takes a FunctionExpression or FunctionDeclaration +// and replaces any Declaration nodes in its body with assignments, then +// returns a VariableDeclaration containing just the names of the removed +// declarations. +exports.hoist = function(funPath) { + assert.ok(funPath instanceof types.NodePath); + n.Function.assert(funPath.value); + + var vars = {}; + + function varDeclToExpr(vdec, includeIdentifiers) { + n.VariableDeclaration.assert(vdec); + var exprs = []; + + vdec.declarations.forEach(function(dec) { + vars[dec.id.name] = dec.id; + + if (dec.init) { + exprs.push(b.assignmentExpression( + "=", dec.id, dec.init + )); + } else if (includeIdentifiers) { + exprs.push(dec.id); + } + }); + + if (exprs.length === 0) + return null; + + if (exprs.length === 1) + return exprs[0]; + + return b.sequenceExpression(exprs); + } + + types.visit(funPath.get("body"), { + visitVariableDeclaration: function(path) { + var expr = varDeclToExpr(path.value, false); + if (expr === null) { + path.replace(); + } else { + // We don't need to traverse this expression any further because + // there can't be any new declarations inside an expression. + return b.expressionStatement(expr); + } + + // Since the original node has been either removed or replaced, + // avoid traversing it any further. + return false; + }, + + visitForStatement: function(path) { + var init = path.value.init; + if (n.VariableDeclaration.check(init)) { + path.get("init").replace(varDeclToExpr(init, false)); + } + this.traverse(path); + }, + + visitForInStatement: function(path) { + var left = path.value.left; + if (n.VariableDeclaration.check(left)) { + path.get("left").replace(varDeclToExpr(left, true)); + } + this.traverse(path); + }, + + visitFunctionDeclaration: function(path) { + var node = path.value; + vars[node.id.name] = node.id; + + var parentNode = path.parent.node; + var assignment = b.expressionStatement( + b.assignmentExpression( + "=", + node.id, + b.functionExpression( + node.id, + node.params, + node.body, + node.generator, + node.expression + ) + ) + ); + + if (n.BlockStatement.check(path.parent.node)) { + // Insert the assignment form before the first statement in the + // enclosing block. + path.parent.get("body").unshift(assignment); + + // Remove the function declaration now that we've inserted the + // equivalent assignment form at the beginning of the block. + path.replace(); + + } else { + // If the parent node is not a block statement, then we can just + // replace the declaration with the equivalent assignment form + // without worrying about hoisting it. + path.replace(assignment); + } + + // Don't hoist variables out of inner functions. + return false; + }, + + visitFunctionExpression: function(path) { + // Don't descend into nested function expressions. + return false; + } + }); + + var paramNames = {}; + funPath.get("params").each(function(paramPath) { + var param = paramPath.value; + if (n.Identifier.check(param)) { + paramNames[param.name] = param; + } else { + // Variables declared by destructuring parameter patterns will be + // harmlessly re-declared. + } + }); + + var declarations = []; + + Object.keys(vars).forEach(function(name) { + if (!hasOwn.call(paramNames, name)) { + declarations.push(b.variableDeclarator(vars[name], null)); + } + }); + + if (declarations.length === 0) { + return null; // Be sure to handle this case! + } + + return b.variableDeclaration("var", declarations); +}; + +},{"1":1,"568":568}],539:[function(_dereq_,module,exports){ +/** + * Copyright (c) 2014, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * https://raw.github.com/facebook/regenerator/master/LICENSE file. An + * additional grant of patent rights can be found in the PATENTS file in + * the same directory. + */ + +var assert = _dereq_(1); +var types = _dereq_(568).types; +var n = types.namedTypes; +var b = types.builders; +var inherits = _dereq_(13).inherits; +var hasOwn = Object.prototype.hasOwnProperty; + +function Entry() { + assert.ok(this instanceof Entry); +} + +function FunctionEntry(returnLoc) { + Entry.call(this); + n.Literal.assert(returnLoc); + this.returnLoc = returnLoc; +} + +inherits(FunctionEntry, Entry); +exports.FunctionEntry = FunctionEntry; + +function LoopEntry(breakLoc, continueLoc, label) { + Entry.call(this); + + n.Literal.assert(breakLoc); + n.Literal.assert(continueLoc); + + if (label) { + n.Identifier.assert(label); + } else { + label = null; + } + + this.breakLoc = breakLoc; + this.continueLoc = continueLoc; + this.label = label; +} + +inherits(LoopEntry, Entry); +exports.LoopEntry = LoopEntry; + +function SwitchEntry(breakLoc) { + Entry.call(this); + n.Literal.assert(breakLoc); + this.breakLoc = breakLoc; +} + +inherits(SwitchEntry, Entry); +exports.SwitchEntry = SwitchEntry; + +function TryEntry(firstLoc, catchEntry, finallyEntry) { + Entry.call(this); + + n.Literal.assert(firstLoc); + + if (catchEntry) { + assert.ok(catchEntry instanceof CatchEntry); + } else { + catchEntry = null; + } + + if (finallyEntry) { + assert.ok(finallyEntry instanceof FinallyEntry); + } else { + finallyEntry = null; + } + + // Have to have one or the other (or both). + assert.ok(catchEntry || finallyEntry); + + this.firstLoc = firstLoc; + this.catchEntry = catchEntry; + this.finallyEntry = finallyEntry; +} + +inherits(TryEntry, Entry); +exports.TryEntry = TryEntry; + +function CatchEntry(firstLoc, paramId) { + Entry.call(this); + + n.Literal.assert(firstLoc); + n.Identifier.assert(paramId); + + this.firstLoc = firstLoc; + this.paramId = paramId; +} + +inherits(CatchEntry, Entry); +exports.CatchEntry = CatchEntry; + +function FinallyEntry(firstLoc, afterLoc) { + Entry.call(this); + n.Literal.assert(firstLoc); + n.Literal.assert(afterLoc); + this.firstLoc = firstLoc; + this.afterLoc = afterLoc; +} + +inherits(FinallyEntry, Entry); +exports.FinallyEntry = FinallyEntry; + +function LabeledEntry(breakLoc, label) { + Entry.call(this); + + n.Literal.assert(breakLoc); + n.Identifier.assert(label); + + this.breakLoc = breakLoc; + this.label = label; +} + +inherits(LabeledEntry, Entry); +exports.LabeledEntry = LabeledEntry; + +function LeapManager(emitter) { + assert.ok(this instanceof LeapManager); + + var Emitter = _dereq_(537).Emitter; + assert.ok(emitter instanceof Emitter); + + this.emitter = emitter; + this.entryStack = [new FunctionEntry(emitter.finalLoc)]; +} + +var LMp = LeapManager.prototype; +exports.LeapManager = LeapManager; + +LMp.withEntry = function(entry, callback) { + assert.ok(entry instanceof Entry); + this.entryStack.push(entry); + try { + callback.call(this.emitter); + } finally { + var popped = this.entryStack.pop(); + assert.strictEqual(popped, entry); + } +}; + +LMp._findLeapLocation = function(property, label) { + for (var i = this.entryStack.length - 1; i >= 0; --i) { + var entry = this.entryStack[i]; + var loc = entry[property]; + if (loc) { + if (label) { + if (entry.label && + entry.label.name === label.name) { + return loc; + } + } else if (entry instanceof LabeledEntry) { + // Ignore LabeledEntry entries unless we are actually breaking to + // a label. + } else { + return loc; + } + } + } + + return null; +}; + +LMp.getBreakLoc = function(label) { + return this._findLeapLocation("breakLoc", label); +}; + +LMp.getContinueLoc = function(label) { + return this._findLeapLocation("continueLoc", label); +}; + +},{"1":1,"13":13,"537":537,"568":568}],540:[function(_dereq_,module,exports){ +/** + * Copyright (c) 2014, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * https://raw.github.com/facebook/regenerator/master/LICENSE file. An + * additional grant of patent rights can be found in the PATENTS file in + * the same directory. + */ + +var assert = _dereq_(1); +var m = _dereq_(536).makeAccessor(); +var types = _dereq_(568).types; +var isArray = types.builtInTypes.array; +var n = types.namedTypes; +var hasOwn = Object.prototype.hasOwnProperty; + +function makePredicate(propertyName, knownTypes) { + function onlyChildren(node) { + n.Node.assert(node); + + // Assume no side effects until we find out otherwise. + var result = false; + + function check(child) { + if (result) { + // Do nothing. + } else if (isArray.check(child)) { + child.some(check); + } else if (n.Node.check(child)) { + assert.strictEqual(result, false); + result = predicate(child); + } + return result; + } + + types.eachField(node, function(name, child) { + check(child); + }); + + return result; + } + + function predicate(node) { + n.Node.assert(node); + + var meta = m(node); + if (hasOwn.call(meta, propertyName)) + return meta[propertyName]; + + // Certain types are "opaque," which means they have no side + // effects or leaps and we don't care about their subexpressions. + if (hasOwn.call(opaqueTypes, node.type)) + return meta[propertyName] = false; + + if (hasOwn.call(knownTypes, node.type)) + return meta[propertyName] = true; + + return meta[propertyName] = onlyChildren(node); + } + + predicate.onlyChildren = onlyChildren; + + return predicate; +} + +var opaqueTypes = { + FunctionExpression: true +}; + +// These types potentially have side effects regardless of what side +// effects their subexpressions have. +var sideEffectTypes = { + CallExpression: true, // Anything could happen! + ForInStatement: true, // Modifies the key variable. + UnaryExpression: true, // Think delete. + BinaryExpression: true, // Might invoke .toString() or .valueOf(). + AssignmentExpression: true, // Side-effecting by definition. + UpdateExpression: true, // Updates are essentially assignments. + NewExpression: true // Similar to CallExpression. +}; + +// These types are the direct cause of all leaps in control flow. +var leapTypes = { + YieldExpression: true, + BreakStatement: true, + ContinueStatement: true, + ReturnStatement: true, + ThrowStatement: true +}; + +// All leap types are also side effect types. +for (var type in leapTypes) { + if (hasOwn.call(leapTypes, type)) { + sideEffectTypes[type] = leapTypes[type]; + } +} + +exports.hasSideEffects = makePredicate("hasSideEffects", sideEffectTypes); +exports.containsLeap = makePredicate("containsLeap", leapTypes); + +},{"1":1,"536":536,"568":568}],541:[function(_dereq_,module,exports){ +/** + * Copyright (c) 2014, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * https://raw.github.com/facebook/regenerator/master/LICENSE file. An + * additional grant of patent rights can be found in the PATENTS file in + * the same directory. + */ + +var assert = _dereq_(1); +var types = _dereq_(568).types; +var n = types.namedTypes; +var b = types.builders; +var hasOwn = Object.prototype.hasOwnProperty; + +exports.defaults = function(obj) { + var len = arguments.length; + var extension; + + for (var i = 1; i < len; ++i) { + if ((extension = arguments[i])) { + for (var key in extension) { + if (hasOwn.call(extension, key) && !hasOwn.call(obj, key)) { + obj[key] = extension[key]; + } + } + } + } + + return obj; +}; + +exports.runtimeProperty = function(name) { + return b.memberExpression( + b.identifier("regeneratorRuntime"), + b.identifier(name), + false + ); +}; + +// Inspired by the isReference function from ast-util: +// https://github.com/eventualbuddha/ast-util/blob/9bf91c5ce8/lib/index.js#L466-L506 +exports.isReference = function(path, name) { + var node = path.value; + + if (!n.Identifier.check(node)) { + return false; + } + + if (name && node.name !== name) { + return false; + } + + var parent = path.parent.value; + + switch (parent.type) { + case "VariableDeclarator": + return path.name === "init"; + + case "MemberExpression": + return path.name === "object" || ( + parent.computed && path.name === "property" + ); + + case "FunctionExpression": + case "FunctionDeclaration": + case "ArrowFunctionExpression": + if (path.name === "id") { + return false; + } + + if (path.parentPath.name === "params" && + parent.params === path.parentPath.value && + parent.params[path.name] === node) { + return false; + } + + return true; + + case "ClassDeclaration": + case "ClassExpression": + return path.name !== "id"; + + case "CatchClause": + return path.name !== "param"; + + case "Property": + case "MethodDefinition": + return path.name !== "key"; + + case "ImportSpecifier": + case "ImportDefaultSpecifier": + case "ImportNamespaceSpecifier": + case "LabeledStatement": + return false; + + default: + return true; + } +}; + +},{"1":1,"568":568}],542:[function(_dereq_,module,exports){ +/** + * Copyright (c) 2014, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * https://raw.github.com/facebook/regenerator/master/LICENSE file. An + * additional grant of patent rights can be found in the PATENTS file in + * the same directory. + */ + +var assert = _dereq_(1); +var fs = _dereq_(3); +var recast = _dereq_(568); +var types = recast.types; +var n = types.namedTypes; +var b = types.builders; +var isArray = types.builtInTypes.array; +var isObject = types.builtInTypes.object; +var NodePath = types.NodePath; +var hoist = _dereq_(538).hoist; +var Emitter = _dereq_(537).Emitter; +var util = _dereq_(541); +var runtimeProperty = util.runtimeProperty; +var getMarkInfo = _dereq_(536).makeAccessor(); + +exports.transform = function transform(node, options) { + options = options || {}; + + var path = node instanceof NodePath ? node : new NodePath(node); + visitor.visit(path, options); + node = path.value; + + if (options.includeRuntime === true || + (options.includeRuntime === 'if used' && visitor.wasChangeReported())) { + injectRuntime(n.File.check(node) ? node.program : node); + } + + options.madeChanges = visitor.wasChangeReported(); + + return node; +}; + +function injectRuntime(program) { + n.Program.assert(program); + + // Include the runtime by modifying the AST rather than by concatenating + // strings. This technique will allow for more accurate source mapping. + var runtimePath = _dereq_(543).runtime.path; + var runtime = fs.readFileSync(runtimePath, "utf8"); + var runtimeBody = recast.parse(runtime, { + sourceFileName: runtimePath + }).program.body; + + var body = program.body; + body.unshift.apply(body, runtimeBody); +} + +var visitor = types.PathVisitor.fromMethodsObject({ + reset: function(node, options) { + this.options = options; + }, + + visitFunction: function(path) { + // Calling this.traverse(path) first makes for a post-order traversal. + this.traverse(path); + + var node = path.value; + var shouldTransformAsync = node.async && !this.options.disableAsync; + + if (!node.generator && !shouldTransformAsync) { + return; + } + + this.reportChanged(); + + if (node.expression) { + // Transform expression lambdas into normal functions. + node.expression = false; + node.body = b.blockStatement([ + b.returnStatement(node.body) + ]); + } + + if (shouldTransformAsync) { + awaitVisitor.visit(path.get("body")); + } + + var outerBody = []; + var innerBody = []; + var bodyPath = path.get("body", "body"); + + bodyPath.each(function(childPath) { + var node = childPath.value; + if (node && node._blockHoist != null) { + outerBody.push(node); + } else { + innerBody.push(node); + } + }); + + if (outerBody.length > 0) { + // Only replace the inner body if we actually hoisted any statements + // to the outer body. + bodyPath.replace(innerBody); + } + + var outerFnExpr = getOuterFnExpr(path); + // Note that getOuterFnExpr has the side-effect of ensuring that the + // function has a name (so node.id will always be an Identifier), even + // if a temporary name has to be synthesized. + n.Identifier.assert(node.id); + var innerFnId = b.identifier(node.id.name + "$"); + var contextId = path.scope.declareTemporary("context$"); + var argsId = path.scope.declareTemporary("args$"); + + // Turn all declarations into vars, and replace the original + // declarations with equivalent assignment expressions. + var vars = hoist(path); + + var didRenameArguments = renameArguments(path, argsId); + if (didRenameArguments) { + vars = vars || b.variableDeclaration("var", []); + vars.declarations.push(b.variableDeclarator( + argsId, b.identifier("arguments") + )); + } + + var emitter = new Emitter(contextId); + emitter.explode(path.get("body")); + + if (vars && vars.declarations.length > 0) { + outerBody.push(vars); + } + + var wrapArgs = [ + emitter.getContextFunction(innerFnId), + // Async functions that are not generators don't care about the + // outer function because they don't need it to be marked and don't + // inherit from its .prototype. + node.generator ? outerFnExpr : b.literal(null), + b.thisExpression() + ]; + + var tryLocsList = emitter.getTryLocsList(); + if (tryLocsList) { + wrapArgs.push(tryLocsList); + } + + var wrapCall = b.callExpression( + runtimeProperty(shouldTransformAsync ? "async" : "wrap"), + wrapArgs + ); + + outerBody.push(b.returnStatement(wrapCall)); + node.body = b.blockStatement(outerBody); + + var wasGeneratorFunction = node.generator; + if (wasGeneratorFunction) { + node.generator = false; + } + + if (shouldTransformAsync) { + node.async = false; + } + + if (wasGeneratorFunction && + n.Expression.check(node)) { + return b.callExpression(runtimeProperty("mark"), [node]); + } + }, + + visitForOfStatement: function(path) { + this.traverse(path); + + var node = path.value; + var tempIterId = path.scope.declareTemporary("t$"); + var tempIterDecl = b.variableDeclarator( + tempIterId, + b.callExpression( + runtimeProperty("values"), + [node.right] + ) + ); + + var tempInfoId = path.scope.declareTemporary("t$"); + var tempInfoDecl = b.variableDeclarator(tempInfoId, null); + + var init = node.left; + var loopId; + if (n.VariableDeclaration.check(init)) { + loopId = init.declarations[0].id; + init.declarations.push(tempIterDecl, tempInfoDecl); + } else { + loopId = init; + init = b.variableDeclaration("var", [ + tempIterDecl, + tempInfoDecl + ]); + } + n.Identifier.assert(loopId); + + var loopIdAssignExprStmt = b.expressionStatement( + b.assignmentExpression( + "=", + loopId, + b.memberExpression( + tempInfoId, + b.identifier("value"), + false + ) + ) + ); + + if (n.BlockStatement.check(node.body)) { + node.body.body.unshift(loopIdAssignExprStmt); + } else { + node.body = b.blockStatement([ + loopIdAssignExprStmt, + node.body + ]); + } + + return b.forStatement( + init, + b.unaryExpression( + "!", + b.memberExpression( + b.assignmentExpression( + "=", + tempInfoId, + b.callExpression( + b.memberExpression( + tempIterId, + b.identifier("next"), + false + ), + [] + ) + ), + b.identifier("done"), + false + ) + ), + null, + node.body + ); + } +}); + +// Given a NodePath for a Function, return an Expression node that can be +// used to refer reliably to the function object from inside the function. +// This expression is essentially a replacement for arguments.callee, with +// the key advantage that it works in strict mode. +function getOuterFnExpr(funPath) { + var node = funPath.value; + n.Function.assert(node); + + if (node.generator && // Non-generator functions don't need to be marked. + n.FunctionDeclaration.check(node)) { + var pp = funPath.parent; + + while (pp && !(n.BlockStatement.check(pp.value) || + n.Program.check(pp.value))) { + pp = pp.parent; + } + + if (!pp) { + return node.id; + } + + var markDecl = getRuntimeMarkDecl(pp); + var markedArray = markDecl.declarations[0].id; + var funDeclIdArray = markDecl.declarations[0].init.callee.object; + n.ArrayExpression.assert(funDeclIdArray); + + var index = funDeclIdArray.elements.length; + funDeclIdArray.elements.push(node.id); + + return b.memberExpression( + markedArray, + b.literal(index), + true + ); + } + + return node.id || ( + node.id = funPath.scope.parent.declareTemporary("callee$") + ); +} + +function getRuntimeMarkDecl(blockPath) { + assert.ok(blockPath instanceof NodePath); + var block = blockPath.node; + isArray.assert(block.body); + + var info = getMarkInfo(block); + if (info.decl) { + return info.decl; + } + + info.decl = b.variableDeclaration("var", [ + b.variableDeclarator( + blockPath.scope.declareTemporary("marked"), + b.callExpression( + b.memberExpression( + b.arrayExpression([]), + b.identifier("map"), + false + ), + [runtimeProperty("mark")] + ) + ) + ]); + + for (var i = 0; i < block.body.length; ++i) { + if (!shouldNotHoistAbove(blockPath.get("body", i))) { + break; + } + } + + blockPath.get("body").insertAt(i, info.decl); + + return info.decl; +} + +function shouldNotHoistAbove(stmtPath) { + var value = stmtPath.value; + n.Statement.assert(value); + + // If the first statement is a "use strict" declaration, make sure to + // insert hoisted declarations afterwards. + return n.ExpressionStatement.check(value) && + n.Literal.check(value.expression) && + value.expression.value === "use strict"; +} + +function renameArguments(funcPath, argsId) { + assert.ok(funcPath instanceof types.NodePath); + var func = funcPath.value; + var didRenameArguments = false; + + recast.visit(funcPath, { + visitFunction: function(path) { + if (path.value === func) { + this.traverse(path); + } else { + return false; + } + }, + + visitIdentifier: function(path) { + if (path.value.name === "arguments" && + util.isReference(path)) { + path.replace(argsId); + didRenameArguments = true; + return false; + } + + this.traverse(path); + } + }); + + // If the traversal replaced any arguments references, then we need to + // alias the outer function's arguments binding (be it the implicit + // arguments object or some other parameter or variable) to the variable + // named by argsId. + return didRenameArguments; +} + +var awaitVisitor = types.PathVisitor.fromMethodsObject({ + visitFunction: function(path) { + return false; // Don't descend into nested function scopes. + }, + + visitAwaitExpression: function(path) { + // Convert await and await* expressions to yield expressions. + var argument = path.value.argument; + + // If the parser supports await* syntax using a boolean .all property + // (#171), desugar that syntax to yield Promise.all(argument). + if (path.value.all) { + argument = b.callExpression( + b.memberExpression( + b.identifier("Promise"), + b.identifier("all"), + false + ), + [argument] + ); + } + + // Transforming `await x` to `yield regeneratorRuntime.awrap(x)` + // causes the argument to be wrapped in such a way that the runtime + // can distinguish between awaited and merely yielded values. + return b.yieldExpression( + b.callExpression( + runtimeProperty("awrap"), + [argument] + ), + false + ); + } +}); + +},{"1":1,"3":3,"536":536,"537":537,"538":538,"541":541,"543":543,"568":568}],543:[function(_dereq_,module,exports){ +(function (__dirname){ +/** + * Copyright (c) 2014, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * https://raw.github.com/facebook/regenerator/master/LICENSE file. An + * additional grant of patent rights can be found in the PATENTS file in + * the same directory. + */ + +var assert = _dereq_(1); +var path = _dereq_(9); +var fs = _dereq_(3); +var through = _dereq_(3); +var transform = _dereq_(542).transform; +var utils = _dereq_(541); +var recast = _dereq_(568); +var types = recast.types; +var genOrAsyncFunExp = /\bfunction\s*\*|\basync\b/; +var blockBindingExp = /\b(let|const)\s+/; + +function exports(file, options) { + var data = []; + return through(write, end); + + function write(buf) { + data.push(buf); + } + + function end() { + this.queue(compile(data.join(""), options).code); + this.queue(null); + } +} + +// To get a writable stream for use as a browserify transform, call +// require("regenerator")(). +module.exports = exports; + +// To include the runtime globally in the current node process, call +// require("regenerator").runtime(). +function runtime() { + _dereq_(585); +} +exports.runtime = runtime; +runtime.path = path.join(__dirname, "runtime.js"); + +function compile(source, options) { + options = normalizeOptions(options); + + if (!genOrAsyncFunExp.test(source)) { + return { + // Shortcut: no generators or async functions to transform. + code: (options.includeRuntime === true ? fs.readFileSync( + path.join(__dirname, "runtime.js"), "utf-8" + ) + "\n" : "") + source + }; + } + + var recastOptions = getRecastOptions(options); + var ast = recast.parse(source, recastOptions); + var nodePath = new types.NodePath(ast); + var programPath = nodePath.get("program"); + + if (shouldVarify(source, options)) { + // Transpile let/const into var declarations. + varifyAst(programPath.node); + } + + transform(programPath, options); + + return recast.print(nodePath, recastOptions); +} + +function normalizeOptions(options) { + options = utils.defaults(options || {}, { + includeRuntime: false, + supportBlockBinding: true + }); + + if (!options.esprima) { + options.esprima = _dereq_(3); + } + + assert.ok( + /harmony/.test(options.esprima.version), + "Bad esprima version: " + options.esprima.version + ); + + return options; +} + +function getRecastOptions(options) { + var recastOptions = { + range: true + }; + + function copy(name) { + if (name in options) { + recastOptions[name] = options[name]; + } + } + + copy("esprima"); + copy("sourceFileName"); + copy("sourceMapName"); + copy("inputSourceMap"); + copy("sourceRoot"); + + return recastOptions; +} + +function shouldVarify(source, options) { + var supportBlockBinding = !!options.supportBlockBinding; + if (supportBlockBinding) { + if (!blockBindingExp.test(source)) { + supportBlockBinding = false; + } + } + + return supportBlockBinding; +} + +function varify(source, options) { + var recastOptions = getRecastOptions(normalizeOptions(options)); + var ast = recast.parse(source, recastOptions); + varifyAst(ast.program); + return recast.print(ast, recastOptions).code; +} + +function varifyAst(ast) { + types.namedTypes.Program.assert(ast); + + var defsResult = _dereq_(544)(ast, { + ast: true, + disallowUnknownReferences: false, + disallowDuplicated: false, + disallowVars: false, + loopClosures: "iife" + }); + + if (defsResult.errors) { + throw new Error(defsResult.errors.join("\n")) + } + + return ast; +} + +// Convenience for just translating let/const to var declarations. +exports.varify = varify; + +// Allow packages that depend on Regenerator to use the same copy of +// ast-types, in case multiple versions are installed by NPM. +exports.types = types; + +// Transforms a string of source code, returning the { code, map? } result +// from recast.print. +exports.compile = compile; + +// To modify an AST directly, call require("regenerator").transform(ast). +exports.transform = transform; + +}).call(this,"/node_modules/regenerator") +},{"1":1,"3":3,"541":541,"542":542,"544":544,"568":568,"585":585,"9":9}],544:[function(_dereq_,module,exports){ +"use strict"; + +var assert = _dereq_(1); +var is = _dereq_(555); +var fmt = _dereq_(554); +var stringmap = _dereq_(556); +var stringset = _dereq_(557); +var alter = _dereq_(550); +var traverse = _dereq_(552); +var breakable = _dereq_(553); +var Scope = _dereq_(548); +var error = _dereq_(545); +var getline = error.getline; +var options = _dereq_(547); +var Stats = _dereq_(549); +var jshint_vars = _dereq_(546); + + +function isConstLet(kind) { + return is.someof(kind, ["const", "let"]); +} + +function isVarConstLet(kind) { + return is.someof(kind, ["var", "const", "let"]); +} + +function isNonFunctionBlock(node) { + return node.type === "BlockStatement" && is.noneof(node.$parent.type, ["FunctionDeclaration", "FunctionExpression"]); +} + +function isForWithConstLet(node) { + return node.type === "ForStatement" && node.init && node.init.type === "VariableDeclaration" && isConstLet(node.init.kind); +} + +function isForInOfWithConstLet(node) { + return isForInOf(node) && node.left.type === "VariableDeclaration" && isConstLet(node.left.kind); +} + +function isForInOf(node) { + return is.someof(node.type, ["ForInStatement", "ForOfStatement"]); +} + +function isFunction(node) { + return is.someof(node.type, ["FunctionDeclaration", "FunctionExpression"]); +} + +function isLoop(node) { + return is.someof(node.type, ["ForStatement", "ForInStatement", "ForOfStatement", "WhileStatement", "DoWhileStatement"]); +} + +function isReference(node) { + var parent = node.$parent; + return node.$refToScope || + node.type === "Identifier" && + !(parent.type === "VariableDeclarator" && parent.id === node) && // var|let|const $ + !(parent.type === "MemberExpression" && parent.computed === false && parent.property === node) && // obj.$ + !(parent.type === "Property" && parent.key === node) && // {$: ...} + !(parent.type === "LabeledStatement" && parent.label === node) && // $: ... + !(parent.type === "CatchClause" && parent.param === node) && // catch($) + !(isFunction(parent) && parent.id === node) && // function $(.. + !(isFunction(parent) && is.someof(node, parent.params)) && // function f($).. + true; +} + +function isLvalue(node) { + return isReference(node) && + ((node.$parent.type === "AssignmentExpression" && node.$parent.left === node) || + (node.$parent.type === "UpdateExpression" && node.$parent.argument === node)); +} + +function createScopes(node, parent) { + assert(!node.$scope); + + node.$parent = parent; + node.$scope = node.$parent ? node.$parent.$scope : null; // may be overridden + + if (node.type === "Program") { + // Top-level program is a scope + // There's no block-scope under it + node.$scope = new Scope({ + kind: "hoist", + node: node, + parent: null, + }); + + } else if (isFunction(node)) { + // Function is a scope, with params in it + // There's no block-scope under it + + node.$scope = new Scope({ + kind: "hoist", + node: node, + parent: node.$parent.$scope, + }); + + // function has a name + if (node.id) { + assert(node.id.type === "Identifier"); + + if (node.type === "FunctionDeclaration") { + // Function name goes in parent scope for declared functions + node.$parent.$scope.add(node.id.name, "fun", node.id, null); + } else if (node.type === "FunctionExpression") { + // Function name goes in function's scope for named function expressions + node.$scope.add(node.id.name, "fun", node.id, null); + } else { + assert(false); + } + } + + node.params.forEach(function(param) { + node.$scope.add(param.name, "param", param, null); + }); + + } else if (node.type === "VariableDeclaration") { + // Variable declarations names goes in current scope + assert(isVarConstLet(node.kind)); + node.declarations.forEach(function(declarator) { + assert(declarator.type === "VariableDeclarator"); + var name = declarator.id.name; + if (options.disallowVars && node.kind === "var") { + error(getline(declarator), "var {0} is not allowed (use let or const)", name); + } + node.$scope.add(name, node.kind, declarator.id, declarator.range[1]); + }); + + } else if (isForWithConstLet(node) || isForInOfWithConstLet(node)) { + // For(In/Of) loop with const|let declaration is a scope, with declaration in it + // There may be a block-scope under it + node.$scope = new Scope({ + kind: "block", + node: node, + parent: node.$parent.$scope, + }); + + } else if (isNonFunctionBlock(node)) { + // A block node is a scope unless parent is a function + node.$scope = new Scope({ + kind: "block", + node: node, + parent: node.$parent.$scope, + }); + + } else if (node.type === "CatchClause") { + var identifier = node.param; + + node.$scope = new Scope({ + kind: "catch-block", + node: node, + parent: node.$parent.$scope, + }); + node.$scope.add(identifier.name, "caught", identifier, null); + + // All hoist-scope keeps track of which variables that are propagated through, + // i.e. an reference inside the scope points to a declaration outside the scope. + // This is used to mark "taint" the name since adding a new variable in the scope, + // with a propagated name, would change the meaning of the existing references. + // + // catch(e) is special because even though e is a variable in its own scope, + // we want to make sure that catch(e){let e} is never transformed to + // catch(e){var e} (but rather var e$0). For that reason we taint the use of e + // in the closest hoist-scope, i.e. where var e$0 belongs. + node.$scope.closestHoistScope().markPropagates(identifier.name); + } +} + +function createTopScope(programScope, environments, globals) { + function inject(obj) { + for (var name in obj) { + var writeable = obj[name]; + var kind = (writeable ? "var" : "const"); + if (topScope.hasOwn(name)) { + topScope.remove(name); + } + topScope.add(name, kind, {loc: {start: {line: -1}}}, -1); + } + } + + var topScope = new Scope({ + kind: "hoist", + node: {}, + parent: null, + }); + + var complementary = { + undefined: false, + Infinity: false, + console: false, + }; + + inject(complementary); + inject(jshint_vars.reservedVars); + inject(jshint_vars.ecmaIdentifiers); + if (environments) { + environments.forEach(function(env) { + if (!jshint_vars[env]) { + error(-1, 'environment "{0}" not found', env); + } else { + inject(jshint_vars[env]); + } + }); + } + if (globals) { + inject(globals); + } + + // link it in + programScope.parent = topScope; + topScope.children.push(programScope); + + return topScope; +} + +function setupReferences(ast, allIdentifiers, opts) { + var analyze = (is.own(opts, "analyze") ? opts.analyze : true); + + function visit(node) { + if (!isReference(node)) { + return; + } + allIdentifiers.add(node.name); + + var scope = node.$scope.lookup(node.name); + if (analyze && !scope && options.disallowUnknownReferences) { + error(getline(node), "reference to unknown global variable {0}", node.name); + } + // check const and let for referenced-before-declaration + if (analyze && scope && is.someof(scope.getKind(node.name), ["const", "let"])) { + var allowedFromPos = scope.getFromPos(node.name); + var referencedAtPos = node.range[0]; + assert(is.finitenumber(allowedFromPos)); + assert(is.finitenumber(referencedAtPos)); + if (referencedAtPos < allowedFromPos) { + if (!node.$scope.hasFunctionScopeBetween(scope)) { + error(getline(node), "{0} is referenced before its declaration", node.name); + } + } + } + node.$refToScope = scope; + } + + traverse(ast, {pre: visit}); +} + +// TODO for loops init and body props are parallel to each other but init scope is outer that of body +// TODO is this a problem? + +function varify(ast, stats, allIdentifiers, changes) { + function unique(name) { + assert(allIdentifiers.has(name)); + for (var cnt = 0; ; cnt++) { + var genName = name + "$" + String(cnt); + if (!allIdentifiers.has(genName)) { + return genName; + } + } + } + + function renameDeclarations(node) { + if (node.type === "VariableDeclaration" && isConstLet(node.kind)) { + var hoistScope = node.$scope.closestHoistScope(); + var origScope = node.$scope; + + // text change const|let => var + changes.push({ + start: node.range[0], + end: node.range[0] + node.kind.length, + str: "var", + }); + + node.declarations.forEach(function(declarator) { + assert(declarator.type === "VariableDeclarator"); + var name = declarator.id.name; + + stats.declarator(node.kind); + + // rename if + // 1) name already exists in hoistScope, or + // 2) name is already propagated (passed) through hoistScope or manually tainted + var rename = (origScope !== hoistScope && + (hoistScope.hasOwn(name) || hoistScope.doesPropagate(name))); + + var newName = (rename ? unique(name) : name); + + origScope.remove(name); + hoistScope.add(newName, "var", declarator.id, declarator.range[1]); + + origScope.moves = origScope.moves || stringmap(); + origScope.moves.set(name, { + name: newName, + scope: hoistScope, + }); + + allIdentifiers.add(newName); + + if (newName !== name) { + stats.rename(name, newName, getline(declarator)); + + declarator.id.originalName = name; + declarator.id.name = newName; + + // textchange var x => var x$1 + changes.push({ + start: declarator.id.range[0], + end: declarator.id.range[1], + str: newName, + }); + } + }); + + // ast change const|let => var + node.kind = "var"; + } + } + + function renameReferences(node) { + if (!node.$refToScope) { + return; + } + var move = node.$refToScope.moves && node.$refToScope.moves.get(node.name); + if (!move) { + return; + } + node.$refToScope = move.scope; + + if (node.name !== move.name) { + node.originalName = node.name; + node.name = move.name; + + if (node.alterop) { + // node has no range because it is the result of another alter operation + var existingOp = null; + for (var i = 0; i < changes.length; i++) { + var op = changes[i]; + if (op.node === node) { + existingOp = op; + break; + } + } + assert(existingOp); + + // modify op + existingOp.str = move.name; + } else { + changes.push({ + start: node.range[0], + end: node.range[1], + str: move.name, + }); + } + } + } + + traverse(ast, {pre: renameDeclarations}); + traverse(ast, {pre: renameReferences}); + ast.$scope.traverse({pre: function(scope) { + delete scope.moves; + }}); +} + + +function detectLoopClosures(ast) { + traverse(ast, {pre: visit}); + + function detectIifyBodyBlockers(body, node) { + return breakable(function(brk) { + traverse(body, {pre: function(n) { + // if we hit an inner function of the loop body, don't traverse further + if (isFunction(n)) { + return false; + } + + var err = true; // reset to false in else-statement below + var msg = "loop-variable {0} is captured by a loop-closure that can't be transformed due to use of {1} at line {2}"; + if (n.type === "BreakStatement") { + error(getline(node), msg, node.name, "break", getline(n)); + } else if (n.type === "ContinueStatement") { + error(getline(node), msg, node.name, "continue", getline(n)); + } else if (n.type === "ReturnStatement") { + error(getline(node), msg, node.name, "return", getline(n)); + } else if (n.type === "YieldExpression") { + error(getline(node), msg, node.name, "yield", getline(n)); + } else if (n.type === "Identifier" && n.name === "arguments") { + error(getline(node), msg, node.name, "arguments", getline(n)); + } else if (n.type === "VariableDeclaration" && n.kind === "var") { + error(getline(node), msg, node.name, "var", getline(n)); + } else { + err = false; + } + if (err) { + brk(true); // break traversal + } + }}); + return false; + }); + } + + function visit(node) { + // forbidden pattern: + // * * * * + var loopNode = null; + if (isReference(node) && node.$refToScope && isConstLet(node.$refToScope.getKind(node.name))) { + // traverse nodes up towards root from constlet-def + // if we hit a function (before a loop) - ok! + // if we hit a loop - maybe-ouch + // if we reach root - ok! + for (var n = node.$refToScope.node; ; ) { + if (isFunction(n)) { + // we're ok (function-local) + return; + } else if (isLoop(n)) { + loopNode = n; + // maybe not ok (between loop and function) + break; + } + n = n.$parent; + if (!n) { + // ok (reached root) + return; + } + } + + assert(isLoop(loopNode)); + + // traverse scopes from reference-scope up towards definition-scope + // if we hit a function, ouch! + var defScope = node.$refToScope; + var generateIIFE = (options.loopClosures === "iife"); + + for (var s = node.$scope; s; s = s.parent) { + if (s === defScope) { + // we're ok + return; + } else if (isFunction(s.node)) { + // not ok (there's a function between the reference and definition) + // may be transformable via IIFE + + if (!generateIIFE) { + var msg = "loop-variable {0} is captured by a loop-closure. Tried \"loopClosures\": \"iife\" in defs-config.json?"; + return error(getline(node), msg, node.name); + } + + // here be dragons + // for (let x = ..; .. ; ..) { (function(){x})() } is forbidden because of current + // spec and VM status + if (loopNode.type === "ForStatement" && defScope.node === loopNode) { + var declarationNode = defScope.getNode(node.name); + return error(getline(declarationNode), "Not yet specced ES6 feature. {0} is declared in for-loop header and then captured in loop closure", declarationNode.name); + } + + // speak now or forever hold your peace + if (detectIifyBodyBlockers(loopNode.body, node)) { + // error already generated + return; + } + + // mark loop for IIFE-insertion + loopNode.$iify = true; + } + } + } + } +} + +function transformLoopClosures(root, ops, options) { + function insertOp(pos, str, node) { + var op = { + start: pos, + end: pos, + str: str, + } + if (node) { + op.node = node; + } + ops.push(op); + } + + traverse(root, {pre: function(node) { + if (!node.$iify) { + return; + } + + var hasBlock = (node.body.type === "BlockStatement"); + + var insertHead = (hasBlock ? + node.body.range[0] + 1 : // just after body { + node.body.range[0]); // just before existing expression + var insertFoot = (hasBlock ? + node.body.range[1] - 1 : // just before body } + node.body.range[1]); // just after existing expression + + var forInName = (isForInOf(node) && node.left.declarations[0].id.name);; + var iifeHead = fmt("(function({0}){", forInName ? forInName : ""); + var iifeTail = fmt("}).call(this{0});", forInName ? ", " + forInName : ""); + + // modify AST + var iifeFragment = options.parse(iifeHead + iifeTail); + var iifeExpressionStatement = iifeFragment.body[0]; + var iifeBlockStatement = iifeExpressionStatement.expression.callee.object.body; + + if (hasBlock) { + var forBlockStatement = node.body; + var tmp = forBlockStatement.body; + forBlockStatement.body = [iifeExpressionStatement]; + iifeBlockStatement.body = tmp; + } else { + var tmp$0 = node.body; + node.body = iifeExpressionStatement; + iifeBlockStatement.body[0] = tmp$0; + } + + // create ops + insertOp(insertHead, iifeHead); + + if (forInName) { + insertOp(insertFoot, "}).call(this, "); + + var args = iifeExpressionStatement.expression.arguments; + var iifeArgumentIdentifier = args[1]; + iifeArgumentIdentifier.alterop = true; + insertOp(insertFoot, forInName, iifeArgumentIdentifier); + + insertOp(insertFoot, ");"); + } else { + insertOp(insertFoot, iifeTail); + } + }}); +} + +function detectConstAssignment(ast) { + traverse(ast, {pre: function(node) { + if (isLvalue(node)) { + var scope = node.$scope.lookup(node.name); + if (scope && scope.getKind(node.name) === "const") { + error(getline(node), "can't assign to const variable {0}", node.name); + } + } + }}); +} + +function detectConstantLets(ast) { + traverse(ast, {pre: function(node) { + if (isLvalue(node)) { + var scope = node.$scope.lookup(node.name); + if (scope) { + scope.markWrite(node.name); + } + } + }}); + + ast.$scope.detectUnmodifiedLets(); +} + +function setupScopeAndReferences(root, opts) { + // setup scopes + traverse(root, {pre: createScopes}); + var topScope = createTopScope(root.$scope, options.environments, options.globals); + + // allIdentifiers contains all declared and referenced vars + // collect all declaration names (including those in topScope) + var allIdentifiers = stringset(); + topScope.traverse({pre: function(scope) { + allIdentifiers.addMany(scope.decls.keys()); + }}); + + // setup node.$refToScope, check for errors. + // also collects all referenced names to allIdentifiers + setupReferences(root, allIdentifiers, opts); + return allIdentifiers; +} + +function cleanupTree(root) { + traverse(root, {pre: function(node) { + for (var prop in node) { + if (prop[0] === "$") { + delete node[prop]; + } + } + }}); +} + +function run(src, config) { + // alter the options singleton with user configuration + for (var key in config) { + options[key] = config[key]; + } + + var parsed; + + if (is.object(src)) { + if (!options.ast) { + return { + errors: [ + "Can't produce string output when input is an AST. " + + "Did you forget to set options.ast = true?" + ], + }; + } + + // Received an AST object as src, so no need to parse it. + parsed = src; + + } else if (is.string(src)) { + try { + parsed = options.parse(src, { + loc: true, + range: true, + }); + } catch (e) { + return { + errors: [ + fmt("line {0} column {1}: Error during input file parsing\n{2}\n{3}", + e.lineNumber, + e.column, + src.split("\n")[e.lineNumber - 1], + fmt.repeat(" ", e.column - 1) + "^") + ], + }; + } + + } else { + return { + errors: ["Input was neither an AST object nor a string."], + }; + } + + var ast = parsed; + + // TODO detect unused variables (never read) + error.reset(); + + var allIdentifiers = setupScopeAndReferences(ast, {}); + + // static analysis passes + detectLoopClosures(ast); + detectConstAssignment(ast); + //detectConstantLets(ast); + + var changes = []; + transformLoopClosures(ast, changes, options); + + //ast.$scope.print(); process.exit(-1); + + if (error.errors.length >= 1) { + return { + errors: error.errors, + }; + } + + if (changes.length > 0) { + cleanupTree(ast); + allIdentifiers = setupScopeAndReferences(ast, {analyze: false}); + } + assert(error.errors.length === 0); + + // change constlet declarations to var, renamed if needed + // varify modifies the scopes and AST accordingly and + // returns a list of change fragments (to use with alter) + var stats = new Stats(); + varify(ast, stats, allIdentifiers, changes); + + if (options.ast) { + // return the modified AST instead of src code + // get rid of all added $ properties first, such as $parent and $scope + cleanupTree(ast); + return { + stats: stats, + ast: ast, + }; + } else { + // apply changes produced by varify and return the transformed src + var transformedSrc = alter(src, changes); + return { + stats: stats, + src: transformedSrc, + }; + } +} + +module.exports = run; + +},{"1":1,"545":545,"546":546,"547":547,"548":548,"549":549,"550":550,"552":552,"553":553,"554":554,"555":555,"556":556,"557":557}],545:[function(_dereq_,module,exports){ +"use strict"; + +var fmt = _dereq_(554); +var assert = _dereq_(1); + +function error(line, var_args) { + assert(arguments.length >= 2); + + var msg = (arguments.length === 2 ? + String(var_args) : fmt.apply(fmt, Array.prototype.slice.call(arguments, 1))); + + error.errors.push(line === -1 ? msg : fmt("line {0}: {1}", line, msg)); +} + +error.reset = function() { + error.errors = []; +}; + +error.getline = function(node) { + if (node && node.loc && node.loc.start) { + return node.loc.start.line; + } + return -1; +}; + +error.reset(); + +module.exports = error; + +},{"1":1,"554":554}],546:[function(_dereq_,module,exports){ +// jshint -W001 + +"use strict"; + +// Identifiers provided by the ECMAScript standard. + +exports.reservedVars = { + arguments : false, + NaN : false +}; + +exports.ecmaIdentifiers = { + Array : false, + Boolean : false, + Date : false, + decodeURI : false, + decodeURIComponent : false, + encodeURI : false, + encodeURIComponent : false, + Error : false, + "eval" : false, + EvalError : false, + Function : false, + hasOwnProperty : false, + isFinite : false, + isNaN : false, + JSON : false, + Math : false, + Map : false, + Number : false, + Object : false, + parseInt : false, + parseFloat : false, + RangeError : false, + ReferenceError : false, + RegExp : false, + Set : false, + String : false, + SyntaxError : false, + TypeError : false, + URIError : false, + WeakMap : false +}; + +// Global variables commonly provided by a web browser environment. + +exports.browser = { + ArrayBuffer : false, + ArrayBufferView : false, + Audio : false, + Blob : false, + addEventListener : false, + applicationCache : false, + atob : false, + blur : false, + btoa : false, + clearInterval : false, + clearTimeout : false, + close : false, + closed : false, + DataView : false, + DOMParser : false, + defaultStatus : false, + document : false, + Element : false, + event : false, + FileReader : false, + Float32Array : false, + Float64Array : false, + FormData : false, + focus : false, + frames : false, + getComputedStyle : false, + HTMLElement : false, + HTMLAnchorElement : false, + HTMLBaseElement : false, + HTMLBlockquoteElement: false, + HTMLBodyElement : false, + HTMLBRElement : false, + HTMLButtonElement : false, + HTMLCanvasElement : false, + HTMLDirectoryElement : false, + HTMLDivElement : false, + HTMLDListElement : false, + HTMLFieldSetElement : false, + HTMLFontElement : false, + HTMLFormElement : false, + HTMLFrameElement : false, + HTMLFrameSetElement : false, + HTMLHeadElement : false, + HTMLHeadingElement : false, + HTMLHRElement : false, + HTMLHtmlElement : false, + HTMLIFrameElement : false, + HTMLImageElement : false, + HTMLInputElement : false, + HTMLIsIndexElement : false, + HTMLLabelElement : false, + HTMLLayerElement : false, + HTMLLegendElement : false, + HTMLLIElement : false, + HTMLLinkElement : false, + HTMLMapElement : false, + HTMLMenuElement : false, + HTMLMetaElement : false, + HTMLModElement : false, + HTMLObjectElement : false, + HTMLOListElement : false, + HTMLOptGroupElement : false, + HTMLOptionElement : false, + HTMLParagraphElement : false, + HTMLParamElement : false, + HTMLPreElement : false, + HTMLQuoteElement : false, + HTMLScriptElement : false, + HTMLSelectElement : false, + HTMLStyleElement : false, + HTMLTableCaptionElement: false, + HTMLTableCellElement : false, + HTMLTableColElement : false, + HTMLTableElement : false, + HTMLTableRowElement : false, + HTMLTableSectionElement: false, + HTMLTextAreaElement : false, + HTMLTitleElement : false, + HTMLUListElement : false, + HTMLVideoElement : false, + history : false, + Int16Array : false, + Int32Array : false, + Int8Array : false, + Image : false, + length : false, + localStorage : false, + location : false, + MessageChannel : false, + MessageEvent : false, + MessagePort : false, + moveBy : false, + moveTo : false, + MutationObserver : false, + name : false, + Node : false, + NodeFilter : false, + navigator : false, + onbeforeunload : true, + onblur : true, + onerror : true, + onfocus : true, + onload : true, + onresize : true, + onunload : true, + open : false, + openDatabase : false, + opener : false, + Option : false, + parent : false, + print : false, + removeEventListener : false, + resizeBy : false, + resizeTo : false, + screen : false, + scroll : false, + scrollBy : false, + scrollTo : false, + sessionStorage : false, + setInterval : false, + setTimeout : false, + SharedWorker : false, + status : false, + top : false, + Uint16Array : false, + Uint32Array : false, + Uint8Array : false, + Uint8ClampedArray : false, + WebSocket : false, + window : false, + Worker : false, + XMLHttpRequest : false, + XMLSerializer : false, + XPathEvaluator : false, + XPathException : false, + XPathExpression : false, + XPathNamespace : false, + XPathNSResolver : false, + XPathResult : false +}; + +exports.devel = { + alert : false, + confirm: false, + console: false, + Debug : false, + opera : false, + prompt : false +}; + +exports.worker = { + importScripts: true, + postMessage : true, + self : true +}; + +// Widely adopted global names that are not part of ECMAScript standard +exports.nonstandard = { + escape : false, + unescape: false +}; + +// Globals provided by popular JavaScript environments. + +exports.couch = { + "require" : false, + respond : false, + getRow : false, + emit : false, + send : false, + start : false, + sum : false, + log : false, + exports : false, + module : false, + provides : false +}; + +exports.node = { + __filename : false, + __dirname : false, + Buffer : false, + DataView : false, + console : false, + exports : true, // In Node it is ok to exports = module.exports = foo(); + GLOBAL : false, + global : false, + module : false, + process : false, + require : false, + setTimeout : false, + clearTimeout : false, + setInterval : false, + clearInterval: false +}; + +exports.phantom = { + phantom : true, + require : true, + WebPage : true +}; + +exports.rhino = { + defineClass : false, + deserialize : false, + gc : false, + help : false, + importPackage: false, + "java" : false, + load : false, + loadClass : false, + print : false, + quit : false, + readFile : false, + readUrl : false, + runCommand : false, + seal : false, + serialize : false, + spawn : false, + sync : false, + toint32 : false, + version : false +}; + +exports.wsh = { + ActiveXObject : true, + Enumerator : true, + GetObject : true, + ScriptEngine : true, + ScriptEngineBuildVersion : true, + ScriptEngineMajorVersion : true, + ScriptEngineMinorVersion : true, + VBArray : true, + WSH : true, + WScript : true, + XDomainRequest : true +}; + +// Globals provided by popular JavaScript libraries. + +exports.dojo = { + dojo : false, + dijit : false, + dojox : false, + define : false, + "require": false +}; + +exports.jquery = { + "$" : false, + jQuery : false +}; + +exports.mootools = { + "$" : false, + "$$" : false, + Asset : false, + Browser : false, + Chain : false, + Class : false, + Color : false, + Cookie : false, + Core : false, + Document : false, + DomReady : false, + DOMEvent : false, + DOMReady : false, + Drag : false, + Element : false, + Elements : false, + Event : false, + Events : false, + Fx : false, + Group : false, + Hash : false, + HtmlTable : false, + Iframe : false, + IframeShim : false, + InputValidator: false, + instanceOf : false, + Keyboard : false, + Locale : false, + Mask : false, + MooTools : false, + Native : false, + Options : false, + OverText : false, + Request : false, + Scroller : false, + Slick : false, + Slider : false, + Sortables : false, + Spinner : false, + Swiff : false, + Tips : false, + Type : false, + typeOf : false, + URI : false, + Window : false +}; + +exports.prototypejs = { + "$" : false, + "$$" : false, + "$A" : false, + "$F" : false, + "$H" : false, + "$R" : false, + "$break" : false, + "$continue" : false, + "$w" : false, + Abstract : false, + Ajax : false, + Class : false, + Enumerable : false, + Element : false, + Event : false, + Field : false, + Form : false, + Hash : false, + Insertion : false, + ObjectRange : false, + PeriodicalExecuter: false, + Position : false, + Prototype : false, + Selector : false, + Template : false, + Toggle : false, + Try : false, + Autocompleter : false, + Builder : false, + Control : false, + Draggable : false, + Draggables : false, + Droppables : false, + Effect : false, + Sortable : false, + SortableObserver : false, + Sound : false, + Scriptaculous : false +}; + +exports.yui = { + YUI : false, + Y : false, + YUI_config: false +}; + + +},{}],547:[function(_dereq_,module,exports){ +// default configuration + +module.exports = { + disallowVars: false, + disallowDuplicated: true, + disallowUnknownReferences: true, + parse: _dereq_(3).parse, +}; + +},{"3":3}],548:[function(_dereq_,module,exports){ +"use strict"; + +var assert = _dereq_(1); +var stringmap = _dereq_(556); +var stringset = _dereq_(557); +var is = _dereq_(555); +var fmt = _dereq_(554); +var error = _dereq_(545); +var getline = error.getline; +var options = _dereq_(547); + +function Scope(args) { + assert(is.someof(args.kind, ["hoist", "block", "catch-block"])); + assert(is.object(args.node)); + assert(args.parent === null || is.object(args.parent)); + + // kind === "hoist": function scopes, program scope, injected globals + // kind === "block": ES6 block scopes + // kind === "catch-block": catch block scopes + this.kind = args.kind; + + // the AST node the block corresponds to + this.node = args.node; + + // parent scope + this.parent = args.parent; + + // children scopes for easier traversal (populated internally) + this.children = []; + + // scope declarations. decls[variable_name] = { + // kind: "fun" for functions, + // "param" for function parameters, + // "caught" for catch parameter + // "var", + // "const", + // "let" + // node: the AST node the declaration corresponds to + // from: source code index from which it is visible at earliest + // (only stored for "const", "let" [and "var"] nodes) + // } + this.decls = stringmap(); + + // names of all declarations within this scope that was ever written + // TODO move to decls.w? + // TODO create corresponding read? + this.written = stringset(); + + // names of all variables declared outside this hoist scope but + // referenced in this scope (immediately or in child). + // only stored on hoist scopes for efficiency + // (because we currently generate lots of empty block scopes) + this.propagates = (this.kind === "hoist" ? stringset() : null); + + // scopes register themselves with their parents for easier traversal + if (this.parent) { + this.parent.children.push(this); + } +} + +Scope.prototype.print = function(indent) { + indent = indent || 0; + var scope = this; + var names = this.decls.keys().map(function(name) { + return fmt("{0} [{1}]", name, scope.decls.get(name).kind); + }).join(", "); + var propagates = this.propagates ? this.propagates.items().join(", ") : ""; + console.log(fmt("{0}{1}: {2}. propagates: {3}", fmt.repeat(" ", indent), this.node.type, names, propagates)); + this.children.forEach(function(c) { + c.print(indent + 2); + }); +}; + +Scope.prototype.add = function(name, kind, node, referableFromPos) { + assert(is.someof(kind, ["fun", "param", "var", "caught", "const", "let"])); + + function isConstLet(kind) { + return is.someof(kind, ["const", "let"]); + } + + var scope = this; + + // search nearest hoist-scope for fun, param and var's + // const, let and caught variables go directly in the scope (which may be hoist, block or catch-block) + if (is.someof(kind, ["fun", "param", "var"])) { + while (scope.kind !== "hoist") { + if (scope.decls.has(name) && isConstLet(scope.decls.get(name).kind)) { // could be caught + return error(getline(node), "{0} is already declared", name); + } + scope = scope.parent; + } + } + // name exists in scope and either new or existing kind is const|let => error + if (scope.decls.has(name) && (options.disallowDuplicated || isConstLet(scope.decls.get(name).kind) || isConstLet(kind))) { + return error(getline(node), "{0} is already declared", name); + } + + var declaration = { + kind: kind, + node: node, + }; + if (referableFromPos) { + assert(is.someof(kind, ["var", "const", "let"])); + declaration.from = referableFromPos; + } + scope.decls.set(name, declaration); +}; + +Scope.prototype.getKind = function(name) { + assert(is.string(name)); + var decl = this.decls.get(name); + return decl ? decl.kind : null; +}; + +Scope.prototype.getNode = function(name) { + assert(is.string(name)); + var decl = this.decls.get(name); + return decl ? decl.node : null; +}; + +Scope.prototype.getFromPos = function(name) { + assert(is.string(name)); + var decl = this.decls.get(name); + return decl ? decl.from : null; +}; + +Scope.prototype.hasOwn = function(name) { + return this.decls.has(name); +}; + +Scope.prototype.remove = function(name) { + return this.decls.remove(name); +}; + +Scope.prototype.doesPropagate = function(name) { + return this.propagates.has(name); +}; + +Scope.prototype.markPropagates = function(name) { + this.propagates.add(name); +}; + +Scope.prototype.closestHoistScope = function() { + var scope = this; + while (scope.kind !== "hoist") { + scope = scope.parent; + } + return scope; +}; + +Scope.prototype.hasFunctionScopeBetween = function(outer) { + function isFunction(node) { + return is.someof(node.type, ["FunctionDeclaration", "FunctionExpression"]); + } + + for (var scope = this; scope; scope = scope.parent) { + if (scope === outer) { + return false; + } + if (isFunction(scope.node)) { + return true; + } + } + + throw new Error("wasn't inner scope of outer"); +}; + +Scope.prototype.lookup = function(name) { + for (var scope = this; scope; scope = scope.parent) { + if (scope.decls.has(name)) { + return scope; + } else if (scope.kind === "hoist") { + scope.propagates.add(name); + } + } + return null; +}; + +Scope.prototype.markWrite = function(name) { + assert(is.string(name)); + this.written.add(name); +}; + +// detects let variables that are never modified (ignores top-level) +Scope.prototype.detectUnmodifiedLets = function() { + var outmost = this; + + function detect(scope) { + if (scope !== outmost) { + scope.decls.keys().forEach(function(name) { + if (scope.getKind(name) === "let" && !scope.written.has(name)) { + return error(getline(scope.getNode(name)), "{0} is declared as let but never modified so could be const", name); + } + }); + } + + scope.children.forEach(function(childScope) { + detect(childScope); + }); + } + detect(this); +}; + +Scope.prototype.traverse = function(options) { + options = options || {}; + var pre = options.pre; + var post = options.post; + + function visit(scope) { + if (pre) { + pre(scope); + } + scope.children.forEach(function(childScope) { + visit(childScope); + }); + if (post) { + post(scope); + } + } + + visit(this); +}; + +module.exports = Scope; + +},{"1":1,"545":545,"547":547,"554":554,"555":555,"556":556,"557":557}],549:[function(_dereq_,module,exports){ +var fmt = _dereq_(554); +var is = _dereq_(555); +var assert = _dereq_(1); + +function Stats() { + this.lets = 0; + this.consts = 0; + this.renames = []; +} + +Stats.prototype.declarator = function(kind) { + assert(is.someof(kind, ["const", "let"])); + if (kind === "const") { + this.consts++; + } else { + this.lets++; + } +}; + +Stats.prototype.rename = function(oldName, newName, line) { + this.renames.push({ + oldName: oldName, + newName: newName, + line: line, + }); +}; + +Stats.prototype.toString = function() { +// console.log("defs.js stats for file {0}:", filename) + + var renames = this.renames.map(function(r) { + return r; + }).sort(function(a, b) { + return a.line - b.line; + }); // sort a copy of renames + + var renameStr = renames.map(function(rename) { + return fmt("\nline {0}: {1} => {2}", rename.line, rename.oldName, rename.newName); + }).join(""); + + var sum = this.consts + this.lets; + var constlets = (sum === 0 ? + "can't calculate const coverage (0 consts, 0 lets)" : + fmt("{0}% const coverage ({1} consts, {2} lets)", + Math.floor(100 * this.consts / sum), this.consts, this.lets)); + + return constlets + renameStr + "\n"; +}; + +module.exports = Stats; + +},{"1":1,"554":554,"555":555}],550:[function(_dereq_,module,exports){ +// alter.js +// MIT licensed, see LICENSE file +// Copyright (c) 2013 Olov Lassus + +var assert = _dereq_(1); +var stableSort = _dereq_(551); + +// fragments is a list of {start: index, end: index, str: string to replace with} +function alter(str, fragments) { + "use strict"; + + var isArray = Array.isArray || function(v) { + return Object.prototype.toString.call(v) === "[object Array]"; + };; + + assert(typeof str === "string"); + assert(isArray(fragments)); + + // stableSort isn't in-place so no need to copy array first + var sortedFragments = stableSort(fragments, function(a, b) { + return a.start - b.start; + }); + + var outs = []; + + var pos = 0; + for (var i = 0; i < sortedFragments.length; i++) { + var frag = sortedFragments[i]; + + assert(pos <= frag.start); + assert(frag.start <= frag.end); + outs.push(str.slice(pos, frag.start)); + outs.push(frag.str); + pos = frag.end; + } + if (pos < str.length) { + outs.push(str.slice(pos)); + } + + return outs.join(""); +} + +if (typeof module !== "undefined" && typeof module.exports !== "undefined") { + module.exports = alter; +} + +},{"1":1,"551":551}],551:[function(_dereq_,module,exports){ +//! stable.js 0.1.5, https://github.com/Two-Screen/stable +//! © 2014 Angry Bytes and contributors. MIT licensed. + +(function() { + +// A stable array sort, because `Array#sort()` is not guaranteed stable. +// This is an implementation of merge sort, without recursion. + +var stable = function(arr, comp) { + return exec(arr.slice(), comp); +}; + +stable.inplace = function(arr, comp) { + var result = exec(arr, comp); + + // This simply copies back if the result isn't in the original array, + // which happens on an odd number of passes. + if (result !== arr) { + pass(result, null, arr.length, arr); + } + + return arr; +}; + +// Execute the sort using the input array and a second buffer as work space. +// Returns one of those two, containing the final result. +function exec(arr, comp) { + if (typeof(comp) !== 'function') { + comp = function(a, b) { + return String(a).localeCompare(b); + }; + } + + // Short-circuit when there's nothing to sort. + var len = arr.length; + if (len <= 1) { + return arr; + } + + // Rather than dividing input, simply iterate chunks of 1, 2, 4, 8, etc. + // Chunks are the size of the left or right hand in merge sort. + // Stop when the left-hand covers all of the array. + var buffer = new Array(len); + for (var chk = 1; chk < len; chk *= 2) { + pass(arr, comp, chk, buffer); + + var tmp = arr; + arr = buffer; + buffer = tmp; + } + + return arr; +} + +// Run a single pass with the given chunk size. +var pass = function(arr, comp, chk, result) { + var len = arr.length; + var i = 0; + // Step size / double chunk size. + var dbl = chk * 2; + // Bounds of the left and right chunks. + var l, r, e; + // Iterators over the left and right chunk. + var li, ri; + + // Iterate over pairs of chunks. + for (l = 0; l < len; l += dbl) { + r = l + chk; + e = r + chk; + if (r > len) r = len; + if (e > len) e = len; + + // Iterate both chunks in parallel. + li = l; + ri = r; + while (true) { + // Compare the chunks. + if (li < r && ri < e) { + // This works for a regular `sort()` compatible comparator, + // but also for a simple comparator like: `a > b` + if (comp(arr[li], arr[ri]) <= 0) { + result[i++] = arr[li++]; + } + else { + result[i++] = arr[ri++]; + } + } + // Nothing to compare, just flush what's left. + else if (li < r) { + result[i++] = arr[li++]; + } + else if (ri < e) { + result[i++] = arr[ri++]; + } + // Both iterators are at the chunk ends. + else { + break; + } + } + } +}; + +// Export using CommonJS or to the window. +if (typeof(module) !== 'undefined') { + module.exports = stable; +} +else { + window.stable = stable; +} + +})(); + +},{}],552:[function(_dereq_,module,exports){ +function traverse(root, options) { + "use strict"; + + options = options || {}; + var pre = options.pre; + var post = options.post; + var skipProperty = options.skipProperty; + + function visit(node, parent, prop, idx) { + if (!node || typeof node.type !== "string") { + return; + } + + var res = undefined; + if (pre) { + res = pre(node, parent, prop, idx); + } + + if (res !== false) { + for (var prop in node) { + if (skipProperty ? skipProperty(prop, node) : prop[0] === "$") { + continue; + } + + var child = node[prop]; + + if (Array.isArray(child)) { + for (var i = 0; i < child.length; i++) { + visit(child[i], node, prop, i); + } + } else { + visit(child, node, prop); + } + } + } + + if (post) { + post(node, parent, prop, idx); + } + } + + visit(root, null); +}; + +if (typeof module !== "undefined" && typeof module.exports !== "undefined") { + module.exports = traverse; +} + +},{}],553:[function(_dereq_,module,exports){ +// breakable.js +// MIT licensed, see LICENSE file +// Copyright (c) 2013-2014 Olov Lassus + +var breakable = (function() { + "use strict"; + + function Val(val, brk) { + this.val = val; + this.brk = brk; + } + + function make_brk() { + return function brk(val) { + throw new Val(val, brk); + }; + } + + function breakable(fn) { + var brk = make_brk(); + try { + return fn(brk); + } catch (e) { + if (e instanceof Val && e.brk === brk) { + return e.val; + } + throw e; + } + } + + return breakable; +})(); + +if (typeof module !== "undefined" && typeof module.exports !== "undefined") { + module.exports = breakable; +} + +},{}],554:[function(_dereq_,module,exports){ +// simple-fmt.js +// MIT licensed, see LICENSE file +// Copyright (c) 2013 Olov Lassus + +var fmt = (function() { + "use strict"; + + function fmt(str, var_args) { + var args = Array.prototype.slice.call(arguments, 1); + return str.replace(/\{(\d+)\}/g, function(s, match) { + return (match in args ? args[match] : s); + }); + } + + function obj(str, obj) { + return str.replace(/\{([_$a-zA-Z0-9][_$a-zA-Z0-9]*)\}/g, function(s, match) { + return (match in obj ? obj[match] : s); + }); + } + + function repeat(str, n) { + return (new Array(n + 1)).join(str); + } + + fmt.fmt = fmt; + fmt.obj = obj; + fmt.repeat = repeat; + return fmt; +})(); + +if (typeof module !== "undefined" && typeof module.exports !== "undefined") { + module.exports = fmt; +} + +},{}],555:[function(_dereq_,module,exports){ +// simple-is.js +// MIT licensed, see LICENSE file +// Copyright (c) 2013 Olov Lassus + +var is = (function() { + "use strict"; + + var hasOwnProperty = Object.prototype.hasOwnProperty; + var toString = Object.prototype.toString; + var _undefined = void 0; + + return { + nan: function(v) { + return v !== v; + }, + boolean: function(v) { + return typeof v === "boolean"; + }, + number: function(v) { + return typeof v === "number"; + }, + string: function(v) { + return typeof v === "string"; + }, + fn: function(v) { + return typeof v === "function"; + }, + object: function(v) { + return v !== null && typeof v === "object"; + }, + primitive: function(v) { + var t = typeof v; + return v === null || v === _undefined || + t === "boolean" || t === "number" || t === "string"; + }, + array: Array.isArray || function(v) { + return toString.call(v) === "[object Array]"; + }, + finitenumber: function(v) { + return typeof v === "number" && isFinite(v); + }, + someof: function(v, values) { + return values.indexOf(v) >= 0; + }, + noneof: function(v, values) { + return values.indexOf(v) === -1; + }, + own: function(obj, prop) { + return hasOwnProperty.call(obj, prop); + }, + }; +})(); + +if (typeof module !== "undefined" && typeof module.exports !== "undefined") { + module.exports = is; +} + +},{}],556:[function(_dereq_,module,exports){ +// stringmap.js +// MIT licensed, see LICENSE file +// Copyright (c) 2013 Olov Lassus + +var StringMap = (function() { + "use strict"; + + // to save us a few characters + var hasOwnProperty = Object.prototype.hasOwnProperty; + + var create = (function() { + function hasOwnEnumerableProps(obj) { + for (var prop in obj) { + if (hasOwnProperty.call(obj, prop)) { + return true; + } + } + return false; + } + // FF <= 3.6: + // o = {}; o.hasOwnProperty("__proto__" or "__count__" or "__parent__") => true + // o = {"__proto__": null}; Object.prototype.hasOwnProperty.call(o, "__proto__" or "__count__" or "__parent__") => false + function hasOwnPollutedProps(obj) { + return hasOwnProperty.call(obj, "__count__") || hasOwnProperty.call(obj, "__parent__"); + } + + var useObjectCreate = false; + if (typeof Object.create === "function") { + if (!hasOwnEnumerableProps(Object.create(null))) { + useObjectCreate = true; + } + } + if (useObjectCreate === false) { + if (hasOwnEnumerableProps({})) { + throw new Error("StringMap environment error 0, please file a bug at https://github.com/olov/stringmap/issues"); + } + } + // no throw yet means we can create objects without own enumerable props (safe-guard against VMs and shims) + + var o = (useObjectCreate ? Object.create(null) : {}); + var useProtoClear = false; + if (hasOwnPollutedProps(o)) { + o.__proto__ = null; + if (hasOwnEnumerableProps(o) || hasOwnPollutedProps(o)) { + throw new Error("StringMap environment error 1, please file a bug at https://github.com/olov/stringmap/issues"); + } + useProtoClear = true; + } + // no throw yet means we can create objects without own polluted props (safe-guard against VMs and shims) + + return function() { + var o = (useObjectCreate ? Object.create(null) : {}); + if (useProtoClear) { + o.__proto__ = null; + } + return o; + }; + })(); + + // stringmap ctor + function stringmap(optional_object) { + // use with or without new + if (!(this instanceof stringmap)) { + return new stringmap(optional_object); + } + this.obj = create(); + this.hasProto = false; // false (no __proto__ key) or true (has __proto__ key) + this.proto = undefined; // value for __proto__ key when hasProto is true, undefined otherwise + + if (optional_object) { + this.setMany(optional_object); + } + }; + + // primitive methods that deals with data representation + stringmap.prototype.has = function(key) { + // The type-check of key in has, get, set and delete is important because otherwise an object + // {toString: function() { return "__proto__"; }} can avoid the key === "__proto__" test. + // The alternative to type-checking would be to force string conversion, i.e. key = String(key); + if (typeof key !== "string") { + throw new Error("StringMap expected string key"); + } + return (key === "__proto__" ? + this.hasProto : + hasOwnProperty.call(this.obj, key)); + }; + + stringmap.prototype.get = function(key) { + if (typeof key !== "string") { + throw new Error("StringMap expected string key"); + } + return (key === "__proto__" ? + this.proto : + (hasOwnProperty.call(this.obj, key) ? this.obj[key] : undefined)); + }; + + stringmap.prototype.set = function(key, value) { + if (typeof key !== "string") { + throw new Error("StringMap expected string key"); + } + if (key === "__proto__") { + this.hasProto = true; + this.proto = value; + } else { + this.obj[key] = value; + } + }; + + stringmap.prototype.remove = function(key) { + if (typeof key !== "string") { + throw new Error("StringMap expected string key"); + } + var didExist = this.has(key); + if (key === "__proto__") { + this.hasProto = false; + this.proto = undefined; + } else { + delete this.obj[key]; + } + return didExist; + }; + + // alias remove to delete but beware: + // sm.delete("key"); // OK in ES5 and later + // sm['delete']("key"); // OK in all ES versions + // sm.remove("key"); // OK in all ES versions + stringmap.prototype['delete'] = stringmap.prototype.remove; + + stringmap.prototype.isEmpty = function() { + for (var key in this.obj) { + if (hasOwnProperty.call(this.obj, key)) { + return false; + } + } + return !this.hasProto; + }; + + stringmap.prototype.size = function() { + var len = 0; + for (var key in this.obj) { + if (hasOwnProperty.call(this.obj, key)) { + ++len; + } + } + return (this.hasProto ? len + 1 : len); + }; + + stringmap.prototype.keys = function() { + var keys = []; + for (var key in this.obj) { + if (hasOwnProperty.call(this.obj, key)) { + keys.push(key); + } + } + if (this.hasProto) { + keys.push("__proto__"); + } + return keys; + }; + + stringmap.prototype.values = function() { + var values = []; + for (var key in this.obj) { + if (hasOwnProperty.call(this.obj, key)) { + values.push(this.obj[key]); + } + } + if (this.hasProto) { + values.push(this.proto); + } + return values; + }; + + stringmap.prototype.items = function() { + var items = []; + for (var key in this.obj) { + if (hasOwnProperty.call(this.obj, key)) { + items.push([key, this.obj[key]]); + } + } + if (this.hasProto) { + items.push(["__proto__", this.proto]); + } + return items; + }; + + + // methods that rely on the above primitives + stringmap.prototype.setMany = function(object) { + if (object === null || (typeof object !== "object" && typeof object !== "function")) { + throw new Error("StringMap expected Object"); + } + for (var key in object) { + if (hasOwnProperty.call(object, key)) { + this.set(key, object[key]); + } + } + return this; + }; + + stringmap.prototype.merge = function(other) { + var keys = other.keys(); + for (var i = 0; i < keys.length; i++) { + var key = keys[i]; + this.set(key, other.get(key)); + } + return this; + }; + + stringmap.prototype.map = function(fn) { + var keys = this.keys(); + for (var i = 0; i < keys.length; i++) { + var key = keys[i]; + keys[i] = fn(this.get(key), key); // re-use keys array for results + } + return keys; + }; + + stringmap.prototype.forEach = function(fn) { + var keys = this.keys(); + for (var i = 0; i < keys.length; i++) { + var key = keys[i]; + fn(this.get(key), key); + } + }; + + stringmap.prototype.clone = function() { + var other = stringmap(); + return other.merge(this); + }; + + stringmap.prototype.toString = function() { + var self = this; + return "{" + this.keys().map(function(key) { + return JSON.stringify(key) + ":" + JSON.stringify(self.get(key)); + }).join(",") + "}"; + }; + + return stringmap; +})(); + +if (typeof module !== "undefined" && typeof module.exports !== "undefined") { + module.exports = StringMap; +} + +},{}],557:[function(_dereq_,module,exports){ +// stringset.js +// MIT licensed, see LICENSE file +// Copyright (c) 2013 Olov Lassus + +var StringSet = (function() { + "use strict"; + + // to save us a few characters + var hasOwnProperty = Object.prototype.hasOwnProperty; + + var create = (function() { + function hasOwnEnumerableProps(obj) { + for (var prop in obj) { + if (hasOwnProperty.call(obj, prop)) { + return true; + } + } + return false; + } + + // FF <= 3.6: + // o = {}; o.hasOwnProperty("__proto__" or "__count__" or "__parent__") => true + // o = {"__proto__": null}; Object.prototype.hasOwnProperty.call(o, "__proto__" or "__count__" or "__parent__") => false + function hasOwnPollutedProps(obj) { + return hasOwnProperty.call(obj, "__count__") || hasOwnProperty.call(obj, "__parent__"); + } + + var useObjectCreate = false; + if (typeof Object.create === "function") { + if (!hasOwnEnumerableProps(Object.create(null))) { + useObjectCreate = true; + } + } + if (useObjectCreate === false) { + if (hasOwnEnumerableProps({})) { + throw new Error("StringSet environment error 0, please file a bug at https://github.com/olov/stringset/issues"); + } + } + // no throw yet means we can create objects without own enumerable props (safe-guard against VMs and shims) + + var o = (useObjectCreate ? Object.create(null) : {}); + var useProtoClear = false; + if (hasOwnPollutedProps(o)) { + o.__proto__ = null; + if (hasOwnEnumerableProps(o) || hasOwnPollutedProps(o)) { + throw new Error("StringSet environment error 1, please file a bug at https://github.com/olov/stringset/issues"); + } + useProtoClear = true; + } + // no throw yet means we can create objects without own polluted props (safe-guard against VMs and shims) + + return function() { + var o = (useObjectCreate ? Object.create(null) : {}); + if (useProtoClear) { + o.__proto__ = null; + } + return o; + }; + })(); + + // stringset ctor + function stringset(optional_array) { + // use with or without new + if (!(this instanceof stringset)) { + return new stringset(optional_array); + } + this.obj = create(); + this.hasProto = false; // false (no __proto__ item) or true (has __proto__ item) + + if (optional_array) { + this.addMany(optional_array); + } + }; + + // primitive methods that deals with data representation + stringset.prototype.has = function(item) { + // The type-check of item in has, get, set and delete is important because otherwise an object + // {toString: function() { return "__proto__"; }} can avoid the item === "__proto__" test. + // The alternative to type-checking would be to force string conversion, i.e. item = String(item); + if (typeof item !== "string") { + throw new Error("StringSet expected string item"); + } + return (item === "__proto__" ? + this.hasProto : + hasOwnProperty.call(this.obj, item)); + }; + + stringset.prototype.add = function(item) { + if (typeof item !== "string") { + throw new Error("StringSet expected string item"); + } + if (item === "__proto__") { + this.hasProto = true; + } else { + this.obj[item] = true; + } + }; + + stringset.prototype.remove = function(item) { + if (typeof item !== "string") { + throw new Error("StringSet expected string item"); + } + var didExist = this.has(item); + if (item === "__proto__") { + this.hasProto = false; + } else { + delete this.obj[item]; + } + return didExist; + }; + + // alias remove to delete but beware: + // ss.delete("key"); // OK in ES5 and later + // ss['delete']("key"); // OK in all ES versions + // ss.remove("key"); // OK in all ES versions + stringset.prototype['delete'] = stringset.prototype.remove; + + stringset.prototype.isEmpty = function() { + for (var item in this.obj) { + if (hasOwnProperty.call(this.obj, item)) { + return false; + } + } + return !this.hasProto; + }; + + stringset.prototype.size = function() { + var len = 0; + for (var item in this.obj) { + if (hasOwnProperty.call(this.obj, item)) { + ++len; + } + } + return (this.hasProto ? len + 1 : len); + }; + + stringset.prototype.items = function() { + var items = []; + for (var item in this.obj) { + if (hasOwnProperty.call(this.obj, item)) { + items.push(item); + } + } + if (this.hasProto) { + items.push("__proto__"); + } + return items; + }; + + + // methods that rely on the above primitives + stringset.prototype.addMany = function(items) { + if (!Array.isArray(items)) { + throw new Error("StringSet expected array"); + } + for (var i = 0; i < items.length; i++) { + this.add(items[i]); + } + return this; + }; + + stringset.prototype.merge = function(other) { + this.addMany(other.items()); + return this; + }; + + stringset.prototype.clone = function() { + var other = stringset(); + return other.merge(this); + }; + + stringset.prototype.toString = function() { + return "{" + this.items().map(JSON.stringify).join(",") + "}"; + }; + + return stringset; +})(); + +if (typeof module !== "undefined" && typeof module.exports !== "undefined") { + module.exports = StringSet; +} + +},{}],558:[function(_dereq_,module,exports){ +var assert = _dereq_(1); +var types = _dereq_(566); +var n = types.namedTypes; +var isArray = types.builtInTypes.array; +var isObject = types.builtInTypes.object; +var linesModule = _dereq_(560); +var fromString = linesModule.fromString; +var Lines = linesModule.Lines; +var concat = linesModule.concat; +var util = _dereq_(567); +var comparePos = util.comparePos; +var childNodesCacheKey = _dereq_(536).makeUniqueKey(); + +// TODO Move a non-caching implementation of this function into ast-types, +// and implement a caching wrapper function here. +function getSortedChildNodes(node, resultArray) { + if (!node) { + return; + } + + // The .loc checks below are sensitive to some of the problems that + // are fixed by this utility function. Specifically, if it decides to + // set node.loc to null, indicating that the node's .loc information + // is unreliable, then we don't want to add node to the resultArray. + util.fixFaultyLocations(node); + + if (resultArray) { + if (n.Node.check(node) && + n.SourceLocation.check(node.loc)) { + // This reverse insertion sort almost always takes constant + // time because we almost always (maybe always?) append the + // nodes in order anyway. + for (var i = resultArray.length - 1; i >= 0; --i) { + if (comparePos(resultArray[i].loc.end, + node.loc.start) <= 0) { + break; + } + } + resultArray.splice(i + 1, 0, node); + return; + } + } else if (node[childNodesCacheKey]) { + return node[childNodesCacheKey]; + } + + var names; + if (isArray.check(node)) { + names = Object.keys(node); + } else if (isObject.check(node)) { + names = types.getFieldNames(node); + } else { + return; + } + + if (!resultArray) { + Object.defineProperty(node, childNodesCacheKey, { + value: resultArray = [], + enumerable: false + }); + } + + for (var i = 0, nameCount = names.length; i < nameCount; ++i) { + getSortedChildNodes(node[names[i]], resultArray); + } + + return resultArray; +} + +// As efficiently as possible, decorate the comment object with +// .precedingNode, .enclosingNode, and/or .followingNode properties, at +// least one of which is guaranteed to be defined. +function decorateComment(node, comment) { + var childNodes = getSortedChildNodes(node); + + // Time to dust off the old binary search robes and wizard hat. + var left = 0, right = childNodes.length; + while (left < right) { + var middle = (left + right) >> 1; + var child = childNodes[middle]; + + if (comparePos(child.loc.start, comment.loc.start) <= 0 && + comparePos(comment.loc.end, child.loc.end) <= 0) { + // The comment is completely contained by this child node. + decorateComment(comment.enclosingNode = child, comment); + return; // Abandon the binary search at this level. + } + + if (comparePos(child.loc.end, comment.loc.start) <= 0) { + // This child node falls completely before the comment. + // Because we will never consider this node or any nodes + // before it again, this node must be the closest preceding + // node we have encountered so far. + var precedingNode = child; + left = middle + 1; + continue; + } + + if (comparePos(comment.loc.end, child.loc.start) <= 0) { + // This child node falls completely after the comment. + // Because we will never consider this node or any nodes after + // it again, this node must be the closest following node we + // have encountered so far. + var followingNode = child; + right = middle; + continue; + } + + throw new Error("Comment location overlaps with node location"); + } + + if (precedingNode) { + comment.precedingNode = precedingNode; + } + + if (followingNode) { + comment.followingNode = followingNode; + } +} + +exports.attach = function(comments, ast, lines) { + if (!isArray.check(comments)) { + return; + } + + var tiesToBreak = []; + + comments.forEach(function(comment) { + comment.loc.lines = lines; + decorateComment(ast, comment); + + var pn = comment.precedingNode; + var en = comment.enclosingNode; + var fn = comment.followingNode; + + if (pn && fn) { + var tieCount = tiesToBreak.length; + if (tieCount > 0) { + var lastTie = tiesToBreak[tieCount - 1]; + + assert.strictEqual( + lastTie.precedingNode === comment.precedingNode, + lastTie.followingNode === comment.followingNode + ); + + if (lastTie.followingNode !== comment.followingNode) { + breakTies(tiesToBreak, lines); + } + } + + tiesToBreak.push(comment); + + } else if (pn) { + // No contest: we have a trailing comment. + breakTies(tiesToBreak, lines); + addTrailingComment(pn, comment); + + } else if (fn) { + // No contest: we have a leading comment. + breakTies(tiesToBreak, lines); + addLeadingComment(fn, comment); + + } else if (en) { + // The enclosing node has no child nodes at all, so what we + // have here is a dangling comment, e.g. [/* crickets */]. + breakTies(tiesToBreak, lines); + addDanglingComment(en, comment); + + } else { + throw new Error("AST contains no nodes at all?"); + } + }); + + breakTies(tiesToBreak, lines); + + comments.forEach(function(comment) { + // These node references were useful for breaking ties, but we + // don't need them anymore, and they create cycles in the AST that + // may lead to infinite recursion if we don't delete them here. + delete comment.precedingNode; + delete comment.enclosingNode; + delete comment.followingNode; + }); +}; + +function breakTies(tiesToBreak, lines) { + var tieCount = tiesToBreak.length; + if (tieCount === 0) { + return; + } + + var pn = tiesToBreak[0].precedingNode; + var fn = tiesToBreak[0].followingNode; + var gapEndPos = fn.loc.start; + + // Iterate backwards through tiesToBreak, examining the gaps + // between the tied comments. In order to qualify as leading, a + // comment must be separated from fn by an unbroken series of + // whitespace-only gaps (or other comments). + for (var indexOfFirstLeadingComment = tieCount; + indexOfFirstLeadingComment > 0; + --indexOfFirstLeadingComment) { + var comment = tiesToBreak[indexOfFirstLeadingComment - 1]; + assert.strictEqual(comment.precedingNode, pn); + assert.strictEqual(comment.followingNode, fn); + + var gap = lines.sliceString(comment.loc.end, gapEndPos); + if (/\S/.test(gap)) { + // The gap string contained something other than whitespace. + break; + } + + gapEndPos = comment.loc.start; + } + + while (indexOfFirstLeadingComment <= tieCount && + (comment = tiesToBreak[indexOfFirstLeadingComment]) && + // If the comment is a //-style comment and indented more + // deeply than the node itself, reconsider it as trailing. + comment.type === "Line" && + comment.loc.start.column > fn.loc.start.column) { + ++indexOfFirstLeadingComment; + } + + tiesToBreak.forEach(function(comment, i) { + if (i < indexOfFirstLeadingComment) { + addTrailingComment(pn, comment); + } else { + addLeadingComment(fn, comment); + } + }); + + tiesToBreak.length = 0; +} + +function addCommentHelper(node, comment) { + var comments = node.comments || (node.comments = []); + comments.push(comment); +} + +function addLeadingComment(node, comment) { + comment.leading = true; + comment.trailing = false; + addCommentHelper(node, comment); +} + +function addDanglingComment(node, comment) { + comment.leading = false; + comment.trailing = false; + addCommentHelper(node, comment); +} + +function addTrailingComment(node, comment) { + comment.leading = false; + comment.trailing = true; + addCommentHelper(node, comment); +} + +function printLeadingComment(commentPath, print) { + var comment = commentPath.getValue(); + n.Comment.assert(comment); + + var loc = comment.loc; + var lines = loc && loc.lines; + var parts = [print(commentPath)]; + + if (comment.trailing) { + // When we print trailing comments as leading comments, we don't + // want to bring any trailing spaces along. + parts.push("\n"); + + } else if (lines instanceof Lines) { + var trailingSpace = lines.slice( + loc.end, + lines.skipSpaces(loc.end) + ); + + if (trailingSpace.length === 1) { + // If the trailing space contains no newlines, then we want to + // preserve it exactly as we found it. + parts.push(trailingSpace); + } else { + // If the trailing space contains newlines, then replace it + // with just that many newlines, with all other spaces removed. + parts.push(new Array(trailingSpace.length).join("\n")); + } + + } else { + parts.push("\n"); + } + + return concat(parts); +} + +function printTrailingComment(commentPath, print) { + var comment = commentPath.getValue(commentPath); + n.Comment.assert(comment); + + var loc = comment.loc; + var lines = loc && loc.lines; + var parts = []; + + if (lines instanceof Lines) { + var fromPos = lines.skipSpaces(loc.start, true) || lines.firstPos(); + var leadingSpace = lines.slice(fromPos, loc.start); + + if (leadingSpace.length === 1) { + // If the leading space contains no newlines, then we want to + // preserve it exactly as we found it. + parts.push(leadingSpace); + } else { + // If the leading space contains newlines, then replace it + // with just that many newlines, sans all other spaces. + parts.push(new Array(leadingSpace.length).join("\n")); + } + } + + parts.push(print(commentPath)); + + return concat(parts); +} + +exports.printComments = function(path, print) { + var value = path.getValue(); + var innerLines = print(path); + var comments = n.Node.check(value) && + types.getFieldValue(value, "comments"); + + if (!comments || comments.length === 0) { + return innerLines; + } + + var leadingParts = []; + var trailingParts = [innerLines]; + + path.each(function(commentPath) { + var comment = commentPath.getValue(); + var leading = types.getFieldValue(comment, "leading"); + var trailing = types.getFieldValue(comment, "trailing"); + + if (leading || (trailing && comment.type !== "Block")) { + leadingParts.push(printLeadingComment(commentPath, print)); + } else if (trailing) { + assert.strictEqual(comment.type, "Block"); + trailingParts.push(printTrailingComment(commentPath, print)); + } + }, "comments"); + + leadingParts.push.apply(leadingParts, trailingParts); + return concat(leadingParts); +}; + +},{"1":1,"536":536,"560":560,"566":566,"567":567}],559:[function(_dereq_,module,exports){ +var assert = _dereq_(1); +var types = _dereq_(566); +var n = types.namedTypes; +var Node = n.Node; +var isArray = types.builtInTypes.array; +var isNumber = types.builtInTypes.number; + +function FastPath(value) { + assert.ok(this instanceof FastPath); + this.stack = [value]; +} + +var FPp = FastPath.prototype; +module.exports = FastPath; + +// Static convenience function for coercing a value to a FastPath. +FastPath.from = function(obj) { + if (obj instanceof FastPath) { + // Return a defensive copy of any existing FastPath instances. + return obj.copy(); + } + + if (obj instanceof types.NodePath) { + // For backwards compatibility, unroll NodePath instances into + // lightweight FastPath [..., name, value] stacks. + var copy = Object.create(FastPath.prototype); + var stack = [obj.value]; + for (var pp; (pp = obj.parentPath); obj = pp) + stack.push(obj.name, pp.value); + copy.stack = stack.reverse(); + return copy; + } + + // Otherwise use obj as the value of the new FastPath instance. + return new FastPath(obj); +}; + +FPp.copy = function copy() { + var copy = Object.create(FastPath.prototype); + copy.stack = this.stack.slice(0); + return copy; +}; + +// The name of the current property is always the penultimate element of +// this.stack, and always a String. +FPp.getName = function getName() { + var s = this.stack; + var len = s.length; + if (len > 1) { + return s[len - 2]; + } + // Since the name is always a string, null is a safe sentinel value to + // return if we do not know the name of the (root) value. + return null; +}; + +// The value of the current property is always the final element of +// this.stack. +FPp.getValue = function getValue() { + var s = this.stack; + return s[s.length - 1]; +}; + +function getNodeHelper(path, count) { + var s = path.stack; + + for (var i = s.length - 1; i >= 0; i -= 2) { + var value = s[i]; + if (n.Node.check(value) && --count < 0) { + return value; + } + } + + return null; +} + +FPp.getNode = function getNode(count) { + return getNodeHelper(this, ~~count); +}; + +FPp.getParentNode = function getParentNode(count) { + return getNodeHelper(this, ~~count + 1); +}; + +// The length of the stack can be either even or odd, depending on whether +// or not we have a name for the root value. The difference between the +// index of the root value and the index of the final value is always +// even, though, which allows us to return the root value in constant time +// (i.e. without iterating backwards through the stack). +FPp.getRootValue = function getRootValue() { + var s = this.stack; + if (s.length % 2 === 0) { + return s[1]; + } + return s[0]; +}; + +// Temporarily push properties named by string arguments given after the +// callback function onto this.stack, then call the callback with a +// reference to this (modified) FastPath object. Note that the stack will +// be restored to its original state after the callback is finished, so it +// is probably a mistake to retain a reference to the path. +FPp.call = function call(callback/*, name1, name2, ... */) { + var s = this.stack; + var origLen = s.length; + var value = s[origLen - 1]; + var argc = arguments.length; + for (var i = 1; i < argc; ++i) { + var name = arguments[i]; + value = value[name]; + s.push(name, value); + } + var result = callback(this); + s.length = origLen; + return result; +}; + +// Similar to FastPath.prototype.call, except that the value obtained by +// accessing this.getValue()[name1][name2]... should be array-like. The +// callback will be called with a reference to this path object for each +// element of the array. +FPp.each = function each(callback/*, name1, name2, ... */) { + var s = this.stack; + var origLen = s.length; + var value = s[origLen - 1]; + var argc = arguments.length; + + for (var i = 1; i < argc; ++i) { + var name = arguments[i]; + value = value[name]; + s.push(name, value); + } + + for (var i = 0; i < value.length; ++i) { + if (i in value) { + s.push(i, value[i]); + // If the callback needs to know the value of i, call + // path.getName(), assuming path is the parameter name. + callback(this); + s.length -= 2; + } + } + + s.length = origLen; +}; + +// Similar to FastPath.prototype.each, except that the results of the +// callback function invocations are stored in an array and returned at +// the end of the iteration. +FPp.map = function map(callback/*, name1, name2, ... */) { + var s = this.stack; + var origLen = s.length; + var value = s[origLen - 1]; + var argc = arguments.length; + + for (var i = 1; i < argc; ++i) { + var name = arguments[i]; + value = value[name]; + s.push(name, value); + } + + var result = new Array(value.length); + + for (var i = 0; i < value.length; ++i) { + if (i in value) { + s.push(i, value[i]); + result[i] = callback(this, i); + s.length -= 2; + } + } + + s.length = origLen; + + return result; +}; + +// Inspired by require("ast-types").NodePath.prototype.needsParens, but +// more efficient because we're iterating backwards through a stack. +FPp.needsParens = function(assumeExpressionContext) { + var parent = this.getParentNode(); + if (!parent) { + return false; + } + + var name = this.getName(); + var node = this.getNode(); + + // If the value of this path is some child of a Node and not a Node + // itself, then it doesn't need parentheses. Only Node objects (in + // fact, only Expression nodes) need parentheses. + if (this.getValue() !== node) { + return false; + } + + // Only expressions need parentheses. + if (!n.Expression.check(node)) { + return false; + } + + // Identifiers never need parentheses. + if (node.type === "Identifier") { + return false; + } + + if (parent.type === "ParenthesizedExpression") { + return false; + } + + switch (node.type) { + case "UnaryExpression": + case "SpreadElement": + case "SpreadProperty": + return parent.type === "MemberExpression" + && name === "object" + && parent.object === node; + + case "BinaryExpression": + case "LogicalExpression": + switch (parent.type) { + case "CallExpression": + return name === "callee" + && parent.callee === node; + + case "UnaryExpression": + case "SpreadElement": + case "SpreadProperty": + return true; + + case "MemberExpression": + return name === "object" + && parent.object === node; + + case "BinaryExpression": + case "LogicalExpression": + var po = parent.operator; + var pp = PRECEDENCE[po]; + var no = node.operator; + var np = PRECEDENCE[no]; + + if (pp > np) { + return true; + } + + if (pp === np && name === "right") { + assert.strictEqual(parent.right, node); + return true; + } + + default: + return false; + } + + case "SequenceExpression": + switch (parent.type) { + case "ForStatement": + // Although parentheses wouldn't hurt around sequence + // expressions in the head of for loops, traditional style + // dictates that e.g. i++, j++ should not be wrapped with + // parentheses. + return false; + + case "ExpressionStatement": + return name !== "expression"; + + default: + // Otherwise err on the side of overparenthesization, adding + // explicit exceptions above if this proves overzealous. + return true; + } + + case "YieldExpression": + switch (parent.type) { + case "BinaryExpression": + case "LogicalExpression": + case "UnaryExpression": + case "SpreadElement": + case "SpreadProperty": + case "CallExpression": + case "MemberExpression": + case "NewExpression": + case "ConditionalExpression": + case "YieldExpression": + return true; + + default: + return false; + } + + case "Literal": + return parent.type === "MemberExpression" + && isNumber.check(node.value) + && name === "object" + && parent.object === node; + + case "AssignmentExpression": + case "ConditionalExpression": + switch (parent.type) { + case "UnaryExpression": + case "SpreadElement": + case "SpreadProperty": + case "BinaryExpression": + case "LogicalExpression": + return true; + + case "CallExpression": + return name === "callee" + && parent.callee === node; + + case "ConditionalExpression": + return name === "test" + && parent.test === node; + + case "MemberExpression": + return name === "object" + && parent.object === node; + + default: + return false; + } + + case "ArrowFunctionExpression": + return isBinary(parent); + + case "ObjectExpression": + if (parent.type === "ArrowFunctionExpression" && + name === "body") { + return true; + } + + default: + if (parent.type === "NewExpression" && + name === "callee" && + parent.callee === node) { + return containsCallExpression(node); + } + } + + if (assumeExpressionContext !== true && + !this.canBeFirstInStatement() && + this.firstInStatement()) + return true; + + return false; +}; + +function isBinary(node) { + return n.BinaryExpression.check(node) + || n.LogicalExpression.check(node); +} + +function isUnaryLike(node) { + return n.UnaryExpression.check(node) + // I considered making SpreadElement and SpreadProperty subtypes + // of UnaryExpression, but they're not really Expression nodes. + || (n.SpreadElement && n.SpreadElement.check(node)) + || (n.SpreadProperty && n.SpreadProperty.check(node)); +} + +var PRECEDENCE = {}; +[["||"], + ["&&"], + ["|"], + ["^"], + ["&"], + ["==", "===", "!=", "!=="], + ["<", ">", "<=", ">=", "in", "instanceof"], + [">>", "<<", ">>>"], + ["+", "-"], + ["*", "/", "%"] +].forEach(function(tier, i) { + tier.forEach(function(op) { + PRECEDENCE[op] = i; + }); +}); + +function containsCallExpression(node) { + if (n.CallExpression.check(node)) { + return true; + } + + if (isArray.check(node)) { + return node.some(containsCallExpression); + } + + if (n.Node.check(node)) { + return types.someField(node, function(name, child) { + return containsCallExpression(child); + }); + } + + return false; +} + +FPp.canBeFirstInStatement = function() { + var node = this.getNode(); + return !n.FunctionExpression.check(node) + && !n.ObjectExpression.check(node); +}; + +FPp.firstInStatement = function() { + var s = this.stack; + var parentName, parent; + var childName, child; + + for (var i = s.length - 1; i >= 0; i -= 2) { + if (n.Node.check(s[i])) { + childName = parentName; + child = parent; + parentName = s[i - 1]; + parent = s[i]; + } + + if (!parent || !child) { + continue; + } + + if (n.BlockStatement.check(parent) && + parentName === "body" && + childName === 0) { + assert.strictEqual(parent.body[0], child); + return true; + } + + if (n.ExpressionStatement.check(parent) && + childName === "expression") { + assert.strictEqual(parent.expression, child); + return true; + } + + if (n.SequenceExpression.check(parent) && + parentName === "expressions" && + childName === 0) { + assert.strictEqual(parent.expressions[0], child); + continue; + } + + if (n.CallExpression.check(parent) && + childName === "callee") { + assert.strictEqual(parent.callee, child); + continue; + } + + if (n.MemberExpression.check(parent) && + childName === "object") { + assert.strictEqual(parent.object, child); + continue; + } + + if (n.ConditionalExpression.check(parent) && + childName === "test") { + assert.strictEqual(parent.test, child); + continue; + } + + if (isBinary(parent) && + childName === "left") { + assert.strictEqual(parent.left, child); + continue; + } + + if (n.UnaryExpression.check(parent) && + !parent.prefix && + childName === "argument") { + assert.strictEqual(parent.argument, child); + continue; + } + + return false; + } + + return true; +}; + +},{"1":1,"566":566}],560:[function(_dereq_,module,exports){ +var assert = _dereq_(1); +var sourceMap = _dereq_(607); +var normalizeOptions = _dereq_(562).normalize; +var secretKey = _dereq_(536).makeUniqueKey(); +var types = _dereq_(566); +var isString = types.builtInTypes.string; +var comparePos = _dereq_(567).comparePos; +var Mapping = _dereq_(561); + +// Goals: +// 1. Minimize new string creation. +// 2. Keep (de)identation O(lines) time. +// 3. Permit negative indentations. +// 4. Enforce immutability. +// 5. No newline characters. + +function getSecret(lines) { + return lines[secretKey]; +} + +function Lines(infos, sourceFileName) { + assert.ok(this instanceof Lines); + assert.ok(infos.length > 0); + + if (sourceFileName) { + isString.assert(sourceFileName); + } else { + sourceFileName = null; + } + + Object.defineProperty(this, secretKey, { + value: { + infos: infos, + mappings: [], + name: sourceFileName, + cachedSourceMap: null + } + }); + + if (sourceFileName) { + getSecret(this).mappings.push(new Mapping(this, { + start: this.firstPos(), + end: this.lastPos() + })); + } +} + +// Exposed for instanceof checks. The fromString function should be used +// to create new Lines objects. +exports.Lines = Lines; +var Lp = Lines.prototype; + +// These properties used to be assigned to each new object in the Lines +// constructor, but we can more efficiently stuff them into the secret and +// let these lazy accessors compute their values on-the-fly. +Object.defineProperties(Lp, { + length: { + get: function() { + return getSecret(this).infos.length; + } + }, + + name: { + get: function() { + return getSecret(this).name; + } + } +}); + +function copyLineInfo(info) { + return { + line: info.line, + indent: info.indent, + sliceStart: info.sliceStart, + sliceEnd: info.sliceEnd + }; +} + +var fromStringCache = {}; +var hasOwn = fromStringCache.hasOwnProperty; +var maxCacheKeyLen = 10; + +function countSpaces(spaces, tabWidth) { + var count = 0; + var len = spaces.length; + + for (var i = 0; i < len; ++i) { + switch (spaces.charCodeAt(i)) { + case 9: // '\t' + assert.strictEqual(typeof tabWidth, "number"); + assert.ok(tabWidth > 0); + + var next = Math.ceil(count / tabWidth) * tabWidth; + if (next === count) { + count += tabWidth; + } else { + count = next; + } + + break; + + case 11: // '\v' + case 12: // '\f' + case 13: // '\r' + case 0xfeff: // zero-width non-breaking space + // These characters contribute nothing to indentation. + break; + + case 32: // ' ' + default: // Treat all other whitespace like ' '. + count += 1; + break; + } + } + + return count; +} +exports.countSpaces = countSpaces; + +var leadingSpaceExp = /^\s*/; + +// As specified here: http://www.ecma-international.org/ecma-262/6.0/#sec-line-terminators +var lineTerminatorSeqExp = + /\u000D\u000A|\u000D(?!\u000A)|\u000A|\u2028|\u2029/; + +/** + * @param {Object} options - Options object that configures printing. + */ +function fromString(string, options) { + if (string instanceof Lines) + return string; + + string += ""; + + var tabWidth = options && options.tabWidth; + var tabless = string.indexOf("\t") < 0; + var cacheable = !options && tabless && (string.length <= maxCacheKeyLen); + + assert.ok(tabWidth || tabless, "No tab width specified but encountered tabs in string\n" + string); + + if (cacheable && hasOwn.call(fromStringCache, string)) + return fromStringCache[string]; + + var lines = new Lines(string.split(lineTerminatorSeqExp).map(function(line) { + var spaces = leadingSpaceExp.exec(line)[0]; + return { + line: line, + indent: countSpaces(spaces, tabWidth), + sliceStart: spaces.length, + sliceEnd: line.length + }; + }), normalizeOptions(options).sourceFileName); + + if (cacheable) + fromStringCache[string] = lines; + + return lines; +} +exports.fromString = fromString; + +function isOnlyWhitespace(string) { + return !/\S/.test(string); +} + +Lp.toString = function(options) { + return this.sliceString(this.firstPos(), this.lastPos(), options); +}; + +Lp.getSourceMap = function(sourceMapName, sourceRoot) { + if (!sourceMapName) { + // Although we could make up a name or generate an anonymous + // source map, instead we assume that any consumer who does not + // provide a name does not actually want a source map. + return null; + } + + var targetLines = this; + + function updateJSON(json) { + json = json || {}; + + isString.assert(sourceMapName); + json.file = sourceMapName; + + if (sourceRoot) { + isString.assert(sourceRoot); + json.sourceRoot = sourceRoot; + } + + return json; + } + + var secret = getSecret(targetLines); + if (secret.cachedSourceMap) { + // Since Lines objects are immutable, we can reuse any source map + // that was previously generated. Nevertheless, we return a new + // JSON object here to protect the cached source map from outside + // modification. + return updateJSON(secret.cachedSourceMap.toJSON()); + } + + var smg = new sourceMap.SourceMapGenerator(updateJSON()); + var sourcesToContents = {}; + + secret.mappings.forEach(function(mapping) { + var sourceCursor = mapping.sourceLines.skipSpaces( + mapping.sourceLoc.start + ) || mapping.sourceLines.lastPos(); + + var targetCursor = targetLines.skipSpaces( + mapping.targetLoc.start + ) || targetLines.lastPos(); + + while (comparePos(sourceCursor, mapping.sourceLoc.end) < 0 && + comparePos(targetCursor, mapping.targetLoc.end) < 0) { + + var sourceChar = mapping.sourceLines.charAt(sourceCursor); + var targetChar = targetLines.charAt(targetCursor); + assert.strictEqual(sourceChar, targetChar); + + var sourceName = mapping.sourceLines.name; + + // Add mappings one character at a time for maximum resolution. + smg.addMapping({ + source: sourceName, + original: { line: sourceCursor.line, + column: sourceCursor.column }, + generated: { line: targetCursor.line, + column: targetCursor.column } + }); + + if (!hasOwn.call(sourcesToContents, sourceName)) { + var sourceContent = mapping.sourceLines.toString(); + smg.setSourceContent(sourceName, sourceContent); + sourcesToContents[sourceName] = sourceContent; + } + + targetLines.nextPos(targetCursor, true); + mapping.sourceLines.nextPos(sourceCursor, true); + } + }); + + secret.cachedSourceMap = smg; + + return smg.toJSON(); +}; + +Lp.bootstrapCharAt = function(pos) { + assert.strictEqual(typeof pos, "object"); + assert.strictEqual(typeof pos.line, "number"); + assert.strictEqual(typeof pos.column, "number"); + + var line = pos.line, + column = pos.column, + strings = this.toString().split(lineTerminatorSeqExp), + string = strings[line - 1]; + + if (typeof string === "undefined") + return ""; + + if (column === string.length && + line < strings.length) + return "\n"; + + if (column >= string.length) + return ""; + + return string.charAt(column); +}; + +Lp.charAt = function(pos) { + assert.strictEqual(typeof pos, "object"); + assert.strictEqual(typeof pos.line, "number"); + assert.strictEqual(typeof pos.column, "number"); + + var line = pos.line, + column = pos.column, + secret = getSecret(this), + infos = secret.infos, + info = infos[line - 1], + c = column; + + if (typeof info === "undefined" || c < 0) + return ""; + + var indent = this.getIndentAt(line); + if (c < indent) + return " "; + + c += info.sliceStart - indent; + + if (c === info.sliceEnd && + line < this.length) + return "\n"; + + if (c >= info.sliceEnd) + return ""; + + return info.line.charAt(c); +}; + +Lp.stripMargin = function(width, skipFirstLine) { + if (width === 0) + return this; + + assert.ok(width > 0, "negative margin: " + width); + + if (skipFirstLine && this.length === 1) + return this; + + var secret = getSecret(this); + + var lines = new Lines(secret.infos.map(function(info, i) { + if (info.line && (i > 0 || !skipFirstLine)) { + info = copyLineInfo(info); + info.indent = Math.max(0, info.indent - width); + } + return info; + })); + + if (secret.mappings.length > 0) { + var newMappings = getSecret(lines).mappings; + assert.strictEqual(newMappings.length, 0); + secret.mappings.forEach(function(mapping) { + newMappings.push(mapping.indent(width, skipFirstLine, true)); + }); + } + + return lines; +}; + +Lp.indent = function(by) { + if (by === 0) + return this; + + var secret = getSecret(this); + + var lines = new Lines(secret.infos.map(function(info) { + if (info.line) { + info = copyLineInfo(info); + info.indent += by; + } + return info + })); + + if (secret.mappings.length > 0) { + var newMappings = getSecret(lines).mappings; + assert.strictEqual(newMappings.length, 0); + secret.mappings.forEach(function(mapping) { + newMappings.push(mapping.indent(by)); + }); + } + + return lines; +}; + +Lp.indentTail = function(by) { + if (by === 0) + return this; + + if (this.length < 2) + return this; + + var secret = getSecret(this); + + var lines = new Lines(secret.infos.map(function(info, i) { + if (i > 0 && info.line) { + info = copyLineInfo(info); + info.indent += by; + } + + return info; + })); + + if (secret.mappings.length > 0) { + var newMappings = getSecret(lines).mappings; + assert.strictEqual(newMappings.length, 0); + secret.mappings.forEach(function(mapping) { + newMappings.push(mapping.indent(by, true)); + }); + } + + return lines; +}; + +Lp.getIndentAt = function(line) { + assert.ok(line >= 1, "no line " + line + " (line numbers start from 1)"); + var secret = getSecret(this), + info = secret.infos[line - 1]; + return Math.max(info.indent, 0); +}; + +Lp.guessTabWidth = function() { + var secret = getSecret(this); + if (hasOwn.call(secret, "cachedTabWidth")) { + return secret.cachedTabWidth; + } + + var counts = []; // Sparse array. + var lastIndent = 0; + + for (var line = 1, last = this.length; line <= last; ++line) { + var info = secret.infos[line - 1]; + var sliced = info.line.slice(info.sliceStart, info.sliceEnd); + + // Whitespace-only lines don't tell us much about the likely tab + // width of this code. + if (isOnlyWhitespace(sliced)) { + continue; + } + + var diff = Math.abs(info.indent - lastIndent); + counts[diff] = ~~counts[diff] + 1; + lastIndent = info.indent; + } + + var maxCount = -1; + var result = 2; + + for (var tabWidth = 1; + tabWidth < counts.length; + tabWidth += 1) { + if (hasOwn.call(counts, tabWidth) && + counts[tabWidth] > maxCount) { + maxCount = counts[tabWidth]; + result = tabWidth; + } + } + + return secret.cachedTabWidth = result; +}; + +Lp.isOnlyWhitespace = function() { + return isOnlyWhitespace(this.toString()); +}; + +Lp.isPrecededOnlyByWhitespace = function(pos) { + var secret = getSecret(this); + var info = secret.infos[pos.line - 1]; + var indent = Math.max(info.indent, 0); + + var diff = pos.column - indent; + if (diff <= 0) { + // If pos.column does not exceed the indentation amount, then + // there must be only whitespace before it. + return true; + } + + var start = info.sliceStart; + var end = Math.min(start + diff, info.sliceEnd); + var prefix = info.line.slice(start, end); + + return isOnlyWhitespace(prefix); +}; + +Lp.getLineLength = function(line) { + var secret = getSecret(this), + info = secret.infos[line - 1]; + return this.getIndentAt(line) + info.sliceEnd - info.sliceStart; +}; + +Lp.nextPos = function(pos, skipSpaces) { + var l = Math.max(pos.line, 0), + c = Math.max(pos.column, 0); + + if (c < this.getLineLength(l)) { + pos.column += 1; + + return skipSpaces + ? !!this.skipSpaces(pos, false, true) + : true; + } + + if (l < this.length) { + pos.line += 1; + pos.column = 0; + + return skipSpaces + ? !!this.skipSpaces(pos, false, true) + : true; + } + + return false; +}; + +Lp.prevPos = function(pos, skipSpaces) { + var l = pos.line, + c = pos.column; + + if (c < 1) { + l -= 1; + + if (l < 1) + return false; + + c = this.getLineLength(l); + + } else { + c = Math.min(c - 1, this.getLineLength(l)); + } + + pos.line = l; + pos.column = c; + + return skipSpaces + ? !!this.skipSpaces(pos, true, true) + : true; +}; + +Lp.firstPos = function() { + // Trivial, but provided for completeness. + return { line: 1, column: 0 }; +}; + +Lp.lastPos = function() { + return { + line: this.length, + column: this.getLineLength(this.length) + }; +}; + +Lp.skipSpaces = function(pos, backward, modifyInPlace) { + if (pos) { + pos = modifyInPlace ? pos : { + line: pos.line, + column: pos.column + }; + } else if (backward) { + pos = this.lastPos(); + } else { + pos = this.firstPos(); + } + + if (backward) { + while (this.prevPos(pos)) { + if (!isOnlyWhitespace(this.charAt(pos)) && + this.nextPos(pos)) { + return pos; + } + } + + return null; + + } else { + while (isOnlyWhitespace(this.charAt(pos))) { + if (!this.nextPos(pos)) { + return null; + } + } + + return pos; + } +}; + +Lp.trimLeft = function() { + var pos = this.skipSpaces(this.firstPos(), false, true); + return pos ? this.slice(pos) : emptyLines; +}; + +Lp.trimRight = function() { + var pos = this.skipSpaces(this.lastPos(), true, true); + return pos ? this.slice(this.firstPos(), pos) : emptyLines; +}; + +Lp.trim = function() { + var start = this.skipSpaces(this.firstPos(), false, true); + if (start === null) + return emptyLines; + + var end = this.skipSpaces(this.lastPos(), true, true); + assert.notStrictEqual(end, null); + + return this.slice(start, end); +}; + +Lp.eachPos = function(callback, startPos, skipSpaces) { + var pos = this.firstPos(); + + if (startPos) { + pos.line = startPos.line, + pos.column = startPos.column + } + + if (skipSpaces && !this.skipSpaces(pos, false, true)) { + return; // Encountered nothing but spaces. + } + + do callback.call(this, pos); + while (this.nextPos(pos, skipSpaces)); +}; + +Lp.bootstrapSlice = function(start, end) { + var strings = this.toString().split( + lineTerminatorSeqExp + ).slice( + start.line - 1, + end.line + ); + + strings.push(strings.pop().slice(0, end.column)); + strings[0] = strings[0].slice(start.column); + + return fromString(strings.join("\n")); +}; + +Lp.slice = function(start, end) { + if (!end) { + if (!start) { + // The client seems to want a copy of this Lines object, but + // Lines objects are immutable, so it's perfectly adequate to + // return the same object. + return this; + } + + // Slice to the end if no end position was provided. + end = this.lastPos(); + } + + var secret = getSecret(this); + var sliced = secret.infos.slice(start.line - 1, end.line); + + if (start.line === end.line) { + sliced[0] = sliceInfo(sliced[0], start.column, end.column); + } else { + assert.ok(start.line < end.line); + sliced[0] = sliceInfo(sliced[0], start.column); + sliced.push(sliceInfo(sliced.pop(), 0, end.column)); + } + + var lines = new Lines(sliced); + + if (secret.mappings.length > 0) { + var newMappings = getSecret(lines).mappings; + assert.strictEqual(newMappings.length, 0); + secret.mappings.forEach(function(mapping) { + var sliced = mapping.slice(this, start, end); + if (sliced) { + newMappings.push(sliced); + } + }, this); + } + + return lines; +}; + +function sliceInfo(info, startCol, endCol) { + var sliceStart = info.sliceStart; + var sliceEnd = info.sliceEnd; + var indent = Math.max(info.indent, 0); + var lineLength = indent + sliceEnd - sliceStart; + + if (typeof endCol === "undefined") { + endCol = lineLength; + } + + startCol = Math.max(startCol, 0); + endCol = Math.min(endCol, lineLength); + endCol = Math.max(endCol, startCol); + + if (endCol < indent) { + indent = endCol; + sliceEnd = sliceStart; + } else { + sliceEnd -= lineLength - endCol; + } + + lineLength = endCol; + lineLength -= startCol; + + if (startCol < indent) { + indent -= startCol; + } else { + startCol -= indent; + indent = 0; + sliceStart += startCol; + } + + assert.ok(indent >= 0); + assert.ok(sliceStart <= sliceEnd); + assert.strictEqual(lineLength, indent + sliceEnd - sliceStart); + + if (info.indent === indent && + info.sliceStart === sliceStart && + info.sliceEnd === sliceEnd) { + return info; + } + + return { + line: info.line, + indent: indent, + sliceStart: sliceStart, + sliceEnd: sliceEnd + }; +} + +Lp.bootstrapSliceString = function(start, end, options) { + return this.slice(start, end).toString(options); +}; + +Lp.sliceString = function(start, end, options) { + if (!end) { + if (!start) { + // The client seems to want a copy of this Lines object, but + // Lines objects are immutable, so it's perfectly adequate to + // return the same object. + return this; + } + + // Slice to the end if no end position was provided. + end = this.lastPos(); + } + + options = normalizeOptions(options); + + var infos = getSecret(this).infos; + var parts = []; + var tabWidth = options.tabWidth; + + for (var line = start.line; line <= end.line; ++line) { + var info = infos[line - 1]; + + if (line === start.line) { + if (line === end.line) { + info = sliceInfo(info, start.column, end.column); + } else { + info = sliceInfo(info, start.column); + } + } else if (line === end.line) { + info = sliceInfo(info, 0, end.column); + } + + var indent = Math.max(info.indent, 0); + + var before = info.line.slice(0, info.sliceStart); + if (options.reuseWhitespace && + isOnlyWhitespace(before) && + countSpaces(before, options.tabWidth) === indent) { + // Reuse original spaces if the indentation is correct. + parts.push(info.line.slice(0, info.sliceEnd)); + continue; + } + + var tabs = 0; + var spaces = indent; + + if (options.useTabs) { + tabs = Math.floor(indent / tabWidth); + spaces -= tabs * tabWidth; + } + + var result = ""; + + if (tabs > 0) { + result += new Array(tabs + 1).join("\t"); + } + + if (spaces > 0) { + result += new Array(spaces + 1).join(" "); + } + + result += info.line.slice(info.sliceStart, info.sliceEnd); + + parts.push(result); + } + + return parts.join(options.lineTerminator); +}; + +Lp.isEmpty = function() { + return this.length < 2 && this.getLineLength(1) < 1; +}; + +Lp.join = function(elements) { + var separator = this; + var separatorSecret = getSecret(separator); + var infos = []; + var mappings = []; + var prevInfo; + + function appendSecret(secret) { + if (secret === null) + return; + + if (prevInfo) { + var info = secret.infos[0]; + var indent = new Array(info.indent + 1).join(" "); + var prevLine = infos.length; + var prevColumn = Math.max(prevInfo.indent, 0) + + prevInfo.sliceEnd - prevInfo.sliceStart; + + prevInfo.line = prevInfo.line.slice( + 0, prevInfo.sliceEnd) + indent + info.line.slice( + info.sliceStart, info.sliceEnd); + + prevInfo.sliceEnd = prevInfo.line.length; + + if (secret.mappings.length > 0) { + secret.mappings.forEach(function(mapping) { + mappings.push(mapping.add(prevLine, prevColumn)); + }); + } + + } else if (secret.mappings.length > 0) { + mappings.push.apply(mappings, secret.mappings); + } + + secret.infos.forEach(function(info, i) { + if (!prevInfo || i > 0) { + prevInfo = copyLineInfo(info); + infos.push(prevInfo); + } + }); + } + + function appendWithSeparator(secret, i) { + if (i > 0) + appendSecret(separatorSecret); + appendSecret(secret); + } + + elements.map(function(elem) { + var lines = fromString(elem); + if (lines.isEmpty()) + return null; + return getSecret(lines); + }).forEach(separator.isEmpty() + ? appendSecret + : appendWithSeparator); + + if (infos.length < 1) + return emptyLines; + + var lines = new Lines(infos); + + getSecret(lines).mappings = mappings; + + return lines; +}; + +exports.concat = function(elements) { + return emptyLines.join(elements); +}; + +Lp.concat = function(other) { + var args = arguments, + list = [this]; + list.push.apply(list, args); + assert.strictEqual(list.length, args.length + 1); + return emptyLines.join(list); +}; + +// The emptyLines object needs to be created all the way down here so that +// Lines.prototype will be fully populated. +var emptyLines = fromString(""); + +},{"1":1,"536":536,"561":561,"562":562,"566":566,"567":567,"607":607}],561:[function(_dereq_,module,exports){ +var assert = _dereq_(1); +var types = _dereq_(566); +var isString = types.builtInTypes.string; +var isNumber = types.builtInTypes.number; +var SourceLocation = types.namedTypes.SourceLocation; +var Position = types.namedTypes.Position; +var linesModule = _dereq_(560); +var comparePos = _dereq_(567).comparePos; + +function Mapping(sourceLines, sourceLoc, targetLoc) { + assert.ok(this instanceof Mapping); + assert.ok(sourceLines instanceof linesModule.Lines); + SourceLocation.assert(sourceLoc); + + if (targetLoc) { + // In certain cases it's possible for targetLoc.{start,end}.column + // values to be negative, which technically makes them no longer + // valid SourceLocation nodes, so we need to be more forgiving. + assert.ok( + isNumber.check(targetLoc.start.line) && + isNumber.check(targetLoc.start.column) && + isNumber.check(targetLoc.end.line) && + isNumber.check(targetLoc.end.column) + ); + } else { + // Assume identity mapping if no targetLoc specified. + targetLoc = sourceLoc; + } + + Object.defineProperties(this, { + sourceLines: { value: sourceLines }, + sourceLoc: { value: sourceLoc }, + targetLoc: { value: targetLoc } + }); +} + +var Mp = Mapping.prototype; +module.exports = Mapping; + +Mp.slice = function(lines, start, end) { + assert.ok(lines instanceof linesModule.Lines); + Position.assert(start); + + if (end) { + Position.assert(end); + } else { + end = lines.lastPos(); + } + + var sourceLines = this.sourceLines; + var sourceLoc = this.sourceLoc; + var targetLoc = this.targetLoc; + + function skip(name) { + var sourceFromPos = sourceLoc[name]; + var targetFromPos = targetLoc[name]; + var targetToPos = start; + + if (name === "end") { + targetToPos = end; + } else { + assert.strictEqual(name, "start"); + } + + return skipChars( + sourceLines, sourceFromPos, + lines, targetFromPos, targetToPos + ); + } + + if (comparePos(start, targetLoc.start) <= 0) { + if (comparePos(targetLoc.end, end) <= 0) { + targetLoc = { + start: subtractPos(targetLoc.start, start.line, start.column), + end: subtractPos(targetLoc.end, start.line, start.column) + }; + + // The sourceLoc can stay the same because the contents of the + // targetLoc have not changed. + + } else if (comparePos(end, targetLoc.start) <= 0) { + return null; + + } else { + sourceLoc = { + start: sourceLoc.start, + end: skip("end") + }; + + targetLoc = { + start: subtractPos(targetLoc.start, start.line, start.column), + end: subtractPos(end, start.line, start.column) + }; + } + + } else { + if (comparePos(targetLoc.end, start) <= 0) { + return null; + } + + if (comparePos(targetLoc.end, end) <= 0) { + sourceLoc = { + start: skip("start"), + end: sourceLoc.end + }; + + targetLoc = { + // Same as subtractPos(start, start.line, start.column): + start: { line: 1, column: 0 }, + end: subtractPos(targetLoc.end, start.line, start.column) + }; + + } else { + sourceLoc = { + start: skip("start"), + end: skip("end") + }; + + targetLoc = { + // Same as subtractPos(start, start.line, start.column): + start: { line: 1, column: 0 }, + end: subtractPos(end, start.line, start.column) + }; + } + } + + return new Mapping(this.sourceLines, sourceLoc, targetLoc); +}; + +Mp.add = function(line, column) { + return new Mapping(this.sourceLines, this.sourceLoc, { + start: addPos(this.targetLoc.start, line, column), + end: addPos(this.targetLoc.end, line, column) + }); +}; + +function addPos(toPos, line, column) { + return { + line: toPos.line + line - 1, + column: (toPos.line === 1) + ? toPos.column + column + : toPos.column + }; +} + +Mp.subtract = function(line, column) { + return new Mapping(this.sourceLines, this.sourceLoc, { + start: subtractPos(this.targetLoc.start, line, column), + end: subtractPos(this.targetLoc.end, line, column) + }); +}; + +function subtractPos(fromPos, line, column) { + return { + line: fromPos.line - line + 1, + column: (fromPos.line === line) + ? fromPos.column - column + : fromPos.column + }; +} + +Mp.indent = function(by, skipFirstLine, noNegativeColumns) { + if (by === 0) { + return this; + } + + var targetLoc = this.targetLoc; + var startLine = targetLoc.start.line; + var endLine = targetLoc.end.line; + + if (skipFirstLine && startLine === 1 && endLine === 1) { + return this; + } + + targetLoc = { + start: targetLoc.start, + end: targetLoc.end + }; + + if (!skipFirstLine || startLine > 1) { + var startColumn = targetLoc.start.column + by; + targetLoc.start = { + line: startLine, + column: noNegativeColumns + ? Math.max(0, startColumn) + : startColumn + }; + } + + if (!skipFirstLine || endLine > 1) { + var endColumn = targetLoc.end.column + by; + targetLoc.end = { + line: endLine, + column: noNegativeColumns + ? Math.max(0, endColumn) + : endColumn + }; + } + + return new Mapping(this.sourceLines, this.sourceLoc, targetLoc); +}; + +function skipChars( + sourceLines, sourceFromPos, + targetLines, targetFromPos, targetToPos +) { + assert.ok(sourceLines instanceof linesModule.Lines); + assert.ok(targetLines instanceof linesModule.Lines); + Position.assert(sourceFromPos); + Position.assert(targetFromPos); + Position.assert(targetToPos); + + var targetComparison = comparePos(targetFromPos, targetToPos); + if (targetComparison === 0) { + // Trivial case: no characters to skip. + return sourceFromPos; + } + + if (targetComparison < 0) { + // Skipping forward. + + var sourceCursor = sourceLines.skipSpaces(sourceFromPos); + var targetCursor = targetLines.skipSpaces(targetFromPos); + + var lineDiff = targetToPos.line - targetCursor.line; + sourceCursor.line += lineDiff; + targetCursor.line += lineDiff; + + if (lineDiff > 0) { + // If jumping to later lines, reset columns to the beginnings + // of those lines. + sourceCursor.column = 0; + targetCursor.column = 0; + } else { + assert.strictEqual(lineDiff, 0); + } + + while (comparePos(targetCursor, targetToPos) < 0 && + targetLines.nextPos(targetCursor, true)) { + assert.ok(sourceLines.nextPos(sourceCursor, true)); + assert.strictEqual( + sourceLines.charAt(sourceCursor), + targetLines.charAt(targetCursor) + ); + } + + } else { + // Skipping backward. + + var sourceCursor = sourceLines.skipSpaces(sourceFromPos, true); + var targetCursor = targetLines.skipSpaces(targetFromPos, true); + + var lineDiff = targetToPos.line - targetCursor.line; + sourceCursor.line += lineDiff; + targetCursor.line += lineDiff; + + if (lineDiff < 0) { + // If jumping to earlier lines, reset columns to the ends of + // those lines. + sourceCursor.column = sourceLines.getLineLength(sourceCursor.line); + targetCursor.column = targetLines.getLineLength(targetCursor.line); + } else { + assert.strictEqual(lineDiff, 0); + } + + while (comparePos(targetToPos, targetCursor) < 0 && + targetLines.prevPos(targetCursor, true)) { + assert.ok(sourceLines.prevPos(sourceCursor, true)); + assert.strictEqual( + sourceLines.charAt(sourceCursor), + targetLines.charAt(targetCursor) + ); + } + } + + return sourceCursor; +} + +},{"1":1,"560":560,"566":566,"567":567}],562:[function(_dereq_,module,exports){ +var defaults = { + // If you want to use a different branch of esprima, or any other + // module that supports a .parse function, pass that module object to + // recast.parse as options.esprima. + esprima: _dereq_(3), + + // Number of spaces the pretty-printer should use per tab for + // indentation. If you do not pass this option explicitly, it will be + // (quite reliably!) inferred from the original code. + tabWidth: 4, + + // If you really want the pretty-printer to use tabs instead of + // spaces, make this option true. + useTabs: false, + + // The reprinting code leaves leading whitespace untouched unless it + // has to reindent a line, or you pass false for this option. + reuseWhitespace: true, + + // Override this option to use a different line terminator, e.g. \r\n. + lineTerminator: _dereq_(8).EOL, + + // Some of the pretty-printer code (such as that for printing function + // parameter lists) makes a valiant attempt to prevent really long + // lines. You can adjust the limit by changing this option; however, + // there is no guarantee that line length will fit inside this limit. + wrapColumn: 74, // Aspirational for now. + + // Pass a string as options.sourceFileName to recast.parse to tell the + // reprinter to keep track of reused code so that it can construct a + // source map automatically. + sourceFileName: null, + + // Pass a string as options.sourceMapName to recast.print, and + // (provided you passed options.sourceFileName earlier) the + // PrintResult of recast.print will have a .map property for the + // generated source map. + sourceMapName: null, + + // If provided, this option will be passed along to the source map + // generator as a root directory for relative source file paths. + sourceRoot: null, + + // If you provide a source map that was generated from a previous call + // to recast.print as options.inputSourceMap, the old source map will + // be composed with the new source map. + inputSourceMap: null, + + // If you want esprima to generate .range information (recast only + // uses .loc internally), pass true for this option. + range: false, + + // If you want esprima not to throw exceptions when it encounters + // non-fatal errors, keep this option true. + tolerant: true, + + // If you want to override the quotes used in string literals, specify + // either "single", "double", or "auto" here ("auto" will select the one + // which results in the shorter literal) + // Otherwise, the input marks will be preserved + quote: null, + + // If you want to print trailing commas in object literals, + // array expressions, functions calls and function definitions pass true + // for this option. + trailingComma: false, +}, hasOwn = defaults.hasOwnProperty; + +// Copy options and fill in default values. +exports.normalize = function(options) { + options = options || defaults; + + function get(key) { + return hasOwn.call(options, key) + ? options[key] + : defaults[key]; + } + + return { + tabWidth: +get("tabWidth"), + useTabs: !!get("useTabs"), + reuseWhitespace: !!get("reuseWhitespace"), + lineTerminator: get("lineTerminator"), + wrapColumn: Math.max(get("wrapColumn"), 0), + sourceFileName: get("sourceFileName"), + sourceMapName: get("sourceMapName"), + sourceRoot: get("sourceRoot"), + inputSourceMap: get("inputSourceMap"), + esprima: get("esprima"), + range: get("range"), + tolerant: get("tolerant"), + quote: get("quote"), + trailingComma: get("trailingComma"), + }; +}; + +},{"3":3,"8":8}],563:[function(_dereq_,module,exports){ +var assert = _dereq_(1); +var types = _dereq_(566); +var n = types.namedTypes; +var b = types.builders; +var isObject = types.builtInTypes.object; +var isArray = types.builtInTypes.array; +var isFunction = types.builtInTypes.function; +var Patcher = _dereq_(564).Patcher; +var normalizeOptions = _dereq_(562).normalize; +var fromString = _dereq_(560).fromString; +var attachComments = _dereq_(558).attach; +var util = _dereq_(567); + +exports.parse = function parse(source, options) { + options = normalizeOptions(options); + + var lines = fromString(source, options); + + var sourceWithoutTabs = lines.toString({ + tabWidth: options.tabWidth, + reuseWhitespace: false, + useTabs: false + }); + + var comments = []; + var program = options.esprima.parse(sourceWithoutTabs, { + loc: true, + locations: true, + range: options.range, + comment: true, + onComment: comments, + tolerant: options.tolerant, + ecmaVersion: 6, + sourceType: 'module' + }); + + program.loc = program.loc || { + start: lines.firstPos(), + end: lines.lastPos() + }; + + program.loc.lines = lines; + program.loc.indent = 0; + + // Expand the Program node's .loc to include all comments, since + // typically its .loc.start and .loc.end will coincide with those of + // the first and last statements, respectively, excluding any comments + // that fall outside that region. + var trueProgramLoc = util.getTrueLoc(program, lines); + program.loc.start = trueProgramLoc.start; + program.loc.end = trueProgramLoc.end; + + if (program.comments) { + comments = program.comments; + delete program.comments; + } + + // In order to ensure we reprint leading and trailing program + // comments, wrap the original Program node with a File node. + var file = b.file(program); + file.loc = { + lines: lines, + indent: 0, + start: lines.firstPos(), + end: lines.lastPos() + }; + + // Passing file.program here instead of just file means that initial + // comments will be attached to program.body[0] instead of program. + attachComments( + comments, + program.body.length ? file.program : file, + lines + ); + + // Return a copy of the original AST so that any changes made may be + // compared to the original. + return new TreeCopier(lines).copy(file); +}; + +function TreeCopier(lines) { + assert.ok(this instanceof TreeCopier); + this.lines = lines; + this.indent = 0; +} + +var TCp = TreeCopier.prototype; + +TCp.copy = function(node) { + if (isArray.check(node)) { + return node.map(this.copy, this); + } + + if (!isObject.check(node)) { + return node; + } + + util.fixFaultyLocations(node); + + var copy = Object.create(Object.getPrototypeOf(node), { + original: { // Provide a link from the copy to the original. + value: node, + configurable: false, + enumerable: false, + writable: true + } + }); + + var loc = node.loc; + var oldIndent = this.indent; + var newIndent = oldIndent; + + if (loc) { + // When node is a comment, we set node.loc.indent to + // node.loc.start.column so that, when/if we print the comment by + // itself, we can strip that much whitespace from the left margin + // of the comment. This only really matters for multiline Block + // comments, but it doesn't hurt for Line comments. + if (node.type === "Block" || node.type === "Line" || + this.lines.isPrecededOnlyByWhitespace(loc.start)) { + newIndent = this.indent = loc.start.column; + } + + loc.lines = this.lines; + loc.indent = newIndent; + } + + var keys = Object.keys(node); + var keyCount = keys.length; + for (var i = 0; i < keyCount; ++i) { + var key = keys[i]; + if (key === "loc") { + copy[key] = node[key]; + } else { + copy[key] = this.copy(node[key]); + } + } + + this.indent = oldIndent; + + return copy; +}; + +},{"1":1,"558":558,"560":560,"562":562,"564":564,"566":566,"567":567}],564:[function(_dereq_,module,exports){ +var assert = _dereq_(1); +var linesModule = _dereq_(560); +var types = _dereq_(566); +var getFieldValue = types.getFieldValue; +var Printable = types.namedTypes.Printable; +var Expression = types.namedTypes.Expression; +var SourceLocation = types.namedTypes.SourceLocation; +var util = _dereq_(567); +var comparePos = util.comparePos; +var FastPath = _dereq_(559); +var isObject = types.builtInTypes.object; +var isArray = types.builtInTypes.array; +var isString = types.builtInTypes.string; +var riskyAdjoiningCharExp = /[0-9a-z_$]/i; + +function Patcher(lines) { + assert.ok(this instanceof Patcher); + assert.ok(lines instanceof linesModule.Lines); + + var self = this, + replacements = []; + + self.replace = function(loc, lines) { + if (isString.check(lines)) + lines = linesModule.fromString(lines); + + replacements.push({ + lines: lines, + start: loc.start, + end: loc.end + }); + }; + + self.get = function(loc) { + // If no location is provided, return the complete Lines object. + loc = loc || { + start: { line: 1, column: 0 }, + end: { line: lines.length, + column: lines.getLineLength(lines.length) } + }; + + var sliceFrom = loc.start, + toConcat = []; + + function pushSlice(from, to) { + assert.ok(comparePos(from, to) <= 0); + toConcat.push(lines.slice(from, to)); + } + + replacements.sort(function(a, b) { + return comparePos(a.start, b.start); + }).forEach(function(rep) { + if (comparePos(sliceFrom, rep.start) > 0) { + // Ignore nested replacement ranges. + } else { + pushSlice(sliceFrom, rep.start); + toConcat.push(rep.lines); + sliceFrom = rep.end; + } + }); + + pushSlice(sliceFrom, loc.end); + + return linesModule.concat(toConcat); + }; +} +exports.Patcher = Patcher; + +var Pp = Patcher.prototype; + +Pp.tryToReprintComments = function(newNode, oldNode, print) { + var patcher = this; + + if (!newNode.comments && + !oldNode.comments) { + // We were (vacuously) able to reprint all the comments! + return true; + } + + var newPath = FastPath.from(newNode); + var oldPath = FastPath.from(oldNode); + + newPath.stack.push("comments", getSurroundingComments(newNode)); + oldPath.stack.push("comments", getSurroundingComments(oldNode)); + + var reprints = []; + var ableToReprintComments = + findArrayReprints(newPath, oldPath, reprints); + + // No need to pop anything from newPath.stack or oldPath.stack, since + // newPath and oldPath are fresh local variables. + + if (ableToReprintComments && reprints.length > 0) { + reprints.forEach(function(reprint) { + var oldComment = reprint.oldPath.getValue(); + assert.ok(oldComment.leading || oldComment.trailing); + patcher.replace( + oldComment.loc, + // Comments can't have .comments, so it doesn't matter + // whether we print with comments or without. + print(reprint.newPath).indentTail(oldComment.loc.indent) + ); + }); + } + + return ableToReprintComments; +}; + +// Get all comments that are either leading or trailing, ignoring any +// comments that occur inside node.loc. Returns an empty array for nodes +// with no leading or trailing comments. +function getSurroundingComments(node) { + var result = []; + if (node.comments && + node.comments.length > 0) { + node.comments.forEach(function(comment) { + if (comment.leading || comment.trailing) { + result.push(comment); + } + }); + } + return result; +} + +Pp.deleteComments = function(node) { + if (!node.comments) { + return; + } + + var patcher = this; + + node.comments.forEach(function(comment) { + if (comment.leading) { + // Delete leading comments along with any trailing whitespace + // they might have. + patcher.replace({ + start: comment.loc.start, + end: node.loc.lines.skipSpaces( + comment.loc.end, false, false) + }, ""); + + } else if (comment.trailing) { + // Delete trailing comments along with any leading whitespace + // they might have. + patcher.replace({ + start: node.loc.lines.skipSpaces( + comment.loc.start, true, false), + end: comment.loc.end + }, ""); + } + }); +}; + +exports.getReprinter = function(path) { + assert.ok(path instanceof FastPath); + + // Make sure that this path refers specifically to a Node, rather than + // some non-Node subproperty of a Node. + var node = path.getValue(); + if (!Printable.check(node)) + return; + + var orig = node.original; + var origLoc = orig && orig.loc; + var lines = origLoc && origLoc.lines; + var reprints = []; + + if (!lines || !findReprints(path, reprints)) + return; + + return function(print) { + var patcher = new Patcher(lines); + + reprints.forEach(function(reprint) { + var newNode = reprint.newPath.getValue(); + var oldNode = reprint.oldPath.getValue(); + + SourceLocation.assert(oldNode.loc, true); + + var needToPrintNewPathWithComments = + !patcher.tryToReprintComments(newNode, oldNode, print) + + if (needToPrintNewPathWithComments) { + // Since we were not able to preserve all leading/trailing + // comments, we delete oldNode's comments, print newPath + // with comments, and then patch the resulting lines where + // oldNode used to be. + patcher.deleteComments(oldNode); + } + + var pos = util.copyPos(oldNode.loc.start); + var needsLeadingSpace = lines.prevPos(pos) && + riskyAdjoiningCharExp.test(lines.charAt(pos)); + + var newLines = print( + reprint.newPath, + needToPrintNewPathWithComments + ).indentTail(oldNode.loc.indent); + + var needsTrailingSpace = + riskyAdjoiningCharExp.test(lines.charAt(oldNode.loc.end)); + + // If we try to replace the argument of a ReturnStatement like + // return"asdf" with e.g. a literal null expression, we run + // the risk of ending up with returnnull, so we need to add an + // extra leading space in situations where that might + // happen. Likewise for "asdf"in obj. See #170. + if (needsLeadingSpace || needsTrailingSpace) { + var newParts = []; + needsLeadingSpace && newParts.push(" "); + newParts.push(newLines); + needsTrailingSpace && newParts.push(" "); + newLines = linesModule.concat(newParts); + } + + patcher.replace(oldNode.loc, newLines); + }); + + // Recall that origLoc is the .loc of an ancestor node that is + // guaranteed to contain all the reprinted nodes and comments. + return patcher.get(origLoc).indentTail(-orig.loc.indent); + }; +}; + +function findReprints(newPath, reprints) { + var newNode = newPath.getValue(); + Printable.assert(newNode); + + var oldNode = newNode.original; + Printable.assert(oldNode); + + assert.deepEqual(reprints, []); + + if (newNode.type !== oldNode.type) { + return false; + } + + var oldPath = new FastPath(oldNode); + var canReprint = findChildReprints(newPath, oldPath, reprints); + + if (!canReprint) { + // Make absolutely sure the calling code does not attempt to reprint + // any nodes. + reprints.length = 0; + } + + return canReprint; +} + +function findAnyReprints(newPath, oldPath, reprints) { + var newNode = newPath.getValue(); + var oldNode = oldPath.getValue(); + + if (newNode === oldNode) + return true; + + if (isArray.check(newNode)) + return findArrayReprints(newPath, oldPath, reprints); + + if (isObject.check(newNode)) + return findObjectReprints(newPath, oldPath, reprints); + + return false; +} + +function findArrayReprints(newPath, oldPath, reprints) { + var newNode = newPath.getValue(); + var oldNode = oldPath.getValue(); + isArray.assert(newNode); + var len = newNode.length; + + if (!(isArray.check(oldNode) && + oldNode.length === len)) + return false; + + for (var i = 0; i < len; ++i) { + newPath.stack.push(i, newNode[i]); + oldPath.stack.push(i, oldNode[i]); + var canReprint = findAnyReprints(newPath, oldPath, reprints); + newPath.stack.length -= 2; + oldPath.stack.length -= 2; + if (!canReprint) { + return false; + } + } + + return true; +} + +function findObjectReprints(newPath, oldPath, reprints) { + var newNode = newPath.getValue(); + isObject.assert(newNode); + + if (newNode.original === null) { + // If newNode.original node was set to null, reprint the node. + return false; + } + + var oldNode = oldPath.getValue(); + if (!isObject.check(oldNode)) + return false; + + if (Printable.check(newNode)) { + if (!Printable.check(oldNode)) { + return false; + } + + // Here we need to decide whether the reprinted code for newNode + // is appropriate for patching into the location of oldNode. + + if (newNode.type === oldNode.type) { + var childReprints = []; + + if (findChildReprints(newPath, oldPath, childReprints)) { + reprints.push.apply(reprints, childReprints); + } else if (oldNode.loc) { + // If we have no .loc information for oldNode, then we + // won't be able to reprint it. + reprints.push({ + oldPath: oldPath.copy(), + newPath: newPath.copy() + }); + } else { + return false; + } + + return true; + } + + if (Expression.check(newNode) && + Expression.check(oldNode) && + // If we have no .loc information for oldNode, then we won't + // be able to reprint it. + oldNode.loc) { + + // If both nodes are subtypes of Expression, then we should be + // able to fill the location occupied by the old node with + // code printed for the new node with no ill consequences. + reprints.push({ + oldPath: oldPath.copy(), + newPath: newPath.copy() + }); + + return true; + } + + // The nodes have different types, and at least one of the types + // is not a subtype of the Expression type, so we cannot safely + // assume the nodes are syntactically interchangeable. + return false; + } + + return findChildReprints(newPath, oldPath, reprints); +} + +// This object is reused in hasOpeningParen and hasClosingParen to avoid +// having to allocate a temporary object. +var reusablePos = { line: 1, column: 0 }; +var nonSpaceExp = /\S/; + +function hasOpeningParen(oldPath) { + var oldNode = oldPath.getValue(); + var loc = oldNode.loc; + var lines = loc && loc.lines; + + if (lines) { + var pos = reusablePos; + pos.line = loc.start.line; + pos.column = loc.start.column; + + while (lines.prevPos(pos)) { + var ch = lines.charAt(pos); + + if (ch === "(") { + // If we found an opening parenthesis but it occurred before + // the start of the original subtree for this reprinting, then + // we must not return true for hasOpeningParen(oldPath). + return comparePos(oldPath.getRootValue().loc.start, pos) <= 0; + } + + if (nonSpaceExp.test(ch)) { + return false; + } + } + } + + return false; +} + +function hasClosingParen(oldPath) { + var oldNode = oldPath.getValue(); + var loc = oldNode.loc; + var lines = loc && loc.lines; + + if (lines) { + var pos = reusablePos; + pos.line = loc.end.line; + pos.column = loc.end.column; + + do { + var ch = lines.charAt(pos); + + if (ch === ")") { + // If we found a closing parenthesis but it occurred after the + // end of the original subtree for this reprinting, then we + // must not return true for hasClosingParen(oldPath). + return comparePos(pos, oldPath.getRootValue().loc.end) <= 0; + } + + if (nonSpaceExp.test(ch)) { + return false; + } + + } while (lines.nextPos(pos)); + } + + return false; +} + +function hasParens(oldPath) { + // This logic can technically be fooled if the node has parentheses + // but there are comments intervening between the parentheses and the + // node. In such cases the node will be harmlessly wrapped in an + // additional layer of parentheses. + return hasOpeningParen(oldPath) && hasClosingParen(oldPath); +} + +function findChildReprints(newPath, oldPath, reprints) { + var newNode = newPath.getValue(); + var oldNode = oldPath.getValue(); + + isObject.assert(newNode); + isObject.assert(oldNode); + + if (newNode.original === null) { + // If newNode.original node was set to null, reprint the node. + return false; + } + + // If this type of node cannot come lexically first in its enclosing + // statement (e.g. a function expression or object literal), and it + // seems to be doing so, then the only way we can ignore this problem + // and save ourselves from falling back to the pretty printer is if an + // opening parenthesis happens to precede the node. For example, + // (function(){ ... }()); does not need to be reprinted, even though + // the FunctionExpression comes lexically first in the enclosing + // ExpressionStatement and fails the hasParens test, because the + // parent CallExpression passes the hasParens test. If we relied on + // the path.needsParens() && !hasParens(oldNode) check below, the + // absence of a closing parenthesis after the FunctionExpression would + // trigger pretty-printing unnecessarily. + if (!newPath.canBeFirstInStatement() && + newPath.firstInStatement() && + !hasOpeningParen(oldPath)) + return false; + + // If this node needs parentheses and will not be wrapped with + // parentheses when reprinted, then return false to skip reprinting + // and let it be printed generically. + if (newPath.needsParens(true) && !hasParens(oldPath)) { + return false; + } + + for (var k in util.getUnionOfKeys(newNode, oldNode)) { + if (k === "loc") + continue; + + newPath.stack.push(k, types.getFieldValue(newNode, k)); + oldPath.stack.push(k, types.getFieldValue(oldNode, k)); + var canReprint = findAnyReprints(newPath, oldPath, reprints); + newPath.stack.length -= 2; + oldPath.stack.length -= 2; + + if (!canReprint) { + return false; + } + } + + return true; +} + +},{"1":1,"559":559,"560":560,"566":566,"567":567}],565:[function(_dereq_,module,exports){ +var assert = _dereq_(1); +var sourceMap = _dereq_(607); +var printComments = _dereq_(558).printComments; +var linesModule = _dereq_(560); +var fromString = linesModule.fromString; +var concat = linesModule.concat; +var normalizeOptions = _dereq_(562).normalize; +var getReprinter = _dereq_(564).getReprinter; +var types = _dereq_(566); +var namedTypes = types.namedTypes; +var isString = types.builtInTypes.string; +var isObject = types.builtInTypes.object; +var FastPath = _dereq_(559); +var util = _dereq_(567); + +function PrintResult(code, sourceMap) { + assert.ok(this instanceof PrintResult); + + isString.assert(code); + this.code = code; + + if (sourceMap) { + isObject.assert(sourceMap); + this.map = sourceMap; + } +} + +var PRp = PrintResult.prototype; +var warnedAboutToString = false; + +PRp.toString = function() { + if (!warnedAboutToString) { + console.warn( + "Deprecation warning: recast.print now returns an object with " + + "a .code property. You appear to be treating the object as a " + + "string, which might still work but is strongly discouraged." + ); + + warnedAboutToString = true; + } + + return this.code; +}; + +var emptyPrintResult = new PrintResult(""); + +function Printer(originalOptions) { + assert.ok(this instanceof Printer); + + var explicitTabWidth = originalOptions && originalOptions.tabWidth; + var options = normalizeOptions(originalOptions); + assert.notStrictEqual(options, originalOptions); + + // It's common for client code to pass the same options into both + // recast.parse and recast.print, but the Printer doesn't need (and + // can be confused by) options.sourceFileName, so we null it out. + options.sourceFileName = null; + + function printWithComments(path) { + assert.ok(path instanceof FastPath); + return printComments(path, print); + } + + function print(path, includeComments) { + if (includeComments) + return printWithComments(path); + + assert.ok(path instanceof FastPath); + + if (!explicitTabWidth) { + var oldTabWidth = options.tabWidth; + var loc = path.getNode().loc; + if (loc && loc.lines && loc.lines.guessTabWidth) { + options.tabWidth = loc.lines.guessTabWidth(); + var lines = maybeReprint(path); + options.tabWidth = oldTabWidth; + return lines; + } + } + + return maybeReprint(path); + } + + function maybeReprint(path) { + var reprinter = getReprinter(path); + if (reprinter) + return maybeAddParens(path, reprinter(print)); + return printRootGenerically(path); + } + + // Print the root node generically, but then resume reprinting its + // children non-generically. + function printRootGenerically(path) { + return genericPrint(path, options, printWithComments); + } + + // Print the entire AST generically. + function printGenerically(path) { + return genericPrint(path, options, printGenerically); + } + + this.print = function(ast) { + if (!ast) { + return emptyPrintResult; + } + + var lines = print(FastPath.from(ast), true); + + return new PrintResult( + lines.toString(options), + util.composeSourceMaps( + options.inputSourceMap, + lines.getSourceMap( + options.sourceMapName, + options.sourceRoot + ) + ) + ); + }; + + this.printGenerically = function(ast) { + if (!ast) { + return emptyPrintResult; + } + + var path = FastPath.from(ast); + var oldReuseWhitespace = options.reuseWhitespace; + + // Do not reuse whitespace (or anything else, for that matter) + // when printing generically. + options.reuseWhitespace = false; + + // TODO Allow printing of comments? + var pr = new PrintResult(printGenerically(path).toString(options)); + options.reuseWhitespace = oldReuseWhitespace; + return pr; + }; +} + +exports.Printer = Printer; + +function maybeAddParens(path, lines) { + return path.needsParens() ? concat(["(", lines, ")"]) : lines; +} + +function genericPrint(path, options, printPath) { + assert.ok(path instanceof FastPath); + return maybeAddParens(path, genericPrintNoParens(path, options, printPath)); +} + +function genericPrintNoParens(path, options, print) { + var n = path.getValue(); + + if (!n) { + return fromString(""); + } + + if (typeof n === "string") { + return fromString(n, options); + } + + namedTypes.Printable.assert(n); + + switch (n.type) { + case "File": + return path.call(print, "program"); + + case "Program": + return path.call(function(bodyPath) { + return printStatementSequence(bodyPath, options, print); + }, "body"); + + case "Noop": // Babel extension. + case "EmptyStatement": + return fromString(""); + + case "ExpressionStatement": + return concat([path.call(print, "expression"), ";"]); + + case "ParenthesizedExpression": // Babel extension. + return concat(["(", path.call(print, "expression"), ")"]); + + case "BinaryExpression": + case "LogicalExpression": + case "AssignmentExpression": + return fromString(" ").join([ + path.call(print, "left"), + n.operator, + path.call(print, "right") + ]); + + case "AssignmentPattern": + return concat([ + path.call(print, "left"), + "=", + path.call(print, "right") + ]); + + case "MemberExpression": + var parts = [path.call(print, "object")]; + + var property = path.call(print, "property"); + if (n.computed) { + parts.push("[", property, "]"); + } else { + parts.push(".", property); + } + + return concat(parts); + + case "MetaProperty": + return concat([ + path.call(print, "meta"), + ".", + path.call(print, "property") + ]); + + case "BindExpression": + var parts = []; + + if (n.object) { + parts.push(path.call(print, "object")); + } + + parts.push("::", path.call(print, "callee")); + + return concat(parts); + + case "Path": + return fromString(".").join(n.body); + + case "Identifier": + return concat([ + fromString(n.name, options), + path.call(print, "typeAnnotation") + ]); + + case "SpreadElement": + case "SpreadElementPattern": + case "SpreadProperty": + case "SpreadPropertyPattern": + case "RestElement": + return concat(["...", path.call(print, "argument")]); + + case "FunctionDeclaration": + case "FunctionExpression": + var parts = []; + + if (n.async) + parts.push("async "); + + parts.push("function"); + + if (n.generator) + parts.push("*"); + + if (n.id) { + parts.push( + " ", + path.call(print, "id"), + path.call(print, "typeParameters") + ); + } + + parts.push( + "(", + printFunctionParams(path, options, print), + ")", + path.call(print, "returnType"), + " ", + path.call(print, "body") + ); + + return concat(parts); + + case "ArrowFunctionExpression": + var parts = []; + + if (n.async) + parts.push("async "); + + if ( + n.params.length === 1 && + !n.rest && + n.params[0].type !== 'SpreadElementPattern' && + n.params[0].type !== 'RestElement' + ) { + parts.push(path.call(print, "params", 0)); + } else { + parts.push( + "(", + printFunctionParams(path, options, print), + ")" + ); + } + + parts.push(" => ", path.call(print, "body")); + + return concat(parts); + + case "MethodDefinition": + var parts = []; + + if (n.static) { + parts.push("static "); + } + + parts.push(printMethod(path, options, print)); + + return concat(parts); + + case "YieldExpression": + var parts = ["yield"]; + + if (n.delegate) + parts.push("*"); + + if (n.argument) + parts.push(" ", path.call(print, "argument")); + + return concat(parts); + + case "AwaitExpression": + var parts = ["await"]; + + if (n.all) + parts.push("*"); + + if (n.argument) + parts.push(" ", path.call(print, "argument")); + + return concat(parts); + + case "ModuleDeclaration": + var parts = ["module", path.call(print, "id")]; + + if (n.source) { + assert.ok(!n.body); + parts.push("from", path.call(print, "source")); + } else { + parts.push(path.call(print, "body")); + } + + return fromString(" ").join(parts); + + case "ImportSpecifier": + var parts = []; + + if (n.imported) { + parts.push(path.call(print, "imported")); + if (n.local && + n.local.name !== n.imported.name) { + parts.push(" as ", path.call(print, "local")); + } + } else if (n.id) { + parts.push(path.call(print, "id")); + if (n.name) { + parts.push(" as ", path.call(print, "name")); + } + } + + return concat(parts); + + case "ExportSpecifier": + var parts = []; + + if (n.local) { + parts.push(path.call(print, "local")); + if (n.exported && + n.exported.name !== n.local.name) { + parts.push(" as ", path.call(print, "exported")); + } + } else if (n.id) { + parts.push(path.call(print, "id")); + if (n.name) { + parts.push(" as ", path.call(print, "name")); + } + } + + return concat(parts); + + case "ExportBatchSpecifier": + return fromString("*"); + + case "ImportNamespaceSpecifier": + var parts = ["* as "]; + if (n.local) { + parts.push(path.call(print, "local")); + } else if (n.id) { + parts.push(path.call(print, "id")); + } + return concat(parts); + + case "ImportDefaultSpecifier": + if (n.local) { + return path.call(print, "local"); + } + return path.call(print, "id"); + + case "ExportDeclaration": + var parts = ["export"]; + + if (n["default"]) { + parts.push(" default"); + + } else if (n.specifiers && + n.specifiers.length > 0) { + + if (n.specifiers.length === 1 && + n.specifiers[0].type === "ExportBatchSpecifier") { + parts.push(" *"); + } else { + parts.push( + " { ", + fromString(", ").join(path.map(print, "specifiers")), + " }" + ); + } + + if (n.source) + parts.push(" from ", path.call(print, "source")); + + parts.push(";"); + + return concat(parts); + } + + if (n.declaration) { + var decLines = path.call(print, "declaration"); + parts.push(" ", decLines); + if (lastNonSpaceCharacter(decLines) !== ";") { + parts.push(";"); + } + } + + return concat(parts); + + case "ExportDefaultDeclaration": + return concat([ + "export default ", + path.call(print, "declaration") + ]); + + case "ExportNamedDeclaration": + var parts = ["export "]; + + if (n.declaration) { + parts.push(path.call(print, "declaration")); + } + + if (n.specifiers && + n.specifiers.length > 0) { + parts.push( + n.declaration ? ", {" : "{", + fromString(", ").join(path.map(print, "specifiers")), + "}" + ); + } + + if (n.source) { + parts.push(" from ", path.call(print, "source")); + } + + return concat(parts); + + case "ExportAllDeclaration": + var parts = ["export *"]; + + if (n.exported) { + parts.push(" as ", path.call(print, "exported")); + } + + return concat([ + " from ", + path.call(print, "source") + ]); + + case "ExportNamespaceSpecifier": + return concat(["* as ", path.call(print, "exported")]); + + case "ExportDefaultSpecifier": + return path.call(print, "exported"); + + case "ImportDeclaration": + var parts = ["import "]; + + if (n.importKind && n.importKind !== "value") { + parts.push(n.importKind + " "); + } + + if (n.specifiers && + n.specifiers.length > 0) { + + var foundImportSpecifier = false; + + path.each(function(specifierPath) { + var i = specifierPath.getName(); + if (i > 0) { + parts.push(", "); + } + + var value = specifierPath.getValue(); + + if (namedTypes.ImportDefaultSpecifier.check(value) || + namedTypes.ImportNamespaceSpecifier.check(value)) { + assert.strictEqual(foundImportSpecifier, false); + } else { + namedTypes.ImportSpecifier.assert(value); + if (!foundImportSpecifier) { + foundImportSpecifier = true; + parts.push("{"); + } + } + + parts.push(print(specifierPath)); + }, "specifiers"); + + if (foundImportSpecifier) { + parts.push("}"); + } + + parts.push(" from "); + } + + parts.push(path.call(print, "source"), ";"); + + return concat(parts); + + case "BlockStatement": + var naked = path.call(function(bodyPath) { + return printStatementSequence(bodyPath, options, print); + }, "body"); + + if (naked.isEmpty()) { + return fromString("{}"); + } + + return concat([ + "{\n", + naked.indent(options.tabWidth), + "\n}" + ]); + + case "ReturnStatement": + var parts = ["return"]; + + if (n.argument) { + var argLines = path.call(print, "argument"); + if (argLines.length > 1 && + (namedTypes.XJSElement && + namedTypes.XJSElement.check(n.argument) || + namedTypes.JSXElement && + namedTypes.JSXElement.check(n.argument))) { + parts.push( + " (\n", + argLines.indent(options.tabWidth), + "\n)" + ); + } else { + parts.push(" ", argLines); + } + } + + parts.push(";"); + + return concat(parts); + + case "CallExpression": + return concat([ + path.call(print, "callee"), + printArgumentsList(path, options, print) + ]); + + case "ObjectExpression": + case "ObjectPattern": + case "ObjectTypeAnnotation": + var allowBreak = false; + var isTypeAnnotation = n.type === "ObjectTypeAnnotation"; + var separator = isTypeAnnotation ? ';' : ','; + var fields = []; + + if (isTypeAnnotation) { + fields.push("indexers", "callProperties"); + } + + fields.push("properties"); + + var len = 0; + fields.forEach(function(field) { + len += n[field].length; + }); + + var oneLine = (isTypeAnnotation && len === 1) || len === 0; + var parts = [oneLine ? "{" : "{\n"]; + + var i = 0; + fields.forEach(function(field) { + path.each(function(childPath) { + var lines = print(childPath); + + if (!oneLine) { + lines = lines.indent(options.tabWidth); + } + + var multiLine = !isTypeAnnotation && lines.length > 1; + if (multiLine && allowBreak) { + // Similar to the logic for BlockStatement. + parts.push("\n"); + } + + parts.push(lines); + + if (i < len - 1) { + // Add an extra line break if the previous object property + // had a multi-line value. + parts.push(separator + (multiLine ? "\n\n" : "\n")); + allowBreak = !multiLine; + } else if (len !== 1 && isTypeAnnotation) { + parts.push(separator); + } else if (options.trailingComma) { + parts.push(separator); + } + i++; + }, field); + }); + + parts.push(oneLine ? "}" : "\n}"); + + return concat(parts); + + case "PropertyPattern": + return concat([ + path.call(print, "key"), + ": ", + path.call(print, "pattern") + ]); + + case "Property": // Non-standard AST node type. + if (n.method || n.kind === "get" || n.kind === "set") { + return printMethod(path, options, print); + } + + var parts = []; + + if (n.decorators) { + path.each(function(decoratorPath) { + parts.push(print(decoratorPath), "\n"); + }, "decorators"); + } + + var key = path.call(print, "key"); + if (n.computed) { + parts.push("[", key, "]"); + } else { + parts.push(key); + } + + if (! n.shorthand) { + parts.push(": ", path.call(print, "value")); + } + + return concat(parts); + + case "Decorator": + return concat(["@", path.call(print, "expression")]); + + case "ArrayExpression": + case "ArrayPattern": + var elems = n.elements, + len = elems.length; + + var printed = path.map(print, "elements"); + var joined = fromString(", ").join(printed); + var oneLine = joined.getLineLength(1) <= options.wrapColumn; + var parts = [oneLine ? "[" : "[\n"]; + + path.each(function(elemPath) { + var i = elemPath.getName(); + var elem = elemPath.getValue(); + if (!elem) { + // If the array expression ends with a hole, that hole + // will be ignored by the interpreter, but if it ends with + // two (or more) holes, we need to write out two (or more) + // commas so that the resulting code is interpreted with + // both (all) of the holes. + parts.push(","); + } else { + var lines = printed[i]; + if (oneLine) { + if (i > 0) + parts.push(" "); + } else { + lines = lines.indent(options.tabWidth); + } + parts.push(lines); + if (i < len - 1 || (!oneLine && options.trailingComma)) + parts.push(","); + if (!oneLine) + parts.push("\n"); + } + }, "elements"); + + parts.push("]"); + + return concat(parts); + + case "SequenceExpression": + return fromString(", ").join(path.map(print, "expressions")); + + case "ThisExpression": + return fromString("this"); + + case "Super": + return fromString("super"); + + case "Literal": + if (typeof n.value !== "string") + return fromString(n.value, options); + + return fromString(nodeStr(n.value, options), options); + + case "ModuleSpecifier": + if (n.local) { + throw new Error( + "The ESTree ModuleSpecifier type should be abstract" + ); + } + + // The Esprima ModuleSpecifier type is just a string-valued + // Literal identifying the imported-from module. + return fromString(nodeStr(n.value, options), options); + + case "UnaryExpression": + var parts = [n.operator]; + if (/[a-z]$/.test(n.operator)) + parts.push(" "); + parts.push(path.call(print, "argument")); + return concat(parts); + + case "UpdateExpression": + var parts = [path.call(print, "argument"), n.operator]; + + if (n.prefix) + parts.reverse(); + + return concat(parts); + + case "ConditionalExpression": + return concat([ + "(", path.call(print, "test"), + " ? ", path.call(print, "consequent"), + " : ", path.call(print, "alternate"), ")" + ]); + + case "NewExpression": + var parts = ["new ", path.call(print, "callee")]; + var args = n.arguments; + if (args) { + parts.push(printArgumentsList(path, options, print)); + } + + return concat(parts); + + case "VariableDeclaration": + var parts = [n.kind, " "]; + var maxLen = 0; + var printed = path.map(function(childPath) { + var lines = print(childPath); + maxLen = Math.max(lines.length, maxLen); + return lines; + }, "declarations"); + + if (maxLen === 1) { + parts.push(fromString(", ").join(printed)); + } else if (printed.length > 1 ) { + parts.push( + fromString(",\n").join(printed) + .indentTail(n.kind.length + 1) + ); + } else { + parts.push(printed[0]); + } + + // We generally want to terminate all variable declarations with a + // semicolon, except when they are children of for loops. + var parentNode = path.getParentNode(); + if (!namedTypes.ForStatement.check(parentNode) && + !namedTypes.ForInStatement.check(parentNode) && + !(namedTypes.ForOfStatement && + namedTypes.ForOfStatement.check(parentNode))) { + parts.push(";"); + } + + return concat(parts); + + case "VariableDeclarator": + return n.init ? fromString(" = ").join([ + path.call(print, "id"), + path.call(print, "init") + ]) : path.call(print, "id"); + + case "WithStatement": + return concat([ + "with (", + path.call(print, "object"), + ") ", + path.call(print, "body") + ]); + + case "IfStatement": + var con = adjustClause(path.call(print, "consequent"), options), + parts = ["if (", path.call(print, "test"), ")", con]; + + if (n.alternate) + parts.push( + endsWithBrace(con) ? " else" : "\nelse", + adjustClause(path.call(print, "alternate"), options)); + + return concat(parts); + + case "ForStatement": + // TODO Get the for (;;) case right. + var init = path.call(print, "init"), + sep = init.length > 1 ? ";\n" : "; ", + forParen = "for (", + indented = fromString(sep).join([ + init, + path.call(print, "test"), + path.call(print, "update") + ]).indentTail(forParen.length), + head = concat([forParen, indented, ")"]), + clause = adjustClause(path.call(print, "body"), options), + parts = [head]; + + if (head.length > 1) { + parts.push("\n"); + clause = clause.trimLeft(); + } + + parts.push(clause); + + return concat(parts); + + case "WhileStatement": + return concat([ + "while (", + path.call(print, "test"), + ")", + adjustClause(path.call(print, "body"), options) + ]); + + case "ForInStatement": + // Note: esprima can't actually parse "for each (". + return concat([ + n.each ? "for each (" : "for (", + path.call(print, "left"), + " in ", + path.call(print, "right"), + ")", + adjustClause(path.call(print, "body"), options) + ]); + + case "ForOfStatement": + return concat([ + "for (", + path.call(print, "left"), + " of ", + path.call(print, "right"), + ")", + adjustClause(path.call(print, "body"), options) + ]); + + case "DoWhileStatement": + var doBody = concat([ + "do", + adjustClause(path.call(print, "body"), options) + ]), parts = [doBody]; + + if (endsWithBrace(doBody)) + parts.push(" while"); + else + parts.push("\nwhile"); + + parts.push(" (", path.call(print, "test"), ");"); + + return concat(parts); + + case "DoExpression": + var statements = path.call(function(bodyPath) { + return printStatementSequence(bodyPath, options, print); + }, "body"); + + return concat([ + "do {\n", + statements.indent(options.tabWidth), + "\n}" + ]); + + case "BreakStatement": + var parts = ["break"]; + if (n.label) + parts.push(" ", path.call(print, "label")); + parts.push(";"); + return concat(parts); + + case "ContinueStatement": + var parts = ["continue"]; + if (n.label) + parts.push(" ", path.call(print, "label")); + parts.push(";"); + return concat(parts); + + case "LabeledStatement": + return concat([ + path.call(print, "label"), + ":\n", + path.call(print, "body") + ]); + + case "TryStatement": + var parts = [ + "try ", + path.call(print, "block") + ]; + + if (n.handler) { + parts.push(" ", path.call(print, "handler")); + } else if (n.handlers) { + path.each(function(handlerPath) { + parts.push(" ", print(handlerPath)); + }, "handlers"); + } + + if (n.finalizer) { + parts.push(" finally ", path.call(print, "finalizer")); + } + + return concat(parts); + + case "CatchClause": + var parts = ["catch (", path.call(print, "param")]; + + if (n.guard) + // Note: esprima does not recognize conditional catch clauses. + parts.push(" if ", path.call(print, "guard")); + + parts.push(") ", path.call(print, "body")); + + return concat(parts); + + case "ThrowStatement": + return concat(["throw ", path.call(print, "argument"), ";"]); + + case "SwitchStatement": + return concat([ + "switch (", + path.call(print, "discriminant"), + ") {\n", + fromString("\n").join(path.map(print, "cases")), + "\n}" + ]); + + // Note: ignoring n.lexical because it has no printing consequences. + + case "SwitchCase": + var parts = []; + + if (n.test) + parts.push("case ", path.call(print, "test"), ":"); + else + parts.push("default:"); + + if (n.consequent.length > 0) { + parts.push("\n", path.call(function(consequentPath) { + return printStatementSequence(consequentPath, options, print); + }, "consequent").indent(options.tabWidth)); + } + + return concat(parts); + + case "DebuggerStatement": + return fromString("debugger;"); + + // JSX extensions below. + + case "XJSAttribute": + case "JSXAttribute": + var parts = [path.call(print, "name")]; + if (n.value) + parts.push("=", path.call(print, "value")); + return concat(parts); + + case "XJSIdentifier": + case "JSXIdentifier": + return fromString(n.name, options); + + case "XJSNamespacedName": + case "JSXNamespacedName": + return fromString(":").join([ + path.call(print, "namespace"), + path.call(print, "name") + ]); + + case "XJSMemberExpression": + case "JSXMemberExpression": + return fromString(".").join([ + path.call(print, "object"), + path.call(print, "property") + ]); + + case "XJSSpreadAttribute": + case "JSXSpreadAttribute": + return concat(["{...", path.call(print, "argument"), "}"]); + + case "XJSExpressionContainer": + case "JSXExpressionContainer": + return concat(["{", path.call(print, "expression"), "}"]); + + case "XJSElement": + case "JSXElement": + var openingLines = path.call(print, "openingElement"); + + if (n.openingElement.selfClosing) { + assert.ok(!n.closingElement); + return openingLines; + } + + var childLines = concat( + path.map(function(childPath) { + var child = childPath.getValue(); + + if (namedTypes.Literal.check(child) && + typeof child.value === "string") { + if (/\S/.test(child.value)) { + return child.value.replace(/^\s+|\s+$/g, ""); + } else if (/\n/.test(child.value)) { + return "\n"; + } + } + + return print(childPath); + }, "children") + ).indentTail(options.tabWidth); + + var closingLines = path.call(print, "closingElement"); + + return concat([ + openingLines, + childLines, + closingLines + ]); + + case "XJSOpeningElement": + case "JSXOpeningElement": + var parts = ["<", path.call(print, "name")]; + var attrParts = []; + + path.each(function(attrPath) { + attrParts.push(" ", print(attrPath)); + }, "attributes"); + + var attrLines = concat(attrParts); + + var needLineWrap = ( + attrLines.length > 1 || + attrLines.getLineLength(1) > options.wrapColumn + ); + + if (needLineWrap) { + attrParts.forEach(function(part, i) { + if (part === " ") { + assert.strictEqual(i % 2, 0); + attrParts[i] = "\n"; + } + }); + + attrLines = concat(attrParts).indentTail(options.tabWidth); + } + + parts.push(attrLines, n.selfClosing ? " />" : ">"); + + return concat(parts); + + case "XJSClosingElement": + case "JSXClosingElement": + return concat([""]); + + case "XJSText": + case "JSXText": + return fromString(n.value, options); + + case "XJSEmptyExpression": + case "JSXEmptyExpression": + return fromString(""); + + case "TypeAnnotatedIdentifier": + return concat([ + path.call(print, "annotation"), + " ", + path.call(print, "identifier") + ]); + + case "ClassBody": + if (n.body.length === 0) { + return fromString("{}"); + } + + return concat([ + "{\n", + path.call(function(bodyPath) { + return printStatementSequence(bodyPath, options, print); + }, "body").indent(options.tabWidth), + "\n}" + ]); + + case "ClassPropertyDefinition": + var parts = ["static ", path.call(print, "definition")]; + if (!namedTypes.MethodDefinition.check(n.definition)) + parts.push(";"); + return concat(parts); + + case "ClassProperty": + var parts = []; + if (n.static) + parts.push("static "); + + parts.push(path.call(print, "key")); + if (n.typeAnnotation) + parts.push(path.call(print, "typeAnnotation")); + + if (n.value) + parts.push(" = ", path.call(print, "value")); + + parts.push(";"); + return concat(parts); + + case "ClassDeclaration": + case "ClassExpression": + var parts = ["class"]; + + if (n.id) { + parts.push( + " ", + path.call(print, "id"), + path.call(print, "typeParameters") + ); + } + + if (n.superClass) { + parts.push( + " extends ", + path.call(print, "superClass"), + path.call(print, "superTypeParameters") + ); + } + + if (n["implements"]) { + parts.push( + " implements ", + fromString(", ").join(path.map(print, "implements")) + ); + } + + parts.push(" ", path.call(print, "body")); + + return concat(parts); + + case "TemplateElement": + return fromString(n.value.raw, options); + + case "TemplateLiteral": + var expressions = path.map(print, "expressions"); + var parts = ["`"]; + + path.each(function(childPath) { + var i = childPath.getName(); + parts.push(print(childPath)); + if (i < expressions.length) { + parts.push("${", expressions[i], "}"); + } + }, "quasis"); + + parts.push("`"); + + return concat(parts); + + case "TaggedTemplateExpression": + return concat([ + path.call(print, "tag"), + path.call(print, "quasi") + ]); + + // These types are unprintable because they serve as abstract + // supertypes for other (printable) types. + case "Node": + case "Printable": + case "SourceLocation": + case "Position": + case "Statement": + case "Function": + case "Pattern": + case "Expression": + case "Declaration": + case "Specifier": + case "NamedSpecifier": + case "Comment": // Supertype of Block and Line. + case "MemberTypeAnnotation": // Flow + case "TupleTypeAnnotation": // Flow + case "Type": // Flow + throw new Error("unprintable type: " + JSON.stringify(n.type)); + + case "CommentBlock": // Babel block comment. + case "Block": // Esprima block comment. + return concat(["/*", fromString(n.value, options), "*/"]); + + case "CommentLine": // Babel line comment. + case "Line": // Esprima line comment. + return concat(["//", fromString(n.value, options)]); + + // Type Annotations for Facebook Flow, typically stripped out or + // transformed away before printing. + case "TypeAnnotation": + var parts = []; + + if (n.typeAnnotation) { + if (n.typeAnnotation.type !== "FunctionTypeAnnotation") { + parts.push(": "); + } + parts.push(path.call(print, "typeAnnotation")); + return concat(parts); + } + + return fromString(""); + + case "AnyTypeAnnotation": + return fromString("any", options); + + case "MixedTypeAnnotation": + return fromString("mixed", options); + + case "ArrayTypeAnnotation": + return concat([ + path.call(print, "elementType"), + "[]" + ]); + + case "BooleanTypeAnnotation": + return fromString("boolean", options); + + case "BooleanLiteralTypeAnnotation": + assert.strictEqual(typeof n.value, "boolean"); + return fromString("" + n.value, options); + + case "DeclareClass": + return concat([ + fromString("declare class ", options), + path.call(print, "id"), + " ", + path.call(print, "body"), + ]); + + case "DeclareFunction": + return concat([ + fromString("declare function ", options), + path.call(print, "id"), + ";" + ]); + + case "DeclareModule": + return concat([ + fromString("declare module ", options), + path.call(print, "id"), + " ", + path.call(print, "body"), + ]); + + case "DeclareVariable": + return concat([ + fromString("declare var ", options), + path.call(print, "id"), + ";" + ]); + + case "FunctionTypeAnnotation": + // FunctionTypeAnnotation is ambiguous: + // declare function(a: B): void; OR + // var A: (a: B) => void; + var parts = []; + var parent = path.getParentNode(0); + var isArrowFunctionTypeAnnotation = !( + namedTypes.ObjectTypeCallProperty.check(parent) || + namedTypes.DeclareFunction.check(path.getParentNode(2)) + ); + + var needsColon = + isArrowFunctionTypeAnnotation && + !namedTypes.FunctionTypeParam.check(parent); + + if (needsColon) { + parts.push(": "); + } + + parts.push( + "(", + fromString(", ").join(path.map(print, "params")), + ")" + ); + + // The returnType is not wrapped in a TypeAnnotation, so the colon + // needs to be added separately. + if (n.returnType) { + parts.push( + isArrowFunctionTypeAnnotation ? " => " : ": ", + path.call(print, "returnType") + ); + } + + return concat(parts); + + case "FunctionTypeParam": + return concat([ + path.call(print, "name"), + ": ", + path.call(print, "typeAnnotation"), + ]); + + case "GenericTypeAnnotation": + return concat([ + path.call(print, "id"), + path.call(print, "typeParameters") + ]); + + case "InterfaceDeclaration": + var parts = [ + fromString("interface ", options), + path.call(print, "id"), + path.call(print, "typeParameters"), + " " + ]; + + if (n["extends"]) { + parts.push( + "extends ", + fromString(", ").join(path.map(print, "extends")) + ); + } + + parts.push(" ", path.call(print, "body")); + + return concat(parts); + + case "ClassImplements": + case "InterfaceExtends": + return concat([ + path.call(print, "id"), + path.call(print, "typeParameters") + ]); + + case "IntersectionTypeAnnotation": + return fromString(" & ").join(path.map(print, "types")); + + case "NullableTypeAnnotation": + return concat([ + "?", + path.call(print, "typeAnnotation") + ]); + + case "NumberTypeAnnotation": + return fromString("number", options); + + case "ObjectTypeCallProperty": + return path.call(print, "value"); + + case "ObjectTypeIndexer": + return concat([ + "[", + path.call(print, "id"), + ": ", + path.call(print, "key"), + "]: ", + path.call(print, "value") + ]); + + case "ObjectTypeProperty": + return concat([ + path.call(print, "key"), + ": ", + path.call(print, "value") + ]); + + case "QualifiedTypeIdentifier": + return concat([ + path.call(print, "qualification"), + ".", + path.call(print, "id") + ]); + + case "StringLiteralTypeAnnotation": + return fromString(nodeStr(n.value, options), options); + + case "NumberLiteralTypeAnnotation": + assert.strictEqual(typeof n.value, "number"); + return fromString("" + n.value, options); + + case "StringTypeAnnotation": + return fromString("string", options); + + case "TypeAlias": + return concat([ + "type ", + path.call(print, "id"), + " = ", + path.call(print, "right"), + ";" + ]); + + case "TypeCastExpression": + return concat([ + "(", + path.call(print, "expression"), + path.call(print, "typeAnnotation"), + ")" + ]); + + case "TypeParameterDeclaration": + case "TypeParameterInstantiation": + return concat([ + "<", + fromString(", ").join(path.map(print, "params")), + ">" + ]); + + case "TypeofTypeAnnotation": + return concat([ + fromString("typeof ", options), + path.call(print, "argument") + ]); + + case "UnionTypeAnnotation": + return fromString(" | ").join(path.map(print, "types")); + + case "VoidTypeAnnotation": + return fromString("void", options); + + // Unhandled types below. If encountered, nodes of these types should + // be either left alone or desugared into AST types that are fully + // supported by the pretty-printer. + case "ClassHeritage": // TODO + case "ComprehensionBlock": // TODO + case "ComprehensionExpression": // TODO + case "Glob": // TODO + case "GeneratorExpression": // TODO + case "LetStatement": // TODO + case "LetExpression": // TODO + case "GraphExpression": // TODO + case "GraphIndexExpression": // TODO + + // XML types that nobody cares about or needs to print. + case "XMLDefaultDeclaration": + case "XMLAnyName": + case "XMLQualifiedIdentifier": + case "XMLFunctionQualifiedIdentifier": + case "XMLAttributeSelector": + case "XMLFilterExpression": + case "XML": + case "XMLElement": + case "XMLList": + case "XMLEscape": + case "XMLText": + case "XMLStartTag": + case "XMLEndTag": + case "XMLPointTag": + case "XMLName": + case "XMLAttribute": + case "XMLCdata": + case "XMLComment": + case "XMLProcessingInstruction": + default: + debugger; + throw new Error("unknown type: " + JSON.stringify(n.type)); + } + + return p; +} + +function printStatementSequence(path, options, print) { + var inClassBody = + namedTypes.ClassBody && + namedTypes.ClassBody.check(path.getParentNode()); + + var filtered = []; + var sawComment = false; + var sawStatement = false; + + path.each(function(stmtPath) { + var i = stmtPath.getName(); + var stmt = stmtPath.getValue(); + + // Just in case the AST has been modified to contain falsy + // "statements," it's safer simply to skip them. + if (!stmt) { + return; + } + + // Skip printing EmptyStatement nodes to avoid leaving stray + // semicolons lying around. + if (stmt.type === "EmptyStatement") { + return; + } + + if (namedTypes.Comment.check(stmt)) { + // The pretty printer allows a dangling Comment node to act as + // a Statement when the Comment can't be attached to any other + // non-Comment node in the tree. + sawComment = true; + } else if (!inClassBody) { + namedTypes.Statement.assert(stmt); + sawStatement = true; + } + + // We can't hang onto stmtPath outside of this function, because + // it's just a reference to a mutable FastPath object, so we have + // to go ahead and print it here. + filtered.push({ + node: stmt, + printed: print(stmtPath) + }); + }); + + if (sawComment) { + assert.strictEqual( + sawStatement, false, + "Comments may appear as statements in otherwise empty statement " + + "lists, but may not coexist with non-Comment nodes." + ); + } + + var prevTrailingSpace = null; + var len = filtered.length; + var parts = []; + + filtered.forEach(function(info, i) { + var printed = info.printed; + var stmt = info.node; + var multiLine = printed.length > 1; + var notFirst = i > 0; + var notLast = i < len - 1; + var leadingSpace; + var trailingSpace; + var lines = stmt && stmt.loc && stmt.loc.lines; + var trueLoc = lines && options.reuseWhitespace && + util.getTrueLoc(stmt, lines); + + if (notFirst) { + if (trueLoc) { + var beforeStart = lines.skipSpaces(trueLoc.start, true); + var beforeStartLine = beforeStart ? beforeStart.line : 1; + var leadingGap = trueLoc.start.line - beforeStartLine; + leadingSpace = Array(leadingGap + 1).join("\n"); + } else { + leadingSpace = multiLine ? "\n\n" : "\n"; + } + } else { + leadingSpace = ""; + } + + if (notLast) { + if (trueLoc) { + var afterEnd = lines.skipSpaces(trueLoc.end); + var afterEndLine = afterEnd ? afterEnd.line : lines.length; + var trailingGap = afterEndLine - trueLoc.end.line; + trailingSpace = Array(trailingGap + 1).join("\n"); + } else { + trailingSpace = multiLine ? "\n\n" : "\n"; + } + } else { + trailingSpace = ""; + } + + parts.push( + maxSpace(prevTrailingSpace, leadingSpace), + printed + ); + + if (notLast) { + prevTrailingSpace = trailingSpace; + } else if (trailingSpace) { + parts.push(trailingSpace); + } + }); + + return concat(parts); +} + +function maxSpace(s1, s2) { + if (!s1 && !s2) { + return fromString(""); + } + + if (!s1) { + return fromString(s2); + } + + if (!s2) { + return fromString(s1); + } + + var spaceLines1 = fromString(s1); + var spaceLines2 = fromString(s2); + + if (spaceLines2.length > spaceLines1.length) { + return spaceLines2; + } + + return spaceLines1; +} + +function printMethod(path, options, print) { + var node = path.getNode(); + var kind = node.kind; + var parts = []; + + namedTypes.FunctionExpression.assert(node.value); + + if (node.decorators) { + path.each(function(decoratorPath) { + parts.push(print(decoratorPath), "\n"); + }, "decorators"); + } + + if (node.value.async) { + parts.push("async "); + } + + if (!kind || kind === "init" || kind === "method" || kind === "constructor") { + if (node.value.generator) { + parts.push("*"); + } + } else { + assert.ok(kind === "get" || kind === "set"); + parts.push(kind, " "); + } + + var key = path.call(print, "key"); + if (node.computed) { + key = concat(["[", key, "]"]); + } + + parts.push( + key, + path.call(print, "value", "typeParameters"), + "(", + path.call(function(valuePath) { + return printFunctionParams(valuePath, options, print); + }, "value"), + ")", + path.call(print, "value", "returnType"), + " ", + path.call(print, "value", "body") + ); + + return concat(parts); +} + +function printArgumentsList(path, options, print) { + var printed = path.map(print, "arguments"); + + var joined = fromString(", ").join(printed); + if (joined.getLineLength(1) > options.wrapColumn) { + joined = fromString(",\n").join(printed); + return concat([ + "(\n", + joined.indent(options.tabWidth), + options.trailingComma ? ",\n)" : "\n)" + ]); + } + + return concat(["(", joined, ")"]); +} + +function printFunctionParams(path, options, print) { + var fun = path.getValue(); + namedTypes.Function.assert(fun); + + var printed = path.map(print, "params"); + + if (fun.defaults) { + path.each(function(defExprPath) { + var i = defExprPath.getName(); + var p = printed[i]; + if (p && defExprPath.getValue()) { + printed[i] = concat([p, "=", print(defExprPath)]); + } + }, "defaults"); + } + + if (fun.rest) { + printed.push(concat(["...", path.call(print, "rest")])); + } + + var joined = fromString(", ").join(printed); + if (joined.length > 1 || + joined.getLineLength(1) > options.wrapColumn) { + joined = fromString(",\n").join(printed); + if (options.trailingComma && !fun.rest) { + joined = concat([joined, ",\n"]); + } + return concat(["\n", joined.indent(options.tabWidth)]); + } + + return joined; +} + +function adjustClause(clause, options) { + if (clause.length > 1) + return concat([" ", clause]); + + return concat([ + "\n", + maybeAddSemicolon(clause).indent(options.tabWidth) + ]); +} + +function lastNonSpaceCharacter(lines) { + var pos = lines.lastPos(); + do { + var ch = lines.charAt(pos); + if (/\S/.test(ch)) + return ch; + } while (lines.prevPos(pos)); +} + +function endsWithBrace(lines) { + return lastNonSpaceCharacter(lines) === "}"; +} + +function swapQuotes(str) { + return str.replace(/['"]/g, function(m) { + return m === '"' ? '\'' : '"'; + }); +} + +function nodeStr(str, options) { + isString.assert(str); + switch (options.quote) { + case "auto": + var double = JSON.stringify(str); + var single = swapQuotes(JSON.stringify(swapQuotes(str))); + return double.length > single.length ? single : double; + case "single": + return swapQuotes(JSON.stringify(swapQuotes(str))); + case "double": + default: + return JSON.stringify(str); + } +} + +function maybeAddSemicolon(lines) { + var eoc = lastNonSpaceCharacter(lines); + if (!eoc || "\n};".indexOf(eoc) < 0) + return concat([lines, ";"]); + return lines; +} + +},{"1":1,"558":558,"559":559,"560":560,"562":562,"564":564,"566":566,"567":567,"607":607}],566:[function(_dereq_,module,exports){ +// This module was originally created so that Recast could add its own +// custom types to the AST type system (in particular, the File type), but +// those types are now incorporated into ast-types, so this module doesn't +// have much to do anymore. Still, it might prove useful in the future. +module.exports = _dereq_(584); + +},{"584":584}],567:[function(_dereq_,module,exports){ +var assert = _dereq_(1); +var types = _dereq_(566); +var getFieldValue = types.getFieldValue; +var n = types.namedTypes; +var sourceMap = _dereq_(607); +var SourceMapConsumer = sourceMap.SourceMapConsumer; +var SourceMapGenerator = sourceMap.SourceMapGenerator; +var hasOwn = Object.prototype.hasOwnProperty; + +function getUnionOfKeys() { + var result = {}; + var argc = arguments.length; + for (var i = 0; i < argc; ++i) { + var keys = Object.keys(arguments[i]); + var keyCount = keys.length; + for (var j = 0; j < keyCount; ++j) { + result[keys[j]] = true; + } + } + return result; +} +exports.getUnionOfKeys = getUnionOfKeys; + +function comparePos(pos1, pos2) { + return (pos1.line - pos2.line) || (pos1.column - pos2.column); +} +exports.comparePos = comparePos; + +function copyPos(pos) { + return { + line: pos.line, + column: pos.column + }; +} +exports.copyPos = copyPos; + +exports.composeSourceMaps = function(formerMap, latterMap) { + if (formerMap) { + if (!latterMap) { + return formerMap; + } + } else { + return latterMap || null; + } + + var smcFormer = new SourceMapConsumer(formerMap); + var smcLatter = new SourceMapConsumer(latterMap); + var smg = new SourceMapGenerator({ + file: latterMap.file, + sourceRoot: latterMap.sourceRoot + }); + + var sourcesToContents = {}; + + smcLatter.eachMapping(function(mapping) { + var origPos = smcFormer.originalPositionFor({ + line: mapping.originalLine, + column: mapping.originalColumn + }); + + var sourceName = origPos.source; + if (sourceName === null) { + return; + } + + smg.addMapping({ + source: sourceName, + original: copyPos(origPos), + generated: { + line: mapping.generatedLine, + column: mapping.generatedColumn + }, + name: mapping.name + }); + + var sourceContent = smcFormer.sourceContentFor(sourceName); + if (sourceContent && !hasOwn.call(sourcesToContents, sourceName)) { + sourcesToContents[sourceName] = sourceContent; + smg.setSourceContent(sourceName, sourceContent); + } + }); + + return smg.toJSON(); +}; + +exports.getTrueLoc = function(node, lines) { + // It's possible that node is newly-created (not parsed by Esprima), + // in which case it probably won't have a .loc property (or an + // .original property for that matter). That's fine; we'll just + // pretty-print it as usual. + if (!node.loc) { + return null; + } + + var start = node.loc.start; + var end = node.loc.end; + + // If the node has any comments, their locations might contribute to + // the true start/end positions of the node. + if (node.comments) { + node.comments.forEach(function(comment) { + if (comment.loc) { + if (comparePos(comment.loc.start, start) < 0) { + start = comment.loc.start; + } + + if (comparePos(end, comment.loc.end) < 0) { + end = comment.loc.end; + } + } + }); + } + + return { + // Finally, trim any leading or trailing whitespace from the true + // location of the node. + start: lines.skipSpaces(start, false, false), + end: lines.skipSpaces(end, true, false) + }; +}; + +exports.fixFaultyLocations = function(node) { + if ((n.MethodDefinition && n.MethodDefinition.check(node)) || + (n.Property.check(node) && (node.method || node.shorthand))) { + // If the node is a MethodDefinition or a .method or .shorthand + // Property, then the location information stored in + // node.value.loc is very likely untrustworthy (just the {body} + // part of a method, or nothing in the case of shorthand + // properties), so we null out that information to prevent + // accidental reuse of bogus source code during reprinting. + node.value.loc = null; + + if (n.FunctionExpression.check(node.value)) { + // FunctionExpression method values should be anonymous, + // because their .id fields are ignored anyway. + node.value.id = null; + } + } + + var loc = node.loc; + if (loc) { + if (loc.start.line < 1) { + loc.start.line = 1; + } + + if (loc.end.line < 1) { + loc.end.line = 1; + } + } +}; + +},{"1":1,"566":566,"607":607}],568:[function(_dereq_,module,exports){ +(function (process){ +var types = _dereq_(566); +var parse = _dereq_(563).parse; +var Printer = _dereq_(565).Printer; + +function print(node, options) { + return new Printer(options).print(node); +} + +function prettyPrint(node, options) { + return new Printer(options).printGenerically(node); +} + +function run(transformer, options) { + return runFile(process.argv[2], transformer, options); +} + +function runFile(path, transformer, options) { + _dereq_(3).readFile(path, "utf-8", function(err, code) { + if (err) { + console.error(err); + return; + } + + runString(code, transformer, options); + }); +} + +function defaultWriteback(output) { + process.stdout.write(output); +} + +function runString(code, transformer, options) { + var writeback = options && options.writeback || defaultWriteback; + transformer(parse(code, options), function(node) { + writeback(print(node, options).code); + }); +} + +Object.defineProperties(exports, { + /** + * Parse a string of code into an augmented syntax tree suitable for + * arbitrary modification and reprinting. + */ + parse: { + enumerable: true, + value: parse + }, + + /** + * Traverse and potentially modify an abstract syntax tree using a + * convenient visitor syntax: + * + * recast.visit(ast, { + * names: [], + * visitIdentifier: function(path) { + * var node = path.value; + * this.visitor.names.push(node.name); + * this.traverse(path); + * } + * }); + */ + visit: { + enumerable: true, + value: types.visit + }, + + /** + * Reprint a modified syntax tree using as much of the original source + * code as possible. + */ + print: { + enumerable: true, + value: print + }, + + /** + * Print without attempting to reuse any original source code. + */ + prettyPrint: { + enumerable: false, + value: prettyPrint + }, + + /** + * Customized version of require("ast-types"). + */ + types: { + enumerable: false, + value: types + }, + + /** + * Convenient command-line interface (see e.g. example/add-braces). + */ + run: { + enumerable: false, + value: run + } +}); + +}).call(this,_dereq_(10)) +},{"10":10,"3":3,"563":563,"565":565,"566":566}],569:[function(_dereq_,module,exports){ +_dereq_(573); + +var types = _dereq_(583); +var defaults = _dereq_(582).defaults; +var def = types.Type.def; +var or = types.Type.or; + +def("Noop") + .bases("Node") + .build(); + +def("DoExpression") + .bases("Expression") + .build("body") + .field("body", [def("Statement")]); + +def("Super") + .bases("Expression") + .build(); + +def("BindExpression") + .bases("Expression") + .build("object", "callee") + .field("object", or(def("Expression"), null)) + .field("callee", def("Expression")); + +def("Decorator") + .bases("Node") + .build("expression") + .field("expression", def("Expression")); + +def("Property") + .field("decorators", + or([def("Decorator")], null), + defaults["null"]); + +def("MethodDefinition") + .field("decorators", + or([def("Decorator")], null), + defaults["null"]); + +def("MetaProperty") + .bases("Expression") + .build("meta", "property") + .field("meta", def("Identifier")) + .field("property", def("Identifier")); + +def("ParenthesizedExpression") + .bases("Expression") + .build("expression") + .field("expression", def("Expression")); + +def("ImportSpecifier") + .bases("ModuleSpecifier") + .build("imported", "local") + .field("imported", def("Identifier")); + +def("ImportDefaultSpecifier") + .bases("ModuleSpecifier") + .build("local"); + +def("ImportNamespaceSpecifier") + .bases("ModuleSpecifier") + .build("local"); + +def("ExportDefaultDeclaration") + .bases("Declaration") + .build("declaration") + .field("declaration", or(def("Declaration"), def("Expression"))); + +def("ExportNamedDeclaration") + .bases("Declaration") + .build("declaration", "specifiers", "source") + .field("declaration", or(def("Declaration"), null)) + .field("specifiers", [def("ExportSpecifier")], defaults.emptyArray) + .field("source", or(def("Literal"), null), defaults["null"]); + +def("ExportSpecifier") + .bases("ModuleSpecifier") + .build("local", "exported") + .field("exported", def("Identifier")); + +def("ExportNamespaceSpecifier") + .bases("Specifier") + .build("exported") + .field("exported", def("Identifier")); + +def("ExportDefaultSpecifier") + .bases("Specifier") + .build("exported") + .field("exported", def("Identifier")); + +def("ExportAllDeclaration") + .bases("Declaration") + .build("exported", "source") + .field("exported", or(def("Identifier"), null)) + .field("source", def("Literal")); + +def("CommentBlock") + .bases("Comment") + .build("value", /*optional:*/ "leading", "trailing"); + +def("CommentLine") + .bases("Comment") + .build("value", /*optional:*/ "leading", "trailing"); + +},{"573":573,"582":582,"583":583}],570:[function(_dereq_,module,exports){ +var types = _dereq_(583); +var Type = types.Type; +var def = Type.def; +var or = Type.or; +var shared = _dereq_(582); +var defaults = shared.defaults; +var geq = shared.geq; + +// Abstract supertype of all syntactic entities that are allowed to have a +// .loc field. +def("Printable") + .field("loc", or( + def("SourceLocation"), + null + ), defaults["null"], true); + +def("Node") + .bases("Printable") + .field("type", String) + .field("comments", or( + [def("Comment")], + null + ), defaults["null"], true); + +def("SourceLocation") + .build("start", "end", "source") + .field("start", def("Position")) + .field("end", def("Position")) + .field("source", or(String, null), defaults["null"]); + +def("Position") + .build("line", "column") + .field("line", geq(1)) + .field("column", geq(0)); + +def("File") + .bases("Node") + .build("program") + .field("program", def("Program")); + +def("Program") + .bases("Node") + .build("body") + .field("body", [def("Statement")]); + +def("Function") + .bases("Node") + .field("id", or(def("Identifier"), null), defaults["null"]) + .field("params", [def("Pattern")]) + .field("body", def("BlockStatement")); + +def("Statement").bases("Node"); + +// The empty .build() here means that an EmptyStatement can be constructed +// (i.e. it's not abstract) but that it needs no arguments. +def("EmptyStatement").bases("Statement").build(); + +def("BlockStatement") + .bases("Statement") + .build("body") + .field("body", [def("Statement")]); + +// TODO Figure out how to silently coerce Expressions to +// ExpressionStatements where a Statement was expected. +def("ExpressionStatement") + .bases("Statement") + .build("expression") + .field("expression", def("Expression")); + +def("IfStatement") + .bases("Statement") + .build("test", "consequent", "alternate") + .field("test", def("Expression")) + .field("consequent", def("Statement")) + .field("alternate", or(def("Statement"), null), defaults["null"]); + +def("LabeledStatement") + .bases("Statement") + .build("label", "body") + .field("label", def("Identifier")) + .field("body", def("Statement")); + +def("BreakStatement") + .bases("Statement") + .build("label") + .field("label", or(def("Identifier"), null), defaults["null"]); + +def("ContinueStatement") + .bases("Statement") + .build("label") + .field("label", or(def("Identifier"), null), defaults["null"]); + +def("WithStatement") + .bases("Statement") + .build("object", "body") + .field("object", def("Expression")) + .field("body", def("Statement")); + +def("SwitchStatement") + .bases("Statement") + .build("discriminant", "cases", "lexical") + .field("discriminant", def("Expression")) + .field("cases", [def("SwitchCase")]) + .field("lexical", Boolean, defaults["false"]); + +def("ReturnStatement") + .bases("Statement") + .build("argument") + .field("argument", or(def("Expression"), null)); + +def("ThrowStatement") + .bases("Statement") + .build("argument") + .field("argument", def("Expression")); + +def("TryStatement") + .bases("Statement") + .build("block", "handler", "finalizer") + .field("block", def("BlockStatement")) + .field("handler", or(def("CatchClause"), null), function() { + return this.handlers && this.handlers[0] || null; + }) + .field("handlers", [def("CatchClause")], function() { + return this.handler ? [this.handler] : []; + }, true) // Indicates this field is hidden from eachField iteration. + .field("guardedHandlers", [def("CatchClause")], defaults.emptyArray) + .field("finalizer", or(def("BlockStatement"), null), defaults["null"]); + +def("CatchClause") + .bases("Node") + .build("param", "guard", "body") + .field("param", def("Pattern")) + .field("guard", or(def("Expression"), null), defaults["null"]) + .field("body", def("BlockStatement")); + +def("WhileStatement") + .bases("Statement") + .build("test", "body") + .field("test", def("Expression")) + .field("body", def("Statement")); + +def("DoWhileStatement") + .bases("Statement") + .build("body", "test") + .field("body", def("Statement")) + .field("test", def("Expression")); + +def("ForStatement") + .bases("Statement") + .build("init", "test", "update", "body") + .field("init", or( + def("VariableDeclaration"), + def("Expression"), + null)) + .field("test", or(def("Expression"), null)) + .field("update", or(def("Expression"), null)) + .field("body", def("Statement")); + +def("ForInStatement") + .bases("Statement") + .build("left", "right", "body") + .field("left", or( + def("VariableDeclaration"), + def("Expression"))) + .field("right", def("Expression")) + .field("body", def("Statement")); + +def("DebuggerStatement").bases("Statement").build(); + +def("Declaration").bases("Statement"); + +def("FunctionDeclaration") + .bases("Function", "Declaration") + .build("id", "params", "body") + .field("id", def("Identifier")); + +def("FunctionExpression") + .bases("Function", "Expression") + .build("id", "params", "body"); + +def("VariableDeclaration") + .bases("Declaration") + .build("kind", "declarations") + .field("kind", or("var", "let", "const")) + .field("declarations", [def("VariableDeclarator")]); + +def("VariableDeclarator") + .bases("Node") + .build("id", "init") + .field("id", def("Pattern")) + .field("init", or(def("Expression"), null)); + +// TODO Are all Expressions really Patterns? +def("Expression").bases("Node", "Pattern"); + +def("ThisExpression").bases("Expression").build(); + +def("ArrayExpression") + .bases("Expression") + .build("elements") + .field("elements", [or(def("Expression"), null)]); + +def("ObjectExpression") + .bases("Expression") + .build("properties") + .field("properties", [def("Property")]); + +// TODO Not in the Mozilla Parser API, but used by Esprima. +def("Property") + .bases("Node") // Want to be able to visit Property Nodes. + .build("kind", "key", "value") + .field("kind", or("init", "get", "set")) + .field("key", or(def("Literal"), def("Identifier"))) + .field("value", def("Expression")); + +def("SequenceExpression") + .bases("Expression") + .build("expressions") + .field("expressions", [def("Expression")]); + +var UnaryOperator = or( + "-", "+", "!", "~", + "typeof", "void", "delete"); + +def("UnaryExpression") + .bases("Expression") + .build("operator", "argument", "prefix") + .field("operator", UnaryOperator) + .field("argument", def("Expression")) + // Esprima doesn't bother with this field, presumably because it's + // always true for unary operators. + .field("prefix", Boolean, defaults["true"]); + +var BinaryOperator = or( + "==", "!=", "===", "!==", + "<", "<=", ">", ">=", + "<<", ">>", ">>>", + "+", "-", "*", "/", "%", + "&", // TODO Missing from the Parser API. + "|", "^", "in", + "instanceof", ".."); + +def("BinaryExpression") + .bases("Expression") + .build("operator", "left", "right") + .field("operator", BinaryOperator) + .field("left", def("Expression")) + .field("right", def("Expression")); + +var AssignmentOperator = or( + "=", "+=", "-=", "*=", "/=", "%=", + "<<=", ">>=", ">>>=", + "|=", "^=", "&="); + +def("AssignmentExpression") + .bases("Expression") + .build("operator", "left", "right") + .field("operator", AssignmentOperator) + .field("left", def("Pattern")) + .field("right", def("Expression")); + +var UpdateOperator = or("++", "--"); + +def("UpdateExpression") + .bases("Expression") + .build("operator", "argument", "prefix") + .field("operator", UpdateOperator) + .field("argument", def("Expression")) + .field("prefix", Boolean); + +var LogicalOperator = or("||", "&&"); + +def("LogicalExpression") + .bases("Expression") + .build("operator", "left", "right") + .field("operator", LogicalOperator) + .field("left", def("Expression")) + .field("right", def("Expression")); + +def("ConditionalExpression") + .bases("Expression") + .build("test", "consequent", "alternate") + .field("test", def("Expression")) + .field("consequent", def("Expression")) + .field("alternate", def("Expression")); + +def("NewExpression") + .bases("Expression") + .build("callee", "arguments") + .field("callee", def("Expression")) + // The Mozilla Parser API gives this type as [or(def("Expression"), + // null)], but null values don't really make sense at the call site. + // TODO Report this nonsense. + .field("arguments", [def("Expression")]); + +def("CallExpression") + .bases("Expression") + .build("callee", "arguments") + .field("callee", def("Expression")) + // See comment for NewExpression above. + .field("arguments", [def("Expression")]); + +def("MemberExpression") + .bases("Expression") + .build("object", "property", "computed") + .field("object", def("Expression")) + .field("property", or(def("Identifier"), def("Expression"))) + .field("computed", Boolean, defaults["false"]); + +def("Pattern").bases("Node"); + +def("SwitchCase") + .bases("Node") + .build("test", "consequent") + .field("test", or(def("Expression"), null)) + .field("consequent", [def("Statement")]); + +def("Identifier") + // But aren't Expressions and Patterns already Nodes? TODO Report this. + .bases("Node", "Expression", "Pattern") + .build("name") + .field("name", String); + +def("Literal") + // But aren't Expressions already Nodes? TODO Report this. + .bases("Node", "Expression") + .build("value") + .field("value", or(String, Boolean, null, Number, RegExp)) + .field("regex", or({ + pattern: String, + flags: String + }, null), function() { + if (this.value instanceof RegExp) { + var flags = ""; + + if (this.value.ignoreCase) flags += "i"; + if (this.value.multiline) flags += "m"; + if (this.value.global) flags += "g"; + + return { + pattern: this.value.source, + flags: flags + }; + } + + return null; + }); + +// Abstract (non-buildable) comment supertype. Not a Node. +def("Comment") + .bases("Printable") + .field("value", String) + // A .leading comment comes before the node, whereas a .trailing + // comment comes after it. These two fields should not both be true, + // but they might both be false when the comment falls inside a node + // and the node has no children for the comment to lead or trail, + // e.g. { /*dangling*/ }. + .field("leading", Boolean, defaults["true"]) + .field("trailing", Boolean, defaults["false"]); + +},{"582":582,"583":583}],571:[function(_dereq_,module,exports){ +_dereq_(570); +var types = _dereq_(583); +var def = types.Type.def; +var or = types.Type.or; + +// Note that none of these types are buildable because the Mozilla Parser +// API doesn't specify any builder functions, and nobody uses E4X anymore. + +def("XMLDefaultDeclaration") + .bases("Declaration") + .field("namespace", def("Expression")); + +def("XMLAnyName").bases("Expression"); + +def("XMLQualifiedIdentifier") + .bases("Expression") + .field("left", or(def("Identifier"), def("XMLAnyName"))) + .field("right", or(def("Identifier"), def("Expression"))) + .field("computed", Boolean); + +def("XMLFunctionQualifiedIdentifier") + .bases("Expression") + .field("right", or(def("Identifier"), def("Expression"))) + .field("computed", Boolean); + +def("XMLAttributeSelector") + .bases("Expression") + .field("attribute", def("Expression")); + +def("XMLFilterExpression") + .bases("Expression") + .field("left", def("Expression")) + .field("right", def("Expression")); + +def("XMLElement") + .bases("XML", "Expression") + .field("contents", [def("XML")]); + +def("XMLList") + .bases("XML", "Expression") + .field("contents", [def("XML")]); + +def("XML").bases("Node"); + +def("XMLEscape") + .bases("XML") + .field("expression", def("Expression")); + +def("XMLText") + .bases("XML") + .field("text", String); + +def("XMLStartTag") + .bases("XML") + .field("contents", [def("XML")]); + +def("XMLEndTag") + .bases("XML") + .field("contents", [def("XML")]); + +def("XMLPointTag") + .bases("XML") + .field("contents", [def("XML")]); + +def("XMLName") + .bases("XML") + .field("contents", or(String, [def("XML")])); + +def("XMLAttribute") + .bases("XML") + .field("value", String); + +def("XMLCdata") + .bases("XML") + .field("contents", String); + +def("XMLComment") + .bases("XML") + .field("contents", String); + +def("XMLProcessingInstruction") + .bases("XML") + .field("target", String) + .field("contents", or(String, null)); + +},{"570":570,"583":583}],572:[function(_dereq_,module,exports){ +_dereq_(570); +var types = _dereq_(583); +var def = types.Type.def; +var or = types.Type.or; +var defaults = _dereq_(582).defaults; + +def("Function") + .field("generator", Boolean, defaults["false"]) + .field("expression", Boolean, defaults["false"]) + .field("defaults", [or(def("Expression"), null)], defaults.emptyArray) + // TODO This could be represented as a RestElement in .params. + .field("rest", or(def("Identifier"), null), defaults["null"]); + +// The ESTree way of representing a ...rest parameter. +def("RestElement") + .bases("Pattern") + .build("argument") + .field("argument", def("Pattern")); + +def("SpreadElementPattern") + .bases("Pattern") + .build("argument") + .field("argument", def("Pattern")); + +def("FunctionDeclaration") + .build("id", "params", "body", "generator", "expression"); + +def("FunctionExpression") + .build("id", "params", "body", "generator", "expression"); + +// The Parser API calls this ArrowExpression, but Esprima and all other +// actual parsers use ArrowFunctionExpression. +def("ArrowFunctionExpression") + .bases("Function", "Expression") + .build("params", "body", "expression") + // The forced null value here is compatible with the overridden + // definition of the "id" field in the Function interface. + .field("id", null, defaults["null"]) + // Arrow function bodies are allowed to be expressions. + .field("body", or(def("BlockStatement"), def("Expression"))) + // The current spec forbids arrow generators, so I have taken the + // liberty of enforcing that. TODO Report this. + .field("generator", false, defaults["false"]); + +def("YieldExpression") + .bases("Expression") + .build("argument", "delegate") + .field("argument", or(def("Expression"), null)) + .field("delegate", Boolean, defaults["false"]); + +def("GeneratorExpression") + .bases("Expression") + .build("body", "blocks", "filter") + .field("body", def("Expression")) + .field("blocks", [def("ComprehensionBlock")]) + .field("filter", or(def("Expression"), null)); + +def("ComprehensionExpression") + .bases("Expression") + .build("body", "blocks", "filter") + .field("body", def("Expression")) + .field("blocks", [def("ComprehensionBlock")]) + .field("filter", or(def("Expression"), null)); + +def("ComprehensionBlock") + .bases("Node") + .build("left", "right", "each") + .field("left", def("Pattern")) + .field("right", def("Expression")) + .field("each", Boolean); + +def("Property") + .field("key", or(def("Literal"), def("Identifier"), def("Expression"))) + .field("value", or(def("Expression"), def("Pattern"))) + .field("method", Boolean, defaults["false"]) + .field("shorthand", Boolean, defaults["false"]) + .field("computed", Boolean, defaults["false"]); + +def("PropertyPattern") + .bases("Pattern") + .build("key", "pattern") + .field("key", or(def("Literal"), def("Identifier"), def("Expression"))) + .field("pattern", def("Pattern")) + .field("computed", Boolean, defaults["false"]); + +def("ObjectPattern") + .bases("Pattern") + .build("properties") + .field("properties", [or(def("PropertyPattern"), def("Property"))]); + +def("ArrayPattern") + .bases("Pattern") + .build("elements") + .field("elements", [or(def("Pattern"), null)]); + +def("MethodDefinition") + .bases("Declaration") + .build("kind", "key", "value", "static") + .field("kind", or("constructor", "method", "get", "set")) + .field("key", or(def("Literal"), def("Identifier"), def("Expression"))) + .field("value", def("Function")) + .field("computed", Boolean, defaults["false"]) + .field("static", Boolean, defaults["false"]); + +def("SpreadElement") + .bases("Node") + .build("argument") + .field("argument", def("Expression")); + +def("ArrayExpression") + .field("elements", [or( + def("Expression"), + def("SpreadElement"), + def("RestElement"), + null + )]); + +def("NewExpression") + .field("arguments", [or(def("Expression"), def("SpreadElement"))]); + +def("CallExpression") + .field("arguments", [or(def("Expression"), def("SpreadElement"))]); + +// Note: this node type is *not* an AssignmentExpression with a Pattern on +// the left-hand side! The existing AssignmentExpression type already +// supports destructuring assignments. AssignmentPattern nodes may appear +// wherever a Pattern is allowed, and the right-hand side represents a +// default value to be destructured against the left-hand side, if no +// value is otherwise provided. For example: default parameter values. +def("AssignmentPattern") + .bases("Pattern") + .build("left", "right") + .field("left", def("Pattern")) + .field("right", def("Expression")); + +var ClassBodyElement = or( + def("MethodDefinition"), + def("VariableDeclarator"), + def("ClassPropertyDefinition"), + def("ClassProperty") +); + +def("ClassProperty") + .bases("Declaration") + .build("key") + .field("key", or(def("Literal"), def("Identifier"), def("Expression"))) + .field("computed", Boolean, defaults["false"]); + +def("ClassPropertyDefinition") // static property + .bases("Declaration") + .build("definition") + // Yes, Virginia, circular definitions are permitted. + .field("definition", ClassBodyElement); + +def("ClassBody") + .bases("Declaration") + .build("body") + .field("body", [ClassBodyElement]); + +def("ClassDeclaration") + .bases("Declaration") + .build("id", "body", "superClass") + .field("id", or(def("Identifier"), null)) + .field("body", def("ClassBody")) + .field("superClass", or(def("Expression"), null), defaults["null"]); + +def("ClassExpression") + .bases("Expression") + .build("id", "body", "superClass") + .field("id", or(def("Identifier"), null), defaults["null"]) + .field("body", def("ClassBody")) + .field("superClass", or(def("Expression"), null), defaults["null"]) + .field("implements", [def("ClassImplements")], defaults.emptyArray); + +def("ClassImplements") + .bases("Node") + .build("id") + .field("id", def("Identifier")) + .field("superClass", or(def("Expression"), null), defaults["null"]); + +// Specifier and ModuleSpecifier are abstract non-standard types +// introduced for definitional convenience. +def("Specifier").bases("Node"); + +// This supertype is shared/abused by both def/babel.js and +// def/esprima.js. In the future, it will be possible to load only one set +// of definitions appropriate for a given parser, but until then we must +// rely on default functions to reconcile the conflicting AST formats. +def("ModuleSpecifier") + .bases("Specifier") + // This local field is used by Babel/Acorn. It should not technically + // be optional in the Babel/Acorn AST format, but it must be optional + // in the Esprima AST format. + .field("local", or(def("Identifier"), null), defaults["null"]) + // The id and name fields are used by Esprima. The id field should not + // technically be optional in the Esprima AST format, but it must be + // optional in the Babel/Acorn AST format. + .field("id", or(def("Identifier"), null), defaults["null"]) + .field("name", or(def("Identifier"), null), defaults["null"]); + +def("TaggedTemplateExpression") + .bases("Expression") + .build("tag", "quasi") + .field("tag", def("Expression")) + .field("quasi", def("TemplateLiteral")); + +def("TemplateLiteral") + .bases("Expression") + .build("quasis", "expressions") + .field("quasis", [def("TemplateElement")]) + .field("expressions", [def("Expression")]); + +def("TemplateElement") + .bases("Node") + .build("value", "tail") + .field("value", {"cooked": String, "raw": String}) + .field("tail", Boolean); + +},{"570":570,"582":582,"583":583}],573:[function(_dereq_,module,exports){ +_dereq_(572); + +var types = _dereq_(583); +var def = types.Type.def; +var or = types.Type.or; +var builtin = types.builtInTypes; +var defaults = _dereq_(582).defaults; + +def("Function") + .field("async", Boolean, defaults["false"]); + +def("SpreadProperty") + .bases("Node") + .build("argument") + .field("argument", def("Expression")); + +def("ObjectExpression") + .field("properties", [or(def("Property"), def("SpreadProperty"))]); + +def("SpreadPropertyPattern") + .bases("Pattern") + .build("argument") + .field("argument", def("Pattern")); + +def("ObjectPattern") + .field("properties", [or( + def("Property"), + def("PropertyPattern"), + def("SpreadPropertyPattern") + )]); + +def("AwaitExpression") + .bases("Expression") + .build("argument", "all") + .field("argument", or(def("Expression"), null)) + .field("all", Boolean, defaults["false"]); + +},{"572":572,"582":582,"583":583}],574:[function(_dereq_,module,exports){ +_dereq_(573); + +var types = _dereq_(583); +var defaults = _dereq_(582).defaults; +var def = types.Type.def; +var or = types.Type.or; + +def("VariableDeclaration") + .field("declarations", [or( + def("VariableDeclarator"), + def("Identifier") // Esprima deviation. + )]); + +def("Property") + .field("value", or( + def("Expression"), + def("Pattern") // Esprima deviation. + )); + +def("ArrayPattern") + .field("elements", [or( + def("Pattern"), + def("SpreadElement"), + null + )]); + +def("ObjectPattern") + .field("properties", [or( + def("Property"), + def("PropertyPattern"), + def("SpreadPropertyPattern"), + def("SpreadProperty") // Used by Esprima. + )]); + +// Like ModuleSpecifier, except type:"ExportSpecifier" and buildable. +// export {} [from ...]; +def("ExportSpecifier") + .bases("ModuleSpecifier") + .build("id", "name"); + +// export <*> from ...; +def("ExportBatchSpecifier") + .bases("Specifier") + .build(); + +// Like ModuleSpecifier, except type:"ImportSpecifier" and buildable. +// import {} from ...; +def("ImportSpecifier") + .bases("ModuleSpecifier") + .build("id", "name"); + +// import <* as id> from ...; +def("ImportNamespaceSpecifier") + .bases("ModuleSpecifier") + .build("id"); + +// import from ...; +def("ImportDefaultSpecifier") + .bases("ModuleSpecifier") + .build("id"); + +def("ExportDeclaration") + .bases("Declaration") + .build("default", "declaration", "specifiers", "source") + .field("default", Boolean) + .field("declaration", or( + def("Declaration"), + def("Expression"), // Implies default. + null + )) + .field("specifiers", [or( + def("ExportSpecifier"), + def("ExportBatchSpecifier") + )], defaults.emptyArray) + .field("source", or( + def("Literal"), + null + ), defaults["null"]); + +def("ImportDeclaration") + .bases("Declaration") + .build("specifiers", "source") + .field("specifiers", [or( + def("ImportSpecifier"), + def("ImportNamespaceSpecifier"), + def("ImportDefaultSpecifier") + )], defaults.emptyArray) + .field("source", def("Literal")); + +def("Block") + .bases("Comment") + .build("value", /*optional:*/ "leading", "trailing"); + +def("Line") + .bases("Comment") + .build("value", /*optional:*/ "leading", "trailing"); + +},{"573":573,"582":582,"583":583}],575:[function(_dereq_,module,exports){ +_dereq_(573); + +var types = _dereq_(583); +var def = types.Type.def; +var or = types.Type.or; +var defaults = _dereq_(582).defaults; + +def("JSXAttribute") + .bases("Node") + .build("name", "value") + .field("name", or(def("JSXIdentifier"), def("JSXNamespacedName"))) + .field("value", or( + def("Literal"), // attr="value" + def("JSXExpressionContainer"), // attr={value} + null // attr= or just attr + ), defaults["null"]); + +def("JSXIdentifier") + .bases("Identifier") + .build("name") + .field("name", String); + +def("JSXNamespacedName") + .bases("Node") + .build("namespace", "name") + .field("namespace", def("JSXIdentifier")) + .field("name", def("JSXIdentifier")); + +def("JSXMemberExpression") + .bases("MemberExpression") + .build("object", "property") + .field("object", or(def("JSXIdentifier"), def("JSXMemberExpression"))) + .field("property", def("JSXIdentifier")) + .field("computed", Boolean, defaults.false); + +var JSXElementName = or( + def("JSXIdentifier"), + def("JSXNamespacedName"), + def("JSXMemberExpression") +); + +def("JSXSpreadAttribute") + .bases("Node") + .build("argument") + .field("argument", def("Expression")); + +var JSXAttributes = [or( + def("JSXAttribute"), + def("JSXSpreadAttribute") +)]; + +def("JSXExpressionContainer") + .bases("Expression") + .build("expression") + .field("expression", def("Expression")); + +def("JSXElement") + .bases("Expression") + .build("openingElement", "closingElement", "children") + .field("openingElement", def("JSXOpeningElement")) + .field("closingElement", or(def("JSXClosingElement"), null), defaults["null"]) + .field("children", [or( + def("JSXElement"), + def("JSXExpressionContainer"), + def("JSXText"), + def("Literal") // TODO Esprima should return JSXText instead. + )], defaults.emptyArray) + .field("name", JSXElementName, function() { + // Little-known fact: the `this` object inside a default function + // is none other than the partially-built object itself, and any + // fields initialized directly from builder function arguments + // (like openingElement, closingElement, and children) are + // guaranteed to be available. + return this.openingElement.name; + }, true) // hidden from traversal + .field("selfClosing", Boolean, function() { + return this.openingElement.selfClosing; + }, true) // hidden from traversal + .field("attributes", JSXAttributes, function() { + return this.openingElement.attributes; + }, true); // hidden from traversal + +def("JSXOpeningElement") + .bases("Node") // TODO Does this make sense? Can't really be an JSXElement. + .build("name", "attributes", "selfClosing") + .field("name", JSXElementName) + .field("attributes", JSXAttributes, defaults.emptyArray) + .field("selfClosing", Boolean, defaults["false"]); + +def("JSXClosingElement") + .bases("Node") // TODO Same concern. + .build("name") + .field("name", JSXElementName); + +def("JSXText") + .bases("Literal") + .build("value") + .field("value", String); + +def("JSXEmptyExpression").bases("Expression").build(); + +// Type Annotations +def("Type").bases("Node"); + +def("AnyTypeAnnotation") + .bases("Type") + .build(); + +def("MixedTypeAnnotation") + .bases("Type") + .build(); + +def("VoidTypeAnnotation") + .bases("Type") + .build(); + +def("NumberTypeAnnotation") + .bases("Type") + .build(); + +def("NumberLiteralTypeAnnotation") + .bases("Type") + .build("value", "raw") + .field("value", Number) + .field("raw", String); + +def("StringTypeAnnotation") + .bases("Type") + .build(); + +def("StringLiteralTypeAnnotation") + .bases("Type") + .build("value", "raw") + .field("value", String) + .field("raw", String); + +def("BooleanTypeAnnotation") + .bases("Type") + .build(); + +def("BooleanLiteralTypeAnnotation") + .bases("Type") + .build("value", "raw") + .field("value", Boolean) + .field("raw", String); + +def("TypeAnnotation") + .bases("Node") + .build("typeAnnotation") + .field("typeAnnotation", def("Type")); + +def("NullableTypeAnnotation") + .bases("Type") + .build("typeAnnotation") + .field("typeAnnotation", def("Type")); + +def("FunctionTypeAnnotation") + .bases("Type") + .build("params", "returnType", "rest", "typeParameters") + .field("params", [def("FunctionTypeParam")]) + .field("returnType", def("Type")) + .field("rest", or(def("FunctionTypeParam"), null)) + .field("typeParameters", or(def("TypeParameterDeclaration"), null)); + +def("FunctionTypeParam") + .bases("Node") + .build("name", "typeAnnotation", "optional") + .field("name", def("Identifier")) + .field("typeAnnotation", def("Type")) + .field("optional", Boolean); + +def("ArrayTypeAnnotation") + .bases("Type") + .build("elementType") + .field("elementType", def("Type")); + +def("ObjectTypeAnnotation") + .bases("Type") + .build("properties") + .field("properties", [def("ObjectTypeProperty")]) + .field("indexers", [def("ObjectTypeIndexer")], defaults.emptyArray) + .field("callProperties", + [def("ObjectTypeCallProperty")], + defaults.emptyArray); + +def("ObjectTypeProperty") + .bases("Node") + .build("key", "value", "optional") + .field("key", or(def("Literal"), def("Identifier"))) + .field("value", def("Type")) + .field("optional", Boolean); + +def("ObjectTypeIndexer") + .bases("Node") + .build("id", "key", "value") + .field("id", def("Identifier")) + .field("key", def("Type")) + .field("value", def("Type")); + +def("ObjectTypeCallProperty") + .bases("Node") + .build("value") + .field("value", def("FunctionTypeAnnotation")) + .field("static", Boolean, false); + +def("QualifiedTypeIdentifier") + .bases("Node") + .build("qualification", "id") + .field("qualification", + or(def("Identifier"), + def("QualifiedTypeIdentifier"))) + .field("id", def("Identifier")); + +def("GenericTypeAnnotation") + .bases("Type") + .build("id", "typeParameters") + .field("id", or(def("Identifier"), def("QualifiedTypeIdentifier"))) + .field("typeParameters", or(def("TypeParameterInstantiation"), null)); + +def("MemberTypeAnnotation") + .bases("Type") + .build("object", "property") + .field("object", def("Identifier")) + .field("property", + or(def("MemberTypeAnnotation"), + def("GenericTypeAnnotation"))); + +def("UnionTypeAnnotation") + .bases("Type") + .build("types") + .field("types", [def("Type")]); + +def("IntersectionTypeAnnotation") + .bases("Type") + .build("types") + .field("types", [def("Type")]); + +def("TypeofTypeAnnotation") + .bases("Type") + .build("argument") + .field("argument", def("Type")); + +def("Identifier") + .field("typeAnnotation", or(def("TypeAnnotation"), null), defaults["null"]); + +def("TypeParameterDeclaration") + .bases("Node") + .build("params") + .field("params", [def("Identifier")]); + +def("TypeParameterInstantiation") + .bases("Node") + .build("params") + .field("params", [def("Type")]); + +def("Function") + .field("returnType", + or(def("TypeAnnotation"), null), + defaults["null"]) + .field("typeParameters", + or(def("TypeParameterDeclaration"), null), + defaults["null"]); + +def("ClassProperty") + .build("key", "value", "typeAnnotation", "static") + .field("value", or(def("Expression"), null)) + .field("typeAnnotation", or(def("TypeAnnotation"), null)) + .field("static", Boolean, defaults["false"]); + +def("ClassImplements") + .field("typeParameters", + or(def("TypeParameterInstantiation"), null), + defaults["null"]); + +def("InterfaceDeclaration") + .bases("Statement") + .build("id", "body", "extends") + .field("id", def("Identifier")) + .field("typeParameters", + or(def("TypeParameterDeclaration"), null), + defaults["null"]) + .field("body", def("ObjectTypeAnnotation")) + .field("extends", [def("InterfaceExtends")]); + +def("InterfaceExtends") + .bases("Node") + .build("id") + .field("id", def("Identifier")) + .field("typeParameters", or(def("TypeParameterInstantiation"), null)); + +def("TypeAlias") + .bases("Statement") + .build("id", "typeParameters", "right") + .field("id", def("Identifier")) + .field("typeParameters", or(def("TypeParameterDeclaration"), null)) + .field("right", def("Type")); + +def("TypeCastExpression") + .bases("Expression") + .build("expression", "typeAnnotation") + .field("expression", def("Expression")) + .field("typeAnnotation", def("TypeAnnotation")); + +def("TupleTypeAnnotation") + .bases("Type") + .build("types") + .field("types", [def("Type")]); + +def("DeclareVariable") + .bases("Statement") + .build("id") + .field("id", def("Identifier")); + +def("DeclareFunction") + .bases("Statement") + .build("id") + .field("id", def("Identifier")); + +def("DeclareClass") + .bases("InterfaceDeclaration") + .build("id"); + +def("DeclareModule") + .bases("Statement") + .build("id", "body") + .field("id", or(def("Identifier"), def("Literal"))) + .field("body", def("BlockStatement")); + +},{"573":573,"582":582,"583":583}],576:[function(_dereq_,module,exports){ +_dereq_(570); +var types = _dereq_(583); +var def = types.Type.def; +var or = types.Type.or; +var shared = _dereq_(582); +var geq = shared.geq; +var defaults = shared.defaults; + +def("Function") + // SpiderMonkey allows expression closures: function(x) x+1 + .field("body", or(def("BlockStatement"), def("Expression"))); + +def("ForInStatement") + .build("left", "right", "body", "each") + .field("each", Boolean, defaults["false"]); + +def("ForOfStatement") + .bases("Statement") + .build("left", "right", "body") + .field("left", or( + def("VariableDeclaration"), + def("Expression"))) + .field("right", def("Expression")) + .field("body", def("Statement")); + +def("LetStatement") + .bases("Statement") + .build("head", "body") + // TODO Deviating from the spec by reusing VariableDeclarator here. + .field("head", [def("VariableDeclarator")]) + .field("body", def("Statement")); + +def("LetExpression") + .bases("Expression") + .build("head", "body") + // TODO Deviating from the spec by reusing VariableDeclarator here. + .field("head", [def("VariableDeclarator")]) + .field("body", def("Expression")); + +def("GraphExpression") + .bases("Expression") + .build("index", "expression") + .field("index", geq(0)) + .field("expression", def("Literal")); + +def("GraphIndexExpression") + .bases("Expression") + .build("index") + .field("index", geq(0)); + +},{"570":570,"582":582,"583":583}],577:[function(_dereq_,module,exports){ +var types = _dereq_(584); +var getFieldNames = types.getFieldNames; +var getFieldValue = types.getFieldValue; +var isArray = types.builtInTypes.array; +var isObject = types.builtInTypes.object; +var isDate = types.builtInTypes.Date; +var isRegExp = types.builtInTypes.RegExp; +var hasOwn = Object.prototype.hasOwnProperty; + +function astNodesAreEquivalent(a, b, problemPath) { + if (isArray.check(problemPath)) { + problemPath.length = 0; + } else { + problemPath = null; + } + + return areEquivalent(a, b, problemPath); +} + +astNodesAreEquivalent.assert = function(a, b) { + var problemPath = []; + if (!astNodesAreEquivalent(a, b, problemPath)) { + if (problemPath.length === 0) { + if (a !== b) { + throw new Error("Nodes must be equal"); + } + } else { + throw new Error( + "Nodes differ in the following path: " + + problemPath.map(subscriptForProperty).join("") + ); + } + } +}; + +function subscriptForProperty(property) { + if (/[_$a-z][_$a-z0-9]*/i.test(property)) { + return "." + property; + } + return "[" + JSON.stringify(property) + "]"; +} + +function areEquivalent(a, b, problemPath) { + if (a === b) { + return true; + } + + if (isArray.check(a)) { + return arraysAreEquivalent(a, b, problemPath); + } + + if (isObject.check(a)) { + return objectsAreEquivalent(a, b, problemPath); + } + + if (isDate.check(a)) { + return isDate.check(b) && (+a === +b); + } + + if (isRegExp.check(a)) { + return isRegExp.check(b) && ( + a.source === b.source && + a.global === b.global && + a.multiline === b.multiline && + a.ignoreCase === b.ignoreCase + ); + } + + return a == b; +} + +function arraysAreEquivalent(a, b, problemPath) { + isArray.assert(a); + var aLength = a.length; + + if (!isArray.check(b) || b.length !== aLength) { + if (problemPath) { + problemPath.push("length"); + } + return false; + } + + for (var i = 0; i < aLength; ++i) { + if (problemPath) { + problemPath.push(i); + } + + if (i in a !== i in b) { + return false; + } + + if (!areEquivalent(a[i], b[i], problemPath)) { + return false; + } + + if (problemPath) { + var problemPathTail = problemPath.pop(); + if (problemPathTail !== i) { + throw new Error("" + problemPathTail); + } + } + } + + return true; +} + +function objectsAreEquivalent(a, b, problemPath) { + isObject.assert(a); + if (!isObject.check(b)) { + return false; + } + + // Fast path for a common property of AST nodes. + if (a.type !== b.type) { + if (problemPath) { + problemPath.push("type"); + } + return false; + } + + var aNames = getFieldNames(a); + var aNameCount = aNames.length; + + var bNames = getFieldNames(b); + var bNameCount = bNames.length; + + if (aNameCount === bNameCount) { + for (var i = 0; i < aNameCount; ++i) { + var name = aNames[i]; + var aChild = getFieldValue(a, name); + var bChild = getFieldValue(b, name); + + if (problemPath) { + problemPath.push(name); + } + + if (!areEquivalent(aChild, bChild, problemPath)) { + return false; + } + + if (problemPath) { + var problemPathTail = problemPath.pop(); + if (problemPathTail !== name) { + throw new Error("" + problemPathTail); + } + } + } + + return true; + } + + if (!problemPath) { + return false; + } + + // Since aNameCount !== bNameCount, we need to find some name that's + // missing in aNames but present in bNames, or vice-versa. + + var seenNames = Object.create(null); + + for (i = 0; i < aNameCount; ++i) { + seenNames[aNames[i]] = true; + } + + for (i = 0; i < bNameCount; ++i) { + name = bNames[i]; + + if (!hasOwn.call(seenNames, name)) { + problemPath.push(name); + return false; + } + + delete seenNames[name]; + } + + for (name in seenNames) { + problemPath.push(name); + break; + } + + return false; +} + +module.exports = astNodesAreEquivalent; + +},{"584":584}],578:[function(_dereq_,module,exports){ +var types = _dereq_(583); +var n = types.namedTypes; +var b = types.builders; +var isNumber = types.builtInTypes.number; +var isArray = types.builtInTypes.array; +var Path = _dereq_(580); +var Scope = _dereq_(581); + +function NodePath(value, parentPath, name) { + if (!(this instanceof NodePath)) { + throw new Error("NodePath constructor cannot be invoked without 'new'"); + } + Path.call(this, value, parentPath, name); +} + +var NPp = NodePath.prototype = Object.create(Path.prototype, { + constructor: { + value: NodePath, + enumerable: false, + writable: true, + configurable: true + } +}); + +Object.defineProperties(NPp, { + node: { + get: function() { + Object.defineProperty(this, "node", { + configurable: true, // Enable deletion. + value: this._computeNode() + }); + + return this.node; + } + }, + + parent: { + get: function() { + Object.defineProperty(this, "parent", { + configurable: true, // Enable deletion. + value: this._computeParent() + }); + + return this.parent; + } + }, + + scope: { + get: function() { + Object.defineProperty(this, "scope", { + configurable: true, // Enable deletion. + value: this._computeScope() + }); + + return this.scope; + } + } +}); + +NPp.replace = function() { + delete this.node; + delete this.parent; + delete this.scope; + return Path.prototype.replace.apply(this, arguments); +}; + +NPp.prune = function() { + var remainingNodePath = this.parent; + + this.replace(); + + return cleanUpNodesAfterPrune(remainingNodePath); +}; + +// The value of the first ancestor Path whose value is a Node. +NPp._computeNode = function() { + var value = this.value; + if (n.Node.check(value)) { + return value; + } + + var pp = this.parentPath; + return pp && pp.node || null; +}; + +// The first ancestor Path whose value is a Node distinct from this.node. +NPp._computeParent = function() { + var value = this.value; + var pp = this.parentPath; + + if (!n.Node.check(value)) { + while (pp && !n.Node.check(pp.value)) { + pp = pp.parentPath; + } + + if (pp) { + pp = pp.parentPath; + } + } + + while (pp && !n.Node.check(pp.value)) { + pp = pp.parentPath; + } + + return pp || null; +}; + +// The closest enclosing scope that governs this node. +NPp._computeScope = function() { + var value = this.value; + var pp = this.parentPath; + var scope = pp && pp.scope; + + if (n.Node.check(value) && + Scope.isEstablishedBy(value)) { + scope = new Scope(this, scope); + } + + return scope || null; +}; + +NPp.getValueProperty = function(name) { + return types.getFieldValue(this.value, name); +}; + +/** + * Determine whether this.node needs to be wrapped in parentheses in order + * for a parser to reproduce the same local AST structure. + * + * For instance, in the expression `(1 + 2) * 3`, the BinaryExpression + * whose operator is "+" needs parentheses, because `1 + 2 * 3` would + * parse differently. + * + * If assumeExpressionContext === true, we don't worry about edge cases + * like an anonymous FunctionExpression appearing lexically first in its + * enclosing statement and thus needing parentheses to avoid being parsed + * as a FunctionDeclaration with a missing name. + */ +NPp.needsParens = function(assumeExpressionContext) { + var pp = this.parentPath; + if (!pp) { + return false; + } + + var node = this.value; + + // Only expressions need parentheses. + if (!n.Expression.check(node)) { + return false; + } + + // Identifiers never need parentheses. + if (node.type === "Identifier") { + return false; + } + + while (!n.Node.check(pp.value)) { + pp = pp.parentPath; + if (!pp) { + return false; + } + } + + var parent = pp.value; + + switch (node.type) { + case "UnaryExpression": + case "SpreadElement": + case "SpreadProperty": + return parent.type === "MemberExpression" + && this.name === "object" + && parent.object === node; + + case "BinaryExpression": + case "LogicalExpression": + switch (parent.type) { + case "CallExpression": + return this.name === "callee" + && parent.callee === node; + + case "UnaryExpression": + case "SpreadElement": + case "SpreadProperty": + return true; + + case "MemberExpression": + return this.name === "object" + && parent.object === node; + + case "BinaryExpression": + case "LogicalExpression": + var po = parent.operator; + var pp = PRECEDENCE[po]; + var no = node.operator; + var np = PRECEDENCE[no]; + + if (pp > np) { + return true; + } + + if (pp === np && this.name === "right") { + if (parent.right !== node) { + throw new Error("Nodes must be equal"); + } + return true; + } + + default: + return false; + } + + case "SequenceExpression": + switch (parent.type) { + case "ForStatement": + // Although parentheses wouldn't hurt around sequence + // expressions in the head of for loops, traditional style + // dictates that e.g. i++, j++ should not be wrapped with + // parentheses. + return false; + + case "ExpressionStatement": + return this.name !== "expression"; + + default: + // Otherwise err on the side of overparenthesization, adding + // explicit exceptions above if this proves overzealous. + return true; + } + + case "YieldExpression": + switch (parent.type) { + case "BinaryExpression": + case "LogicalExpression": + case "UnaryExpression": + case "SpreadElement": + case "SpreadProperty": + case "CallExpression": + case "MemberExpression": + case "NewExpression": + case "ConditionalExpression": + case "YieldExpression": + return true; + + default: + return false; + } + + case "Literal": + return parent.type === "MemberExpression" + && isNumber.check(node.value) + && this.name === "object" + && parent.object === node; + + case "AssignmentExpression": + case "ConditionalExpression": + switch (parent.type) { + case "UnaryExpression": + case "SpreadElement": + case "SpreadProperty": + case "BinaryExpression": + case "LogicalExpression": + return true; + + case "CallExpression": + return this.name === "callee" + && parent.callee === node; + + case "ConditionalExpression": + return this.name === "test" + && parent.test === node; + + case "MemberExpression": + return this.name === "object" + && parent.object === node; + + default: + return false; + } + + default: + if (parent.type === "NewExpression" && + this.name === "callee" && + parent.callee === node) { + return containsCallExpression(node); + } + } + + if (assumeExpressionContext !== true && + !this.canBeFirstInStatement() && + this.firstInStatement()) + return true; + + return false; +}; + +function isBinary(node) { + return n.BinaryExpression.check(node) + || n.LogicalExpression.check(node); +} + +function isUnaryLike(node) { + return n.UnaryExpression.check(node) + // I considered making SpreadElement and SpreadProperty subtypes + // of UnaryExpression, but they're not really Expression nodes. + || (n.SpreadElement && n.SpreadElement.check(node)) + || (n.SpreadProperty && n.SpreadProperty.check(node)); +} + +var PRECEDENCE = {}; +[["||"], + ["&&"], + ["|"], + ["^"], + ["&"], + ["==", "===", "!=", "!=="], + ["<", ">", "<=", ">=", "in", "instanceof"], + [">>", "<<", ">>>"], + ["+", "-"], + ["*", "/", "%"] +].forEach(function(tier, i) { + tier.forEach(function(op) { + PRECEDENCE[op] = i; + }); +}); + +function containsCallExpression(node) { + if (n.CallExpression.check(node)) { + return true; + } + + if (isArray.check(node)) { + return node.some(containsCallExpression); + } + + if (n.Node.check(node)) { + return types.someField(node, function(name, child) { + return containsCallExpression(child); + }); + } + + return false; +} + +NPp.canBeFirstInStatement = function() { + var node = this.node; + return !n.FunctionExpression.check(node) + && !n.ObjectExpression.check(node); +}; + +NPp.firstInStatement = function() { + return firstInStatement(this); +}; + +function firstInStatement(path) { + for (var node, parent; path.parent; path = path.parent) { + node = path.node; + parent = path.parent.node; + + if (n.BlockStatement.check(parent) && + path.parent.name === "body" && + path.name === 0) { + if (parent.body[0] !== node) { + throw new Error("Nodes must be equal"); + } + return true; + } + + if (n.ExpressionStatement.check(parent) && + path.name === "expression") { + if (parent.expression !== node) { + throw new Error("Nodes must be equal"); + } + return true; + } + + if (n.SequenceExpression.check(parent) && + path.parent.name === "expressions" && + path.name === 0) { + if (parent.expressions[0] !== node) { + throw new Error("Nodes must be equal"); + } + continue; + } + + if (n.CallExpression.check(parent) && + path.name === "callee") { + if (parent.callee !== node) { + throw new Error("Nodes must be equal"); + } + continue; + } + + if (n.MemberExpression.check(parent) && + path.name === "object") { + if (parent.object !== node) { + throw new Error("Nodes must be equal"); + } + continue; + } + + if (n.ConditionalExpression.check(parent) && + path.name === "test") { + if (parent.test !== node) { + throw new Error("Nodes must be equal"); + } + continue; + } + + if (isBinary(parent) && + path.name === "left") { + if (parent.left !== node) { + throw new Error("Nodes must be equal"); + } + continue; + } + + if (n.UnaryExpression.check(parent) && + !parent.prefix && + path.name === "argument") { + if (parent.argument !== node) { + throw new Error("Nodes must be equal"); + } + continue; + } + + return false; + } + + return true; +} + +/** + * Pruning certain nodes will result in empty or incomplete nodes, here we clean those nodes up. + */ +function cleanUpNodesAfterPrune(remainingNodePath) { + if (n.VariableDeclaration.check(remainingNodePath.node)) { + var declarations = remainingNodePath.get('declarations').value; + if (!declarations || declarations.length === 0) { + return remainingNodePath.prune(); + } + } else if (n.ExpressionStatement.check(remainingNodePath.node)) { + if (!remainingNodePath.get('expression').value) { + return remainingNodePath.prune(); + } + } else if (n.IfStatement.check(remainingNodePath.node)) { + cleanUpIfStatementAfterPrune(remainingNodePath); + } + + return remainingNodePath; +} + +function cleanUpIfStatementAfterPrune(ifStatement) { + var testExpression = ifStatement.get('test').value; + var alternate = ifStatement.get('alternate').value; + var consequent = ifStatement.get('consequent').value; + + if (!consequent && !alternate) { + var testExpressionStatement = b.expressionStatement(testExpression); + + ifStatement.replace(testExpressionStatement); + } else if (!consequent && alternate) { + var negatedTestExpression = b.unaryExpression('!', testExpression, true); + + if (n.UnaryExpression.check(testExpression) && testExpression.operator === '!') { + negatedTestExpression = testExpression.argument; + } + + ifStatement.get("test").replace(negatedTestExpression); + ifStatement.get("consequent").replace(alternate); + ifStatement.get("alternate").replace(); + } +} + +module.exports = NodePath; + +},{"580":580,"581":581,"583":583}],579:[function(_dereq_,module,exports){ +var types = _dereq_(583); +var NodePath = _dereq_(578); +var Printable = types.namedTypes.Printable; +var isArray = types.builtInTypes.array; +var isObject = types.builtInTypes.object; +var isFunction = types.builtInTypes.function; +var hasOwn = Object.prototype.hasOwnProperty; +var undefined; + +function PathVisitor() { + if (!(this instanceof PathVisitor)) { + throw new Error( + "PathVisitor constructor cannot be invoked without 'new'" + ); + } + + // Permanent state. + this._reusableContextStack = []; + + this._methodNameTable = computeMethodNameTable(this); + this._shouldVisitComments = + hasOwn.call(this._methodNameTable, "Block") || + hasOwn.call(this._methodNameTable, "Line"); + + this.Context = makeContextConstructor(this); + + // State reset every time PathVisitor.prototype.visit is called. + this._visiting = false; + this._changeReported = false; +} + +function computeMethodNameTable(visitor) { + var typeNames = Object.create(null); + + for (var methodName in visitor) { + if (/^visit[A-Z]/.test(methodName)) { + typeNames[methodName.slice("visit".length)] = true; + } + } + + var supertypeTable = types.computeSupertypeLookupTable(typeNames); + var methodNameTable = Object.create(null); + + var typeNames = Object.keys(supertypeTable); + var typeNameCount = typeNames.length; + for (var i = 0; i < typeNameCount; ++i) { + var typeName = typeNames[i]; + methodName = "visit" + supertypeTable[typeName]; + if (isFunction.check(visitor[methodName])) { + methodNameTable[typeName] = methodName; + } + } + + return methodNameTable; +} + +PathVisitor.fromMethodsObject = function fromMethodsObject(methods) { + if (methods instanceof PathVisitor) { + return methods; + } + + if (!isObject.check(methods)) { + // An empty visitor? + return new PathVisitor; + } + + function Visitor() { + if (!(this instanceof Visitor)) { + throw new Error( + "Visitor constructor cannot be invoked without 'new'" + ); + } + PathVisitor.call(this); + } + + var Vp = Visitor.prototype = Object.create(PVp); + Vp.constructor = Visitor; + + extend(Vp, methods); + extend(Visitor, PathVisitor); + + isFunction.assert(Visitor.fromMethodsObject); + isFunction.assert(Visitor.visit); + + return new Visitor; +}; + +function extend(target, source) { + for (var property in source) { + if (hasOwn.call(source, property)) { + target[property] = source[property]; + } + } + + return target; +} + +PathVisitor.visit = function visit(node, methods) { + return PathVisitor.fromMethodsObject(methods).visit(node); +}; + +var PVp = PathVisitor.prototype; + +PVp.visit = function() { + if (this._visiting) { + throw new Error( + "Recursively calling visitor.visit(path) resets visitor state. " + + "Try this.visit(path) or this.traverse(path) instead." + ); + } + + // Private state that needs to be reset before every traversal. + this._visiting = true; + this._changeReported = false; + this._abortRequested = false; + + var argc = arguments.length; + var args = new Array(argc) + for (var i = 0; i < argc; ++i) { + args[i] = arguments[i]; + } + + if (!(args[0] instanceof NodePath)) { + args[0] = new NodePath({ root: args[0] }).get("root"); + } + + // Called with the same arguments as .visit. + this.reset.apply(this, args); + + try { + var root = this.visitWithoutReset(args[0]); + var didNotThrow = true; + } finally { + this._visiting = false; + + if (!didNotThrow && this._abortRequested) { + // If this.visitWithoutReset threw an exception and + // this._abortRequested was set to true, return the root of + // the AST instead of letting the exception propagate, so that + // client code does not have to provide a try-catch block to + // intercept the AbortRequest exception. Other kinds of + // exceptions will propagate without being intercepted and + // rethrown by a catch block, so their stacks will accurately + // reflect the original throwing context. + return args[0].value; + } + } + + return root; +}; + +PVp.AbortRequest = function AbortRequest() {}; +PVp.abort = function() { + var visitor = this; + visitor._abortRequested = true; + var request = new visitor.AbortRequest(); + + // If you decide to catch this exception and stop it from propagating, + // make sure to call its cancel method to avoid silencing other + // exceptions that might be thrown later in the traversal. + request.cancel = function() { + visitor._abortRequested = false; + }; + + throw request; +}; + +PVp.reset = function(path/*, additional arguments */) { + // Empty stub; may be reassigned or overridden by subclasses. +}; + +PVp.visitWithoutReset = function(path) { + if (this instanceof this.Context) { + // Since this.Context.prototype === this, there's a chance we + // might accidentally call context.visitWithoutReset. If that + // happens, re-invoke the method against context.visitor. + return this.visitor.visitWithoutReset(path); + } + + if (!(path instanceof NodePath)) { + throw new Error(""); + } + + var value = path.value; + + var methodName = value && + typeof value === "object" && + typeof value.type === "string" && + this._methodNameTable[value.type]; + + if (methodName) { + var context = this.acquireContext(path); + try { + return context.invokeVisitorMethod(methodName); + } finally { + this.releaseContext(context); + } + + } else { + // If there was no visitor method to call, visit the children of + // this node generically. + return visitChildren(path, this); + } +}; + +function visitChildren(path, visitor) { + if (!(path instanceof NodePath)) { + throw new Error(""); + } + if (!(visitor instanceof PathVisitor)) { + throw new Error(""); + } + + var value = path.value; + + if (isArray.check(value)) { + path.each(visitor.visitWithoutReset, visitor); + } else if (!isObject.check(value)) { + // No children to visit. + } else { + var childNames = types.getFieldNames(value); + + // The .comments field of the Node type is hidden, so we only + // visit it if the visitor defines visitBlock or visitLine, and + // value.comments is defined. + if (visitor._shouldVisitComments && + value.comments && + childNames.indexOf("comments") < 0) { + childNames.push("comments"); + } + + var childCount = childNames.length; + var childPaths = []; + + for (var i = 0; i < childCount; ++i) { + var childName = childNames[i]; + if (!hasOwn.call(value, childName)) { + value[childName] = types.getFieldValue(value, childName); + } + childPaths.push(path.get(childName)); + } + + for (var i = 0; i < childCount; ++i) { + visitor.visitWithoutReset(childPaths[i]); + } + } + + return path.value; +} + +PVp.acquireContext = function(path) { + if (this._reusableContextStack.length === 0) { + return new this.Context(path); + } + return this._reusableContextStack.pop().reset(path); +}; + +PVp.releaseContext = function(context) { + if (!(context instanceof this.Context)) { + throw new Error(""); + } + this._reusableContextStack.push(context); + context.currentPath = null; +}; + +PVp.reportChanged = function() { + this._changeReported = true; +}; + +PVp.wasChangeReported = function() { + return this._changeReported; +}; + +function makeContextConstructor(visitor) { + function Context(path) { + if (!(this instanceof Context)) { + throw new Error(""); + } + if (!(this instanceof PathVisitor)) { + throw new Error(""); + } + if (!(path instanceof NodePath)) { + throw new Error(""); + } + + Object.defineProperty(this, "visitor", { + value: visitor, + writable: false, + enumerable: true, + configurable: false + }); + + this.currentPath = path; + this.needToCallTraverse = true; + + Object.seal(this); + } + + if (!(visitor instanceof PathVisitor)) { + throw new Error(""); + } + + // Note that the visitor object is the prototype of Context.prototype, + // so all visitor methods are inherited by context objects. + var Cp = Context.prototype = Object.create(visitor); + + Cp.constructor = Context; + extend(Cp, sharedContextProtoMethods); + + return Context; +} + +// Every PathVisitor has a different this.Context constructor and +// this.Context.prototype object, but those prototypes can all use the +// same reset, invokeVisitorMethod, and traverse function objects. +var sharedContextProtoMethods = Object.create(null); + +sharedContextProtoMethods.reset = +function reset(path) { + if (!(this instanceof this.Context)) { + throw new Error(""); + } + if (!(path instanceof NodePath)) { + throw new Error(""); + } + + this.currentPath = path; + this.needToCallTraverse = true; + + return this; +}; + +sharedContextProtoMethods.invokeVisitorMethod = +function invokeVisitorMethod(methodName) { + if (!(this instanceof this.Context)) { + throw new Error(""); + } + if (!(this.currentPath instanceof NodePath)) { + throw new Error(""); + } + + var result = this.visitor[methodName].call(this, this.currentPath); + + if (result === false) { + // Visitor methods return false to indicate that they have handled + // their own traversal needs, and we should not complain if + // this.needToCallTraverse is still true. + this.needToCallTraverse = false; + + } else if (result !== undefined) { + // Any other non-undefined value returned from the visitor method + // is interpreted as a replacement value. + this.currentPath = this.currentPath.replace(result)[0]; + + if (this.needToCallTraverse) { + // If this.traverse still hasn't been called, visit the + // children of the replacement node. + this.traverse(this.currentPath); + } + } + + if (this.needToCallTraverse !== false) { + throw new Error( + "Must either call this.traverse or return false in " + methodName + ); + } + + var path = this.currentPath; + return path && path.value; +}; + +sharedContextProtoMethods.traverse = +function traverse(path, newVisitor) { + if (!(this instanceof this.Context)) { + throw new Error(""); + } + if (!(path instanceof NodePath)) { + throw new Error(""); + } + if (!(this.currentPath instanceof NodePath)) { + throw new Error(""); + } + + this.needToCallTraverse = false; + + return visitChildren(path, PathVisitor.fromMethodsObject( + newVisitor || this.visitor + )); +}; + +sharedContextProtoMethods.visit = +function visit(path, newVisitor) { + if (!(this instanceof this.Context)) { + throw new Error(""); + } + if (!(path instanceof NodePath)) { + throw new Error(""); + } + if (!(this.currentPath instanceof NodePath)) { + throw new Error(""); + } + + this.needToCallTraverse = false; + + return PathVisitor.fromMethodsObject( + newVisitor || this.visitor + ).visitWithoutReset(path); +}; + +sharedContextProtoMethods.reportChanged = function reportChanged() { + this.visitor.reportChanged(); +}; + +sharedContextProtoMethods.abort = function abort() { + this.needToCallTraverse = false; + this.visitor.abort(); +}; + +module.exports = PathVisitor; + +},{"578":578,"583":583}],580:[function(_dereq_,module,exports){ +var Op = Object.prototype; +var hasOwn = Op.hasOwnProperty; +var types = _dereq_(583); +var isArray = types.builtInTypes.array; +var isNumber = types.builtInTypes.number; +var Ap = Array.prototype; +var slice = Ap.slice; +var map = Ap.map; + +function Path(value, parentPath, name) { + if (!(this instanceof Path)) { + throw new Error("Path constructor cannot be invoked without 'new'"); + } + + if (parentPath) { + if (!(parentPath instanceof Path)) { + throw new Error(""); + } + } else { + parentPath = null; + name = null; + } + + // The value encapsulated by this Path, generally equal to + // parentPath.value[name] if we have a parentPath. + this.value = value; + + // The immediate parent Path of this Path. + this.parentPath = parentPath; + + // The name of the property of parentPath.value through which this + // Path's value was reached. + this.name = name; + + // Calling path.get("child") multiple times always returns the same + // child Path object, for both performance and consistency reasons. + this.__childCache = null; +} + +var Pp = Path.prototype; + +function getChildCache(path) { + // Lazily create the child cache. This also cheapens cache + // invalidation, since you can just reset path.__childCache to null. + return path.__childCache || (path.__childCache = Object.create(null)); +} + +function getChildPath(path, name) { + var cache = getChildCache(path); + var actualChildValue = path.getValueProperty(name); + var childPath = cache[name]; + if (!hasOwn.call(cache, name) || + // Ensure consistency between cache and reality. + childPath.value !== actualChildValue) { + childPath = cache[name] = new path.constructor( + actualChildValue, path, name + ); + } + return childPath; +} + +// This method is designed to be overridden by subclasses that need to +// handle missing properties, etc. +Pp.getValueProperty = function getValueProperty(name) { + return this.value[name]; +}; + +Pp.get = function get(name) { + var path = this; + var names = arguments; + var count = names.length; + + for (var i = 0; i < count; ++i) { + path = getChildPath(path, names[i]); + } + + return path; +}; + +Pp.each = function each(callback, context) { + var childPaths = []; + var len = this.value.length; + var i = 0; + + // Collect all the original child paths before invoking the callback. + for (var i = 0; i < len; ++i) { + if (hasOwn.call(this.value, i)) { + childPaths[i] = this.get(i); + } + } + + // Invoke the callback on just the original child paths, regardless of + // any modifications made to the array by the callback. I chose these + // semantics over cleverly invoking the callback on new elements because + // this way is much easier to reason about. + context = context || this; + for (i = 0; i < len; ++i) { + if (hasOwn.call(childPaths, i)) { + callback.call(context, childPaths[i]); + } + } +}; + +Pp.map = function map(callback, context) { + var result = []; + + this.each(function(childPath) { + result.push(callback.call(this, childPath)); + }, context); + + return result; +}; + +Pp.filter = function filter(callback, context) { + var result = []; + + this.each(function(childPath) { + if (callback.call(this, childPath)) { + result.push(childPath); + } + }, context); + + return result; +}; + +function emptyMoves() {} +function getMoves(path, offset, start, end) { + isArray.assert(path.value); + + if (offset === 0) { + return emptyMoves; + } + + var length = path.value.length; + if (length < 1) { + return emptyMoves; + } + + var argc = arguments.length; + if (argc === 2) { + start = 0; + end = length; + } else if (argc === 3) { + start = Math.max(start, 0); + end = length; + } else { + start = Math.max(start, 0); + end = Math.min(end, length); + } + + isNumber.assert(start); + isNumber.assert(end); + + var moves = Object.create(null); + var cache = getChildCache(path); + + for (var i = start; i < end; ++i) { + if (hasOwn.call(path.value, i)) { + var childPath = path.get(i); + if (childPath.name !== i) { + throw new Error(""); + } + var newIndex = i + offset; + childPath.name = newIndex; + moves[newIndex] = childPath; + delete cache[i]; + } + } + + delete cache.length; + + return function() { + for (var newIndex in moves) { + var childPath = moves[newIndex]; + if (childPath.name !== +newIndex) { + throw new Error(""); + } + cache[newIndex] = childPath; + path.value[newIndex] = childPath.value; + } + }; +} + +Pp.shift = function shift() { + var move = getMoves(this, -1); + var result = this.value.shift(); + move(); + return result; +}; + +Pp.unshift = function unshift(node) { + var move = getMoves(this, arguments.length); + var result = this.value.unshift.apply(this.value, arguments); + move(); + return result; +}; + +Pp.push = function push(node) { + isArray.assert(this.value); + delete getChildCache(this).length + return this.value.push.apply(this.value, arguments); +}; + +Pp.pop = function pop() { + isArray.assert(this.value); + var cache = getChildCache(this); + delete cache[this.value.length - 1]; + delete cache.length; + return this.value.pop(); +}; + +Pp.insertAt = function insertAt(index, node) { + var argc = arguments.length; + var move = getMoves(this, argc - 1, index); + if (move === emptyMoves) { + return this; + } + + index = Math.max(index, 0); + + for (var i = 1; i < argc; ++i) { + this.value[index + i - 1] = arguments[i]; + } + + move(); + + return this; +}; + +Pp.insertBefore = function insertBefore(node) { + var pp = this.parentPath; + var argc = arguments.length; + var insertAtArgs = [this.name]; + for (var i = 0; i < argc; ++i) { + insertAtArgs.push(arguments[i]); + } + return pp.insertAt.apply(pp, insertAtArgs); +}; + +Pp.insertAfter = function insertAfter(node) { + var pp = this.parentPath; + var argc = arguments.length; + var insertAtArgs = [this.name + 1]; + for (var i = 0; i < argc; ++i) { + insertAtArgs.push(arguments[i]); + } + return pp.insertAt.apply(pp, insertAtArgs); +}; + +function repairRelationshipWithParent(path) { + if (!(path instanceof Path)) { + throw new Error(""); + } + + var pp = path.parentPath; + if (!pp) { + // Orphan paths have no relationship to repair. + return path; + } + + var parentValue = pp.value; + var parentCache = getChildCache(pp); + + // Make sure parentCache[path.name] is populated. + if (parentValue[path.name] === path.value) { + parentCache[path.name] = path; + } else if (isArray.check(parentValue)) { + // Something caused path.name to become out of date, so attempt to + // recover by searching for path.value in parentValue. + var i = parentValue.indexOf(path.value); + if (i >= 0) { + parentCache[path.name = i] = path; + } + } else { + // If path.value disagrees with parentValue[path.name], and + // path.name is not an array index, let path.value become the new + // parentValue[path.name] and update parentCache accordingly. + parentValue[path.name] = path.value; + parentCache[path.name] = path; + } + + if (parentValue[path.name] !== path.value) { + throw new Error(""); + } + if (path.parentPath.get(path.name) !== path) { + throw new Error(""); + } + + return path; +} + +Pp.replace = function replace(replacement) { + var results = []; + var parentValue = this.parentPath.value; + var parentCache = getChildCache(this.parentPath); + var count = arguments.length; + + repairRelationshipWithParent(this); + + if (isArray.check(parentValue)) { + var originalLength = parentValue.length; + var move = getMoves(this.parentPath, count - 1, this.name + 1); + + var spliceArgs = [this.name, 1]; + for (var i = 0; i < count; ++i) { + spliceArgs.push(arguments[i]); + } + + var splicedOut = parentValue.splice.apply(parentValue, spliceArgs); + + if (splicedOut[0] !== this.value) { + throw new Error(""); + } + if (parentValue.length !== (originalLength - 1 + count)) { + throw new Error(""); + } + + move(); + + if (count === 0) { + delete this.value; + delete parentCache[this.name]; + this.__childCache = null; + + } else { + if (parentValue[this.name] !== replacement) { + throw new Error(""); + } + + if (this.value !== replacement) { + this.value = replacement; + this.__childCache = null; + } + + for (i = 0; i < count; ++i) { + results.push(this.parentPath.get(this.name + i)); + } + + if (results[0] !== this) { + throw new Error(""); + } + } + + } else if (count === 1) { + if (this.value !== replacement) { + this.__childCache = null; + } + this.value = parentValue[this.name] = replacement; + results.push(this); + + } else if (count === 0) { + delete parentValue[this.name]; + delete this.value; + this.__childCache = null; + + // Leave this path cached as parentCache[this.name], even though + // it no longer has a value defined. + + } else { + throw new Error("Could not replace path"); + } + + return results; +}; + +module.exports = Path; + +},{"583":583}],581:[function(_dereq_,module,exports){ +var types = _dereq_(583); +var Type = types.Type; +var namedTypes = types.namedTypes; +var Node = namedTypes.Node; +var Expression = namedTypes.Expression; +var isArray = types.builtInTypes.array; +var hasOwn = Object.prototype.hasOwnProperty; +var b = types.builders; + +function Scope(path, parentScope) { + if (!(this instanceof Scope)) { + throw new Error("Scope constructor cannot be invoked without 'new'"); + } + if (!(path instanceof _dereq_(578))) { + throw new Error(""); + } + ScopeType.assert(path.value); + + var depth; + + if (parentScope) { + if (!(parentScope instanceof Scope)) { + throw new Error(""); + } + depth = parentScope.depth + 1; + } else { + parentScope = null; + depth = 0; + } + + Object.defineProperties(this, { + path: { value: path }, + node: { value: path.value }, + isGlobal: { value: !parentScope, enumerable: true }, + depth: { value: depth }, + parent: { value: parentScope }, + bindings: { value: {} } + }); +} + +var scopeTypes = [ + // Program nodes introduce global scopes. + namedTypes.Program, + + // Function is the supertype of FunctionExpression, + // FunctionDeclaration, ArrowExpression, etc. + namedTypes.Function, + + // In case you didn't know, the caught parameter shadows any variable + // of the same name in an outer scope. + namedTypes.CatchClause +]; + +var ScopeType = Type.or.apply(Type, scopeTypes); + +Scope.isEstablishedBy = function(node) { + return ScopeType.check(node); +}; + +var Sp = Scope.prototype; + +// Will be overridden after an instance lazily calls scanScope. +Sp.didScan = false; + +Sp.declares = function(name) { + this.scan(); + return hasOwn.call(this.bindings, name); +}; + +Sp.declareTemporary = function(prefix) { + if (prefix) { + if (!/^[a-z$_]/i.test(prefix)) { + throw new Error(""); + } + } else { + prefix = "t$"; + } + + // Include this.depth in the name to make sure the name does not + // collide with any variables in nested/enclosing scopes. + prefix += this.depth.toString(36) + "$"; + + this.scan(); + + var index = 0; + while (this.declares(prefix + index)) { + ++index; + } + + var name = prefix + index; + return this.bindings[name] = types.builders.identifier(name); +}; + +Sp.injectTemporary = function(identifier, init) { + identifier || (identifier = this.declareTemporary()); + + var bodyPath = this.path.get("body"); + if (namedTypes.BlockStatement.check(bodyPath.value)) { + bodyPath = bodyPath.get("body"); + } + + bodyPath.unshift( + b.variableDeclaration( + "var", + [b.variableDeclarator(identifier, init || null)] + ) + ); + + return identifier; +}; + +Sp.scan = function(force) { + if (force || !this.didScan) { + for (var name in this.bindings) { + // Empty out this.bindings, just in cases. + delete this.bindings[name]; + } + scanScope(this.path, this.bindings); + this.didScan = true; + } +}; + +Sp.getBindings = function () { + this.scan(); + return this.bindings; +}; + +function scanScope(path, bindings) { + var node = path.value; + ScopeType.assert(node); + + if (namedTypes.CatchClause.check(node)) { + // A catch clause establishes a new scope but the only variable + // bound in that scope is the catch parameter. Any other + // declarations create bindings in the outer scope. + addPattern(path.get("param"), bindings); + + } else { + recursiveScanScope(path, bindings); + } +} + +function recursiveScanScope(path, bindings) { + var node = path.value; + + if (path.parent && + namedTypes.FunctionExpression.check(path.parent.node) && + path.parent.node.id) { + addPattern(path.parent.get("id"), bindings); + } + + if (!node) { + // None of the remaining cases matter if node is falsy. + + } else if (isArray.check(node)) { + path.each(function(childPath) { + recursiveScanChild(childPath, bindings); + }); + + } else if (namedTypes.Function.check(node)) { + path.get("params").each(function(paramPath) { + addPattern(paramPath, bindings); + }); + + recursiveScanChild(path.get("body"), bindings); + + } else if (namedTypes.VariableDeclarator.check(node)) { + addPattern(path.get("id"), bindings); + recursiveScanChild(path.get("init"), bindings); + + } else if (node.type === "ImportSpecifier" || + node.type === "ImportNamespaceSpecifier" || + node.type === "ImportDefaultSpecifier") { + addPattern( + // Esprima used to use the .name field to refer to the local + // binding identifier for ImportSpecifier nodes, but .id for + // ImportNamespaceSpecifier and ImportDefaultSpecifier nodes. + // ESTree/Acorn/ESpree use .local for all three node types. + path.get(node.local ? "local" : + node.name ? "name" : "id"), + bindings + ); + + } else if (Node.check(node) && !Expression.check(node)) { + types.eachField(node, function(name, child) { + var childPath = path.get(name); + if (childPath.value !== child) { + throw new Error(""); + } + recursiveScanChild(childPath, bindings); + }); + } +} + +function recursiveScanChild(path, bindings) { + var node = path.value; + + if (!node || Expression.check(node)) { + // Ignore falsy values and Expressions. + + } else if (namedTypes.FunctionDeclaration.check(node)) { + addPattern(path.get("id"), bindings); + + } else if (namedTypes.ClassDeclaration && + namedTypes.ClassDeclaration.check(node)) { + addPattern(path.get("id"), bindings); + + } else if (ScopeType.check(node)) { + if (namedTypes.CatchClause.check(node)) { + var catchParamName = node.param.name; + var hadBinding = hasOwn.call(bindings, catchParamName); + + // Any declarations that occur inside the catch body that do + // not have the same name as the catch parameter should count + // as bindings in the outer scope. + recursiveScanScope(path.get("body"), bindings); + + // If a new binding matching the catch parameter name was + // created while scanning the catch body, ignore it because it + // actually refers to the catch parameter and not the outer + // scope that we're currently scanning. + if (!hadBinding) { + delete bindings[catchParamName]; + } + } + + } else { + recursiveScanScope(path, bindings); + } +} + +function addPattern(patternPath, bindings) { + var pattern = patternPath.value; + namedTypes.Pattern.assert(pattern); + + if (namedTypes.Identifier.check(pattern)) { + if (hasOwn.call(bindings, pattern.name)) { + bindings[pattern.name].push(patternPath); + } else { + bindings[pattern.name] = [patternPath]; + } + + } else if (namedTypes.ObjectPattern && + namedTypes.ObjectPattern.check(pattern)) { + patternPath.get('properties').each(function(propertyPath) { + var property = propertyPath.value; + if (namedTypes.Pattern.check(property)) { + addPattern(propertyPath, bindings); + } else if (namedTypes.Property.check(property)) { + addPattern(propertyPath.get('value'), bindings); + } else if (namedTypes.SpreadProperty && + namedTypes.SpreadProperty.check(property)) { + addPattern(propertyPath.get('argument'), bindings); + } + }); + + } else if (namedTypes.ArrayPattern && + namedTypes.ArrayPattern.check(pattern)) { + patternPath.get('elements').each(function(elementPath) { + var element = elementPath.value; + if (namedTypes.Pattern.check(element)) { + addPattern(elementPath, bindings); + } else if (namedTypes.SpreadElement && + namedTypes.SpreadElement.check(element)) { + addPattern(elementPath.get("argument"), bindings); + } + }); + + } else if (namedTypes.PropertyPattern && + namedTypes.PropertyPattern.check(pattern)) { + addPattern(patternPath.get('pattern'), bindings); + + } else if ((namedTypes.SpreadElementPattern && + namedTypes.SpreadElementPattern.check(pattern)) || + (namedTypes.SpreadPropertyPattern && + namedTypes.SpreadPropertyPattern.check(pattern))) { + addPattern(patternPath.get('argument'), bindings); + } +} + +Sp.lookup = function(name) { + for (var scope = this; scope; scope = scope.parent) + if (scope.declares(name)) + break; + return scope; +}; + +Sp.getGlobalScope = function() { + var scope = this; + while (!scope.isGlobal) + scope = scope.parent; + return scope; +}; + +module.exports = Scope; + +},{"578":578,"583":583}],582:[function(_dereq_,module,exports){ +var types = _dereq_(583); +var Type = types.Type; +var builtin = types.builtInTypes; +var isNumber = builtin.number; + +// An example of constructing a new type with arbitrary constraints from +// an existing type. +exports.geq = function(than) { + return new Type(function(value) { + return isNumber.check(value) && value >= than; + }, isNumber + " >= " + than); +}; + +// Default value-returning functions that may optionally be passed as a +// third argument to Def.prototype.field. +exports.defaults = { + // Functions were used because (among other reasons) that's the most + // elegant way to allow for the emptyArray one always to give a new + // array instance. + "null": function() { return null }, + "emptyArray": function() { return [] }, + "false": function() { return false }, + "true": function() { return true }, + "undefined": function() {} +}; + +var naiveIsPrimitive = Type.or( + builtin.string, + builtin.number, + builtin.boolean, + builtin.null, + builtin.undefined +); + +exports.isPrimitive = new Type(function(value) { + if (value === null) + return true; + var type = typeof value; + return !(type === "object" || + type === "function"); +}, naiveIsPrimitive.toString()); + +},{"583":583}],583:[function(_dereq_,module,exports){ +var Ap = Array.prototype; +var slice = Ap.slice; +var map = Ap.map; +var each = Ap.forEach; +var Op = Object.prototype; +var objToStr = Op.toString; +var funObjStr = objToStr.call(function(){}); +var strObjStr = objToStr.call(""); +var hasOwn = Op.hasOwnProperty; + +// A type is an object with a .check method that takes a value and returns +// true or false according to whether the value matches the type. + +function Type(check, name) { + var self = this; + if (!(self instanceof Type)) { + throw new Error("Type constructor cannot be invoked without 'new'"); + } + + // Unfortunately we can't elegantly reuse isFunction and isString, + // here, because this code is executed while defining those types. + if (objToStr.call(check) !== funObjStr) { + throw new Error(check + " is not a function"); + } + + // The `name` parameter can be either a function or a string. + var nameObjStr = objToStr.call(name); + if (!(nameObjStr === funObjStr || + nameObjStr === strObjStr)) { + throw new Error(name + " is neither a function nor a string"); + } + + Object.defineProperties(self, { + name: { value: name }, + check: { + value: function(value, deep) { + var result = check.call(self, value, deep); + if (!result && deep && objToStr.call(deep) === funObjStr) + deep(self, value); + return result; + } + } + }); +} + +var Tp = Type.prototype; + +// Throughout this file we use Object.defineProperty to prevent +// redefinition of exported properties. +exports.Type = Type; + +// Like .check, except that failure triggers an AssertionError. +Tp.assert = function(value, deep) { + if (!this.check(value, deep)) { + var str = shallowStringify(value); + throw new Error(str + " does not match type " + this); + } + return true; +}; + +function shallowStringify(value) { + if (isObject.check(value)) + return "{" + Object.keys(value).map(function(key) { + return key + ": " + value[key]; + }).join(", ") + "}"; + + if (isArray.check(value)) + return "[" + value.map(shallowStringify).join(", ") + "]"; + + return JSON.stringify(value); +} + +Tp.toString = function() { + var name = this.name; + + if (isString.check(name)) + return name; + + if (isFunction.check(name)) + return name.call(this) + ""; + + return name + " type"; +}; + +var builtInCtorFns = []; +var builtInCtorTypes = []; +var builtInTypes = {}; +exports.builtInTypes = builtInTypes; + +function defBuiltInType(example, name) { + var objStr = objToStr.call(example); + + var type = new Type(function(value) { + return objToStr.call(value) === objStr; + }, name); + + builtInTypes[name] = type; + + if (example && typeof example.constructor === "function") { + builtInCtorFns.push(example.constructor); + builtInCtorTypes.push(type); + } + + return type; +} + +// These types check the underlying [[Class]] attribute of the given +// value, rather than using the problematic typeof operator. Note however +// that no subtyping is considered; so, for instance, isObject.check +// returns false for [], /./, new Date, and null. +var isString = defBuiltInType("truthy", "string"); +var isFunction = defBuiltInType(function(){}, "function"); +var isArray = defBuiltInType([], "array"); +var isObject = defBuiltInType({}, "object"); +var isRegExp = defBuiltInType(/./, "RegExp"); +var isDate = defBuiltInType(new Date, "Date"); +var isNumber = defBuiltInType(3, "number"); +var isBoolean = defBuiltInType(true, "boolean"); +var isNull = defBuiltInType(null, "null"); +var isUndefined = defBuiltInType(void 0, "undefined"); + +// There are a number of idiomatic ways of expressing types, so this +// function serves to coerce them all to actual Type objects. Note that +// providing the name argument is not necessary in most cases. +function toType(from, name) { + // The toType function should of course be idempotent. + if (from instanceof Type) + return from; + + // The Def type is used as a helper for constructing compound + // interface types for AST nodes. + if (from instanceof Def) + return from.type; + + // Support [ElemType] syntax. + if (isArray.check(from)) + return Type.fromArray(from); + + // Support { someField: FieldType, ... } syntax. + if (isObject.check(from)) + return Type.fromObject(from); + + if (isFunction.check(from)) { + var bicfIndex = builtInCtorFns.indexOf(from); + if (bicfIndex >= 0) { + return builtInCtorTypes[bicfIndex]; + } + + // If isFunction.check(from), and from is not a built-in + // constructor, assume from is a binary predicate function we can + // use to define the type. + return new Type(from, name); + } + + // As a last resort, toType returns a type that matches any value that + // is === from. This is primarily useful for literal values like + // toType(null), but it has the additional advantage of allowing + // toType to be a total function. + return new Type(function(value) { + return value === from; + }, isUndefined.check(name) ? function() { + return from + ""; + } : name); +} + +// Returns a type that matches the given value iff any of type1, type2, +// etc. match the value. +Type.or = function(/* type1, type2, ... */) { + var types = []; + var len = arguments.length; + for (var i = 0; i < len; ++i) + types.push(toType(arguments[i])); + + return new Type(function(value, deep) { + for (var i = 0; i < len; ++i) + if (types[i].check(value, deep)) + return true; + return false; + }, function() { + return types.join(" | "); + }); +}; + +Type.fromArray = function(arr) { + if (!isArray.check(arr)) { + throw new Error(""); + } + if (arr.length !== 1) { + throw new Error("only one element type is permitted for typed arrays"); + } + return toType(arr[0]).arrayOf(); +}; + +Tp.arrayOf = function() { + var elemType = this; + return new Type(function(value, deep) { + return isArray.check(value) && value.every(function(elem) { + return elemType.check(elem, deep); + }); + }, function() { + return "[" + elemType + "]"; + }); +}; + +Type.fromObject = function(obj) { + var fields = Object.keys(obj).map(function(name) { + return new Field(name, obj[name]); + }); + + return new Type(function(value, deep) { + return isObject.check(value) && fields.every(function(field) { + return field.type.check(value[field.name], deep); + }); + }, function() { + return "{ " + fields.join(", ") + " }"; + }); +}; + +function Field(name, type, defaultFn, hidden) { + var self = this; + + if (!(self instanceof Field)) { + throw new Error("Field constructor cannot be invoked without 'new'"); + } + isString.assert(name); + + type = toType(type); + + var properties = { + name: { value: name }, + type: { value: type }, + hidden: { value: !!hidden } + }; + + if (isFunction.check(defaultFn)) { + properties.defaultFn = { value: defaultFn }; + } + + Object.defineProperties(self, properties); +} + +var Fp = Field.prototype; + +Fp.toString = function() { + return JSON.stringify(this.name) + ": " + this.type; +}; + +Fp.getValue = function(obj) { + var value = obj[this.name]; + + if (!isUndefined.check(value)) + return value; + + if (this.defaultFn) + value = this.defaultFn.call(obj); + + return value; +}; + +// Define a type whose name is registered in a namespace (the defCache) so +// that future definitions will return the same type given the same name. +// In particular, this system allows for circular and forward definitions. +// The Def object d returned from Type.def may be used to configure the +// type d.type by calling methods such as d.bases, d.build, and d.field. +Type.def = function(typeName) { + isString.assert(typeName); + return hasOwn.call(defCache, typeName) + ? defCache[typeName] + : defCache[typeName] = new Def(typeName); +}; + +// In order to return the same Def instance every time Type.def is called +// with a particular name, those instances need to be stored in a cache. +var defCache = Object.create(null); + +function Def(typeName) { + var self = this; + if (!(self instanceof Def)) { + throw new Error("Def constructor cannot be invoked without 'new'"); + } + + Object.defineProperties(self, { + typeName: { value: typeName }, + baseNames: { value: [] }, + ownFields: { value: Object.create(null) }, + + // These two are populated during finalization. + allSupertypes: { value: Object.create(null) }, // Includes own typeName. + supertypeList: { value: [] }, // Linear inheritance hierarchy. + allFields: { value: Object.create(null) }, // Includes inherited fields. + fieldNames: { value: [] }, // Non-hidden keys of allFields. + + type: { + value: new Type(function(value, deep) { + return self.check(value, deep); + }, typeName) + } + }); +} + +Def.fromValue = function(value) { + if (value && typeof value === "object") { + var type = value.type; + if (typeof type === "string" && + hasOwn.call(defCache, type)) { + var d = defCache[type]; + if (d.finalized) { + return d; + } + } + } + + return null; +}; + +var Dp = Def.prototype; + +Dp.isSupertypeOf = function(that) { + if (that instanceof Def) { + if (this.finalized !== true || + that.finalized !== true) { + throw new Error(""); + } + return hasOwn.call(that.allSupertypes, this.typeName); + } else { + throw new Error(that + " is not a Def"); + } +}; + +// Note that the list returned by this function is a copy of the internal +// supertypeList, *without* the typeName itself as the first element. +exports.getSupertypeNames = function(typeName) { + if (!hasOwn.call(defCache, typeName)) { + throw new Error(""); + } + var d = defCache[typeName]; + if (d.finalized !== true) { + throw new Error(""); + } + return d.supertypeList.slice(1); +}; + +// Returns an object mapping from every known type in the defCache to the +// most specific supertype whose name is an own property of the candidates +// object. +exports.computeSupertypeLookupTable = function(candidates) { + var table = {}; + var typeNames = Object.keys(defCache); + var typeNameCount = typeNames.length; + + for (var i = 0; i < typeNameCount; ++i) { + var typeName = typeNames[i]; + var d = defCache[typeName]; + if (d.finalized !== true) { + throw new Error("" + typeName); + } + for (var j = 0; j < d.supertypeList.length; ++j) { + var superTypeName = d.supertypeList[j]; + if (hasOwn.call(candidates, superTypeName)) { + table[typeName] = superTypeName; + break; + } + } + } + + return table; +}; + +Dp.checkAllFields = function(value, deep) { + var allFields = this.allFields; + if (this.finalized !== true) { + throw new Error("" + this.typeName); + } + + function checkFieldByName(name) { + var field = allFields[name]; + var type = field.type; + var child = field.getValue(value); + return type.check(child, deep); + } + + return isObject.check(value) + && Object.keys(allFields).every(checkFieldByName); +}; + +Dp.check = function(value, deep) { + if (this.finalized !== true) { + throw new Error( + "prematurely checking unfinalized type " + this.typeName + ); + } + + // A Def type can only match an object value. + if (!isObject.check(value)) + return false; + + var vDef = Def.fromValue(value); + if (!vDef) { + // If we couldn't infer the Def associated with the given value, + // and we expected it to be a SourceLocation or a Position, it was + // probably just missing a "type" field (because Esprima does not + // assign a type property to such nodes). Be optimistic and let + // this.checkAllFields make the final decision. + if (this.typeName === "SourceLocation" || + this.typeName === "Position") { + return this.checkAllFields(value, deep); + } + + // Calling this.checkAllFields for any other type of node is both + // bad for performance and way too forgiving. + return false; + } + + // If checking deeply and vDef === this, then we only need to call + // checkAllFields once. Calling checkAllFields is too strict when deep + // is false, because then we only care about this.isSupertypeOf(vDef). + if (deep && vDef === this) + return this.checkAllFields(value, deep); + + // In most cases we rely exclusively on isSupertypeOf to make O(1) + // subtyping determinations. This suffices in most situations outside + // of unit tests, since interface conformance is checked whenever new + // instances are created using builder functions. + if (!this.isSupertypeOf(vDef)) + return false; + + // The exception is when deep is true; then, we recursively check all + // fields. + if (!deep) + return true; + + // Use the more specific Def (vDef) to perform the deep check, but + // shallow-check fields defined by the less specific Def (this). + return vDef.checkAllFields(value, deep) + && this.checkAllFields(value, false); +}; + +Dp.bases = function() { + var args = slice.call(arguments); + var bases = this.baseNames; + + if (this.finalized) { + if (args.length !== bases.length) { + throw new Error(""); + } + for (var i = 0; i < args.length; i++) { + if (args[i] !== bases[i]) { + throw new Error(""); + } + } + return this; + } + + args.forEach(function(baseName) { + isString.assert(baseName); + + // This indexOf lookup may be O(n), but the typical number of base + // names is very small, and indexOf is a native Array method. + if (bases.indexOf(baseName) < 0) + bases.push(baseName); + }); + + return this; // For chaining. +}; + +// False by default until .build(...) is called on an instance. +Object.defineProperty(Dp, "buildable", { value: false }); + +var builders = {}; +exports.builders = builders; + +// This object is used as prototype for any node created by a builder. +var nodePrototype = {}; + +// Call this function to define a new method to be shared by all AST +// nodes. The replaced method (if any) is returned for easy wrapping. +exports.defineMethod = function(name, func) { + var old = nodePrototype[name]; + + // Pass undefined as func to delete nodePrototype[name]. + if (isUndefined.check(func)) { + delete nodePrototype[name]; + + } else { + isFunction.assert(func); + + Object.defineProperty(nodePrototype, name, { + enumerable: true, // For discoverability. + configurable: true, // For delete proto[name]. + value: func + }); + } + + return old; +}; + +var isArrayOfString = isString.arrayOf(); + +// Calling the .build method of a Def simultaneously marks the type as +// buildable (by defining builders[getBuilderName(typeName)]) and +// specifies the order of arguments that should be passed to the builder +// function to create an instance of the type. +Dp.build = function(/* param1, param2, ... */) { + var self = this; + + var newBuildParams = slice.call(arguments); + isArrayOfString.assert(newBuildParams); + + // Calling Def.prototype.build multiple times has the effect of merely + // redefining this property. + Object.defineProperty(self, "buildParams", { + value: newBuildParams, + writable: false, + enumerable: false, + configurable: true + }); + + if (self.buildable) { + // If this Def is already buildable, update self.buildParams and + // continue using the old builder function. + return self; + } + + // Every buildable type will have its "type" field filled in + // automatically. This includes types that are not subtypes of Node, + // like SourceLocation, but that seems harmless (TODO?). + self.field("type", String, function() { return self.typeName }); + + // Override Dp.buildable for this Def instance. + Object.defineProperty(self, "buildable", { value: true }); + + Object.defineProperty(builders, getBuilderName(self.typeName), { + enumerable: true, + + value: function() { + var args = arguments; + var argc = args.length; + var built = Object.create(nodePrototype); + + if (!self.finalized) { + throw new Error( + "attempting to instantiate unfinalized type " + + self.typeName + ); + } + + function add(param, i) { + if (hasOwn.call(built, param)) + return; + + var all = self.allFields; + if (!hasOwn.call(all, param)) { + throw new Error("" + param); + } + + var field = all[param]; + var type = field.type; + var value; + + if (isNumber.check(i) && i < argc) { + value = args[i]; + } else if (field.defaultFn) { + // Expose the partially-built object to the default + // function as its `this` object. + value = field.defaultFn.call(built); + } else { + var message = "no value or default function given for field " + + JSON.stringify(param) + " of " + self.typeName + "(" + + self.buildParams.map(function(name) { + return all[name]; + }).join(", ") + ")"; + throw new Error(message); + } + + if (!type.check(value)) { + throw new Error( + shallowStringify(value) + + " does not match field " + field + + " of type " + self.typeName + ); + } + + // TODO Could attach getters and setters here to enforce + // dynamic type safety. + built[param] = value; + } + + self.buildParams.forEach(function(param, i) { + add(param, i); + }); + + Object.keys(self.allFields).forEach(function(param) { + add(param); // Use the default value. + }); + + // Make sure that the "type" field was filled automatically. + if (built.type !== self.typeName) { + throw new Error(""); + } + + return built; + } + }); + + return self; // For chaining. +}; + +function getBuilderName(typeName) { + return typeName.replace(/^[A-Z]+/, function(upperCasePrefix) { + var len = upperCasePrefix.length; + switch (len) { + case 0: return ""; + // If there's only one initial capital letter, just lower-case it. + case 1: return upperCasePrefix.toLowerCase(); + default: + // If there's more than one initial capital letter, lower-case + // all but the last one, so that XMLDefaultDeclaration (for + // example) becomes xmlDefaultDeclaration. + return upperCasePrefix.slice( + 0, len - 1).toLowerCase() + + upperCasePrefix.charAt(len - 1); + } + }); +} +exports.getBuilderName = getBuilderName; + +function getStatementBuilderName(typeName) { + typeName = getBuilderName(typeName); + return typeName.replace(/(Expression)?$/, "Statement"); +} +exports.getStatementBuilderName = getStatementBuilderName; + +// The reason fields are specified using .field(...) instead of an object +// literal syntax is somewhat subtle: the object literal syntax would +// support only one key and one value, but with .field(...) we can pass +// any number of arguments to specify the field. +Dp.field = function(name, type, defaultFn, hidden) { + if (this.finalized) { + console.error("Ignoring attempt to redefine field " + + JSON.stringify(name) + " of finalized type " + + JSON.stringify(this.typeName)); + return this; + } + this.ownFields[name] = new Field(name, type, defaultFn, hidden); + return this; // For chaining. +}; + +var namedTypes = {}; +exports.namedTypes = namedTypes; + +// Like Object.keys, but aware of what fields each AST type should have. +function getFieldNames(object) { + var d = Def.fromValue(object); + if (d) { + return d.fieldNames.slice(0); + } + + if ("type" in object) { + throw new Error( + "did not recognize object of type " + + JSON.stringify(object.type) + ); + } + + return Object.keys(object); +} +exports.getFieldNames = getFieldNames; + +// Get the value of an object property, taking object.type and default +// functions into account. +function getFieldValue(object, fieldName) { + var d = Def.fromValue(object); + if (d) { + var field = d.allFields[fieldName]; + if (field) { + return field.getValue(object); + } + } + + return object[fieldName]; +} +exports.getFieldValue = getFieldValue; + +// Iterate over all defined fields of an object, including those missing +// or undefined, passing each field name and effective value (as returned +// by getFieldValue) to the callback. If the object has no corresponding +// Def, the callback will never be called. +exports.eachField = function(object, callback, context) { + getFieldNames(object).forEach(function(name) { + callback.call(this, name, getFieldValue(object, name)); + }, context); +}; + +// Similar to eachField, except that iteration stops as soon as the +// callback returns a truthy value. Like Array.prototype.some, the final +// result is either true or false to indicates whether the callback +// returned true for any element or not. +exports.someField = function(object, callback, context) { + return getFieldNames(object).some(function(name) { + return callback.call(this, name, getFieldValue(object, name)); + }, context); +}; + +// This property will be overridden as true by individual Def instances +// when they are finalized. +Object.defineProperty(Dp, "finalized", { value: false }); + +Dp.finalize = function() { + var self = this; + + // It's not an error to finalize a type more than once, but only the + // first call to .finalize does anything. + if (!self.finalized) { + var allFields = self.allFields; + var allSupertypes = self.allSupertypes; + + self.baseNames.forEach(function(name) { + var def = defCache[name]; + if (def instanceof Def) { + def.finalize(); + extend(allFields, def.allFields); + extend(allSupertypes, def.allSupertypes); + } else { + var message = "unknown supertype name " + + JSON.stringify(name) + + " for subtype " + + JSON.stringify(self.typeName); + throw new Error(message); + } + }); + + // TODO Warn if fields are overridden with incompatible types. + extend(allFields, self.ownFields); + allSupertypes[self.typeName] = self; + + self.fieldNames.length = 0; + for (var fieldName in allFields) { + if (hasOwn.call(allFields, fieldName) && + !allFields[fieldName].hidden) { + self.fieldNames.push(fieldName); + } + } + + // Types are exported only once they have been finalized. + Object.defineProperty(namedTypes, self.typeName, { + enumerable: true, + value: self.type + }); + + Object.defineProperty(self, "finalized", { value: true }); + + // A linearization of the inheritance hierarchy. + populateSupertypeList(self.typeName, self.supertypeList); + + if (self.buildable && self.supertypeList.lastIndexOf("Expression") >= 0) { + wrapExpressionBuilderWithStatement(self.typeName); + } + } +}; + +// Adds an additional builder for Expression subtypes +// that wraps the built Expression in an ExpressionStatements. +function wrapExpressionBuilderWithStatement(typeName) { + var wrapperName = getStatementBuilderName(typeName); + + // skip if the builder already exists + if (builders[wrapperName]) return; + + // the builder function to wrap with builders.ExpressionStatement + var wrapped = builders[getBuilderName(typeName)]; + + // skip if there is nothing to wrap + if (!wrapped) return; + + builders[wrapperName] = function() { + return builders.expressionStatement(wrapped.apply(builders, arguments)); + }; +} + +function populateSupertypeList(typeName, list) { + list.length = 0; + list.push(typeName); + + var lastSeen = Object.create(null); + + for (var pos = 0; pos < list.length; ++pos) { + typeName = list[pos]; + var d = defCache[typeName]; + if (d.finalized !== true) { + throw new Error(""); + } + + // If we saw typeName earlier in the breadth-first traversal, + // delete the last-seen occurrence. + if (hasOwn.call(lastSeen, typeName)) { + delete list[lastSeen[typeName]]; + } + + // Record the new index of the last-seen occurrence of typeName. + lastSeen[typeName] = pos; + + // Enqueue the base names of this type. + list.push.apply(list, d.baseNames); + } + + // Compaction loop to remove array holes. + for (var to = 0, from = to, len = list.length; from < len; ++from) { + if (hasOwn.call(list, from)) { + list[to++] = list[from]; + } + } + + list.length = to; +} + +function extend(into, from) { + Object.keys(from).forEach(function(name) { + into[name] = from[name]; + }); + + return into; +}; + +exports.finalize = function() { + Object.keys(defCache).forEach(function(name) { + defCache[name].finalize(); + }); +}; + +},{}],584:[function(_dereq_,module,exports){ +var types = _dereq_(583); + +// This core module of AST types captures ES5 as it is parsed today by +// git://github.com/ariya/esprima.git#master. +_dereq_(570); + +// Feel free to add to or remove from this list of extension modules to +// configure the precise type hierarchy that you need. +_dereq_(572); +_dereq_(573); +_dereq_(576); +_dereq_(571); +_dereq_(575); +_dereq_(574); +_dereq_(569); + +types.finalize(); + +exports.Type = types.Type; +exports.builtInTypes = types.builtInTypes; +exports.namedTypes = types.namedTypes; +exports.builders = types.builders; +exports.defineMethod = types.defineMethod; +exports.getFieldNames = types.getFieldNames; +exports.getFieldValue = types.getFieldValue; +exports.eachField = types.eachField; +exports.someField = types.someField; +exports.getSupertypeNames = types.getSupertypeNames; +exports.astNodesAreEquivalent = _dereq_(577); +exports.finalize = types.finalize; +exports.NodePath = _dereq_(578); +exports.PathVisitor = _dereq_(579); +exports.visit = exports.PathVisitor.visit; + +},{"569":569,"570":570,"571":571,"572":572,"573":573,"574":574,"575":575,"576":576,"577":577,"578":578,"579":579,"583":583}],585:[function(_dereq_,module,exports){ +(function (process,global){ +/** + * Copyright (c) 2014, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * https://raw.github.com/facebook/regenerator/master/LICENSE file. An + * additional grant of patent rights can be found in the PATENTS file in + * the same directory. + */ + +!(function(global) { + "use strict"; + + var hasOwn = Object.prototype.hasOwnProperty; + var undefined; // More compressible than void 0. + var iteratorSymbol = + typeof Symbol === "function" && Symbol.iterator || "@@iterator"; + + var inModule = typeof module === "object"; + var runtime = global.regeneratorRuntime; + if (runtime) { + if (inModule) { + // If regeneratorRuntime is defined globally and we're in a module, + // make the exports object identical to regeneratorRuntime. + module.exports = runtime; + } + // Don't bother evaluating the rest of this file if the runtime was + // already defined globally. + return; + } + + // Define the runtime globally (as expected by generated code) as either + // module.exports (if we're in a module) or a new, empty object. + runtime = global.regeneratorRuntime = inModule ? module.exports : {}; + + function wrap(innerFn, outerFn, self, tryLocsList) { + // If outerFn provided, then outerFn.prototype instanceof Generator. + var generator = Object.create((outerFn || Generator).prototype); + var context = new Context(tryLocsList || []); + + // The ._invoke method unifies the implementations of the .next, + // .throw, and .return methods. + generator._invoke = makeInvokeMethod(innerFn, self, context); + + return generator; + } + runtime.wrap = wrap; + + // Try/catch helper to minimize deoptimizations. Returns a completion + // record like context.tryEntries[i].completion. This interface could + // have been (and was previously) designed to take a closure to be + // invoked without arguments, but in all the cases we care about we + // already have an existing method we want to call, so there's no need + // to create a new function object. We can even get away with assuming + // the method takes exactly one argument, since that happens to be true + // in every case, so we don't have to touch the arguments object. The + // only additional allocation required is the completion record, which + // has a stable shape and so hopefully should be cheap to allocate. + function tryCatch(fn, obj, arg) { + try { + return { type: "normal", arg: fn.call(obj, arg) }; + } catch (err) { + return { type: "throw", arg: err }; + } + } + + var GenStateSuspendedStart = "suspendedStart"; + var GenStateSuspendedYield = "suspendedYield"; + var GenStateExecuting = "executing"; + var GenStateCompleted = "completed"; + + // Returning this object from the innerFn has the same effect as + // breaking out of the dispatch switch statement. + var ContinueSentinel = {}; + + // Dummy constructor functions that we use as the .constructor and + // .constructor.prototype properties for functions that return Generator + // objects. For full spec compliance, you may wish to configure your + // minifier not to mangle the names of these two functions. + function Generator() {} + function GeneratorFunction() {} + function GeneratorFunctionPrototype() {} + + var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype; + GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype; + GeneratorFunctionPrototype.constructor = GeneratorFunction; + GeneratorFunction.displayName = "GeneratorFunction"; + + // Helper for defining the .next, .throw, and .return methods of the + // Iterator interface in terms of a single ._invoke method. + function defineIteratorMethods(prototype) { + ["next", "throw", "return"].forEach(function(method) { + prototype[method] = function(arg) { + return this._invoke(method, arg); + }; + }); + } + + runtime.isGeneratorFunction = function(genFun) { + var ctor = typeof genFun === "function" && genFun.constructor; + return ctor + ? ctor === GeneratorFunction || + // For the native GeneratorFunction constructor, the best we can + // do is to check its .name property. + (ctor.displayName || ctor.name) === "GeneratorFunction" + : false; + }; + + runtime.mark = function(genFun) { + if (Object.setPrototypeOf) { + Object.setPrototypeOf(genFun, GeneratorFunctionPrototype); + } else { + genFun.__proto__ = GeneratorFunctionPrototype; + } + genFun.prototype = Object.create(Gp); + return genFun; + }; + + // Within the body of any async function, `await x` is transformed to + // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test + // `value instanceof AwaitArgument` to determine if the yielded value is + // meant to be awaited. Some may consider the name of this method too + // cutesy, but they are curmudgeons. + runtime.awrap = function(arg) { + return new AwaitArgument(arg); + }; + + function AwaitArgument(arg) { + this.arg = arg; + } + + function AsyncIterator(generator) { + // This invoke function is written in a style that assumes some + // calling function (or Promise) will handle exceptions. + function invoke(method, arg) { + var result = generator[method](arg); + var value = result.value; + return value instanceof AwaitArgument + ? Promise.resolve(value.arg).then(invokeNext, invokeThrow) + : Promise.resolve(value).then(function(unwrapped) { + // When a yielded Promise is resolved, its final value becomes + // the .value of the Promise<{value,done}> result for the + // current iteration. If the Promise is rejected, however, the + // result for this iteration will be rejected with the same + // reason. Note that rejections of yielded Promises are not + // thrown back into the generator function, as is the case + // when an awaited Promise is rejected. This difference in + // behavior between yield and await is important, because it + // allows the consumer to decide what to do with the yielded + // rejection (swallow it and continue, manually .throw it back + // into the generator, abandon iteration, whatever). With + // await, by contrast, there is no opportunity to examine the + // rejection reason outside the generator function, so the + // only option is to throw it from the await expression, and + // let the generator function handle the exception. + result.value = unwrapped; + return result; + }); + } + + if (typeof process === "object" && process.domain) { + invoke = process.domain.bind(invoke); + } + + var invokeNext = invoke.bind(generator, "next"); + var invokeThrow = invoke.bind(generator, "throw"); + var invokeReturn = invoke.bind(generator, "return"); + var previousPromise; + + function enqueue(method, arg) { + function callInvokeWithMethodAndArg() { + return invoke(method, arg); + } + + return previousPromise = + // If enqueue has been called before, then we want to wait until + // all previous Promises have been resolved before calling invoke, + // so that results are always delivered in the correct order. If + // enqueue has not been called before, then it is important to + // call invoke immediately, without waiting on a callback to fire, + // so that the async generator function has the opportunity to do + // any necessary setup in a predictable way. This predictability + // is why the Promise constructor synchronously invokes its + // executor callback, and why async functions synchronously + // execute code before the first await. Since we implement simple + // async functions in terms of async generators, it is especially + // important to get this right, even though it requires care. + previousPromise ? previousPromise.then( + callInvokeWithMethodAndArg, + // Avoid propagating failures to Promises returned by later + // invocations of the iterator. + callInvokeWithMethodAndArg + ) : new Promise(function (resolve) { + resolve(callInvokeWithMethodAndArg()); + }); + } + + // Define the unified helper method that is used to implement .next, + // .throw, and .return (see defineIteratorMethods). + this._invoke = enqueue; + } + + defineIteratorMethods(AsyncIterator.prototype); + + // Note that simple async functions are implemented on top of + // AsyncIterator objects; they just return a Promise for the value of + // the final result produced by the iterator. + runtime.async = function(innerFn, outerFn, self, tryLocsList) { + var iter = new AsyncIterator( + wrap(innerFn, outerFn, self, tryLocsList) + ); + + return runtime.isGeneratorFunction(outerFn) + ? iter // If outerFn is a generator, return the full iterator. + : iter.next().then(function(result) { + return result.done ? result.value : iter.next(); + }); + }; + + function makeInvokeMethod(innerFn, self, context) { + var state = GenStateSuspendedStart; + + return function invoke(method, arg) { + if (state === GenStateExecuting) { + throw new Error("Generator is already running"); + } + + if (state === GenStateCompleted) { + if (method === "throw") { + throw arg; + } + + // Be forgiving, per 25.3.3.3.3 of the spec: + // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume + return doneResult(); + } + + while (true) { + var delegate = context.delegate; + if (delegate) { + if (method === "return" || + (method === "throw" && delegate.iterator[method] === undefined)) { + // A return or throw (when the delegate iterator has no throw + // method) always terminates the yield* loop. + context.delegate = null; + + // If the delegate iterator has a return method, give it a + // chance to clean up. + var returnMethod = delegate.iterator["return"]; + if (returnMethod) { + var record = tryCatch(returnMethod, delegate.iterator, arg); + if (record.type === "throw") { + // If the return method threw an exception, let that + // exception prevail over the original return or throw. + method = "throw"; + arg = record.arg; + continue; + } + } + + if (method === "return") { + // Continue with the outer return, now that the delegate + // iterator has been terminated. + continue; + } + } + + var record = tryCatch( + delegate.iterator[method], + delegate.iterator, + arg + ); + + if (record.type === "throw") { + context.delegate = null; + + // Like returning generator.throw(uncaught), but without the + // overhead of an extra function call. + method = "throw"; + arg = record.arg; + continue; + } + + // Delegate generator ran and handled its own exceptions so + // regardless of what the method was, we continue as if it is + // "next" with an undefined arg. + method = "next"; + arg = undefined; + + var info = record.arg; + if (info.done) { + context[delegate.resultName] = info.value; + context.next = delegate.nextLoc; + } else { + state = GenStateSuspendedYield; + return info; + } + + context.delegate = null; + } + + if (method === "next") { + if (state === GenStateSuspendedYield) { + context.sent = arg; + } else { + context.sent = undefined; + } + + } else if (method === "throw") { + if (state === GenStateSuspendedStart) { + state = GenStateCompleted; + throw arg; + } + + if (context.dispatchException(arg)) { + // If the dispatched exception was caught by a catch block, + // then let that catch block handle the exception normally. + method = "next"; + arg = undefined; + } + + } else if (method === "return") { + context.abrupt("return", arg); + } + + state = GenStateExecuting; + + var record = tryCatch(innerFn, self, context); + if (record.type === "normal") { + // If an exception is thrown from innerFn, we leave state === + // GenStateExecuting and loop back for another invocation. + state = context.done + ? GenStateCompleted + : GenStateSuspendedYield; + + var info = { + value: record.arg, + done: context.done + }; + + if (record.arg === ContinueSentinel) { + if (context.delegate && method === "next") { + // Deliberately forget the last sent value so that we don't + // accidentally pass it on to the delegate. + arg = undefined; + } + } else { + return info; + } + + } else if (record.type === "throw") { + state = GenStateCompleted; + // Dispatch the exception by looping back around to the + // context.dispatchException(arg) call above. + method = "throw"; + arg = record.arg; + } + } + }; + } + + // Define Generator.prototype.{next,throw,return} in terms of the + // unified ._invoke helper method. + defineIteratorMethods(Gp); + + Gp[iteratorSymbol] = function() { + return this; + }; + + Gp.toString = function() { + return "[object Generator]"; + }; + + function pushTryEntry(locs) { + var entry = { tryLoc: locs[0] }; + + if (1 in locs) { + entry.catchLoc = locs[1]; + } + + if (2 in locs) { + entry.finallyLoc = locs[2]; + entry.afterLoc = locs[3]; + } + + this.tryEntries.push(entry); + } + + function resetTryEntry(entry) { + var record = entry.completion || {}; + record.type = "normal"; + delete record.arg; + entry.completion = record; + } + + function Context(tryLocsList) { + // The root entry object (effectively a try statement without a catch + // or a finally block) gives us a place to store values thrown from + // locations where there is no enclosing try statement. + this.tryEntries = [{ tryLoc: "root" }]; + tryLocsList.forEach(pushTryEntry, this); + this.reset(true); + } + + runtime.keys = function(object) { + var keys = []; + for (var key in object) { + keys.push(key); + } + keys.reverse(); + + // Rather than returning an object with a next method, we keep + // things simple and return the next function itself. + return function next() { + while (keys.length) { + var key = keys.pop(); + if (key in object) { + next.value = key; + next.done = false; + return next; + } + } + + // To avoid creating an additional object, we just hang the .value + // and .done properties off the next function object itself. This + // also ensures that the minifier will not anonymize the function. + next.done = true; + return next; + }; + }; + + function values(iterable) { + if (iterable) { + var iteratorMethod = iterable[iteratorSymbol]; + if (iteratorMethod) { + return iteratorMethod.call(iterable); + } + + if (typeof iterable.next === "function") { + return iterable; + } + + if (!isNaN(iterable.length)) { + var i = -1, next = function next() { + while (++i < iterable.length) { + if (hasOwn.call(iterable, i)) { + next.value = iterable[i]; + next.done = false; + return next; + } + } + + next.value = undefined; + next.done = true; + + return next; + }; + + return next.next = next; + } + } + + // Return an iterator with no values. + return { next: doneResult }; + } + runtime.values = values; + + function doneResult() { + return { value: undefined, done: true }; + } + + Context.prototype = { + constructor: Context, + + reset: function(skipTempReset) { + this.prev = 0; + this.next = 0; + this.sent = undefined; + this.done = false; + this.delegate = null; + + this.tryEntries.forEach(resetTryEntry); + + if (!skipTempReset) { + for (var name in this) { + // Not sure about the optimal order of these conditions: + if (name.charAt(0) === "t" && + hasOwn.call(this, name) && + !isNaN(+name.slice(1))) { + this[name] = undefined; + } + } + } + }, + + stop: function() { + this.done = true; + + var rootEntry = this.tryEntries[0]; + var rootRecord = rootEntry.completion; + if (rootRecord.type === "throw") { + throw rootRecord.arg; + } + + return this.rval; + }, + + dispatchException: function(exception) { + if (this.done) { + throw exception; + } + + var context = this; + function handle(loc, caught) { + record.type = "throw"; + record.arg = exception; + context.next = loc; + return !!caught; + } + + for (var i = this.tryEntries.length - 1; i >= 0; --i) { + var entry = this.tryEntries[i]; + var record = entry.completion; + + if (entry.tryLoc === "root") { + // Exception thrown outside of any try block that could handle + // it, so set the completion value of the entire function to + // throw the exception. + return handle("end"); + } + + if (entry.tryLoc <= this.prev) { + var hasCatch = hasOwn.call(entry, "catchLoc"); + var hasFinally = hasOwn.call(entry, "finallyLoc"); + + if (hasCatch && hasFinally) { + if (this.prev < entry.catchLoc) { + return handle(entry.catchLoc, true); + } else if (this.prev < entry.finallyLoc) { + return handle(entry.finallyLoc); + } + + } else if (hasCatch) { + if (this.prev < entry.catchLoc) { + return handle(entry.catchLoc, true); + } + + } else if (hasFinally) { + if (this.prev < entry.finallyLoc) { + return handle(entry.finallyLoc); + } + + } else { + throw new Error("try statement without catch or finally"); + } + } + } + }, + + abrupt: function(type, arg) { + for (var i = this.tryEntries.length - 1; i >= 0; --i) { + var entry = this.tryEntries[i]; + if (entry.tryLoc <= this.prev && + hasOwn.call(entry, "finallyLoc") && + this.prev < entry.finallyLoc) { + var finallyEntry = entry; + break; + } + } + + if (finallyEntry && + (type === "break" || + type === "continue") && + finallyEntry.tryLoc <= arg && + arg <= finallyEntry.finallyLoc) { + // Ignore the finally entry if control is not jumping to a + // location outside the try/catch block. + finallyEntry = null; + } + + var record = finallyEntry ? finallyEntry.completion : {}; + record.type = type; + record.arg = arg; + + if (finallyEntry) { + this.next = finallyEntry.finallyLoc; + } else { + this.complete(record); + } + + return ContinueSentinel; + }, + + complete: function(record, afterLoc) { + if (record.type === "throw") { + throw record.arg; + } + + if (record.type === "break" || + record.type === "continue") { + this.next = record.arg; + } else if (record.type === "return") { + this.rval = record.arg; + this.next = "end"; + } else if (record.type === "normal" && afterLoc) { + this.next = afterLoc; + } + }, + + finish: function(finallyLoc) { + for (var i = this.tryEntries.length - 1; i >= 0; --i) { + var entry = this.tryEntries[i]; + if (entry.finallyLoc === finallyLoc) { + this.complete(entry.completion, entry.afterLoc); + resetTryEntry(entry); + return ContinueSentinel; + } + } + }, + + "catch": function(tryLoc) { + for (var i = this.tryEntries.length - 1; i >= 0; --i) { + var entry = this.tryEntries[i]; + if (entry.tryLoc === tryLoc) { + var record = entry.completion; + if (record.type === "throw") { + var thrown = record.arg; + resetTryEntry(entry); + } + return thrown; + } + } + + // The context.catch method must only be called with a location + // argument that corresponds to a known catch block. + throw new Error("illegal catch attempt"); + }, + + delegateYield: function(iterable, resultName, nextLoc) { + this.delegate = { + iterator: values(iterable), + resultName: resultName, + nextLoc: nextLoc + }; + + return ContinueSentinel; + } + }; +})( + // Among the various tricks for obtaining a reference to the global + // object, this seems to be the most reliable technique that does not + // use indirect eval (which violates Content Security Policy). + typeof global === "object" ? global : + typeof window === "object" ? window : + typeof self === "object" ? self : this +); + +}).call(this,_dereq_(10),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"10":10}],586:[function(_dereq_,module,exports){ +// Generated by `/scripts/character-class-escape-sets.js`. Do not edit. +var regenerate = _dereq_(588); + +exports.REGULAR = { + 'd': regenerate() + .addRange(0x30, 0x39), + 'D': regenerate() + .addRange(0x0, 0x2F) + .addRange(0x3A, 0xFFFF), + 's': regenerate(0x20, 0xA0, 0x1680, 0x180E, 0x202F, 0x205F, 0x3000, 0xFEFF) + .addRange(0x9, 0xD) + .addRange(0x2000, 0x200A) + .addRange(0x2028, 0x2029), + 'S': regenerate() + .addRange(0x0, 0x8) + .addRange(0xE, 0x1F) + .addRange(0x21, 0x9F) + .addRange(0xA1, 0x167F) + .addRange(0x1681, 0x180D) + .addRange(0x180F, 0x1FFF) + .addRange(0x200B, 0x2027) + .addRange(0x202A, 0x202E) + .addRange(0x2030, 0x205E) + .addRange(0x2060, 0x2FFF) + .addRange(0x3001, 0xFEFE) + .addRange(0xFF00, 0xFFFF), + 'w': regenerate(0x5F) + .addRange(0x30, 0x39) + .addRange(0x41, 0x5A) + .addRange(0x61, 0x7A), + 'W': regenerate(0x60) + .addRange(0x0, 0x2F) + .addRange(0x3A, 0x40) + .addRange(0x5B, 0x5E) + .addRange(0x7B, 0xFFFF) +}; + +exports.UNICODE = { + 'd': regenerate() + .addRange(0x30, 0x39), + 'D': regenerate() + .addRange(0x0, 0x2F) + .addRange(0x3A, 0x10FFFF), + 's': regenerate(0x20, 0xA0, 0x1680, 0x180E, 0x202F, 0x205F, 0x3000, 0xFEFF) + .addRange(0x9, 0xD) + .addRange(0x2000, 0x200A) + .addRange(0x2028, 0x2029), + 'S': regenerate() + .addRange(0x0, 0x8) + .addRange(0xE, 0x1F) + .addRange(0x21, 0x9F) + .addRange(0xA1, 0x167F) + .addRange(0x1681, 0x180D) + .addRange(0x180F, 0x1FFF) + .addRange(0x200B, 0x2027) + .addRange(0x202A, 0x202E) + .addRange(0x2030, 0x205E) + .addRange(0x2060, 0x2FFF) + .addRange(0x3001, 0xFEFE) + .addRange(0xFF00, 0x10FFFF), + 'w': regenerate(0x5F) + .addRange(0x30, 0x39) + .addRange(0x41, 0x5A) + .addRange(0x61, 0x7A), + 'W': regenerate(0x60) + .addRange(0x0, 0x2F) + .addRange(0x3A, 0x40) + .addRange(0x5B, 0x5E) + .addRange(0x7B, 0x10FFFF) +}; + +exports.UNICODE_IGNORE_CASE = { + 'd': regenerate() + .addRange(0x30, 0x39), + 'D': regenerate() + .addRange(0x0, 0x2F) + .addRange(0x3A, 0x10FFFF), + 's': regenerate(0x20, 0xA0, 0x1680, 0x180E, 0x202F, 0x205F, 0x3000, 0xFEFF) + .addRange(0x9, 0xD) + .addRange(0x2000, 0x200A) + .addRange(0x2028, 0x2029), + 'S': regenerate() + .addRange(0x0, 0x8) + .addRange(0xE, 0x1F) + .addRange(0x21, 0x9F) + .addRange(0xA1, 0x167F) + .addRange(0x1681, 0x180D) + .addRange(0x180F, 0x1FFF) + .addRange(0x200B, 0x2027) + .addRange(0x202A, 0x202E) + .addRange(0x2030, 0x205E) + .addRange(0x2060, 0x2FFF) + .addRange(0x3001, 0xFEFE) + .addRange(0xFF00, 0x10FFFF), + 'w': regenerate(0x5F, 0x17F, 0x212A) + .addRange(0x30, 0x39) + .addRange(0x41, 0x5A) + .addRange(0x61, 0x7A), + 'W': regenerate(0x4B, 0x53, 0x60) + .addRange(0x0, 0x2F) + .addRange(0x3A, 0x40) + .addRange(0x5B, 0x5E) + .addRange(0x7B, 0x10FFFF) +}; + +},{"588":588}],587:[function(_dereq_,module,exports){ +module.exports={ + "75": 8490, + "83": 383, + "107": 8490, + "115": 383, + "181": 924, + "197": 8491, + "383": 83, + "452": 453, + "453": 452, + "455": 456, + "456": 455, + "458": 459, + "459": 458, + "497": 498, + "498": 497, + "837": 8126, + "914": 976, + "917": 1013, + "920": 1012, + "921": 8126, + "922": 1008, + "924": 181, + "928": 982, + "929": 1009, + "931": 962, + "934": 981, + "937": 8486, + "962": 931, + "976": 914, + "977": 1012, + "981": 934, + "982": 928, + "1008": 922, + "1009": 929, + "1012": [ + 920, + 977 + ], + "1013": 917, + "7776": 7835, + "7835": 7776, + "8126": [ + 837, + 921 + ], + "8486": 937, + "8490": 75, + "8491": 197, + "66560": 66600, + "66561": 66601, + "66562": 66602, + "66563": 66603, + "66564": 66604, + "66565": 66605, + "66566": 66606, + "66567": 66607, + "66568": 66608, + "66569": 66609, + "66570": 66610, + "66571": 66611, + "66572": 66612, + "66573": 66613, + "66574": 66614, + "66575": 66615, + "66576": 66616, + "66577": 66617, + "66578": 66618, + "66579": 66619, + "66580": 66620, + "66581": 66621, + "66582": 66622, + "66583": 66623, + "66584": 66624, + "66585": 66625, + "66586": 66626, + "66587": 66627, + "66588": 66628, + "66589": 66629, + "66590": 66630, + "66591": 66631, + "66592": 66632, + "66593": 66633, + "66594": 66634, + "66595": 66635, + "66596": 66636, + "66597": 66637, + "66598": 66638, + "66599": 66639, + "66600": 66560, + "66601": 66561, + "66602": 66562, + "66603": 66563, + "66604": 66564, + "66605": 66565, + "66606": 66566, + "66607": 66567, + "66608": 66568, + "66609": 66569, + "66610": 66570, + "66611": 66571, + "66612": 66572, + "66613": 66573, + "66614": 66574, + "66615": 66575, + "66616": 66576, + "66617": 66577, + "66618": 66578, + "66619": 66579, + "66620": 66580, + "66621": 66581, + "66622": 66582, + "66623": 66583, + "66624": 66584, + "66625": 66585, + "66626": 66586, + "66627": 66587, + "66628": 66588, + "66629": 66589, + "66630": 66590, + "66631": 66591, + "66632": 66592, + "66633": 66593, + "66634": 66594, + "66635": 66595, + "66636": 66596, + "66637": 66597, + "66638": 66598, + "66639": 66599, + "68736": 68800, + "68737": 68801, + "68738": 68802, + "68739": 68803, + "68740": 68804, + "68741": 68805, + "68742": 68806, + "68743": 68807, + "68744": 68808, + "68745": 68809, + "68746": 68810, + "68747": 68811, + "68748": 68812, + "68749": 68813, + "68750": 68814, + "68751": 68815, + "68752": 68816, + "68753": 68817, + "68754": 68818, + "68755": 68819, + "68756": 68820, + "68757": 68821, + "68758": 68822, + "68759": 68823, + "68760": 68824, + "68761": 68825, + "68762": 68826, + "68763": 68827, + "68764": 68828, + "68765": 68829, + "68766": 68830, + "68767": 68831, + "68768": 68832, + "68769": 68833, + "68770": 68834, + "68771": 68835, + "68772": 68836, + "68773": 68837, + "68774": 68838, + "68775": 68839, + "68776": 68840, + "68777": 68841, + "68778": 68842, + "68779": 68843, + "68780": 68844, + "68781": 68845, + "68782": 68846, + "68783": 68847, + "68784": 68848, + "68785": 68849, + "68786": 68850, + "68800": 68736, + "68801": 68737, + "68802": 68738, + "68803": 68739, + "68804": 68740, + "68805": 68741, + "68806": 68742, + "68807": 68743, + "68808": 68744, + "68809": 68745, + "68810": 68746, + "68811": 68747, + "68812": 68748, + "68813": 68749, + "68814": 68750, + "68815": 68751, + "68816": 68752, + "68817": 68753, + "68818": 68754, + "68819": 68755, + "68820": 68756, + "68821": 68757, + "68822": 68758, + "68823": 68759, + "68824": 68760, + "68825": 68761, + "68826": 68762, + "68827": 68763, + "68828": 68764, + "68829": 68765, + "68830": 68766, + "68831": 68767, + "68832": 68768, + "68833": 68769, + "68834": 68770, + "68835": 68771, + "68836": 68772, + "68837": 68773, + "68838": 68774, + "68839": 68775, + "68840": 68776, + "68841": 68777, + "68842": 68778, + "68843": 68779, + "68844": 68780, + "68845": 68781, + "68846": 68782, + "68847": 68783, + "68848": 68784, + "68849": 68785, + "68850": 68786, + "71840": 71872, + "71841": 71873, + "71842": 71874, + "71843": 71875, + "71844": 71876, + "71845": 71877, + "71846": 71878, + "71847": 71879, + "71848": 71880, + "71849": 71881, + "71850": 71882, + "71851": 71883, + "71852": 71884, + "71853": 71885, + "71854": 71886, + "71855": 71887, + "71856": 71888, + "71857": 71889, + "71858": 71890, + "71859": 71891, + "71860": 71892, + "71861": 71893, + "71862": 71894, + "71863": 71895, + "71864": 71896, + "71865": 71897, + "71866": 71898, + "71867": 71899, + "71868": 71900, + "71869": 71901, + "71870": 71902, + "71871": 71903, + "71872": 71840, + "71873": 71841, + "71874": 71842, + "71875": 71843, + "71876": 71844, + "71877": 71845, + "71878": 71846, + "71879": 71847, + "71880": 71848, + "71881": 71849, + "71882": 71850, + "71883": 71851, + "71884": 71852, + "71885": 71853, + "71886": 71854, + "71887": 71855, + "71888": 71856, + "71889": 71857, + "71890": 71858, + "71891": 71859, + "71892": 71860, + "71893": 71861, + "71894": 71862, + "71895": 71863, + "71896": 71864, + "71897": 71865, + "71898": 71866, + "71899": 71867, + "71900": 71868, + "71901": 71869, + "71902": 71870, + "71903": 71871 +} + +},{}],588:[function(_dereq_,module,exports){ +(function (global){ +/*! https://mths.be/regenerate v1.2.0 by @mathias | MIT license */ +;(function(root) { + + // Detect free variables `exports`. + var freeExports = typeof exports == 'object' && exports; + + // Detect free variable `module`. + var freeModule = typeof module == 'object' && module && + module.exports == freeExports && module; + + // Detect free variable `global`, from Node.js or Browserified code, + // and use it as `root`. + var freeGlobal = typeof global == 'object' && global; + if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) { + root = freeGlobal; + } + + /*--------------------------------------------------------------------------*/ + + var ERRORS = { + 'rangeOrder': 'A range\u2019s `stop` value must be greater than or equal ' + + 'to the `start` value.', + 'codePointRange': 'Invalid code point value. Code points range from ' + + 'U+000000 to U+10FFFF.' + }; + + // https://mathiasbynens.be/notes/javascript-encoding#surrogate-pairs + var HIGH_SURROGATE_MIN = 0xD800; + var HIGH_SURROGATE_MAX = 0xDBFF; + var LOW_SURROGATE_MIN = 0xDC00; + var LOW_SURROGATE_MAX = 0xDFFF; + + // In Regenerate output, `\0` will never be preceded by `\` because we sort + // by code point value, so let’s keep this regular expression simple. + var regexNull = /\\x00([^0123456789]|$)/g; + + var object = {}; + var hasOwnProperty = object.hasOwnProperty; + var extend = function(destination, source) { + var key; + for (key in source) { + if (hasOwnProperty.call(source, key)) { + destination[key] = source[key]; + } + } + return destination; + }; + + var forEach = function(array, callback) { + var index = -1; + var length = array.length; + while (++index < length) { + callback(array[index], index); + } + }; + + var toString = object.toString; + var isArray = function(value) { + return toString.call(value) == '[object Array]'; + }; + var isNumber = function(value) { + return typeof value == 'number' || + toString.call(value) == '[object Number]'; + }; + + // This assumes that `number` is a positive integer that `toString()`s nicely + // (which is the case for all code point values). + var zeroes = '0000'; + var pad = function(number, totalCharacters) { + var string = String(number); + return string.length < totalCharacters + ? (zeroes + string).slice(-totalCharacters) + : string; + }; + + var hex = function(number) { + return Number(number).toString(16).toUpperCase(); + }; + + var slice = [].slice; + + /*--------------------------------------------------------------------------*/ + + var dataFromCodePoints = function(codePoints) { + var index = -1; + var length = codePoints.length; + var max = length - 1; + var result = []; + var isStart = true; + var tmp; + var previous = 0; + while (++index < length) { + tmp = codePoints[index]; + if (isStart) { + result.push(tmp); + previous = tmp; + isStart = false; + } else { + if (tmp == previous + 1) { + if (index != max) { + previous = tmp; + continue; + } else { + isStart = true; + result.push(tmp + 1); + } + } else { + // End the previous range and start a new one. + result.push(previous + 1, tmp); + previous = tmp; + } + } + } + if (!isStart) { + result.push(tmp + 1); + } + return result; + }; + + var dataRemove = function(data, codePoint) { + // Iterate over the data per `(start, end)` pair. + var index = 0; + var start; + var end; + var length = data.length; + while (index < length) { + start = data[index]; + end = data[index + 1]; + if (codePoint >= start && codePoint < end) { + // Modify this pair. + if (codePoint == start) { + if (end == start + 1) { + // Just remove `start` and `end`. + data.splice(index, 2); + return data; + } else { + // Just replace `start` with a new value. + data[index] = codePoint + 1; + return data; + } + } else if (codePoint == end - 1) { + // Just replace `end` with a new value. + data[index + 1] = codePoint; + return data; + } else { + // Replace `[start, end]` with `[startA, endA, startB, endB]`. + data.splice(index, 2, start, codePoint, codePoint + 1, end); + return data; + } + } + index += 2; + } + return data; + }; + + var dataRemoveRange = function(data, rangeStart, rangeEnd) { + if (rangeEnd < rangeStart) { + throw Error(ERRORS.rangeOrder); + } + // Iterate over the data per `(start, end)` pair. + var index = 0; + var start; + var end; + while (index < data.length) { + start = data[index]; + end = data[index + 1] - 1; // Note: the `- 1` makes `end` inclusive. + + // Exit as soon as no more matching pairs can be found. + if (start > rangeEnd) { + return data; + } + + // Check if this range pair is equal to, or forms a subset of, the range + // to be removed. + // E.g. we have `[0, 11, 40, 51]` and want to remove 0-10 → `[40, 51]`. + // E.g. we have `[40, 51]` and want to remove 0-100 → `[]`. + if (rangeStart <= start && rangeEnd >= end) { + // Remove this pair. + data.splice(index, 2); + continue; + } + + // Check if both `rangeStart` and `rangeEnd` are within the bounds of + // this pair. + // E.g. we have `[0, 11]` and want to remove 4-6 → `[0, 4, 7, 11]`. + if (rangeStart >= start && rangeEnd < end) { + if (rangeStart == start) { + // Replace `[start, end]` with `[startB, endB]`. + data[index] = rangeEnd + 1; + data[index + 1] = end + 1; + return data; + } + // Replace `[start, end]` with `[startA, endA, startB, endB]`. + data.splice(index, 2, start, rangeStart, rangeEnd + 1, end + 1); + return data; + } + + // Check if only `rangeStart` is within the bounds of this pair. + // E.g. we have `[0, 11]` and want to remove 4-20 → `[0, 4]`. + if (rangeStart >= start && rangeStart <= end) { + // Replace `end` with `rangeStart`. + data[index + 1] = rangeStart; + // Note: we cannot `return` just yet, in case any following pairs still + // contain matching code points. + // E.g. we have `[0, 11, 14, 31]` and want to remove 4-20 + // → `[0, 4, 21, 31]`. + } + + // Check if only `rangeEnd` is within the bounds of this pair. + // E.g. we have `[14, 31]` and want to remove 4-20 → `[21, 31]`. + else if (rangeEnd >= start && rangeEnd <= end) { + // Just replace `start`. + data[index] = rangeEnd + 1; + return data; + } + + index += 2; + } + return data; + }; + + var dataAdd = function(data, codePoint) { + // Iterate over the data per `(start, end)` pair. + var index = 0; + var start; + var end; + var lastIndex = null; + var length = data.length; + if (codePoint < 0x0 || codePoint > 0x10FFFF) { + throw RangeError(ERRORS.codePointRange); + } + while (index < length) { + start = data[index]; + end = data[index + 1]; + + // Check if the code point is already in the set. + if (codePoint >= start && codePoint < end) { + return data; + } + + if (codePoint == start - 1) { + // Just replace `start` with a new value. + data[index] = codePoint; + return data; + } + + // At this point, if `start` is `greater` than `codePoint`, insert a new + // `[start, end]` pair before the current pair, or after the current pair + // if there is a known `lastIndex`. + if (start > codePoint) { + data.splice( + lastIndex != null ? lastIndex + 2 : 0, + 0, + codePoint, + codePoint + 1 + ); + return data; + } + + if (codePoint == end) { + // Check if adding this code point causes two separate ranges to become + // a single range, e.g. `dataAdd([0, 4, 5, 10], 4)` → `[0, 10]`. + if (codePoint + 1 == data[index + 2]) { + data.splice(index, 4, start, data[index + 3]); + return data; + } + // Else, just replace `end` with a new value. + data[index + 1] = codePoint + 1; + return data; + } + lastIndex = index; + index += 2; + } + // The loop has finished; add the new pair to the end of the data set. + data.push(codePoint, codePoint + 1); + return data; + }; + + var dataAddData = function(dataA, dataB) { + // Iterate over the data per `(start, end)` pair. + var index = 0; + var start; + var end; + var data = dataA.slice(); + var length = dataB.length; + while (index < length) { + start = dataB[index]; + end = dataB[index + 1] - 1; + if (start == end) { + data = dataAdd(data, start); + } else { + data = dataAddRange(data, start, end); + } + index += 2; + } + return data; + }; + + var dataRemoveData = function(dataA, dataB) { + // Iterate over the data per `(start, end)` pair. + var index = 0; + var start; + var end; + var data = dataA.slice(); + var length = dataB.length; + while (index < length) { + start = dataB[index]; + end = dataB[index + 1] - 1; + if (start == end) { + data = dataRemove(data, start); + } else { + data = dataRemoveRange(data, start, end); + } + index += 2; + } + return data; + }; + + var dataAddRange = function(data, rangeStart, rangeEnd) { + if (rangeEnd < rangeStart) { + throw Error(ERRORS.rangeOrder); + } + if ( + rangeStart < 0x0 || rangeStart > 0x10FFFF || + rangeEnd < 0x0 || rangeEnd > 0x10FFFF + ) { + throw RangeError(ERRORS.codePointRange); + } + // Iterate over the data per `(start, end)` pair. + var index = 0; + var start; + var end; + var added = false; + var length = data.length; + while (index < length) { + start = data[index]; + end = data[index + 1]; + + if (added) { + // The range has already been added to the set; at this point, we just + // need to get rid of the following ranges in case they overlap. + + // Check if this range can be combined with the previous range. + if (start == rangeEnd + 1) { + data.splice(index - 1, 2); + return data; + } + + // Exit as soon as no more possibly overlapping pairs can be found. + if (start > rangeEnd) { + return data; + } + + // E.g. `[0, 11, 12, 16]` and we’ve added 5-15, so we now have + // `[0, 16, 12, 16]`. Remove the `12,16` part, as it lies within the + // `0,16` range that was previously added. + if (start >= rangeStart && start <= rangeEnd) { + // `start` lies within the range that was previously added. + + if (end > rangeStart && end - 1 <= rangeEnd) { + // `end` lies within the range that was previously added as well, + // so remove this pair. + data.splice(index, 2); + index -= 2; + // Note: we cannot `return` just yet, as there may still be other + // overlapping pairs. + } else { + // `start` lies within the range that was previously added, but + // `end` doesn’t. E.g. `[0, 11, 12, 31]` and we’ve added 5-15, so + // now we have `[0, 16, 12, 31]`. This must be written as `[0, 31]`. + // Remove the previously added `end` and the current `start`. + data.splice(index - 1, 2); + index -= 2; + } + + // Note: we cannot return yet. + } + + } + + else if (start == rangeEnd + 1) { + data[index] = rangeStart; + return data; + } + + // Check if a new pair must be inserted *before* the current one. + else if (start > rangeEnd) { + data.splice(index, 0, rangeStart, rangeEnd + 1); + return data; + } + + else if (rangeStart >= start && rangeStart < end && rangeEnd + 1 <= end) { + // The new range lies entirely within an existing range pair. No action + // needed. + return data; + } + + else if ( + // E.g. `[0, 11]` and you add 5-15 → `[0, 16]`. + (rangeStart >= start && rangeStart < end) || + // E.g. `[0, 3]` and you add 3-6 → `[0, 7]`. + end == rangeStart + ) { + // Replace `end` with the new value. + data[index + 1] = rangeEnd + 1; + // Make sure the next range pair doesn’t overlap, e.g. `[0, 11, 12, 14]` + // and you add 5-15 → `[0, 16]`, i.e. remove the `12,14` part. + added = true; + // Note: we cannot `return` just yet. + } + + else if (rangeStart <= start && rangeEnd + 1 >= end) { + // The new range is a superset of the old range. + data[index] = rangeStart; + data[index + 1] = rangeEnd + 1; + added = true; + } + + index += 2; + } + // The loop has finished without doing anything; add the new pair to the end + // of the data set. + if (!added) { + data.push(rangeStart, rangeEnd + 1); + } + return data; + }; + + var dataContains = function(data, codePoint) { + var index = 0; + var length = data.length; + // Exit early if `codePoint` is not within `data`’s overall range. + var start = data[index]; + var end = data[length - 1]; + if (length >= 2) { + if (codePoint < start || codePoint > end) { + return false; + } + } + // Iterate over the data per `(start, end)` pair. + while (index < length) { + start = data[index]; + end = data[index + 1]; + if (codePoint >= start && codePoint < end) { + return true; + } + index += 2; + } + return false; + }; + + var dataIntersection = function(data, codePoints) { + var index = 0; + var length = codePoints.length; + var codePoint; + var result = []; + while (index < length) { + codePoint = codePoints[index]; + if (dataContains(data, codePoint)) { + result.push(codePoint); + } + ++index; + } + return dataFromCodePoints(result); + }; + + var dataIsEmpty = function(data) { + return !data.length; + }; + + var dataIsSingleton = function(data) { + // Check if the set only represents a single code point. + return data.length == 2 && data[0] + 1 == data[1]; + }; + + var dataToArray = function(data) { + // Iterate over the data per `(start, end)` pair. + var index = 0; + var start; + var end; + var result = []; + var length = data.length; + while (index < length) { + start = data[index]; + end = data[index + 1]; + while (start < end) { + result.push(start); + ++start; + } + index += 2; + } + return result; + }; + + /*--------------------------------------------------------------------------*/ + + // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae + var floor = Math.floor; + var highSurrogate = function(codePoint) { + return parseInt( + floor((codePoint - 0x10000) / 0x400) + HIGH_SURROGATE_MIN, + 10 + ); + }; + + var lowSurrogate = function(codePoint) { + return parseInt( + (codePoint - 0x10000) % 0x400 + LOW_SURROGATE_MIN, + 10 + ); + }; + + var stringFromCharCode = String.fromCharCode; + var codePointToString = function(codePoint) { + var string; + // https://mathiasbynens.be/notes/javascript-escapes#single + // Note: the `\b` escape sequence for U+0008 BACKSPACE in strings has a + // different meaning in regular expressions (word boundary), so it cannot + // be used here. + if (codePoint == 0x09) { + string = '\\t'; + } + // Note: IE < 9 treats `'\v'` as `'v'`, so avoid using it. + // else if (codePoint == 0x0B) { + // string = '\\v'; + // } + else if (codePoint == 0x0A) { + string = '\\n'; + } + else if (codePoint == 0x0C) { + string = '\\f'; + } + else if (codePoint == 0x0D) { + string = '\\r'; + } + else if (codePoint == 0x5C) { + string = '\\\\'; + } + else if ( + codePoint == 0x24 || + (codePoint >= 0x28 && codePoint <= 0x2B) || + codePoint == 0x2D || codePoint == 0x2E || codePoint == 0x3F || + (codePoint >= 0x5B && codePoint <= 0x5E) || + (codePoint >= 0x7B && codePoint <= 0x7D) + ) { + // The code point maps to an unsafe printable ASCII character; + // backslash-escape it. Here’s the list of those symbols: + // + // $()*+-.?[\]^{|} + // + // See #7 for more info. + string = '\\' + stringFromCharCode(codePoint); + } + else if (codePoint >= 0x20 && codePoint <= 0x7E) { + // The code point maps to one of these printable ASCII symbols + // (including the space character): + // + // !"#%&',/0123456789:;<=>@ABCDEFGHIJKLMNO + // PQRSTUVWXYZ_`abcdefghijklmnopqrstuvwxyz~ + // + // These can safely be used directly. + string = stringFromCharCode(codePoint); + } + else if (codePoint <= 0xFF) { + // https://mathiasbynens.be/notes/javascript-escapes#hexadecimal + string = '\\x' + pad(hex(codePoint), 2); + } + else { // `codePoint <= 0xFFFF` holds true. + // https://mathiasbynens.be/notes/javascript-escapes#unicode + string = '\\u' + pad(hex(codePoint), 4); + } + + // There’s no need to account for astral symbols / surrogate pairs here, + // since `codePointToString` is private and only used for BMP code points. + // But if that’s what you need, just add an `else` block with this code: + // + // string = '\\u' + pad(hex(highSurrogate(codePoint)), 4) + // + '\\u' + pad(hex(lowSurrogate(codePoint)), 4); + + return string; + }; + + var symbolToCodePoint = function(symbol) { + var length = symbol.length; + var first = symbol.charCodeAt(0); + var second; + if ( + first >= HIGH_SURROGATE_MIN && first <= HIGH_SURROGATE_MAX && + length > 1 // There is a next code unit. + ) { + // `first` is a high surrogate, and there is a next character. Assume + // it’s a low surrogate (else it’s invalid usage of Regenerate anyway). + second = symbol.charCodeAt(1); + // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae + return (first - HIGH_SURROGATE_MIN) * 0x400 + + second - LOW_SURROGATE_MIN + 0x10000; + } + return first; + }; + + var createBMPCharacterClasses = function(data) { + // Iterate over the data per `(start, end)` pair. + var result = ''; + var index = 0; + var start; + var end; + var length = data.length; + if (dataIsSingleton(data)) { + return codePointToString(data[0]); + } + while (index < length) { + start = data[index]; + end = data[index + 1] - 1; // Note: the `- 1` makes `end` inclusive. + if (start == end) { + result += codePointToString(start); + } else if (start + 1 == end) { + result += codePointToString(start) + codePointToString(end); + } else { + result += codePointToString(start) + '-' + codePointToString(end); + } + index += 2; + } + return '[' + result + ']'; + }; + + var splitAtBMP = function(data) { + // Iterate over the data per `(start, end)` pair. + var loneHighSurrogates = []; + var loneLowSurrogates = []; + var bmp = []; + var astral = []; + var index = 0; + var start; + var end; + var length = data.length; + while (index < length) { + start = data[index]; + end = data[index + 1] - 1; // Note: the `- 1` makes `end` inclusive. + + if (start < HIGH_SURROGATE_MIN) { + + // The range starts and ends before the high surrogate range. + // E.g. (0, 0x10). + if (end < HIGH_SURROGATE_MIN) { + bmp.push(start, end + 1); + } + + // The range starts before the high surrogate range and ends within it. + // E.g. (0, 0xD855). + if (end >= HIGH_SURROGATE_MIN && end <= HIGH_SURROGATE_MAX) { + bmp.push(start, HIGH_SURROGATE_MIN); + loneHighSurrogates.push(HIGH_SURROGATE_MIN, end + 1); + } + + // The range starts before the high surrogate range and ends in the low + // surrogate range. E.g. (0, 0xDCFF). + if (end >= LOW_SURROGATE_MIN && end <= LOW_SURROGATE_MAX) { + bmp.push(start, HIGH_SURROGATE_MIN); + loneHighSurrogates.push(HIGH_SURROGATE_MIN, HIGH_SURROGATE_MAX + 1); + loneLowSurrogates.push(LOW_SURROGATE_MIN, end + 1); + } + + // The range starts before the high surrogate range and ends after the + // low surrogate range. E.g. (0, 0x10FFFF). + if (end > LOW_SURROGATE_MAX) { + bmp.push(start, HIGH_SURROGATE_MIN); + loneHighSurrogates.push(HIGH_SURROGATE_MIN, HIGH_SURROGATE_MAX + 1); + loneLowSurrogates.push(LOW_SURROGATE_MIN, LOW_SURROGATE_MAX + 1); + if (end <= 0xFFFF) { + bmp.push(LOW_SURROGATE_MAX + 1, end + 1); + } else { + bmp.push(LOW_SURROGATE_MAX + 1, 0xFFFF + 1); + astral.push(0xFFFF + 1, end + 1); + } + } + + } else if (start >= HIGH_SURROGATE_MIN && start <= HIGH_SURROGATE_MAX) { + + // The range starts and ends in the high surrogate range. + // E.g. (0xD855, 0xD866). + if (end >= HIGH_SURROGATE_MIN && end <= HIGH_SURROGATE_MAX) { + loneHighSurrogates.push(start, end + 1); + } + + // The range starts in the high surrogate range and ends in the low + // surrogate range. E.g. (0xD855, 0xDCFF). + if (end >= LOW_SURROGATE_MIN && end <= LOW_SURROGATE_MAX) { + loneHighSurrogates.push(start, HIGH_SURROGATE_MAX + 1); + loneLowSurrogates.push(LOW_SURROGATE_MIN, end + 1); + } + + // The range starts in the high surrogate range and ends after the low + // surrogate range. E.g. (0xD855, 0x10FFFF). + if (end > LOW_SURROGATE_MAX) { + loneHighSurrogates.push(start, HIGH_SURROGATE_MAX + 1); + loneLowSurrogates.push(LOW_SURROGATE_MIN, LOW_SURROGATE_MAX + 1); + if (end <= 0xFFFF) { + bmp.push(LOW_SURROGATE_MAX + 1, end + 1); + } else { + bmp.push(LOW_SURROGATE_MAX + 1, 0xFFFF + 1); + astral.push(0xFFFF + 1, end + 1); + } + } + + } else if (start >= LOW_SURROGATE_MIN && start <= LOW_SURROGATE_MAX) { + + // The range starts and ends in the low surrogate range. + // E.g. (0xDCFF, 0xDDFF). + if (end >= LOW_SURROGATE_MIN && end <= LOW_SURROGATE_MAX) { + loneLowSurrogates.push(start, end + 1); + } + + // The range starts in the low surrogate range and ends after the low + // surrogate range. E.g. (0xDCFF, 0x10FFFF). + if (end > LOW_SURROGATE_MAX) { + loneLowSurrogates.push(start, LOW_SURROGATE_MAX + 1); + if (end <= 0xFFFF) { + bmp.push(LOW_SURROGATE_MAX + 1, end + 1); + } else { + bmp.push(LOW_SURROGATE_MAX + 1, 0xFFFF + 1); + astral.push(0xFFFF + 1, end + 1); + } + } + + } else if (start > LOW_SURROGATE_MAX && start <= 0xFFFF) { + + // The range starts and ends after the low surrogate range. + // E.g. (0xFFAA, 0x10FFFF). + if (end <= 0xFFFF) { + bmp.push(start, end + 1); + } else { + bmp.push(start, 0xFFFF + 1); + astral.push(0xFFFF + 1, end + 1); + } + + } else { + + // The range starts and ends in the astral range. + astral.push(start, end + 1); + + } + + index += 2; + } + return { + 'loneHighSurrogates': loneHighSurrogates, + 'loneLowSurrogates': loneLowSurrogates, + 'bmp': bmp, + 'astral': astral + }; + }; + + var optimizeSurrogateMappings = function(surrogateMappings) { + var result = []; + var tmpLow = []; + var addLow = false; + var mapping; + var nextMapping; + var highSurrogates; + var lowSurrogates; + var nextHighSurrogates; + var nextLowSurrogates; + var index = -1; + var length = surrogateMappings.length; + while (++index < length) { + mapping = surrogateMappings[index]; + nextMapping = surrogateMappings[index + 1]; + if (!nextMapping) { + result.push(mapping); + continue; + } + highSurrogates = mapping[0]; + lowSurrogates = mapping[1]; + nextHighSurrogates = nextMapping[0]; + nextLowSurrogates = nextMapping[1]; + + // Check for identical high surrogate ranges. + tmpLow = lowSurrogates; + while ( + nextHighSurrogates && + highSurrogates[0] == nextHighSurrogates[0] && + highSurrogates[1] == nextHighSurrogates[1] + ) { + // Merge with the next item. + if (dataIsSingleton(nextLowSurrogates)) { + tmpLow = dataAdd(tmpLow, nextLowSurrogates[0]); + } else { + tmpLow = dataAddRange( + tmpLow, + nextLowSurrogates[0], + nextLowSurrogates[1] - 1 + ); + } + ++index; + mapping = surrogateMappings[index]; + highSurrogates = mapping[0]; + lowSurrogates = mapping[1]; + nextMapping = surrogateMappings[index + 1]; + nextHighSurrogates = nextMapping && nextMapping[0]; + nextLowSurrogates = nextMapping && nextMapping[1]; + addLow = true; + } + result.push([ + highSurrogates, + addLow ? tmpLow : lowSurrogates + ]); + addLow = false; + } + return optimizeByLowSurrogates(result); + }; + + var optimizeByLowSurrogates = function(surrogateMappings) { + if (surrogateMappings.length == 1) { + return surrogateMappings; + } + var index = -1; + var innerIndex = -1; + while (++index < surrogateMappings.length) { + var mapping = surrogateMappings[index]; + var lowSurrogates = mapping[1]; + var lowSurrogateStart = lowSurrogates[0]; + var lowSurrogateEnd = lowSurrogates[1]; + innerIndex = index; // Note: the loop starts at the next index. + while (++innerIndex < surrogateMappings.length) { + var otherMapping = surrogateMappings[innerIndex]; + var otherLowSurrogates = otherMapping[1]; + var otherLowSurrogateStart = otherLowSurrogates[0]; + var otherLowSurrogateEnd = otherLowSurrogates[1]; + if ( + lowSurrogateStart == otherLowSurrogateStart && + lowSurrogateEnd == otherLowSurrogateEnd + ) { + // Add the code points in the other item to this one. + if (dataIsSingleton(otherMapping[0])) { + mapping[0] = dataAdd(mapping[0], otherMapping[0][0]); + } else { + mapping[0] = dataAddRange( + mapping[0], + otherMapping[0][0], + otherMapping[0][1] - 1 + ); + } + // Remove the other, now redundant, item. + surrogateMappings.splice(innerIndex, 1); + --innerIndex; + } + } + } + return surrogateMappings; + }; + + var surrogateSet = function(data) { + // Exit early if `data` is an empty set. + if (!data.length) { + return []; + } + + // Iterate over the data per `(start, end)` pair. + var index = 0; + var start; + var end; + var startHigh; + var startLow; + var prevStartHigh = 0; + var prevEndHigh = 0; + var tmpLow = []; + var endHigh; + var endLow; + var surrogateMappings = []; + var length = data.length; + var dataHigh = []; + while (index < length) { + start = data[index]; + end = data[index + 1] - 1; + + startHigh = highSurrogate(start); + startLow = lowSurrogate(start); + endHigh = highSurrogate(end); + endLow = lowSurrogate(end); + + var startsWithLowestLowSurrogate = startLow == LOW_SURROGATE_MIN; + var endsWithHighestLowSurrogate = endLow == LOW_SURROGATE_MAX; + var complete = false; + + // Append the previous high-surrogate-to-low-surrogate mappings. + // Step 1: `(startHigh, startLow)` to `(startHigh, LOW_SURROGATE_MAX)`. + if ( + startHigh == endHigh || + startsWithLowestLowSurrogate && endsWithHighestLowSurrogate + ) { + surrogateMappings.push([ + [startHigh, endHigh + 1], + [startLow, endLow + 1] + ]); + complete = true; + } else { + surrogateMappings.push([ + [startHigh, startHigh + 1], + [startLow, LOW_SURROGATE_MAX + 1] + ]); + } + + // Step 2: `(startHigh + 1, LOW_SURROGATE_MIN)` to + // `(endHigh - 1, LOW_SURROGATE_MAX)`. + if (!complete && startHigh + 1 < endHigh) { + if (endsWithHighestLowSurrogate) { + // Combine step 2 and step 3. + surrogateMappings.push([ + [startHigh + 1, endHigh + 1], + [LOW_SURROGATE_MIN, endLow + 1] + ]); + complete = true; + } else { + surrogateMappings.push([ + [startHigh + 1, endHigh], + [LOW_SURROGATE_MIN, LOW_SURROGATE_MAX + 1] + ]); + } + } + + // Step 3. `(endHigh, LOW_SURROGATE_MIN)` to `(endHigh, endLow)`. + if (!complete) { + surrogateMappings.push([ + [endHigh, endHigh + 1], + [LOW_SURROGATE_MIN, endLow + 1] + ]); + } + + prevStartHigh = startHigh; + prevEndHigh = endHigh; + + index += 2; + } + + // The format of `surrogateMappings` is as follows: + // + // [ surrogateMapping1, surrogateMapping2 ] + // + // i.e.: + // + // [ + // [ highSurrogates1, lowSurrogates1 ], + // [ highSurrogates2, lowSurrogates2 ] + // ] + return optimizeSurrogateMappings(surrogateMappings); + }; + + var createSurrogateCharacterClasses = function(surrogateMappings) { + var result = []; + forEach(surrogateMappings, function(surrogateMapping) { + var highSurrogates = surrogateMapping[0]; + var lowSurrogates = surrogateMapping[1]; + result.push( + createBMPCharacterClasses(highSurrogates) + + createBMPCharacterClasses(lowSurrogates) + ); + }); + return result.join('|'); + }; + + var createCharacterClassesFromData = function(data, bmpOnly) { + var result = []; + + var parts = splitAtBMP(data); + var loneHighSurrogates = parts.loneHighSurrogates; + var loneLowSurrogates = parts.loneLowSurrogates; + var bmp = parts.bmp; + var astral = parts.astral; + var hasAstral = !dataIsEmpty(parts.astral); + var hasLoneHighSurrogates = !dataIsEmpty(loneHighSurrogates); + var hasLoneLowSurrogates = !dataIsEmpty(loneLowSurrogates); + + var surrogateMappings = surrogateSet(astral); + + if (bmpOnly) { + bmp = dataAddData(bmp, loneHighSurrogates); + hasLoneHighSurrogates = false; + bmp = dataAddData(bmp, loneLowSurrogates); + hasLoneLowSurrogates = false; + } + + if (!dataIsEmpty(bmp)) { + // The data set contains BMP code points that are not high surrogates + // needed for astral code points in the set. + result.push(createBMPCharacterClasses(bmp)); + } + if (surrogateMappings.length) { + // The data set contains astral code points; append character classes + // based on their surrogate pairs. + result.push(createSurrogateCharacterClasses(surrogateMappings)); + } + // https://gist.github.com/mathiasbynens/bbe7f870208abcfec860 + if (hasLoneHighSurrogates) { + result.push( + createBMPCharacterClasses(loneHighSurrogates) + + // Make sure the high surrogates aren’t part of a surrogate pair. + '(?![\\uDC00-\\uDFFF])' + ); + } + if (hasLoneLowSurrogates) { + result.push( + // Make sure the low surrogates aren’t part of a surrogate pair. + '(?:[^\\uD800-\\uDBFF]|^)' + + createBMPCharacterClasses(loneLowSurrogates) + ); + } + return result.join('|'); + }; + + /*--------------------------------------------------------------------------*/ + + // `regenerate` can be used as a constructor (and new methods can be added to + // its prototype) but also as a regular function, the latter of which is the + // documented and most common usage. For that reason, it’s not capitalized. + var regenerate = function(value) { + if (arguments.length > 1) { + value = slice.call(arguments); + } + if (this instanceof regenerate) { + this.data = []; + return value ? this.add(value) : this; + } + return (new regenerate).add(value); + }; + + regenerate.version = '1.2.0'; + + var proto = regenerate.prototype; + extend(proto, { + 'add': function(value) { + var $this = this; + if (value == null) { + return $this; + } + if (value instanceof regenerate) { + // Allow passing other Regenerate instances. + $this.data = dataAddData($this.data, value.data); + return $this; + } + if (arguments.length > 1) { + value = slice.call(arguments); + } + if (isArray(value)) { + forEach(value, function(item) { + $this.add(item); + }); + return $this; + } + $this.data = dataAdd( + $this.data, + isNumber(value) ? value : symbolToCodePoint(value) + ); + return $this; + }, + 'remove': function(value) { + var $this = this; + if (value == null) { + return $this; + } + if (value instanceof regenerate) { + // Allow passing other Regenerate instances. + $this.data = dataRemoveData($this.data, value.data); + return $this; + } + if (arguments.length > 1) { + value = slice.call(arguments); + } + if (isArray(value)) { + forEach(value, function(item) { + $this.remove(item); + }); + return $this; + } + $this.data = dataRemove( + $this.data, + isNumber(value) ? value : symbolToCodePoint(value) + ); + return $this; + }, + 'addRange': function(start, end) { + var $this = this; + $this.data = dataAddRange($this.data, + isNumber(start) ? start : symbolToCodePoint(start), + isNumber(end) ? end : symbolToCodePoint(end) + ); + return $this; + }, + 'removeRange': function(start, end) { + var $this = this; + var startCodePoint = isNumber(start) ? start : symbolToCodePoint(start); + var endCodePoint = isNumber(end) ? end : symbolToCodePoint(end); + $this.data = dataRemoveRange( + $this.data, + startCodePoint, + endCodePoint + ); + return $this; + }, + 'intersection': function(argument) { + var $this = this; + // Allow passing other Regenerate instances. + // TODO: Optimize this by writing and using `dataIntersectionData()`. + var array = argument instanceof regenerate ? + dataToArray(argument.data) : + argument; + $this.data = dataIntersection($this.data, array); + return $this; + }, + 'contains': function(codePoint) { + return dataContains( + this.data, + isNumber(codePoint) ? codePoint : symbolToCodePoint(codePoint) + ); + }, + 'clone': function() { + var set = new regenerate; + set.data = this.data.slice(0); + return set; + }, + 'toString': function(options) { + var result = createCharacterClassesFromData( + this.data, + options ? options.bmpOnly : false + ); + // Use `\0` instead of `\x00` where possible. + return result.replace(regexNull, '\\0$1'); + }, + 'toRegExp': function(flags) { + return RegExp(this.toString(), flags || ''); + }, + 'valueOf': function() { // Note: `valueOf` is aliased as `toArray`. + return dataToArray(this.data); + } + }); + + proto.toArray = proto.valueOf; + + // 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(function() { + return regenerate; + }); + } else if (freeExports && !freeExports.nodeType) { + if (freeModule) { // in Node.js, io.js, or RingoJS v0.8.0+ + freeModule.exports = regenerate; + } else { // in Narwhal or RingoJS v0.7.0- + freeExports.regenerate = regenerate; + } + } else { // in Rhino or a web browser + root.regenerate = regenerate; + } + +}(this)); + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{}],589:[function(_dereq_,module,exports){ +(function (global){ +/*! + * RegJSGen + * Copyright 2014 Benjamin Tan + * Available under MIT license + */ +;(function() { + 'use strict'; + + /** Used to determine if values are of the language type `Object` */ + var objectTypes = { + 'function': true, + 'object': true + }; + + /** Used as a reference to the global object */ + var root = (objectTypes[typeof window] && window) || this; + + /** Backup possible global object */ + var oldRoot = root; + + /** Detect free variable `exports` */ + var freeExports = objectTypes[typeof exports] && exports; + + /** Detect free variable `module` */ + var freeModule = objectTypes[typeof module] && module && !module.nodeType && module; + + /** Detect free variable `global` from Node.js or Browserified code and use it as `root` */ + var freeGlobal = freeExports && freeModule && typeof global == 'object' && global; + if (freeGlobal && (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal || freeGlobal.self === freeGlobal)) { + root = freeGlobal; + } + + /*--------------------------------------------------------------------------*/ + + /*! Based on https://mths.be/fromcodepoint v0.2.0 by @mathias */ + + var stringFromCharCode = String.fromCharCode; + var floor = Math.floor; + function fromCodePoint() { + var MAX_SIZE = 0x4000; + var codeUnits = []; + var highSurrogate; + var lowSurrogate; + var index = -1; + var length = arguments.length; + if (!length) { + return ''; + } + var result = ''; + while (++index < length) { + var codePoint = Number(arguments[index]); + if ( + !isFinite(codePoint) || // `NaN`, `+Infinity`, or `-Infinity` + codePoint < 0 || // not a valid Unicode code point + codePoint > 0x10FFFF || // not a valid Unicode code point + floor(codePoint) != codePoint // not an integer + ) { + throw RangeError('Invalid code point: ' + codePoint); + } + if (codePoint <= 0xFFFF) { + // BMP code point + codeUnits.push(codePoint); + } else { + // Astral code point; split in surrogate halves + // http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae + codePoint -= 0x10000; + highSurrogate = (codePoint >> 10) + 0xD800; + lowSurrogate = (codePoint % 0x400) + 0xDC00; + codeUnits.push(highSurrogate, lowSurrogate); + } + if (index + 1 == length || codeUnits.length > MAX_SIZE) { + result += stringFromCharCode.apply(null, codeUnits); + codeUnits.length = 0; + } + } + return result; + } + + function assertType(type, expected) { + if (expected.indexOf('|') == -1) { + if (type == expected) { + return; + } + + throw Error('Invalid node type: ' + type); + } + + expected = assertType.hasOwnProperty(expected) + ? assertType[expected] + : (assertType[expected] = RegExp('^(?:' + expected + ')$')); + + if (expected.test(type)) { + return; + } + + throw Error('Invalid node type: ' + type); + } + + /*--------------------------------------------------------------------------*/ + + function generate(node) { + var type = node.type; + + if (generate.hasOwnProperty(type) && typeof generate[type] == 'function') { + return generate[type](node); + } + + throw Error('Invalid node type: ' + type); + } + + /*--------------------------------------------------------------------------*/ + + function generateAlternative(node) { + assertType(node.type, 'alternative'); + + var terms = node.body, + length = terms ? terms.length : 0; + + if (length == 1) { + return generateTerm(terms[0]); + } else { + var i = -1, + result = ''; + + while (++i < length) { + result += generateTerm(terms[i]); + } + + return result; + } + } + + function generateAnchor(node) { + assertType(node.type, 'anchor'); + + switch (node.kind) { + case 'start': + return '^'; + case 'end': + return '$'; + case 'boundary': + return '\\b'; + case 'not-boundary': + return '\\B'; + default: + throw Error('Invalid assertion'); + } + } + + function generateAtom(node) { + assertType(node.type, 'anchor|characterClass|characterClassEscape|dot|group|reference|value'); + + return generate(node); + } + + function generateCharacterClass(node) { + assertType(node.type, 'characterClass'); + + var classRanges = node.body, + length = classRanges ? classRanges.length : 0; + + var i = -1, + result = '['; + + if (node.negative) { + result += '^'; + } + + while (++i < length) { + result += generateClassAtom(classRanges[i]); + } + + result += ']'; + + return result; + } + + function generateCharacterClassEscape(node) { + assertType(node.type, 'characterClassEscape'); + + return '\\' + node.value; + } + + function generateCharacterClassRange(node) { + assertType(node.type, 'characterClassRange'); + + var min = node.min, + max = node.max; + + if (min.type == 'characterClassRange' || max.type == 'characterClassRange') { + throw Error('Invalid character class range'); + } + + return generateClassAtom(min) + '-' + generateClassAtom(max); + } + + function generateClassAtom(node) { + assertType(node.type, 'anchor|characterClassEscape|characterClassRange|dot|value'); + + return generate(node); + } + + function generateDisjunction(node) { + assertType(node.type, 'disjunction'); + + var body = node.body, + length = body ? body.length : 0; + + if (length == 0) { + throw Error('No body'); + } else if (length == 1) { + return generate(body[0]); + } else { + var i = -1, + result = ''; + + while (++i < length) { + if (i != 0) { + result += '|'; + } + result += generate(body[i]); + } + + return result; + } + } + + function generateDot(node) { + assertType(node.type, 'dot'); + + return '.'; + } + + function generateGroup(node) { + assertType(node.type, 'group'); + + var result = '('; + + switch (node.behavior) { + case 'normal': + break; + case 'ignore': + result += '?:'; + break; + case 'lookahead': + result += '?='; + break; + case 'negativeLookahead': + result += '?!'; + break; + default: + throw Error('Invalid behaviour: ' + node.behaviour); + } + + var body = node.body, + length = body ? body.length : 0; + + if (length == 1) { + result += generate(body[0]); + } else { + var i = -1; + + while (++i < length) { + result += generate(body[i]); + } + } + + result += ')'; + + return result; + } + + function generateQuantifier(node) { + assertType(node.type, 'quantifier'); + + var quantifier = '', + min = node.min, + max = node.max; + + switch (max) { + case undefined: + case null: + switch (min) { + case 0: + quantifier = '*' + break; + case 1: + quantifier = '+'; + break; + default: + quantifier = '{' + min + ',}'; + break; + } + break; + default: + if (min == max) { + quantifier = '{' + min + '}'; + } + else if (min == 0 && max == 1) { + quantifier = '?'; + } else { + quantifier = '{' + min + ',' + max + '}'; + } + break; + } + + if (!node.greedy) { + quantifier += '?'; + } + + return generateAtom(node.body[0]) + quantifier; + } + + function generateReference(node) { + assertType(node.type, 'reference'); + + return '\\' + node.matchIndex; + } + + function generateTerm(node) { + assertType(node.type, 'anchor|characterClass|characterClassEscape|empty|group|quantifier|reference|value'); + + return generate(node); + } + + function generateValue(node) { + assertType(node.type, 'value'); + + var kind = node.kind, + codePoint = node.codePoint; + + switch (kind) { + case 'controlLetter': + return '\\c' + fromCodePoint(codePoint + 64); + case 'hexadecimalEscape': + return '\\x' + ('00' + codePoint.toString(16).toUpperCase()).slice(-2); + case 'identifier': + return '\\' + fromCodePoint(codePoint); + case 'null': + return '\\' + codePoint; + case 'octal': + return '\\' + codePoint.toString(8); + case 'singleEscape': + switch (codePoint) { + case 0x0008: + return '\\b'; + case 0x009: + return '\\t'; + case 0x00A: + return '\\n'; + case 0x00B: + return '\\v'; + case 0x00C: + return '\\f'; + case 0x00D: + return '\\r'; + default: + throw Error('Invalid codepoint: ' + codePoint); + } + case 'symbol': + return fromCodePoint(codePoint); + case 'unicodeEscape': + return '\\u' + ('0000' + codePoint.toString(16).toUpperCase()).slice(-4); + case 'unicodeCodePointEscape': + return '\\u{' + codePoint.toString(16).toUpperCase() + '}'; + default: + throw Error('Unsupported node kind: ' + kind); + } + } + + /*--------------------------------------------------------------------------*/ + + generate.alternative = generateAlternative; + generate.anchor = generateAnchor; + generate.characterClass = generateCharacterClass; + generate.characterClassEscape = generateCharacterClassEscape; + generate.characterClassRange = generateCharacterClassRange; + generate.disjunction = generateDisjunction; + generate.dot = generateDot; + generate.group = generateGroup; + generate.quantifier = generateQuantifier; + generate.reference = generateReference; + generate.value = generateValue; + + /*--------------------------------------------------------------------------*/ + + // export regjsgen + // some AMD build optimizers, like r.js, check for condition patterns like the following: + if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) { + // define as an anonymous module so, through path mapping, it can be aliased + define(function() { + return { + 'generate': generate + }; + }); + } + // check for `exports` after `define` in case a build optimizer adds an `exports` object + else if (freeExports && freeModule) { + // in Narwhal, Node.js, Rhino -require, or RingoJS + freeExports.generate = generate; + } + // in a browser or Rhino + else { + root.regjsgen = { + 'generate': generate + }; + } +}.call(this)); + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{}],590:[function(_dereq_,module,exports){ +// regjsparser +// +// ================================================================== +// +// See ECMA-262 Standard: 15.10.1 +// +// NOTE: The ECMA-262 standard uses the term "Assertion" for /^/. Here the +// term "Anchor" is used. +// +// Pattern :: +// Disjunction +// +// Disjunction :: +// Alternative +// Alternative | Disjunction +// +// Alternative :: +// [empty] +// Alternative Term +// +// Term :: +// Anchor +// Atom +// Atom Quantifier +// +// Anchor :: +// ^ +// $ +// \ b +// \ B +// ( ? = Disjunction ) +// ( ? ! Disjunction ) +// +// Quantifier :: +// QuantifierPrefix +// QuantifierPrefix ? +// +// QuantifierPrefix :: +// * +// + +// ? +// { DecimalDigits } +// { DecimalDigits , } +// { DecimalDigits , DecimalDigits } +// +// Atom :: +// PatternCharacter +// . +// \ AtomEscape +// CharacterClass +// ( Disjunction ) +// ( ? : Disjunction ) +// +// PatternCharacter :: +// SourceCharacter but not any of: ^ $ \ . * + ? ( ) [ ] { } | +// +// AtomEscape :: +// DecimalEscape +// CharacterEscape +// CharacterClassEscape +// +// CharacterEscape[U] :: +// ControlEscape +// c ControlLetter +// HexEscapeSequence +// RegExpUnicodeEscapeSequence[?U] (ES6) +// IdentityEscape[?U] +// +// ControlEscape :: +// one of f n r t v +// ControlLetter :: +// one of +// a b c d e f g h i j k l m n o p q r s t u v w x y z +// A B C D E F G H I J K L M N O P Q R S T U V W X Y Z +// +// IdentityEscape :: +// SourceCharacter but not IdentifierPart +// +// +// +// DecimalEscape :: +// DecimalIntegerLiteral [lookahead ∉ DecimalDigit] +// +// CharacterClassEscape :: +// one of d D s S w W +// +// CharacterClass :: +// [ [lookahead ∉ {^}] ClassRanges ] +// [ ^ ClassRanges ] +// +// ClassRanges :: +// [empty] +// NonemptyClassRanges +// +// NonemptyClassRanges :: +// ClassAtom +// ClassAtom NonemptyClassRangesNoDash +// ClassAtom - ClassAtom ClassRanges +// +// NonemptyClassRangesNoDash :: +// ClassAtom +// ClassAtomNoDash NonemptyClassRangesNoDash +// ClassAtomNoDash - ClassAtom ClassRanges +// +// ClassAtom :: +// - +// ClassAtomNoDash +// +// ClassAtomNoDash :: +// SourceCharacter but not one of \ or ] or - +// \ ClassEscape +// +// ClassEscape :: +// DecimalEscape +// b +// CharacterEscape +// CharacterClassEscape + +(function() { + + function parse(str, flags) { + function addRaw(node) { + node.raw = str.substring(node.range[0], node.range[1]); + return node; + } + + function updateRawStart(node, start) { + node.range[0] = start; + return addRaw(node); + } + + function createAnchor(kind, rawLength) { + return addRaw({ + type: 'anchor', + kind: kind, + range: [ + pos - rawLength, + pos + ] + }); + } + + function createValue(kind, codePoint, from, to) { + return addRaw({ + type: 'value', + kind: kind, + codePoint: codePoint, + range: [from, to] + }); + } + + function createEscaped(kind, codePoint, value, fromOffset) { + fromOffset = fromOffset || 0; + return createValue(kind, codePoint, pos - (value.length + fromOffset), pos); + } + + function createCharacter(matches) { + var _char = matches[0]; + var first = _char.charCodeAt(0); + if (hasUnicodeFlag) { + var second; + if (_char.length === 1 && first >= 0xD800 && first <= 0xDBFF) { + second = lookahead().charCodeAt(0); + if (second >= 0xDC00 && second <= 0xDFFF) { + // Unicode surrogate pair + pos++; + return createValue( + 'symbol', + (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000, + pos - 2, pos); + } + } + } + return createValue('symbol', first, pos - 1, pos); + } + + function createDisjunction(alternatives, from, to) { + return addRaw({ + type: 'disjunction', + body: alternatives, + range: [ + from, + to + ] + }); + } + + function createDot() { + return addRaw({ + type: 'dot', + range: [ + pos - 1, + pos + ] + }); + } + + function createCharacterClassEscape(value) { + return addRaw({ + type: 'characterClassEscape', + value: value, + range: [ + pos - 2, + pos + ] + }); + } + + function createReference(matchIndex) { + return addRaw({ + type: 'reference', + matchIndex: parseInt(matchIndex, 10), + range: [ + pos - 1 - matchIndex.length, + pos + ] + }); + } + + function createGroup(behavior, disjunction, from, to) { + return addRaw({ + type: 'group', + behavior: behavior, + body: disjunction, + range: [ + from, + to + ] + }); + } + + function createQuantifier(min, max, from, to) { + if (to == null) { + from = pos - 1; + to = pos; + } + + return addRaw({ + type: 'quantifier', + min: min, + max: max, + greedy: true, + body: null, // set later on + range: [ + from, + to + ] + }); + } + + function createAlternative(terms, from, to) { + return addRaw({ + type: 'alternative', + body: terms, + range: [ + from, + to + ] + }); + } + + function createCharacterClass(classRanges, negative, from, to) { + return addRaw({ + type: 'characterClass', + body: classRanges, + negative: negative, + range: [ + from, + to + ] + }); + } + + function createClassRange(min, max, from, to) { + // See 15.10.2.15: + if (min.codePoint > max.codePoint) { + bail('invalid range in character class', min.raw + '-' + max.raw, from, to); + } + + return addRaw({ + type: 'characterClassRange', + min: min, + max: max, + range: [ + from, + to + ] + }); + } + + function flattenBody(body) { + if (body.type === 'alternative') { + return body.body; + } else { + return [body]; + } + } + + function isEmpty(obj) { + return obj.type === 'empty'; + } + + function incr(amount) { + amount = (amount || 1); + var res = str.substring(pos, pos + amount); + pos += (amount || 1); + return res; + } + + function skip(value) { + if (!match(value)) { + bail('character', value); + } + } + + function match(value) { + if (str.indexOf(value, pos) === pos) { + return incr(value.length); + } + } + + function lookahead() { + return str[pos]; + } + + function current(value) { + return str.indexOf(value, pos) === pos; + } + + function next(value) { + return str[pos + 1] === value; + } + + function matchReg(regExp) { + var subStr = str.substring(pos); + var res = subStr.match(regExp); + if (res) { + res.range = []; + res.range[0] = pos; + incr(res[0].length); + res.range[1] = pos; + } + return res; + } + + function parseDisjunction() { + // Disjunction :: + // Alternative + // Alternative | Disjunction + var res = [], from = pos; + res.push(parseAlternative()); + + while (match('|')) { + res.push(parseAlternative()); + } + + if (res.length === 1) { + return res[0]; + } + + return createDisjunction(res, from, pos); + } + + function parseAlternative() { + var res = [], from = pos; + var term; + + // Alternative :: + // [empty] + // Alternative Term + while (term = parseTerm()) { + res.push(term); + } + + if (res.length === 1) { + return res[0]; + } + + return createAlternative(res, from, pos); + } + + function parseTerm() { + // Term :: + // Anchor + // Atom + // Atom Quantifier + + if (pos >= str.length || current('|') || current(')')) { + return null; /* Means: The term is empty */ + } + + var anchor = parseAnchor(); + + if (anchor) { + return anchor; + } + + var atom = parseAtom(); + if (!atom) { + bail('Expected atom'); + } + var quantifier = parseQuantifier() || false; + if (quantifier) { + quantifier.body = flattenBody(atom); + // The quantifier contains the atom. Therefore, the beginning of the + // quantifier range is given by the beginning of the atom. + updateRawStart(quantifier, atom.range[0]); + return quantifier; + } + return atom; + } + + function parseGroup(matchA, typeA, matchB, typeB) { + var type = null, from = pos; + + if (match(matchA)) { + type = typeA; + } else if (match(matchB)) { + type = typeB; + } else { + return false; + } + + var body = parseDisjunction(); + if (!body) { + bail('Expected disjunction'); + } + skip(')'); + var group = createGroup(type, flattenBody(body), from, pos); + + if (type == 'normal') { + // Keep track of the number of closed groups. This is required for + // parseDecimalEscape(). In case the string is parsed a second time the + // value already holds the total count and no incrementation is required. + if (firstIteration) { + closedCaptureCounter++; + } + } + return group; + } + + function parseAnchor() { + // Anchor :: + // ^ + // $ + // \ b + // \ B + // ( ? = Disjunction ) + // ( ? ! Disjunction ) + var res, from = pos; + + if (match('^')) { + return createAnchor('start', 1 /* rawLength */); + } else if (match('$')) { + return createAnchor('end', 1 /* rawLength */); + } else if (match('\\b')) { + return createAnchor('boundary', 2 /* rawLength */); + } else if (match('\\B')) { + return createAnchor('not-boundary', 2 /* rawLength */); + } else { + return parseGroup('(?=', 'lookahead', '(?!', 'negativeLookahead'); + } + } + + function parseQuantifier() { + // Quantifier :: + // QuantifierPrefix + // QuantifierPrefix ? + // + // QuantifierPrefix :: + // * + // + + // ? + // { DecimalDigits } + // { DecimalDigits , } + // { DecimalDigits , DecimalDigits } + + var res, from = pos; + var quantifier; + var min, max; + + if (match('*')) { + quantifier = createQuantifier(0); + } + else if (match('+')) { + quantifier = createQuantifier(1); + } + else if (match('?')) { + quantifier = createQuantifier(0, 1); + } + else if (res = matchReg(/^\{([0-9]+)\}/)) { + min = parseInt(res[1], 10); + quantifier = createQuantifier(min, min, res.range[0], res.range[1]); + } + else if (res = matchReg(/^\{([0-9]+),\}/)) { + min = parseInt(res[1], 10); + quantifier = createQuantifier(min, undefined, res.range[0], res.range[1]); + } + else if (res = matchReg(/^\{([0-9]+),([0-9]+)\}/)) { + min = parseInt(res[1], 10); + max = parseInt(res[2], 10); + if (min > max) { + bail('numbers out of order in {} quantifier', '', from, pos); + } + quantifier = createQuantifier(min, max, res.range[0], res.range[1]); + } + + if (quantifier) { + if (match('?')) { + quantifier.greedy = false; + quantifier.range[1] += 1; + } + } + + return quantifier; + } + + function parseAtom() { + // Atom :: + // PatternCharacter + // . + // \ AtomEscape + // CharacterClass + // ( Disjunction ) + // ( ? : Disjunction ) + + var res; + + // jviereck: allow ']', '}' here as well to be compatible with browser's + // implementations: ']'.match(/]/); + // if (res = matchReg(/^[^^$\\.*+?()[\]{}|]/)) { + if (res = matchReg(/^[^^$\\.*+?(){[|]/)) { + // PatternCharacter + return createCharacter(res); + } + else if (match('.')) { + // . + return createDot(); + } + else if (match('\\')) { + // \ AtomEscape + res = parseAtomEscape(); + if (!res) { + bail('atomEscape'); + } + return res; + } + else if (res = parseCharacterClass()) { + return res; + } + else { + // ( Disjunction ) + // ( ? : Disjunction ) + return parseGroup('(?:', 'ignore', '(', 'normal'); + } + } + + function parseUnicodeSurrogatePairEscape(firstEscape) { + if (hasUnicodeFlag) { + var first, second; + if (firstEscape.kind == 'unicodeEscape' && + (first = firstEscape.codePoint) >= 0xD800 && first <= 0xDBFF && + current('\\') && next('u') ) { + var prevPos = pos; + pos++; + var secondEscape = parseClassEscape(); + if (secondEscape.kind == 'unicodeEscape' && + (second = secondEscape.codePoint) >= 0xDC00 && second <= 0xDFFF) { + // Unicode surrogate pair + firstEscape.range[1] = secondEscape.range[1]; + firstEscape.codePoint = (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000; + firstEscape.type = 'value'; + firstEscape.kind = 'unicodeCodePointEscape'; + addRaw(firstEscape); + } + else { + pos = prevPos; + } + } + } + return firstEscape; + } + + function parseClassEscape() { + return parseAtomEscape(true); + } + + function parseAtomEscape(insideCharacterClass) { + // AtomEscape :: + // DecimalEscape + // CharacterEscape + // CharacterClassEscape + + var res, from = pos; + + res = parseDecimalEscape(); + if (res) { + return res; + } + + // For ClassEscape + if (insideCharacterClass) { + if (match('b')) { + // 15.10.2.19 + // The production ClassEscape :: b evaluates by returning the + // CharSet containing the one character (Unicode value 0008). + return createEscaped('singleEscape', 0x0008, '\\b'); + } else if (match('B')) { + bail('\\B not possible inside of CharacterClass', '', from); + } + } + + res = parseCharacterEscape(); + + return res; + } + + + function parseDecimalEscape() { + // DecimalEscape :: + // DecimalIntegerLiteral [lookahead ∉ DecimalDigit] + // CharacterClassEscape :: one of d D s S w W + + var res, match; + + if (res = matchReg(/^(?!0)\d+/)) { + match = res[0]; + var refIdx = parseInt(res[0], 10); + if (refIdx <= closedCaptureCounter) { + // If the number is smaller than the normal-groups found so + // far, then it is a reference... + return createReference(res[0]); + } else { + // ... otherwise it needs to be interpreted as a octal (if the + // number is in an octal format). If it is NOT octal format, + // then the slash is ignored and the number is matched later + // as normal characters. + + // Recall the negative decision to decide if the input must be parsed + // a second time with the total normal-groups. + backrefDenied.push(refIdx); + + // Reset the position again, as maybe only parts of the previous + // matched numbers are actual octal numbers. E.g. in '019' only + // the '01' should be matched. + incr(-res[0].length); + if (res = matchReg(/^[0-7]{1,3}/)) { + return createEscaped('octal', parseInt(res[0], 8), res[0], 1); + } else { + // If we end up here, we have a case like /\91/. Then the + // first slash is to be ignored and the 9 & 1 to be treated + // like ordinary characters. Create a character for the + // first number only here - other number-characters + // (if available) will be matched later. + res = createCharacter(matchReg(/^[89]/)); + return updateRawStart(res, res.range[0] - 1); + } + } + } + // Only allow octal numbers in the following. All matched numbers start + // with a zero (if the do not, the previous if-branch is executed). + // If the number is not octal format and starts with zero (e.g. `091`) + // then only the zeros `0` is treated here and the `91` are ordinary + // characters. + // Example: + // /\091/.exec('\091')[0].length === 3 + else if (res = matchReg(/^[0-7]{1,3}/)) { + match = res[0]; + if (/^0{1,3}$/.test(match)) { + // If they are all zeros, then only take the first one. + return createEscaped('null', 0x0000, '0', match.length + 1); + } else { + return createEscaped('octal', parseInt(match, 8), match, 1); + } + } else if (res = matchReg(/^[dDsSwW]/)) { + return createCharacterClassEscape(res[0]); + } + return false; + } + + function parseCharacterEscape() { + // CharacterEscape :: + // ControlEscape + // c ControlLetter + // HexEscapeSequence + // UnicodeEscapeSequence + // IdentityEscape + + var res; + if (res = matchReg(/^[fnrtv]/)) { + // ControlEscape + var codePoint = 0; + switch (res[0]) { + case 't': codePoint = 0x009; break; + case 'n': codePoint = 0x00A; break; + case 'v': codePoint = 0x00B; break; + case 'f': codePoint = 0x00C; break; + case 'r': codePoint = 0x00D; break; + } + return createEscaped('singleEscape', codePoint, '\\' + res[0]); + } else if (res = matchReg(/^c([a-zA-Z])/)) { + // c ControlLetter + return createEscaped('controlLetter', res[1].charCodeAt(0) % 32, res[1], 2); + } else if (res = matchReg(/^x([0-9a-fA-F]{2})/)) { + // HexEscapeSequence + return createEscaped('hexadecimalEscape', parseInt(res[1], 16), res[1], 2); + } else if (res = matchReg(/^u([0-9a-fA-F]{4})/)) { + // UnicodeEscapeSequence + return parseUnicodeSurrogatePairEscape( + createEscaped('unicodeEscape', parseInt(res[1], 16), res[1], 2) + ); + } else if (hasUnicodeFlag && (res = matchReg(/^u\{([0-9a-fA-F]+)\}/))) { + // RegExpUnicodeEscapeSequence (ES6 Unicode code point escape) + return createEscaped('unicodeCodePointEscape', parseInt(res[1], 16), res[1], 4); + } else { + // IdentityEscape + return parseIdentityEscape(); + } + } + + // Taken from the Esprima parser. + function isIdentifierPart(ch) { + // Generated by `tools/generate-identifier-regex.js`. + var NonAsciiIdentifierPart = new RegExp('[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u0483-\u0487\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u05D0-\u05EA\u05F0-\u05F2\u0610-\u061A\u0620-\u0669\u066E-\u06D3\u06D5-\u06DC\u06DF-\u06E8\u06EA-\u06FC\u06FF\u0710-\u074A\u074D-\u07B1\u07C0-\u07F5\u07FA\u0800-\u082D\u0840-\u085B\u08A0-\u08B2\u08E4-\u0963\u0966-\u096F\u0971-\u0983\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BC-\u09C4\u09C7\u09C8\u09CB-\u09CE\u09D7\u09DC\u09DD\u09DF-\u09E3\u09E6-\u09F1\u0A01-\u0A03\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A59-\u0A5C\u0A5E\u0A66-\u0A75\u0A81-\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABC-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AD0\u0AE0-\u0AE3\u0AE6-\u0AEF\u0B01-\u0B03\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3C-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B5C\u0B5D\u0B5F-\u0B63\u0B66-\u0B6F\u0B71\u0B82\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD0\u0BD7\u0BE6-\u0BEF\u0C00-\u0C03\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C58\u0C59\u0C60-\u0C63\u0C66-\u0C6F\u0C81-\u0C83\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBC-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CDE\u0CE0-\u0CE3\u0CE6-\u0CEF\u0CF1\u0CF2\u0D01-\u0D03\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D-\u0D44\u0D46-\u0D48\u0D4A-\u0D4E\u0D57\u0D60-\u0D63\u0D66-\u0D6F\u0D7A-\u0D7F\u0D82\u0D83\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E01-\u0E3A\u0E40-\u0E4E\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB9\u0EBB-\u0EBD\u0EC0-\u0EC4\u0EC6\u0EC8-\u0ECD\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E-\u0F47\u0F49-\u0F6C\u0F71-\u0F84\u0F86-\u0F97\u0F99-\u0FBC\u0FC6\u1000-\u1049\u1050-\u109D\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u135D-\u135F\u1380-\u138F\u13A0-\u13F4\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1714\u1720-\u1734\u1740-\u1753\u1760-\u176C\u176E-\u1770\u1772\u1773\u1780-\u17D3\u17D7\u17DC\u17DD\u17E0-\u17E9\u180B-\u180D\u1810-\u1819\u1820-\u1877\u1880-\u18AA\u18B0-\u18F5\u1900-\u191E\u1920-\u192B\u1930-\u193B\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19D9\u1A00-\u1A1B\u1A20-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AA7\u1AB0-\u1ABD\u1B00-\u1B4B\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1BF3\u1C00-\u1C37\u1C40-\u1C49\u1C4D-\u1C7D\u1CD0-\u1CD2\u1CD4-\u1CF6\u1CF8\u1CF9\u1D00-\u1DF5\u1DFC-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u200C\u200D\u203F\u2040\u2054\u2071\u207F\u2090-\u209C\u20D0-\u20DC\u20E1\u20E5-\u20F0\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D7F-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2DE0-\u2DFF\u2E2F\u3005-\u3007\u3021-\u302F\u3031-\u3035\u3038-\u303C\u3041-\u3096\u3099\u309A\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FCC\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66F\uA674-\uA67D\uA67F-\uA69D\uA69F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA78E\uA790-\uA7AD\uA7B0\uA7B1\uA7F7-\uA827\uA840-\uA873\uA880-\uA8C4\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\uA900-\uA92D\uA930-\uA953\uA960-\uA97C\uA980-\uA9C0\uA9CF-\uA9D9\uA9E0-\uA9FE\uAA00-\uAA36\uAA40-\uAA4D\uAA50-\uAA59\uAA60-\uAA76\uAA7A-\uAAC2\uAADB-\uAADD\uAAE0-\uAAEF\uAAF2-\uAAF6\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB5F\uAB64\uAB65\uABC0-\uABEA\uABEC\uABED\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE00-\uFE0F\uFE20-\uFE2D\uFE33\uFE34\uFE4D-\uFE4F\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF3F\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]'); + + return (ch === 36) || (ch === 95) || // $ (dollar) and _ (underscore) + (ch >= 65 && ch <= 90) || // A..Z + (ch >= 97 && ch <= 122) || // a..z + (ch >= 48 && ch <= 57) || // 0..9 + (ch === 92) || // \ (backslash) + ((ch >= 0x80) && NonAsciiIdentifierPart.test(String.fromCharCode(ch))); + } + + function parseIdentityEscape() { + // IdentityEscape :: + // SourceCharacter but not IdentifierPart + // + // + + var ZWJ = '\u200C'; + var ZWNJ = '\u200D'; + + var tmp; + + if (!isIdentifierPart(lookahead())) { + tmp = incr(); + return createEscaped('identifier', tmp.charCodeAt(0), tmp, 1); + } + + if (match(ZWJ)) { + // + return createEscaped('identifier', 0x200C, ZWJ); + } else if (match(ZWNJ)) { + // + return createEscaped('identifier', 0x200D, ZWNJ); + } + + return null; + } + + function parseCharacterClass() { + // CharacterClass :: + // [ [lookahead ∉ {^}] ClassRanges ] + // [ ^ ClassRanges ] + + var res, from = pos; + if (res = matchReg(/^\[\^/)) { + res = parseClassRanges(); + skip(']'); + return createCharacterClass(res, true, from, pos); + } else if (match('[')) { + res = parseClassRanges(); + skip(']'); + return createCharacterClass(res, false, from, pos); + } + + return null; + } + + function parseClassRanges() { + // ClassRanges :: + // [empty] + // NonemptyClassRanges + + var res; + if (current(']')) { + // Empty array means nothing insinde of the ClassRange. + return []; + } else { + res = parseNonemptyClassRanges(); + if (!res) { + bail('nonEmptyClassRanges'); + } + return res; + } + } + + function parseHelperClassRanges(atom) { + var from, to, res; + if (current('-') && !next(']')) { + // ClassAtom - ClassAtom ClassRanges + skip('-'); + + res = parseClassAtom(); + if (!res) { + bail('classAtom'); + } + to = pos; + var classRanges = parseClassRanges(); + if (!classRanges) { + bail('classRanges'); + } + from = atom.range[0]; + if (classRanges.type === 'empty') { + return [createClassRange(atom, res, from, to)]; + } + return [createClassRange(atom, res, from, to)].concat(classRanges); + } + + res = parseNonemptyClassRangesNoDash(); + if (!res) { + bail('nonEmptyClassRangesNoDash'); + } + + return [atom].concat(res); + } + + function parseNonemptyClassRanges() { + // NonemptyClassRanges :: + // ClassAtom + // ClassAtom NonemptyClassRangesNoDash + // ClassAtom - ClassAtom ClassRanges + + var atom = parseClassAtom(); + if (!atom) { + bail('classAtom'); + } + + if (current(']')) { + // ClassAtom + return [atom]; + } + + // ClassAtom NonemptyClassRangesNoDash + // ClassAtom - ClassAtom ClassRanges + return parseHelperClassRanges(atom); + } + + function parseNonemptyClassRangesNoDash() { + // NonemptyClassRangesNoDash :: + // ClassAtom + // ClassAtomNoDash NonemptyClassRangesNoDash + // ClassAtomNoDash - ClassAtom ClassRanges + + var res = parseClassAtom(); + if (!res) { + bail('classAtom'); + } + if (current(']')) { + // ClassAtom + return res; + } + + // ClassAtomNoDash NonemptyClassRangesNoDash + // ClassAtomNoDash - ClassAtom ClassRanges + return parseHelperClassRanges(res); + } + + function parseClassAtom() { + // ClassAtom :: + // - + // ClassAtomNoDash + if (match('-')) { + return createCharacter('-'); + } else { + return parseClassAtomNoDash(); + } + } + + function parseClassAtomNoDash() { + // ClassAtomNoDash :: + // SourceCharacter but not one of \ or ] or - + // \ ClassEscape + + var res; + if (res = matchReg(/^[^\\\]-]/)) { + return createCharacter(res[0]); + } else if (match('\\')) { + res = parseClassEscape(); + if (!res) { + bail('classEscape'); + } + + return parseUnicodeSurrogatePairEscape(res); + } + } + + function bail(message, details, from, to) { + from = from == null ? pos : from; + to = to == null ? from : to; + + var contextStart = Math.max(0, from - 10); + var contextEnd = Math.min(to + 10, str.length); + + // Output a bit of context and a line pointing to where our error is. + // + // We are assuming that there are no actual newlines in the content as this is a regular expression. + var context = ' ' + str.substring(contextStart, contextEnd); + var pointer = ' ' + new Array(from - contextStart + 1).join(' ') + '^'; + + throw SyntaxError(message + ' at position ' + from + (details ? ': ' + details : '') + '\n' + context + '\n' + pointer); + } + + var backrefDenied = []; + var closedCaptureCounter = 0; + var firstIteration = true; + var hasUnicodeFlag = (flags || "").indexOf("u") !== -1; + var pos = 0; + + // Convert the input to a string and treat the empty string special. + str = String(str); + if (str === '') { + str = '(?:)'; + } + + var result = parseDisjunction(); + + if (result.range[1] !== str.length) { + bail('Could not parse entire input - got stuck', '', result.range[1]); + } + + // The spec requires to interpret the `\2` in `/\2()()/` as backreference. + // As the parser collects the number of capture groups as the string is + // parsed it is impossible to make these decisions at the point when the + // `\2` is handled. In case the local decision turns out to be wrong after + // the parsing has finished, the input string is parsed a second time with + // the total number of capture groups set. + // + // SEE: https://github.com/jviereck/regjsparser/issues/70 + for (var i = 0; i < backrefDenied.length; i++) { + if (backrefDenied[i] <= closedCaptureCounter) { + // Parse the input a second time. + pos = 0; + firstIteration = false; + return parseDisjunction(); + } + } + + return result; + } + + var regjsparser = { + parse: parse + }; + + if (typeof module !== 'undefined' && module.exports) { + module.exports = regjsparser; + } else { + window.regjsparser = regjsparser; + } + +}()); + +},{}],591:[function(_dereq_,module,exports){ +var generate = _dereq_(589).generate; +var parse = _dereq_(590).parse; +var regenerate = _dereq_(588); +var iuMappings = _dereq_(587); +var ESCAPE_SETS = _dereq_(586); + +function getCharacterClassEscapeSet(character) { + if (unicode) { + if (ignoreCase) { + return ESCAPE_SETS.UNICODE_IGNORE_CASE[character]; + } + return ESCAPE_SETS.UNICODE[character]; + } + return ESCAPE_SETS.REGULAR[character]; +} + +var object = {}; +var hasOwnProperty = object.hasOwnProperty; +function has(object, property) { + return hasOwnProperty.call(object, property); +} + +// Prepare a Regenerate set containing all code points, used for negative +// character classes (if any). +var UNICODE_SET = regenerate().addRange(0x0, 0x10FFFF); +// Without the `u` flag, the range stops at 0xFFFF. +// https://mths.be/es6#sec-pattern-semantics +var BMP_SET = regenerate().addRange(0x0, 0xFFFF); + +// Prepare a Regenerate set containing all code points that are supposed to be +// matched by `/./u`. https://mths.be/es6#sec-atom +var DOT_SET_UNICODE = UNICODE_SET.clone() // all Unicode code points + .remove( + // minus `LineTerminator`s (https://mths.be/es6#sec-line-terminators): + 0x000A, // Line Feed + 0x000D, // Carriage Return + 0x2028, // Line Separator + 0x2029 // Paragraph Separator + ); +// Prepare a Regenerate set containing all code points that are supposed to be +// matched by `/./` (only BMP code points). +var DOT_SET = DOT_SET_UNICODE.clone() + .intersection(BMP_SET); + +// Add a range of code points + any case-folded code points in that range to a +// set. +regenerate.prototype.iuAddRange = function(min, max) { + var $this = this; + do { + var folded = caseFold(min); + if (folded) { + $this.add(folded); + } + } while (++min <= max); + return $this; +}; + +function assign(target, source) { + for (var key in source) { + // Note: `hasOwnProperty` is not needed here. + target[key] = source[key]; + } +} + +function update(item, pattern) { + // TODO: Test if memoizing `pattern` here is worth the effort. + if (!pattern) { + return; + } + var tree = parse(pattern, ''); + switch (tree.type) { + case 'characterClass': + case 'group': + case 'value': + // No wrapping needed. + break; + default: + // Wrap the pattern in a non-capturing group. + tree = wrap(tree, pattern); + } + assign(item, tree); +} + +function wrap(tree, pattern) { + // Wrap the pattern in a non-capturing group. + return { + 'type': 'group', + 'behavior': 'ignore', + 'body': [tree], + 'raw': '(?:' + pattern + ')' + }; +} + +function caseFold(codePoint) { + return has(iuMappings, codePoint) ? iuMappings[codePoint] : false; +} + +var ignoreCase = false; +var unicode = false; +function processCharacterClass(characterClassItem) { + var set = regenerate(); + var body = characterClassItem.body.forEach(function(item) { + switch (item.type) { + case 'value': + set.add(item.codePoint); + if (ignoreCase && unicode) { + var folded = caseFold(item.codePoint); + if (folded) { + set.add(folded); + } + } + break; + case 'characterClassRange': + var min = item.min.codePoint; + var max = item.max.codePoint; + set.addRange(min, max); + if (ignoreCase && unicode) { + set.iuAddRange(min, max); + } + break; + case 'characterClassEscape': + set.add(getCharacterClassEscapeSet(item.value)); + break; + // The `default` clause is only here as a safeguard; it should never be + // reached. Code coverage tools should ignore it. + /* istanbul ignore next */ + default: + throw Error('Unknown term type: ' + item.type); + } + }); + if (characterClassItem.negative) { + set = (unicode ? UNICODE_SET : BMP_SET).clone().remove(set); + } + update(characterClassItem, set.toString()); + return characterClassItem; +} + +function processTerm(item) { + switch (item.type) { + case 'dot': + update( + item, + (unicode ? DOT_SET_UNICODE : DOT_SET).toString() + ); + break; + case 'characterClass': + item = processCharacterClass(item); + break; + case 'characterClassEscape': + update( + item, + getCharacterClassEscapeSet(item.value).toString() + ); + break; + case 'alternative': + case 'disjunction': + case 'group': + case 'quantifier': + item.body = item.body.map(processTerm); + break; + case 'value': + var codePoint = item.codePoint; + var set = regenerate(codePoint); + if (ignoreCase && unicode) { + var folded = caseFold(codePoint); + if (folded) { + set.add(folded); + } + } + update(item, set.toString()); + break; + case 'anchor': + case 'empty': + case 'group': + case 'reference': + // Nothing to do here. + break; + // The `default` clause is only here as a safeguard; it should never be + // reached. Code coverage tools should ignore it. + /* istanbul ignore next */ + default: + throw Error('Unknown term type: ' + item.type); + } + return item; +}; + +module.exports = function(pattern, flags) { + var tree = parse(pattern, flags); + ignoreCase = flags ? flags.indexOf('i') > -1 : false; + unicode = flags ? flags.indexOf('u') > -1 : false; + assign(tree, processTerm(tree)); + return generate(tree); +}; + +},{"586":586,"587":587,"588":588,"589":589,"590":590}],592:[function(_dereq_,module,exports){ +'use strict'; +var isFinite = _dereq_(593); + +module.exports = function (str, n) { + if (typeof str !== 'string') { + throw new TypeError('Expected a string as the first argument'); + } + + if (n < 0 || !isFinite(n)) { + throw new TypeError('Expected a finite positive number'); + } + + var ret = ''; + + do { + if (n & 1) { + ret += str; + } + + str += str; + } while (n = n >> 1); + + return ret; +}; + +},{"593":593}],593:[function(_dereq_,module,exports){ +arguments[4][407][0].apply(exports,arguments) +},{"407":407,"594":594}],594:[function(_dereq_,module,exports){ +arguments[4][408][0].apply(exports,arguments) +},{"408":408}],595:[function(_dereq_,module,exports){ +'use strict'; +module.exports = /^#!.*/; + +},{}],596:[function(_dereq_,module,exports){ +'use strict'; +module.exports = function (str) { + var isExtendedLengthPath = /^\\\\\?\\/.test(str); + var hasNonAscii = /[^\x00-\x80]+/.test(str); + + if (isExtendedLengthPath || hasNonAscii) { + return str; + } + + return str.replace(/\\/g, '/'); +}; + +},{}],597:[function(_dereq_,module,exports){ +/* -*- Mode: js; js-indent-level: 2; -*- */ +/* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ +{ + var util = _dereq_(606); + + /** + * A data structure which is a combination of an array and a set. Adding a new + * member is O(1), testing for membership is O(1), and finding the index of an + * element is O(1). Removing elements from the set is not supported. Only + * strings are supported for membership. + */ + function ArraySet() { + this._array = []; + this._set = {}; + } + + /** + * Static method for creating ArraySet instances from an existing array. + */ + ArraySet.fromArray = function ArraySet_fromArray(aArray, aAllowDuplicates) { + var set = new ArraySet(); + for (var i = 0, len = aArray.length; i < len; i++) { + set.add(aArray[i], aAllowDuplicates); + } + return set; + }; + + /** + * Return how many unique items are in this ArraySet. If duplicates have been + * added, than those do not count towards the size. + * + * @returns Number + */ + ArraySet.prototype.size = function ArraySet_size() { + return Object.getOwnPropertyNames(this._set).length; + }; + + /** + * Add the given string to this set. + * + * @param String aStr + */ + ArraySet.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) { + var sStr = util.toSetString(aStr); + var isDuplicate = this._set.hasOwnProperty(sStr); + var idx = this._array.length; + if (!isDuplicate || aAllowDuplicates) { + this._array.push(aStr); + } + if (!isDuplicate) { + this._set[sStr] = idx; + } + }; + + /** + * Is the given string a member of this set? + * + * @param String aStr + */ + ArraySet.prototype.has = function ArraySet_has(aStr) { + var sStr = util.toSetString(aStr); + return this._set.hasOwnProperty(sStr); + }; + + /** + * What is the index of the given string in the array? + * + * @param String aStr + */ + ArraySet.prototype.indexOf = function ArraySet_indexOf(aStr) { + var sStr = util.toSetString(aStr); + if (this._set.hasOwnProperty(sStr)) { + return this._set[sStr]; + } + throw new Error('"' + aStr + '" is not in the set.'); + }; + + /** + * What is the element at the given index? + * + * @param Number aIdx + */ + ArraySet.prototype.at = function ArraySet_at(aIdx) { + if (aIdx >= 0 && aIdx < this._array.length) { + return this._array[aIdx]; + } + throw new Error('No element indexed by ' + aIdx); + }; + + /** + * Returns the array representation of this set (which has the proper indices + * indicated by indexOf). Note that this is a copy of the internal array used + * for storing the members so that no one can mess with internal state. + */ + ArraySet.prototype.toArray = function ArraySet_toArray() { + return this._array.slice(); + }; + + exports.ArraySet = ArraySet; +} + +},{"606":606}],598:[function(_dereq_,module,exports){ +/* -*- Mode: js; js-indent-level: 2; -*- */ +/* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + * + * Based on the Base 64 VLQ implementation in Closure Compiler: + * https://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/debugging/sourcemap/Base64VLQ.java + * + * Copyright 2011 The Closure Compiler Authors. All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +{ + var base64 = _dereq_(599); + + // A single base 64 digit can contain 6 bits of data. For the base 64 variable + // length quantities we use in the source map spec, the first bit is the sign, + // the next four bits are the actual value, and the 6th bit is the + // continuation bit. The continuation bit tells us whether there are more + // digits in this value following this digit. + // + // Continuation + // | Sign + // | | + // V V + // 101011 + + var VLQ_BASE_SHIFT = 5; + + // binary: 100000 + var VLQ_BASE = 1 << VLQ_BASE_SHIFT; + + // binary: 011111 + var VLQ_BASE_MASK = VLQ_BASE - 1; + + // binary: 100000 + var VLQ_CONTINUATION_BIT = VLQ_BASE; + + /** + * Converts from a two-complement value to a value where the sign bit is + * placed in the least significant bit. For example, as decimals: + * 1 becomes 2 (10 binary), -1 becomes 3 (11 binary) + * 2 becomes 4 (100 binary), -2 becomes 5 (101 binary) + */ + function toVLQSigned(aValue) { + return aValue < 0 + ? ((-aValue) << 1) + 1 + : (aValue << 1) + 0; + } + + /** + * Converts to a two-complement value from a value where the sign bit is + * placed in the least significant bit. For example, as decimals: + * 2 (10 binary) becomes 1, 3 (11 binary) becomes -1 + * 4 (100 binary) becomes 2, 5 (101 binary) becomes -2 + */ + function fromVLQSigned(aValue) { + var isNegative = (aValue & 1) === 1; + var shifted = aValue >> 1; + return isNegative + ? -shifted + : shifted; + } + + /** + * Returns the base 64 VLQ encoded value. + */ + exports.encode = function base64VLQ_encode(aValue) { + var encoded = ""; + var digit; + + var vlq = toVLQSigned(aValue); + + do { + digit = vlq & VLQ_BASE_MASK; + vlq >>>= VLQ_BASE_SHIFT; + if (vlq > 0) { + // There are still more digits in this value, so we must make sure the + // continuation bit is marked. + digit |= VLQ_CONTINUATION_BIT; + } + encoded += base64.encode(digit); + } while (vlq > 0); + + return encoded; + }; + + /** + * Decodes the next base 64 VLQ value from the given string and returns the + * value and the rest of the string via the out parameter. + */ + exports.decode = function base64VLQ_decode(aStr, aIndex, aOutParam) { + var strLen = aStr.length; + var result = 0; + var shift = 0; + var continuation, digit; + + do { + if (aIndex >= strLen) { + throw new Error("Expected more digits in base 64 VLQ value."); + } + + digit = base64.decode(aStr.charCodeAt(aIndex++)); + if (digit === -1) { + throw new Error("Invalid base64 digit: " + aStr.charAt(aIndex - 1)); + } + + continuation = !!(digit & VLQ_CONTINUATION_BIT); + digit &= VLQ_BASE_MASK; + result = result + (digit << shift); + shift += VLQ_BASE_SHIFT; + } while (continuation); + + aOutParam.value = fromVLQSigned(result); + aOutParam.rest = aIndex; + }; +} + +},{"599":599}],599:[function(_dereq_,module,exports){ +/* -*- Mode: js; js-indent-level: 2; -*- */ +/* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ +{ + var intToCharMap = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split(''); + + /** + * Encode an integer in the range of 0 to 63 to a single base 64 digit. + */ + exports.encode = function (number) { + if (0 <= number && number < intToCharMap.length) { + return intToCharMap[number]; + } + throw new TypeError("Must be between 0 and 63: " + number); + }; + + /** + * Decode a single base 64 character code digit to an integer. Returns -1 on + * failure. + */ + exports.decode = function (charCode) { + var bigA = 65; // 'A' + var bigZ = 90; // 'Z' + + var littleA = 97; // 'a' + var littleZ = 122; // 'z' + + var zero = 48; // '0' + var nine = 57; // '9' + + var plus = 43; // '+' + var slash = 47; // '/' + + var littleOffset = 26; + var numberOffset = 52; + + // 0 - 25: ABCDEFGHIJKLMNOPQRSTUVWXYZ + if (bigA <= charCode && charCode <= bigZ) { + return (charCode - bigA); + } + + // 26 - 51: abcdefghijklmnopqrstuvwxyz + if (littleA <= charCode && charCode <= littleZ) { + return (charCode - littleA + littleOffset); + } + + // 52 - 61: 0123456789 + if (zero <= charCode && charCode <= nine) { + return (charCode - zero + numberOffset); + } + + // 62: + + if (charCode == plus) { + return 62; + } + + // 63: / + if (charCode == slash) { + return 63; + } + + // Invalid base64 digit. + return -1; + }; +} + +},{}],600:[function(_dereq_,module,exports){ +/* -*- Mode: js; js-indent-level: 2; -*- */ +/* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ +{ + exports.GREATEST_LOWER_BOUND = 1; + exports.LEAST_UPPER_BOUND = 2; + + /** + * Recursive implementation of binary search. + * + * @param aLow Indices here and lower do not contain the needle. + * @param aHigh Indices here and higher do not contain the needle. + * @param aNeedle The element being searched for. + * @param aHaystack The non-empty array being searched. + * @param aCompare Function which takes two elements and returns -1, 0, or 1. + * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or + * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the + * closest element that is smaller than or greater than the one we are + * searching for, respectively, if the exact element cannot be found. + */ + function recursiveSearch(aLow, aHigh, aNeedle, aHaystack, aCompare, aBias) { + // This function terminates when one of the following is true: + // + // 1. We find the exact element we are looking for. + // + // 2. We did not find the exact element, but we can return the index of + // the next-closest element. + // + // 3. We did not find the exact element, and there is no next-closest + // element than the one we are searching for, so we return -1. + var mid = Math.floor((aHigh - aLow) / 2) + aLow; + var cmp = aCompare(aNeedle, aHaystack[mid], true); + if (cmp === 0) { + // Found the element we are looking for. + return mid; + } + else if (cmp > 0) { + // Our needle is greater than aHaystack[mid]. + if (aHigh - mid > 1) { + // The element is in the upper half. + return recursiveSearch(mid, aHigh, aNeedle, aHaystack, aCompare, aBias); + } + + // The exact needle element was not found in this haystack. Determine if + // we are in termination case (3) or (2) and return the appropriate thing. + if (aBias == exports.LEAST_UPPER_BOUND) { + return aHigh < aHaystack.length ? aHigh : -1; + } else { + return mid; + } + } + else { + // Our needle is less than aHaystack[mid]. + if (mid - aLow > 1) { + // The element is in the lower half. + return recursiveSearch(aLow, mid, aNeedle, aHaystack, aCompare, aBias); + } + + // we are in termination case (3) or (2) and return the appropriate thing. + if (aBias == exports.LEAST_UPPER_BOUND) { + return mid; + } else { + return aLow < 0 ? -1 : aLow; + } + } + } + + /** + * This is an implementation of binary search which will always try and return + * the index of the closest element if there is no exact hit. This is because + * mappings between original and generated line/col pairs are single points, + * and there is an implicit region between each of them, so a miss just means + * that you aren't on the very start of a region. + * + * @param aNeedle The element you are looking for. + * @param aHaystack The array that is being searched. + * @param aCompare A function which takes the needle and an element in the + * array and returns -1, 0, or 1 depending on whether the needle is less + * than, equal to, or greater than the element, respectively. + * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or + * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the + * closest element that is smaller than or greater than the one we are + * searching for, respectively, if the exact element cannot be found. + * Defaults to 'binarySearch.GREATEST_LOWER_BOUND'. + */ + exports.search = function search(aNeedle, aHaystack, aCompare, aBias) { + if (aHaystack.length === 0) { + return -1; + } + + var index = recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack, + aCompare, aBias || exports.GREATEST_LOWER_BOUND); + if (index < 0) { + return -1; + } + + // We have found either the exact element, or the next-closest element than + // the one we are searching for. However, there may be more than one such + // element. Make sure we always return the smallest of these. + while (index - 1 >= 0) { + if (aCompare(aHaystack[index], aHaystack[index - 1], true) !== 0) { + break; + } + --index; + } + + return index; + }; +} + +},{}],601:[function(_dereq_,module,exports){ +/* -*- Mode: js; js-indent-level: 2; -*- */ +/* + * Copyright 2014 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ +{ + var util = _dereq_(606); + + /** + * Determine whether mappingB is after mappingA with respect to generated + * position. + */ + function generatedPositionAfter(mappingA, mappingB) { + // Optimized for most common case + var lineA = mappingA.generatedLine; + var lineB = mappingB.generatedLine; + var columnA = mappingA.generatedColumn; + var columnB = mappingB.generatedColumn; + return lineB > lineA || lineB == lineA && columnB >= columnA || + util.compareByGeneratedPositionsInflated(mappingA, mappingB) <= 0; + } + + /** + * A data structure to provide a sorted view of accumulated mappings in a + * performance conscious manner. It trades a neglibable overhead in general + * case for a large speedup in case of mappings being added in order. + */ + function MappingList() { + this._array = []; + this._sorted = true; + // Serves as infimum + this._last = {generatedLine: -1, generatedColumn: 0}; + } + + /** + * Iterate through internal items. This method takes the same arguments that + * `Array.prototype.forEach` takes. + * + * NOTE: The order of the mappings is NOT guaranteed. + */ + MappingList.prototype.unsortedForEach = + function MappingList_forEach(aCallback, aThisArg) { + this._array.forEach(aCallback, aThisArg); + }; + + /** + * Add the given source mapping. + * + * @param Object aMapping + */ + MappingList.prototype.add = function MappingList_add(aMapping) { + if (generatedPositionAfter(this._last, aMapping)) { + this._last = aMapping; + this._array.push(aMapping); + } else { + this._sorted = false; + this._array.push(aMapping); + } + }; + + /** + * Returns the flat, sorted array of mappings. The mappings are sorted by + * generated position. + * + * WARNING: This method returns internal data without copying, for + * performance. The return value must NOT be mutated, and should be treated as + * an immutable borrow. If you want to take ownership, you must make your own + * copy. + */ + MappingList.prototype.toArray = function MappingList_toArray() { + if (!this._sorted) { + this._array.sort(util.compareByGeneratedPositionsInflated); + this._sorted = true; + } + return this._array; + }; + + exports.MappingList = MappingList; +} + +},{"606":606}],602:[function(_dereq_,module,exports){ +/* -*- Mode: js; js-indent-level: 2; -*- */ +/* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ +{ + // It turns out that some (most?) JavaScript engines don't self-host + // `Array.prototype.sort`. This makes sense because C++ will likely remain + // faster than JS when doing raw CPU-intensive sorting. However, when using a + // custom comparator function, calling back and forth between the VM's C++ and + // JIT'd JS is rather slow *and* loses JIT type information, resulting in + // worse generated code for the comparator function than would be optimal. In + // fact, when sorting with a comparator, these costs outweigh the benefits of + // sorting in C++. By using our own JS-implemented Quick Sort (below), we get + // a ~3500ms mean speed-up in `bench/bench.html`. + + /** + * Swap the elements indexed by `x` and `y` in the array `ary`. + * + * @param {Array} ary + * The array. + * @param {Number} x + * The index of the first item. + * @param {Number} y + * The index of the second item. + */ + function swap(ary, x, y) { + var temp = ary[x]; + ary[x] = ary[y]; + ary[y] = temp; + } + + /** + * Returns a random integer within the range `low .. high` inclusive. + * + * @param {Number} low + * The lower bound on the range. + * @param {Number} high + * The upper bound on the range. + */ + function randomIntInRange(low, high) { + return Math.round(low + (Math.random() * (high - low))); + } + + /** + * The Quick Sort algorithm. + * + * @param {Array} ary + * An array to sort. + * @param {function} comparator + * Function to use to compare two items. + * @param {Number} p + * Start index of the array + * @param {Number} r + * End index of the array + */ + function doQuickSort(ary, comparator, p, r) { + // If our lower bound is less than our upper bound, we (1) partition the + // array into two pieces and (2) recurse on each half. If it is not, this is + // the empty array and our base case. + + if (p < r) { + // (1) Partitioning. + // + // The partitioning chooses a pivot between `p` and `r` and moves all + // elements that are less than or equal to the pivot to the before it, and + // all the elements that are greater than it after it. The effect is that + // once partition is done, the pivot is in the exact place it will be when + // the array is put in sorted order, and it will not need to be moved + // again. This runs in O(n) time. + + // Always choose a random pivot so that an input array which is reverse + // sorted does not cause O(n^2) running time. + var pivotIndex = randomIntInRange(p, r); + var i = p - 1; + + swap(ary, pivotIndex, r); + var pivot = ary[r]; + + // Immediately after `j` is incremented in this loop, the following hold + // true: + // + // * Every element in `ary[p .. i]` is less than or equal to the pivot. + // + // * Every element in `ary[i+1 .. j-1]` is greater than the pivot. + for (var j = p; j < r; j++) { + if (comparator(ary[j], pivot) <= 0) { + i += 1; + swap(ary, i, j); + } + } + + swap(ary, i + 1, j); + var q = i + 1; + + // (2) Recurse on each half. + + doQuickSort(ary, comparator, p, q - 1); + doQuickSort(ary, comparator, q + 1, r); + } + } + + /** + * Sort the given array in-place with the given comparator function. + * + * @param {Array} ary + * An array to sort. + * @param {function} comparator + * Function to use to compare two items. + */ + exports.quickSort = function (ary, comparator) { + doQuickSort(ary, comparator, 0, ary.length - 1); + }; +} + +},{}],603:[function(_dereq_,module,exports){ +/* -*- Mode: js; js-indent-level: 2; -*- */ +/* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ +{ + var util = _dereq_(606); + var binarySearch = _dereq_(600); + var ArraySet = _dereq_(597).ArraySet; + var base64VLQ = _dereq_(598); + var quickSort = _dereq_(602).quickSort; + + function SourceMapConsumer(aSourceMap) { + var sourceMap = aSourceMap; + if (typeof aSourceMap === 'string') { + sourceMap = JSON.parse(aSourceMap.replace(/^\)\]\}'/, '')); + } + + return sourceMap.sections != null + ? new IndexedSourceMapConsumer(sourceMap) + : new BasicSourceMapConsumer(sourceMap); + } + + SourceMapConsumer.fromSourceMap = function(aSourceMap) { + return BasicSourceMapConsumer.fromSourceMap(aSourceMap); + } + + /** + * The version of the source mapping spec that we are consuming. + */ + SourceMapConsumer.prototype._version = 3; + + // `__generatedMappings` and `__originalMappings` are arrays that hold the + // parsed mapping coordinates from the source map's "mappings" attribute. They + // are lazily instantiated, accessed via the `_generatedMappings` and + // `_originalMappings` getters respectively, and we only parse the mappings + // and create these arrays once queried for a source location. We jump through + // these hoops because there can be many thousands of mappings, and parsing + // them is expensive, so we only want to do it if we must. + // + // Each object in the arrays is of the form: + // + // { + // generatedLine: The line number in the generated code, + // generatedColumn: The column number in the generated code, + // source: The path to the original source file that generated this + // chunk of code, + // originalLine: The line number in the original source that + // corresponds to this chunk of generated code, + // originalColumn: The column number in the original source that + // corresponds to this chunk of generated code, + // name: The name of the original symbol which generated this chunk of + // code. + // } + // + // All properties except for `generatedLine` and `generatedColumn` can be + // `null`. + // + // `_generatedMappings` is ordered by the generated positions. + // + // `_originalMappings` is ordered by the original positions. + + SourceMapConsumer.prototype.__generatedMappings = null; + Object.defineProperty(SourceMapConsumer.prototype, '_generatedMappings', { + get: function () { + if (!this.__generatedMappings) { + this._parseMappings(this._mappings, this.sourceRoot); + } + + return this.__generatedMappings; + } + }); + + SourceMapConsumer.prototype.__originalMappings = null; + Object.defineProperty(SourceMapConsumer.prototype, '_originalMappings', { + get: function () { + if (!this.__originalMappings) { + this._parseMappings(this._mappings, this.sourceRoot); + } + + return this.__originalMappings; + } + }); + + SourceMapConsumer.prototype._charIsMappingSeparator = + function SourceMapConsumer_charIsMappingSeparator(aStr, index) { + var c = aStr.charAt(index); + return c === ";" || c === ","; + }; + + /** + * Parse the mappings in a string in to a data structure which we can easily + * query (the ordered arrays in the `this.__generatedMappings` and + * `this.__originalMappings` properties). + */ + SourceMapConsumer.prototype._parseMappings = + function SourceMapConsumer_parseMappings(aStr, aSourceRoot) { + throw new Error("Subclasses must implement _parseMappings"); + }; + + SourceMapConsumer.GENERATED_ORDER = 1; + SourceMapConsumer.ORIGINAL_ORDER = 2; + + SourceMapConsumer.GREATEST_LOWER_BOUND = 1; + SourceMapConsumer.LEAST_UPPER_BOUND = 2; + + /** + * Iterate over each mapping between an original source/line/column and a + * generated line/column in this source map. + * + * @param Function aCallback + * The function that is called with each mapping. + * @param Object aContext + * Optional. If specified, this object will be the value of `this` every + * time that `aCallback` is called. + * @param aOrder + * Either `SourceMapConsumer.GENERATED_ORDER` or + * `SourceMapConsumer.ORIGINAL_ORDER`. Specifies whether you want to + * iterate over the mappings sorted by the generated file's line/column + * order or the original's source/line/column order, respectively. Defaults to + * `SourceMapConsumer.GENERATED_ORDER`. + */ + SourceMapConsumer.prototype.eachMapping = + function SourceMapConsumer_eachMapping(aCallback, aContext, aOrder) { + var context = aContext || null; + var order = aOrder || SourceMapConsumer.GENERATED_ORDER; + + var mappings; + switch (order) { + case SourceMapConsumer.GENERATED_ORDER: + mappings = this._generatedMappings; + break; + case SourceMapConsumer.ORIGINAL_ORDER: + mappings = this._originalMappings; + break; + default: + throw new Error("Unknown order of iteration."); + } + + var sourceRoot = this.sourceRoot; + mappings.map(function (mapping) { + var source = mapping.source === null ? null : this._sources.at(mapping.source); + if (source != null && sourceRoot != null) { + source = util.join(sourceRoot, source); + } + return { + source: source, + generatedLine: mapping.generatedLine, + generatedColumn: mapping.generatedColumn, + originalLine: mapping.originalLine, + originalColumn: mapping.originalColumn, + name: mapping.name === null ? null : this._names.at(mapping.name) + }; + }, this).forEach(aCallback, context); + }; + + /** + * Returns all generated line and column information for the original source, + * line, and column provided. If no column is provided, returns all mappings + * corresponding to a either the line we are searching for or the next + * closest line that has any mappings. Otherwise, returns all mappings + * corresponding to the given line and either the column we are searching for + * or the next closest column that has any offsets. + * + * The only argument is an object with the following properties: + * + * - source: The filename of the original source. + * - line: The line number in the original source. + * - column: Optional. the column number in the original source. + * + * and an array of objects is returned, each with the following properties: + * + * - line: The line number in the generated source, or null. + * - column: The column number in the generated source, or null. + */ + SourceMapConsumer.prototype.allGeneratedPositionsFor = + function SourceMapConsumer_allGeneratedPositionsFor(aArgs) { + var line = util.getArg(aArgs, 'line'); + + // When there is no exact match, BasicSourceMapConsumer.prototype._findMapping + // returns the index of the closest mapping less than the needle. By + // setting needle.originalColumn to 0, we thus find the last mapping for + // the given line, provided such a mapping exists. + var needle = { + source: util.getArg(aArgs, 'source'), + originalLine: line, + originalColumn: util.getArg(aArgs, 'column', 0) + }; + + if (this.sourceRoot != null) { + needle.source = util.relative(this.sourceRoot, needle.source); + } + if (!this._sources.has(needle.source)) { + return []; + } + needle.source = this._sources.indexOf(needle.source); + + var mappings = []; + + var index = this._findMapping(needle, + this._originalMappings, + "originalLine", + "originalColumn", + util.compareByOriginalPositions, + binarySearch.LEAST_UPPER_BOUND); + if (index >= 0) { + var mapping = this._originalMappings[index]; + + if (aArgs.column === undefined) { + var originalLine = mapping.originalLine; + + // Iterate until either we run out of mappings, or we run into + // a mapping for a different line than the one we found. Since + // mappings are sorted, this is guaranteed to find all mappings for + // the line we found. + while (mapping && mapping.originalLine === originalLine) { + mappings.push({ + line: util.getArg(mapping, 'generatedLine', null), + column: util.getArg(mapping, 'generatedColumn', null), + lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null) + }); + + mapping = this._originalMappings[++index]; + } + } else { + var originalColumn = mapping.originalColumn; + + // Iterate until either we run out of mappings, or we run into + // a mapping for a different line than the one we were searching for. + // Since mappings are sorted, this is guaranteed to find all mappings for + // the line we are searching for. + while (mapping && + mapping.originalLine === line && + mapping.originalColumn == originalColumn) { + mappings.push({ + line: util.getArg(mapping, 'generatedLine', null), + column: util.getArg(mapping, 'generatedColumn', null), + lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null) + }); + + mapping = this._originalMappings[++index]; + } + } + } + + return mappings; + }; + + exports.SourceMapConsumer = SourceMapConsumer; + + /** + * A BasicSourceMapConsumer instance represents a parsed source map which we can + * query for information about the original file positions by giving it a file + * position in the generated source. + * + * The only parameter is the raw source map (either as a JSON string, or + * already parsed to an object). According to the spec, source maps have the + * following attributes: + * + * - version: Which version of the source map spec this map is following. + * - sources: An array of URLs to the original source files. + * - names: An array of identifiers which can be referrenced by individual mappings. + * - sourceRoot: Optional. The URL root from which all sources are relative. + * - sourcesContent: Optional. An array of contents of the original source files. + * - mappings: A string of base64 VLQs which contain the actual mappings. + * - file: Optional. The generated file this source map is associated with. + * + * Here is an example source map, taken from the source map spec[0]: + * + * { + * version : 3, + * file: "out.js", + * sourceRoot : "", + * sources: ["foo.js", "bar.js"], + * names: ["src", "maps", "are", "fun"], + * mappings: "AA,AB;;ABCDE;" + * } + * + * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit?pli=1# + */ + function BasicSourceMapConsumer(aSourceMap) { + var sourceMap = aSourceMap; + if (typeof aSourceMap === 'string') { + sourceMap = JSON.parse(aSourceMap.replace(/^\)\]\}'/, '')); + } + + var version = util.getArg(sourceMap, 'version'); + var sources = util.getArg(sourceMap, 'sources'); + // Sass 3.3 leaves out the 'names' array, so we deviate from the spec (which + // requires the array) to play nice here. + var names = util.getArg(sourceMap, 'names', []); + var sourceRoot = util.getArg(sourceMap, 'sourceRoot', null); + var sourcesContent = util.getArg(sourceMap, 'sourcesContent', null); + var mappings = util.getArg(sourceMap, 'mappings'); + var file = util.getArg(sourceMap, 'file', null); + + // Once again, Sass deviates from the spec and supplies the version as a + // string rather than a number, so we use loose equality checking here. + if (version != this._version) { + throw new Error('Unsupported version: ' + version); + } + + sources = sources + // Some source maps produce relative source paths like "./foo.js" instead of + // "foo.js". Normalize these first so that future comparisons will succeed. + // See bugzil.la/1090768. + .map(util.normalize) + // Always ensure that absolute sources are internally stored relative to + // the source root, if the source root is absolute. Not doing this would + // be particularly problematic when the source root is a prefix of the + // source (valid, but why??). See github issue #199 and bugzil.la/1188982. + .map(function (source) { + return sourceRoot && util.isAbsolute(sourceRoot) && util.isAbsolute(source) + ? util.relative(sourceRoot, source) + : source; + }); + + // Pass `true` below to allow duplicate names and sources. While source maps + // are intended to be compressed and deduplicated, the TypeScript compiler + // sometimes generates source maps with duplicates in them. See Github issue + // #72 and bugzil.la/889492. + this._names = ArraySet.fromArray(names, true); + this._sources = ArraySet.fromArray(sources, true); + + this.sourceRoot = sourceRoot; + this.sourcesContent = sourcesContent; + this._mappings = mappings; + this.file = file; + } + + BasicSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype); + BasicSourceMapConsumer.prototype.consumer = SourceMapConsumer; + + /** + * Create a BasicSourceMapConsumer from a SourceMapGenerator. + * + * @param SourceMapGenerator aSourceMap + * The source map that will be consumed. + * @returns BasicSourceMapConsumer + */ + BasicSourceMapConsumer.fromSourceMap = + function SourceMapConsumer_fromSourceMap(aSourceMap) { + var smc = Object.create(BasicSourceMapConsumer.prototype); + + var names = smc._names = ArraySet.fromArray(aSourceMap._names.toArray(), true); + var sources = smc._sources = ArraySet.fromArray(aSourceMap._sources.toArray(), true); + smc.sourceRoot = aSourceMap._sourceRoot; + smc.sourcesContent = aSourceMap._generateSourcesContent(smc._sources.toArray(), + smc.sourceRoot); + smc.file = aSourceMap._file; + + // Because we are modifying the entries (by converting string sources and + // names to indices into the sources and names ArraySets), we have to make + // a copy of the entry or else bad things happen. Shared mutable state + // strikes again! See github issue #191. + + var generatedMappings = aSourceMap._mappings.toArray().slice(); + var destGeneratedMappings = smc.__generatedMappings = []; + var destOriginalMappings = smc.__originalMappings = []; + + for (var i = 0, length = generatedMappings.length; i < length; i++) { + var srcMapping = generatedMappings[i]; + var destMapping = new Mapping; + destMapping.generatedLine = srcMapping.generatedLine; + destMapping.generatedColumn = srcMapping.generatedColumn; + + if (srcMapping.source) { + destMapping.source = sources.indexOf(srcMapping.source); + destMapping.originalLine = srcMapping.originalLine; + destMapping.originalColumn = srcMapping.originalColumn; + + if (srcMapping.name) { + destMapping.name = names.indexOf(srcMapping.name); + } + + destOriginalMappings.push(destMapping); + } + + destGeneratedMappings.push(destMapping); + } + + quickSort(smc.__originalMappings, util.compareByOriginalPositions); + + return smc; + }; + + /** + * The version of the source mapping spec that we are consuming. + */ + BasicSourceMapConsumer.prototype._version = 3; + + /** + * The list of original sources. + */ + Object.defineProperty(BasicSourceMapConsumer.prototype, 'sources', { + get: function () { + return this._sources.toArray().map(function (s) { + return this.sourceRoot != null ? util.join(this.sourceRoot, s) : s; + }, this); + } + }); + + /** + * Provide the JIT with a nice shape / hidden class. + */ + function Mapping() { + this.generatedLine = 0; + this.generatedColumn = 0; + this.source = null; + this.originalLine = null; + this.originalColumn = null; + this.name = null; + } + + /** + * Parse the mappings in a string in to a data structure which we can easily + * query (the ordered arrays in the `this.__generatedMappings` and + * `this.__originalMappings` properties). + */ + BasicSourceMapConsumer.prototype._parseMappings = + function SourceMapConsumer_parseMappings(aStr, aSourceRoot) { + var generatedLine = 1; + var previousGeneratedColumn = 0; + var previousOriginalLine = 0; + var previousOriginalColumn = 0; + var previousSource = 0; + var previousName = 0; + var length = aStr.length; + var index = 0; + var cachedSegments = {}; + var temp = {}; + var originalMappings = []; + var generatedMappings = []; + var mapping, str, segment, end, value; + + while (index < length) { + if (aStr.charAt(index) === ';') { + generatedLine++; + index++; + previousGeneratedColumn = 0; + } + else if (aStr.charAt(index) === ',') { + index++; + } + else { + mapping = new Mapping(); + mapping.generatedLine = generatedLine; + + // Because each offset is encoded relative to the previous one, + // many segments often have the same encoding. We can exploit this + // fact by caching the parsed variable length fields of each segment, + // allowing us to avoid a second parse if we encounter the same + // segment again. + for (end = index; end < length; end++) { + if (this._charIsMappingSeparator(aStr, end)) { + break; + } + } + str = aStr.slice(index, end); + + segment = cachedSegments[str]; + if (segment) { + index += str.length; + } else { + segment = []; + while (index < end) { + base64VLQ.decode(aStr, index, temp); + value = temp.value; + index = temp.rest; + segment.push(value); + } + + if (segment.length === 2) { + throw new Error('Found a source, but no line and column'); + } + + if (segment.length === 3) { + throw new Error('Found a source and line, but no column'); + } + + cachedSegments[str] = segment; + } + + // Generated column. + mapping.generatedColumn = previousGeneratedColumn + segment[0]; + previousGeneratedColumn = mapping.generatedColumn; + + if (segment.length > 1) { + // Original source. + mapping.source = previousSource + segment[1]; + previousSource += segment[1]; + + // Original line. + mapping.originalLine = previousOriginalLine + segment[2]; + previousOriginalLine = mapping.originalLine; + // Lines are stored 0-based + mapping.originalLine += 1; + + // Original column. + mapping.originalColumn = previousOriginalColumn + segment[3]; + previousOriginalColumn = mapping.originalColumn; + + if (segment.length > 4) { + // Original name. + mapping.name = previousName + segment[4]; + previousName += segment[4]; + } + } + + generatedMappings.push(mapping); + if (typeof mapping.originalLine === 'number') { + originalMappings.push(mapping); + } + } + } + + quickSort(generatedMappings, util.compareByGeneratedPositionsDeflated); + this.__generatedMappings = generatedMappings; + + quickSort(originalMappings, util.compareByOriginalPositions); + this.__originalMappings = originalMappings; + }; + + /** + * Find the mapping that best matches the hypothetical "needle" mapping that + * we are searching for in the given "haystack" of mappings. + */ + BasicSourceMapConsumer.prototype._findMapping = + function SourceMapConsumer_findMapping(aNeedle, aMappings, aLineName, + aColumnName, aComparator, aBias) { + // To return the position we are searching for, we must first find the + // mapping for the given position and then return the opposite position it + // points to. Because the mappings are sorted, we can use binary search to + // find the best mapping. + + if (aNeedle[aLineName] <= 0) { + throw new TypeError('Line must be greater than or equal to 1, got ' + + aNeedle[aLineName]); + } + if (aNeedle[aColumnName] < 0) { + throw new TypeError('Column must be greater than or equal to 0, got ' + + aNeedle[aColumnName]); + } + + return binarySearch.search(aNeedle, aMappings, aComparator, aBias); + }; + + /** + * Compute the last column for each generated mapping. The last column is + * inclusive. + */ + BasicSourceMapConsumer.prototype.computeColumnSpans = + function SourceMapConsumer_computeColumnSpans() { + for (var index = 0; index < this._generatedMappings.length; ++index) { + var mapping = this._generatedMappings[index]; + + // Mappings do not contain a field for the last generated columnt. We + // can come up with an optimistic estimate, however, by assuming that + // mappings are contiguous (i.e. given two consecutive mappings, the + // first mapping ends where the second one starts). + if (index + 1 < this._generatedMappings.length) { + var nextMapping = this._generatedMappings[index + 1]; + + if (mapping.generatedLine === nextMapping.generatedLine) { + mapping.lastGeneratedColumn = nextMapping.generatedColumn - 1; + continue; + } + } + + // The last mapping for each line spans the entire line. + mapping.lastGeneratedColumn = Infinity; + } + }; + + /** + * Returns the original source, line, and column information for the generated + * source's line and column positions provided. The only argument is an object + * with the following properties: + * + * - line: The line number in the generated source. + * - column: The column number in the generated source. + * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or + * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the + * closest element that is smaller than or greater than the one we are + * searching for, respectively, if the exact element cannot be found. + * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'. + * + * and an object is returned with the following properties: + * + * - source: The original source file, or null. + * - line: The line number in the original source, or null. + * - column: The column number in the original source, or null. + * - name: The original identifier, or null. + */ + BasicSourceMapConsumer.prototype.originalPositionFor = + function SourceMapConsumer_originalPositionFor(aArgs) { + var needle = { + generatedLine: util.getArg(aArgs, 'line'), + generatedColumn: util.getArg(aArgs, 'column') + }; + + var index = this._findMapping( + needle, + this._generatedMappings, + "generatedLine", + "generatedColumn", + util.compareByGeneratedPositionsDeflated, + util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND) + ); + + if (index >= 0) { + var mapping = this._generatedMappings[index]; + + if (mapping.generatedLine === needle.generatedLine) { + var source = util.getArg(mapping, 'source', null); + if (source !== null) { + source = this._sources.at(source); + if (this.sourceRoot != null) { + source = util.join(this.sourceRoot, source); + } + } + var name = util.getArg(mapping, 'name', null); + if (name !== null) { + name = this._names.at(name); + } + return { + source: source, + line: util.getArg(mapping, 'originalLine', null), + column: util.getArg(mapping, 'originalColumn', null), + name: name + }; + } + } + + return { + source: null, + line: null, + column: null, + name: null + }; + }; + + /** + * Return true if we have the source content for every source in the source + * map, false otherwise. + */ + BasicSourceMapConsumer.prototype.hasContentsOfAllSources = + function BasicSourceMapConsumer_hasContentsOfAllSources() { + if (!this.sourcesContent) { + return false; + } + return this.sourcesContent.length >= this._sources.size() && + !this.sourcesContent.some(function (sc) { return sc == null; }); + }; + + /** + * Returns the original source content. The only argument is the url of the + * original source file. Returns null if no original source content is + * available. + */ + BasicSourceMapConsumer.prototype.sourceContentFor = + function SourceMapConsumer_sourceContentFor(aSource, nullOnMissing) { + if (!this.sourcesContent) { + return null; + } + + if (this.sourceRoot != null) { + aSource = util.relative(this.sourceRoot, aSource); + } + + if (this._sources.has(aSource)) { + return this.sourcesContent[this._sources.indexOf(aSource)]; + } + + var url; + if (this.sourceRoot != null + && (url = util.urlParse(this.sourceRoot))) { + // XXX: file:// URIs and absolute paths lead to unexpected behavior for + // many users. We can help them out when they expect file:// URIs to + // behave like it would if they were running a local HTTP server. See + // https://bugzilla.mozilla.org/show_bug.cgi?id=885597. + var fileUriAbsPath = aSource.replace(/^file:\/\//, ""); + if (url.scheme == "file" + && this._sources.has(fileUriAbsPath)) { + return this.sourcesContent[this._sources.indexOf(fileUriAbsPath)] + } + + if ((!url.path || url.path == "/") + && this._sources.has("/" + aSource)) { + return this.sourcesContent[this._sources.indexOf("/" + aSource)]; + } + } + + // This function is used recursively from + // IndexedSourceMapConsumer.prototype.sourceContentFor. In that case, we + // don't want to throw if we can't find the source - we just want to + // return null, so we provide a flag to exit gracefully. + if (nullOnMissing) { + return null; + } + else { + throw new Error('"' + aSource + '" is not in the SourceMap.'); + } + }; + + /** + * Returns the generated line and column information for the original source, + * line, and column positions provided. The only argument is an object with + * the following properties: + * + * - source: The filename of the original source. + * - line: The line number in the original source. + * - column: The column number in the original source. + * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or + * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the + * closest element that is smaller than or greater than the one we are + * searching for, respectively, if the exact element cannot be found. + * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'. + * + * and an object is returned with the following properties: + * + * - line: The line number in the generated source, or null. + * - column: The column number in the generated source, or null. + */ + BasicSourceMapConsumer.prototype.generatedPositionFor = + function SourceMapConsumer_generatedPositionFor(aArgs) { + var source = util.getArg(aArgs, 'source'); + if (this.sourceRoot != null) { + source = util.relative(this.sourceRoot, source); + } + if (!this._sources.has(source)) { + return { + line: null, + column: null, + lastColumn: null + }; + } + source = this._sources.indexOf(source); + + var needle = { + source: source, + originalLine: util.getArg(aArgs, 'line'), + originalColumn: util.getArg(aArgs, 'column') + }; + + var index = this._findMapping( + needle, + this._originalMappings, + "originalLine", + "originalColumn", + util.compareByOriginalPositions, + util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND) + ); + + if (index >= 0) { + var mapping = this._originalMappings[index]; + + if (mapping.source === needle.source) { + return { + line: util.getArg(mapping, 'generatedLine', null), + column: util.getArg(mapping, 'generatedColumn', null), + lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null) + }; + } + } + + return { + line: null, + column: null, + lastColumn: null + }; + }; + + exports.BasicSourceMapConsumer = BasicSourceMapConsumer; + + /** + * An IndexedSourceMapConsumer instance represents a parsed source map which + * we can query for information. It differs from BasicSourceMapConsumer in + * that it takes "indexed" source maps (i.e. ones with a "sections" field) as + * input. + * + * The only parameter is a raw source map (either as a JSON string, or already + * parsed to an object). According to the spec for indexed source maps, they + * have the following attributes: + * + * - version: Which version of the source map spec this map is following. + * - file: Optional. The generated file this source map is associated with. + * - sections: A list of section definitions. + * + * Each value under the "sections" field has two fields: + * - offset: The offset into the original specified at which this section + * begins to apply, defined as an object with a "line" and "column" + * field. + * - map: A source map definition. This source map could also be indexed, + * but doesn't have to be. + * + * Instead of the "map" field, it's also possible to have a "url" field + * specifying a URL to retrieve a source map from, but that's currently + * unsupported. + * + * Here's an example source map, taken from the source map spec[0], but + * modified to omit a section which uses the "url" field. + * + * { + * version : 3, + * file: "app.js", + * sections: [{ + * offset: {line:100, column:10}, + * map: { + * version : 3, + * file: "section.js", + * sources: ["foo.js", "bar.js"], + * names: ["src", "maps", "are", "fun"], + * mappings: "AAAA,E;;ABCDE;" + * } + * }], + * } + * + * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit#heading=h.535es3xeprgt + */ + function IndexedSourceMapConsumer(aSourceMap) { + var sourceMap = aSourceMap; + if (typeof aSourceMap === 'string') { + sourceMap = JSON.parse(aSourceMap.replace(/^\)\]\}'/, '')); + } + + var version = util.getArg(sourceMap, 'version'); + var sections = util.getArg(sourceMap, 'sections'); + + if (version != this._version) { + throw new Error('Unsupported version: ' + version); + } + + this._sources = new ArraySet(); + this._names = new ArraySet(); + + var lastOffset = { + line: -1, + column: 0 + }; + this._sections = sections.map(function (s) { + if (s.url) { + // The url field will require support for asynchronicity. + // See https://github.com/mozilla/source-map/issues/16 + throw new Error('Support for url field in sections not implemented.'); + } + var offset = util.getArg(s, 'offset'); + var offsetLine = util.getArg(offset, 'line'); + var offsetColumn = util.getArg(offset, 'column'); + + if (offsetLine < lastOffset.line || + (offsetLine === lastOffset.line && offsetColumn < lastOffset.column)) { + throw new Error('Section offsets must be ordered and non-overlapping.'); + } + lastOffset = offset; + + return { + generatedOffset: { + // The offset fields are 0-based, but we use 1-based indices when + // encoding/decoding from VLQ. + generatedLine: offsetLine + 1, + generatedColumn: offsetColumn + 1 + }, + consumer: new SourceMapConsumer(util.getArg(s, 'map')) + } + }); + } + + IndexedSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype); + IndexedSourceMapConsumer.prototype.constructor = SourceMapConsumer; + + /** + * The version of the source mapping spec that we are consuming. + */ + IndexedSourceMapConsumer.prototype._version = 3; + + /** + * The list of original sources. + */ + Object.defineProperty(IndexedSourceMapConsumer.prototype, 'sources', { + get: function () { + var sources = []; + for (var i = 0; i < this._sections.length; i++) { + for (var j = 0; j < this._sections[i].consumer.sources.length; j++) { + sources.push(this._sections[i].consumer.sources[j]); + } + } + return sources; + } + }); + + /** + * Returns the original source, line, and column information for the generated + * source's line and column positions provided. The only argument is an object + * with the following properties: + * + * - line: The line number in the generated source. + * - column: The column number in the generated source. + * + * and an object is returned with the following properties: + * + * - source: The original source file, or null. + * - line: The line number in the original source, or null. + * - column: The column number in the original source, or null. + * - name: The original identifier, or null. + */ + IndexedSourceMapConsumer.prototype.originalPositionFor = + function IndexedSourceMapConsumer_originalPositionFor(aArgs) { + var needle = { + generatedLine: util.getArg(aArgs, 'line'), + generatedColumn: util.getArg(aArgs, 'column') + }; + + // Find the section containing the generated position we're trying to map + // to an original position. + var sectionIndex = binarySearch.search(needle, this._sections, + function(needle, section) { + var cmp = needle.generatedLine - section.generatedOffset.generatedLine; + if (cmp) { + return cmp; + } + + return (needle.generatedColumn - + section.generatedOffset.generatedColumn); + }); + var section = this._sections[sectionIndex]; + + if (!section) { + return { + source: null, + line: null, + column: null, + name: null + }; + } + + return section.consumer.originalPositionFor({ + line: needle.generatedLine - + (section.generatedOffset.generatedLine - 1), + column: needle.generatedColumn - + (section.generatedOffset.generatedLine === needle.generatedLine + ? section.generatedOffset.generatedColumn - 1 + : 0), + bias: aArgs.bias + }); + }; + + /** + * Return true if we have the source content for every source in the source + * map, false otherwise. + */ + IndexedSourceMapConsumer.prototype.hasContentsOfAllSources = + function IndexedSourceMapConsumer_hasContentsOfAllSources() { + return this._sections.every(function (s) { + return s.consumer.hasContentsOfAllSources(); + }); + }; + + /** + * Returns the original source content. The only argument is the url of the + * original source file. Returns null if no original source content is + * available. + */ + IndexedSourceMapConsumer.prototype.sourceContentFor = + function IndexedSourceMapConsumer_sourceContentFor(aSource, nullOnMissing) { + for (var i = 0; i < this._sections.length; i++) { + var section = this._sections[i]; + + var content = section.consumer.sourceContentFor(aSource, true); + if (content) { + return content; + } + } + if (nullOnMissing) { + return null; + } + else { + throw new Error('"' + aSource + '" is not in the SourceMap.'); + } + }; + + /** + * Returns the generated line and column information for the original source, + * line, and column positions provided. The only argument is an object with + * the following properties: + * + * - source: The filename of the original source. + * - line: The line number in the original source. + * - column: The column number in the original source. + * + * and an object is returned with the following properties: + * + * - line: The line number in the generated source, or null. + * - column: The column number in the generated source, or null. + */ + IndexedSourceMapConsumer.prototype.generatedPositionFor = + function IndexedSourceMapConsumer_generatedPositionFor(aArgs) { + for (var i = 0; i < this._sections.length; i++) { + var section = this._sections[i]; + + // Only consider this section if the requested source is in the list of + // sources of the consumer. + if (section.consumer.sources.indexOf(util.getArg(aArgs, 'source')) === -1) { + continue; + } + var generatedPosition = section.consumer.generatedPositionFor(aArgs); + if (generatedPosition) { + var ret = { + line: generatedPosition.line + + (section.generatedOffset.generatedLine - 1), + column: generatedPosition.column + + (section.generatedOffset.generatedLine === generatedPosition.line + ? section.generatedOffset.generatedColumn - 1 + : 0) + }; + return ret; + } + } + + return { + line: null, + column: null + }; + }; + + /** + * Parse the mappings in a string in to a data structure which we can easily + * query (the ordered arrays in the `this.__generatedMappings` and + * `this.__originalMappings` properties). + */ + IndexedSourceMapConsumer.prototype._parseMappings = + function IndexedSourceMapConsumer_parseMappings(aStr, aSourceRoot) { + this.__generatedMappings = []; + this.__originalMappings = []; + for (var i = 0; i < this._sections.length; i++) { + var section = this._sections[i]; + var sectionMappings = section.consumer._generatedMappings; + for (var j = 0; j < sectionMappings.length; j++) { + var mapping = sectionMappings[j]; + + var source = section.consumer._sources.at(mapping.source); + if (section.consumer.sourceRoot !== null) { + source = util.join(section.consumer.sourceRoot, source); + } + this._sources.add(source); + source = this._sources.indexOf(source); + + var name = section.consumer._names.at(mapping.name); + this._names.add(name); + name = this._names.indexOf(name); + + // The mappings coming from the consumer for the section have + // generated positions relative to the start of the section, so we + // need to offset them to be relative to the start of the concatenated + // generated file. + var adjustedMapping = { + source: source, + generatedLine: mapping.generatedLine + + (section.generatedOffset.generatedLine - 1), + generatedColumn: mapping.generatedColumn + + (section.generatedOffset.generatedLine === mapping.generatedLine + ? section.generatedOffset.generatedColumn - 1 + : 0), + originalLine: mapping.originalLine, + originalColumn: mapping.originalColumn, + name: name + }; + + this.__generatedMappings.push(adjustedMapping); + if (typeof adjustedMapping.originalLine === 'number') { + this.__originalMappings.push(adjustedMapping); + } + } + } + + quickSort(this.__generatedMappings, util.compareByGeneratedPositionsDeflated); + quickSort(this.__originalMappings, util.compareByOriginalPositions); + }; + + exports.IndexedSourceMapConsumer = IndexedSourceMapConsumer; +} + +},{"597":597,"598":598,"600":600,"602":602,"606":606}],604:[function(_dereq_,module,exports){ +/* -*- Mode: js; js-indent-level: 2; -*- */ +/* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ +{ + var base64VLQ = _dereq_(598); + var util = _dereq_(606); + var ArraySet = _dereq_(597).ArraySet; + var MappingList = _dereq_(601).MappingList; + + /** + * An instance of the SourceMapGenerator represents a source map which is + * being built incrementally. You may pass an object with the following + * properties: + * + * - file: The filename of the generated source. + * - sourceRoot: A root for all relative URLs in this source map. + */ + function SourceMapGenerator(aArgs) { + if (!aArgs) { + aArgs = {}; + } + this._file = util.getArg(aArgs, 'file', null); + this._sourceRoot = util.getArg(aArgs, 'sourceRoot', null); + this._skipValidation = util.getArg(aArgs, 'skipValidation', false); + this._sources = new ArraySet(); + this._names = new ArraySet(); + this._mappings = new MappingList(); + this._sourcesContents = null; + } + + SourceMapGenerator.prototype._version = 3; + + /** + * Creates a new SourceMapGenerator based on a SourceMapConsumer + * + * @param aSourceMapConsumer The SourceMap. + */ + SourceMapGenerator.fromSourceMap = + function SourceMapGenerator_fromSourceMap(aSourceMapConsumer) { + var sourceRoot = aSourceMapConsumer.sourceRoot; + var generator = new SourceMapGenerator({ + file: aSourceMapConsumer.file, + sourceRoot: sourceRoot + }); + aSourceMapConsumer.eachMapping(function (mapping) { + var newMapping = { + generated: { + line: mapping.generatedLine, + column: mapping.generatedColumn + } + }; + + if (mapping.source != null) { + newMapping.source = mapping.source; + if (sourceRoot != null) { + newMapping.source = util.relative(sourceRoot, newMapping.source); + } + + newMapping.original = { + line: mapping.originalLine, + column: mapping.originalColumn + }; + + if (mapping.name != null) { + newMapping.name = mapping.name; + } + } + + generator.addMapping(newMapping); + }); + aSourceMapConsumer.sources.forEach(function (sourceFile) { + var content = aSourceMapConsumer.sourceContentFor(sourceFile); + if (content != null) { + generator.setSourceContent(sourceFile, content); + } + }); + return generator; + }; + + /** + * Add a single mapping from original source line and column to the generated + * source's line and column for this source map being created. The mapping + * object should have the following properties: + * + * - generated: An object with the generated line and column positions. + * - original: An object with the original line and column positions. + * - source: The original source file (relative to the sourceRoot). + * - name: An optional original token name for this mapping. + */ + SourceMapGenerator.prototype.addMapping = + function SourceMapGenerator_addMapping(aArgs) { + var generated = util.getArg(aArgs, 'generated'); + var original = util.getArg(aArgs, 'original', null); + var source = util.getArg(aArgs, 'source', null); + var name = util.getArg(aArgs, 'name', null); + + if (!this._skipValidation) { + this._validateMapping(generated, original, source, name); + } + + if (source != null && !this._sources.has(source)) { + this._sources.add(source); + } + + if (name != null && !this._names.has(name)) { + this._names.add(name); + } + + this._mappings.add({ + generatedLine: generated.line, + generatedColumn: generated.column, + originalLine: original != null && original.line, + originalColumn: original != null && original.column, + source: source, + name: name + }); + }; + + /** + * Set the source content for a source file. + */ + SourceMapGenerator.prototype.setSourceContent = + function SourceMapGenerator_setSourceContent(aSourceFile, aSourceContent) { + var source = aSourceFile; + if (this._sourceRoot != null) { + source = util.relative(this._sourceRoot, source); + } + + if (aSourceContent != null) { + // Add the source content to the _sourcesContents map. + // Create a new _sourcesContents map if the property is null. + if (!this._sourcesContents) { + this._sourcesContents = {}; + } + this._sourcesContents[util.toSetString(source)] = aSourceContent; + } else if (this._sourcesContents) { + // Remove the source file from the _sourcesContents map. + // If the _sourcesContents map is empty, set the property to null. + delete this._sourcesContents[util.toSetString(source)]; + if (Object.keys(this._sourcesContents).length === 0) { + this._sourcesContents = null; + } + } + }; + + /** + * Applies the mappings of a sub-source-map for a specific source file to the + * source map being generated. Each mapping to the supplied source file is + * rewritten using the supplied source map. Note: The resolution for the + * resulting mappings is the minimium of this map and the supplied map. + * + * @param aSourceMapConsumer The source map to be applied. + * @param aSourceFile Optional. The filename of the source file. + * If omitted, SourceMapConsumer's file property will be used. + * @param aSourceMapPath Optional. The dirname of the path to the source map + * to be applied. If relative, it is relative to the SourceMapConsumer. + * This parameter is needed when the two source maps aren't in the same + * directory, and the source map to be applied contains relative source + * paths. If so, those relative source paths need to be rewritten + * relative to the SourceMapGenerator. + */ + SourceMapGenerator.prototype.applySourceMap = + function SourceMapGenerator_applySourceMap(aSourceMapConsumer, aSourceFile, aSourceMapPath) { + var sourceFile = aSourceFile; + // If aSourceFile is omitted, we will use the file property of the SourceMap + if (aSourceFile == null) { + if (aSourceMapConsumer.file == null) { + throw new Error( + 'SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, ' + + 'or the source map\'s "file" property. Both were omitted.' + ); + } + sourceFile = aSourceMapConsumer.file; + } + var sourceRoot = this._sourceRoot; + // Make "sourceFile" relative if an absolute Url is passed. + if (sourceRoot != null) { + sourceFile = util.relative(sourceRoot, sourceFile); + } + // Applying the SourceMap can add and remove items from the sources and + // the names array. + var newSources = new ArraySet(); + var newNames = new ArraySet(); + + // Find mappings for the "sourceFile" + this._mappings.unsortedForEach(function (mapping) { + if (mapping.source === sourceFile && mapping.originalLine != null) { + // Check if it can be mapped by the source map, then update the mapping. + var original = aSourceMapConsumer.originalPositionFor({ + line: mapping.originalLine, + column: mapping.originalColumn + }); + if (original.source != null) { + // Copy mapping + mapping.source = original.source; + if (aSourceMapPath != null) { + mapping.source = util.join(aSourceMapPath, mapping.source) + } + if (sourceRoot != null) { + mapping.source = util.relative(sourceRoot, mapping.source); + } + mapping.originalLine = original.line; + mapping.originalColumn = original.column; + if (original.name != null) { + mapping.name = original.name; + } + } + } + + var source = mapping.source; + if (source != null && !newSources.has(source)) { + newSources.add(source); + } + + var name = mapping.name; + if (name != null && !newNames.has(name)) { + newNames.add(name); + } + + }, this); + this._sources = newSources; + this._names = newNames; + + // Copy sourcesContents of applied map. + aSourceMapConsumer.sources.forEach(function (sourceFile) { + var content = aSourceMapConsumer.sourceContentFor(sourceFile); + if (content != null) { + if (aSourceMapPath != null) { + sourceFile = util.join(aSourceMapPath, sourceFile); + } + if (sourceRoot != null) { + sourceFile = util.relative(sourceRoot, sourceFile); + } + this.setSourceContent(sourceFile, content); + } + }, this); + }; + + /** + * A mapping can have one of the three levels of data: + * + * 1. Just the generated position. + * 2. The Generated position, original position, and original source. + * 3. Generated and original position, original source, as well as a name + * token. + * + * To maintain consistency, we validate that any new mapping being added falls + * in to one of these categories. + */ + SourceMapGenerator.prototype._validateMapping = + function SourceMapGenerator_validateMapping(aGenerated, aOriginal, aSource, + aName) { + if (aGenerated && 'line' in aGenerated && 'column' in aGenerated + && aGenerated.line > 0 && aGenerated.column >= 0 + && !aOriginal && !aSource && !aName) { + // Case 1. + return; + } + else if (aGenerated && 'line' in aGenerated && 'column' in aGenerated + && aOriginal && 'line' in aOriginal && 'column' in aOriginal + && aGenerated.line > 0 && aGenerated.column >= 0 + && aOriginal.line > 0 && aOriginal.column >= 0 + && aSource) { + // Cases 2 and 3. + return; + } + else { + throw new Error('Invalid mapping: ' + JSON.stringify({ + generated: aGenerated, + source: aSource, + original: aOriginal, + name: aName + })); + } + }; + + /** + * Serialize the accumulated mappings in to the stream of base 64 VLQs + * specified by the source map format. + */ + SourceMapGenerator.prototype._serializeMappings = + function SourceMapGenerator_serializeMappings() { + var previousGeneratedColumn = 0; + var previousGeneratedLine = 1; + var previousOriginalColumn = 0; + var previousOriginalLine = 0; + var previousName = 0; + var previousSource = 0; + var result = ''; + var mapping; + var nameIdx; + var sourceIdx; + + var mappings = this._mappings.toArray(); + for (var i = 0, len = mappings.length; i < len; i++) { + mapping = mappings[i]; + + if (mapping.generatedLine !== previousGeneratedLine) { + previousGeneratedColumn = 0; + while (mapping.generatedLine !== previousGeneratedLine) { + result += ';'; + previousGeneratedLine++; + } + } + else { + if (i > 0) { + if (!util.compareByGeneratedPositionsInflated(mapping, mappings[i - 1])) { + continue; + } + result += ','; + } + } + + result += base64VLQ.encode(mapping.generatedColumn + - previousGeneratedColumn); + previousGeneratedColumn = mapping.generatedColumn; + + if (mapping.source != null) { + sourceIdx = this._sources.indexOf(mapping.source); + result += base64VLQ.encode(sourceIdx - previousSource); + previousSource = sourceIdx; + + // lines are stored 0-based in SourceMap spec version 3 + result += base64VLQ.encode(mapping.originalLine - 1 + - previousOriginalLine); + previousOriginalLine = mapping.originalLine - 1; + + result += base64VLQ.encode(mapping.originalColumn + - previousOriginalColumn); + previousOriginalColumn = mapping.originalColumn; + + if (mapping.name != null) { + nameIdx = this._names.indexOf(mapping.name); + result += base64VLQ.encode(nameIdx - previousName); + previousName = nameIdx; + } + } + } + + return result; + }; + + SourceMapGenerator.prototype._generateSourcesContent = + function SourceMapGenerator_generateSourcesContent(aSources, aSourceRoot) { + return aSources.map(function (source) { + if (!this._sourcesContents) { + return null; + } + if (aSourceRoot != null) { + source = util.relative(aSourceRoot, source); + } + var key = util.toSetString(source); + return Object.prototype.hasOwnProperty.call(this._sourcesContents, + key) + ? this._sourcesContents[key] + : null; + }, this); + }; + + /** + * Externalize the source map. + */ + SourceMapGenerator.prototype.toJSON = + function SourceMapGenerator_toJSON() { + var map = { + version: this._version, + sources: this._sources.toArray(), + names: this._names.toArray(), + mappings: this._serializeMappings() + }; + if (this._file != null) { + map.file = this._file; + } + if (this._sourceRoot != null) { + map.sourceRoot = this._sourceRoot; + } + if (this._sourcesContents) { + map.sourcesContent = this._generateSourcesContent(map.sources, map.sourceRoot); + } + + return map; + }; + + /** + * Render the source map being generated to a string. + */ + SourceMapGenerator.prototype.toString = + function SourceMapGenerator_toString() { + return JSON.stringify(this.toJSON()); + }; + + exports.SourceMapGenerator = SourceMapGenerator; +} + +},{"597":597,"598":598,"601":601,"606":606}],605:[function(_dereq_,module,exports){ +/* -*- Mode: js; js-indent-level: 2; -*- */ +/* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ +{ + var SourceMapGenerator = _dereq_(604).SourceMapGenerator; + var util = _dereq_(606); + + // Matches a Windows-style `\r\n` newline or a `\n` newline used by all other + // operating systems these days (capturing the result). + var REGEX_NEWLINE = /(\r?\n)/; + + // Newline character code for charCodeAt() comparisons + var NEWLINE_CODE = 10; + + // Private symbol for identifying `SourceNode`s when multiple versions of + // the source-map library are loaded. This MUST NOT CHANGE across + // versions! + var isSourceNode = "$$$isSourceNode$$$"; + + /** + * SourceNodes provide a way to abstract over interpolating/concatenating + * snippets of generated JavaScript source code while maintaining the line and + * column information associated with the original source code. + * + * @param aLine The original line number. + * @param aColumn The original column number. + * @param aSource The original source's filename. + * @param aChunks Optional. An array of strings which are snippets of + * generated JS, or other SourceNodes. + * @param aName The original identifier. + */ + function SourceNode(aLine, aColumn, aSource, aChunks, aName) { + this.children = []; + this.sourceContents = {}; + this.line = aLine == null ? null : aLine; + this.column = aColumn == null ? null : aColumn; + this.source = aSource == null ? null : aSource; + this.name = aName == null ? null : aName; + this[isSourceNode] = true; + if (aChunks != null) this.add(aChunks); + } + + /** + * Creates a SourceNode from generated code and a SourceMapConsumer. + * + * @param aGeneratedCode The generated code + * @param aSourceMapConsumer The SourceMap for the generated code + * @param aRelativePath Optional. The path that relative sources in the + * SourceMapConsumer should be relative to. + */ + SourceNode.fromStringWithSourceMap = + function SourceNode_fromStringWithSourceMap(aGeneratedCode, aSourceMapConsumer, aRelativePath) { + // The SourceNode we want to fill with the generated code + // and the SourceMap + var node = new SourceNode(); + + // All even indices of this array are one line of the generated code, + // while all odd indices are the newlines between two adjacent lines + // (since `REGEX_NEWLINE` captures its match). + // Processed fragments are removed from this array, by calling `shiftNextLine`. + var remainingLines = aGeneratedCode.split(REGEX_NEWLINE); + var shiftNextLine = function() { + var lineContents = remainingLines.shift(); + // The last line of a file might not have a newline. + var newLine = remainingLines.shift() || ""; + return lineContents + newLine; + }; + + // We need to remember the position of "remainingLines" + var lastGeneratedLine = 1, lastGeneratedColumn = 0; + + // The generate SourceNodes we need a code range. + // To extract it current and last mapping is used. + // Here we store the last mapping. + var lastMapping = null; + + aSourceMapConsumer.eachMapping(function (mapping) { + if (lastMapping !== null) { + // We add the code from "lastMapping" to "mapping": + // First check if there is a new line in between. + if (lastGeneratedLine < mapping.generatedLine) { + // Associate first line with "lastMapping" + addMappingWithCode(lastMapping, shiftNextLine()); + lastGeneratedLine++; + lastGeneratedColumn = 0; + // The remaining code is added without mapping + } else { + // There is no new line in between. + // Associate the code between "lastGeneratedColumn" and + // "mapping.generatedColumn" with "lastMapping" + var nextLine = remainingLines[0]; + var code = nextLine.substr(0, mapping.generatedColumn - + lastGeneratedColumn); + remainingLines[0] = nextLine.substr(mapping.generatedColumn - + lastGeneratedColumn); + lastGeneratedColumn = mapping.generatedColumn; + addMappingWithCode(lastMapping, code); + // No more remaining code, continue + lastMapping = mapping; + return; + } + } + // We add the generated code until the first mapping + // to the SourceNode without any mapping. + // Each line is added as separate string. + while (lastGeneratedLine < mapping.generatedLine) { + node.add(shiftNextLine()); + lastGeneratedLine++; + } + if (lastGeneratedColumn < mapping.generatedColumn) { + var nextLine = remainingLines[0]; + node.add(nextLine.substr(0, mapping.generatedColumn)); + remainingLines[0] = nextLine.substr(mapping.generatedColumn); + lastGeneratedColumn = mapping.generatedColumn; + } + lastMapping = mapping; + }, this); + // We have processed all mappings. + if (remainingLines.length > 0) { + if (lastMapping) { + // Associate the remaining code in the current line with "lastMapping" + addMappingWithCode(lastMapping, shiftNextLine()); + } + // and add the remaining lines without any mapping + node.add(remainingLines.join("")); + } + + // Copy sourcesContent into SourceNode + aSourceMapConsumer.sources.forEach(function (sourceFile) { + var content = aSourceMapConsumer.sourceContentFor(sourceFile); + if (content != null) { + if (aRelativePath != null) { + sourceFile = util.join(aRelativePath, sourceFile); + } + node.setSourceContent(sourceFile, content); + } + }); + + return node; + + function addMappingWithCode(mapping, code) { + if (mapping === null || mapping.source === undefined) { + node.add(code); + } else { + var source = aRelativePath + ? util.join(aRelativePath, mapping.source) + : mapping.source; + node.add(new SourceNode(mapping.originalLine, + mapping.originalColumn, + source, + code, + mapping.name)); + } + } + }; + + /** + * Add a chunk of generated JS to this source node. + * + * @param aChunk A string snippet of generated JS code, another instance of + * SourceNode, or an array where each member is one of those things. + */ + SourceNode.prototype.add = function SourceNode_add(aChunk) { + if (Array.isArray(aChunk)) { + aChunk.forEach(function (chunk) { + this.add(chunk); + }, this); + } + else if (aChunk[isSourceNode] || typeof aChunk === "string") { + if (aChunk) { + this.children.push(aChunk); + } + } + else { + throw new TypeError( + "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk + ); + } + return this; + }; + + /** + * Add a chunk of generated JS to the beginning of this source node. + * + * @param aChunk A string snippet of generated JS code, another instance of + * SourceNode, or an array where each member is one of those things. + */ + SourceNode.prototype.prepend = function SourceNode_prepend(aChunk) { + if (Array.isArray(aChunk)) { + for (var i = aChunk.length-1; i >= 0; i--) { + this.prepend(aChunk[i]); + } + } + else if (aChunk[isSourceNode] || typeof aChunk === "string") { + this.children.unshift(aChunk); + } + else { + throw new TypeError( + "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk + ); + } + return this; + }; + + /** + * Walk over the tree of JS snippets in this node and its children. The + * walking function is called once for each snippet of JS and is passed that + * snippet and the its original associated source's line/column location. + * + * @param aFn The traversal function. + */ + SourceNode.prototype.walk = function SourceNode_walk(aFn) { + var chunk; + for (var i = 0, len = this.children.length; i < len; i++) { + chunk = this.children[i]; + if (chunk[isSourceNode]) { + chunk.walk(aFn); + } + else { + if (chunk !== '') { + aFn(chunk, { source: this.source, + line: this.line, + column: this.column, + name: this.name }); + } + } + } + }; + + /** + * Like `String.prototype.join` except for SourceNodes. Inserts `aStr` between + * each of `this.children`. + * + * @param aSep The separator. + */ + SourceNode.prototype.join = function SourceNode_join(aSep) { + var newChildren; + var i; + var len = this.children.length; + if (len > 0) { + newChildren = []; + for (i = 0; i < len-1; i++) { + newChildren.push(this.children[i]); + newChildren.push(aSep); + } + newChildren.push(this.children[i]); + this.children = newChildren; + } + return this; + }; + + /** + * Call String.prototype.replace on the very right-most source snippet. Useful + * for trimming whitespace from the end of a source node, etc. + * + * @param aPattern The pattern to replace. + * @param aReplacement The thing to replace the pattern with. + */ + SourceNode.prototype.replaceRight = function SourceNode_replaceRight(aPattern, aReplacement) { + var lastChild = this.children[this.children.length - 1]; + if (lastChild[isSourceNode]) { + lastChild.replaceRight(aPattern, aReplacement); + } + else if (typeof lastChild === 'string') { + this.children[this.children.length - 1] = lastChild.replace(aPattern, aReplacement); + } + else { + this.children.push(''.replace(aPattern, aReplacement)); + } + return this; + }; + + /** + * Set the source content for a source file. This will be added to the SourceMapGenerator + * in the sourcesContent field. + * + * @param aSourceFile The filename of the source file + * @param aSourceContent The content of the source file + */ + SourceNode.prototype.setSourceContent = + function SourceNode_setSourceContent(aSourceFile, aSourceContent) { + this.sourceContents[util.toSetString(aSourceFile)] = aSourceContent; + }; + + /** + * Walk over the tree of SourceNodes. The walking function is called for each + * source file content and is passed the filename and source content. + * + * @param aFn The traversal function. + */ + SourceNode.prototype.walkSourceContents = + function SourceNode_walkSourceContents(aFn) { + for (var i = 0, len = this.children.length; i < len; i++) { + if (this.children[i][isSourceNode]) { + this.children[i].walkSourceContents(aFn); + } + } + + var sources = Object.keys(this.sourceContents); + for (var i = 0, len = sources.length; i < len; i++) { + aFn(util.fromSetString(sources[i]), this.sourceContents[sources[i]]); + } + }; + + /** + * Return the string representation of this source node. Walks over the tree + * and concatenates all the various snippets together to one string. + */ + SourceNode.prototype.toString = function SourceNode_toString() { + var str = ""; + this.walk(function (chunk) { + str += chunk; + }); + return str; + }; + + /** + * Returns the string representation of this source node along with a source + * map. + */ + SourceNode.prototype.toStringWithSourceMap = function SourceNode_toStringWithSourceMap(aArgs) { + var generated = { + code: "", + line: 1, + column: 0 + }; + var map = new SourceMapGenerator(aArgs); + var sourceMappingActive = false; + var lastOriginalSource = null; + var lastOriginalLine = null; + var lastOriginalColumn = null; + var lastOriginalName = null; + this.walk(function (chunk, original) { + generated.code += chunk; + if (original.source !== null + && original.line !== null + && original.column !== null) { + if(lastOriginalSource !== original.source + || lastOriginalLine !== original.line + || lastOriginalColumn !== original.column + || lastOriginalName !== original.name) { + map.addMapping({ + source: original.source, + original: { + line: original.line, + column: original.column + }, + generated: { + line: generated.line, + column: generated.column + }, + name: original.name + }); + } + lastOriginalSource = original.source; + lastOriginalLine = original.line; + lastOriginalColumn = original.column; + lastOriginalName = original.name; + sourceMappingActive = true; + } else if (sourceMappingActive) { + map.addMapping({ + generated: { + line: generated.line, + column: generated.column + } + }); + lastOriginalSource = null; + sourceMappingActive = false; + } + for (var idx = 0, length = chunk.length; idx < length; idx++) { + if (chunk.charCodeAt(idx) === NEWLINE_CODE) { + generated.line++; + generated.column = 0; + // Mappings end at eol + if (idx + 1 === length) { + lastOriginalSource = null; + sourceMappingActive = false; + } else if (sourceMappingActive) { + map.addMapping({ + source: original.source, + original: { + line: original.line, + column: original.column + }, + generated: { + line: generated.line, + column: generated.column + }, + name: original.name + }); + } + } else { + generated.column++; + } + } + }); + this.walkSourceContents(function (sourceFile, sourceContent) { + map.setSourceContent(sourceFile, sourceContent); + }); + + return { code: generated.code, map: map }; + }; + + exports.SourceNode = SourceNode; +} + +},{"604":604,"606":606}],606:[function(_dereq_,module,exports){ +/* -*- Mode: js; js-indent-level: 2; -*- */ +/* + * Copyright 2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE or: + * http://opensource.org/licenses/BSD-3-Clause + */ +{ + /** + * This is a helper function for getting values from parameter/options + * objects. + * + * @param args The object we are extracting values from + * @param name The name of the property we are getting. + * @param defaultValue An optional value to return if the property is missing + * from the object. If this is not specified and the property is missing, an + * error will be thrown. + */ + function getArg(aArgs, aName, aDefaultValue) { + if (aName in aArgs) { + return aArgs[aName]; + } else if (arguments.length === 3) { + return aDefaultValue; + } else { + throw new Error('"' + aName + '" is a required argument.'); + } + } + exports.getArg = getArg; + + var urlRegexp = /^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.]*)(?::(\d+))?(\S*)$/; + var dataUrlRegexp = /^data:.+\,.+$/; + + function urlParse(aUrl) { + var match = aUrl.match(urlRegexp); + if (!match) { + return null; + } + return { + scheme: match[1], + auth: match[2], + host: match[3], + port: match[4], + path: match[5] + }; + } + exports.urlParse = urlParse; + + function urlGenerate(aParsedUrl) { + var url = ''; + if (aParsedUrl.scheme) { + url += aParsedUrl.scheme + ':'; + } + url += '//'; + if (aParsedUrl.auth) { + url += aParsedUrl.auth + '@'; + } + if (aParsedUrl.host) { + url += aParsedUrl.host; + } + if (aParsedUrl.port) { + url += ":" + aParsedUrl.port + } + if (aParsedUrl.path) { + url += aParsedUrl.path; + } + return url; + } + exports.urlGenerate = urlGenerate; + + /** + * Normalizes a path, or the path portion of a URL: + * + * - Replaces consequtive slashes with one slash. + * - Removes unnecessary '.' parts. + * - Removes unnecessary '/..' parts. + * + * Based on code in the Node.js 'path' core module. + * + * @param aPath The path or url to normalize. + */ + function normalize(aPath) { + var path = aPath; + var url = urlParse(aPath); + if (url) { + if (!url.path) { + return aPath; + } + path = url.path; + } + var isAbsolute = exports.isAbsolute(path); + + var parts = path.split(/\/+/); + for (var part, up = 0, i = parts.length - 1; i >= 0; i--) { + part = parts[i]; + if (part === '.') { + parts.splice(i, 1); + } else if (part === '..') { + up++; + } else if (up > 0) { + if (part === '') { + // The first part is blank if the path is absolute. Trying to go + // above the root is a no-op. Therefore we can remove all '..' parts + // directly after the root. + parts.splice(i + 1, up); + up = 0; + } else { + parts.splice(i, 2); + up--; + } + } + } + path = parts.join('/'); + + if (path === '') { + path = isAbsolute ? '/' : '.'; + } + + if (url) { + url.path = path; + return urlGenerate(url); + } + return path; + } + exports.normalize = normalize; + + /** + * Joins two paths/URLs. + * + * @param aRoot The root path or URL. + * @param aPath The path or URL to be joined with the root. + * + * - If aPath is a URL or a data URI, aPath is returned, unless aPath is a + * scheme-relative URL: Then the scheme of aRoot, if any, is prepended + * first. + * - Otherwise aPath is a path. If aRoot is a URL, then its path portion + * is updated with the result and aRoot is returned. Otherwise the result + * is returned. + * - If aPath is absolute, the result is aPath. + * - Otherwise the two paths are joined with a slash. + * - Joining for example 'http://' and 'www.example.com' is also supported. + */ + function join(aRoot, aPath) { + if (aRoot === "") { + aRoot = "."; + } + if (aPath === "") { + aPath = "."; + } + var aPathUrl = urlParse(aPath); + var aRootUrl = urlParse(aRoot); + if (aRootUrl) { + aRoot = aRootUrl.path || '/'; + } + + // `join(foo, '//www.example.org')` + if (aPathUrl && !aPathUrl.scheme) { + if (aRootUrl) { + aPathUrl.scheme = aRootUrl.scheme; + } + return urlGenerate(aPathUrl); + } + + if (aPathUrl || aPath.match(dataUrlRegexp)) { + return aPath; + } + + // `join('http://', 'www.example.com')` + if (aRootUrl && !aRootUrl.host && !aRootUrl.path) { + aRootUrl.host = aPath; + return urlGenerate(aRootUrl); + } + + var joined = aPath.charAt(0) === '/' + ? aPath + : normalize(aRoot.replace(/\/+$/, '') + '/' + aPath); + + if (aRootUrl) { + aRootUrl.path = joined; + return urlGenerate(aRootUrl); + } + return joined; + } + exports.join = join; + + exports.isAbsolute = function (aPath) { + return aPath.charAt(0) === '/' || !!aPath.match(urlRegexp); + }; + + /** + * Make a path relative to a URL or another path. + * + * @param aRoot The root path or URL. + * @param aPath The path or URL to be made relative to aRoot. + */ + function relative(aRoot, aPath) { + if (aRoot === "") { + aRoot = "."; + } + + aRoot = aRoot.replace(/\/$/, ''); + + // It is possible for the path to be above the root. In this case, simply + // checking whether the root is a prefix of the path won't work. Instead, we + // need to remove components from the root one by one, until either we find + // a prefix that fits, or we run out of components to remove. + var level = 0; + while (aPath.indexOf(aRoot + '/') !== 0) { + var index = aRoot.lastIndexOf("/"); + if (index < 0) { + return aPath; + } + + // If the only part of the root that is left is the scheme (i.e. http://, + // file:///, etc.), one or more slashes (/), or simply nothing at all, we + // have exhausted all components, so the path is not relative to the root. + aRoot = aRoot.slice(0, index); + if (aRoot.match(/^([^\/]+:\/)?\/*$/)) { + return aPath; + } + + ++level; + } + + // Make sure we add a "../" for each component we removed from the root. + return Array(level + 1).join("../") + aPath.substr(aRoot.length + 1); + } + exports.relative = relative; + + /** + * Because behavior goes wacky when you set `__proto__` on objects, we + * have to prefix all the strings in our set with an arbitrary character. + * + * See https://github.com/mozilla/source-map/pull/31 and + * https://github.com/mozilla/source-map/issues/30 + * + * @param String aStr + */ + function toSetString(aStr) { + return '$' + aStr; + } + exports.toSetString = toSetString; + + function fromSetString(aStr) { + return aStr.substr(1); + } + exports.fromSetString = fromSetString; + + /** + * Comparator between two mappings where the original positions are compared. + * + * Optionally pass in `true` as `onlyCompareGenerated` to consider two + * mappings with the same original source/line/column, but different generated + * line and column the same. Useful when searching for a mapping with a + * stubbed out mapping. + */ + function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) { + var cmp = mappingA.source - mappingB.source; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalLine - mappingB.originalLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalColumn - mappingB.originalColumn; + if (cmp !== 0 || onlyCompareOriginal) { + return cmp; + } + + cmp = mappingA.generatedColumn - mappingB.generatedColumn; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.generatedLine - mappingB.generatedLine; + if (cmp !== 0) { + return cmp; + } + + return mappingA.name - mappingB.name; + } + exports.compareByOriginalPositions = compareByOriginalPositions; + + /** + * Comparator between two mappings with deflated source and name indices where + * the generated positions are compared. + * + * Optionally pass in `true` as `onlyCompareGenerated` to consider two + * mappings with the same generated line and column, but different + * source/name/original line and column the same. Useful when searching for a + * mapping with a stubbed out mapping. + */ + function compareByGeneratedPositionsDeflated(mappingA, mappingB, onlyCompareGenerated) { + var cmp = mappingA.generatedLine - mappingB.generatedLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.generatedColumn - mappingB.generatedColumn; + if (cmp !== 0 || onlyCompareGenerated) { + return cmp; + } + + cmp = mappingA.source - mappingB.source; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalLine - mappingB.originalLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalColumn - mappingB.originalColumn; + if (cmp !== 0) { + return cmp; + } + + return mappingA.name - mappingB.name; + } + exports.compareByGeneratedPositionsDeflated = compareByGeneratedPositionsDeflated; + + function strcmp(aStr1, aStr2) { + if (aStr1 === aStr2) { + return 0; + } + + if (aStr1 > aStr2) { + return 1; + } + + return -1; + } + + /** + * Comparator between two mappings with inflated source and name strings where + * the generated positions are compared. + */ + function compareByGeneratedPositionsInflated(mappingA, mappingB) { + var cmp = mappingA.generatedLine - mappingB.generatedLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.generatedColumn - mappingB.generatedColumn; + if (cmp !== 0) { + return cmp; + } + + cmp = strcmp(mappingA.source, mappingB.source); + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalLine - mappingB.originalLine; + if (cmp !== 0) { + return cmp; + } + + cmp = mappingA.originalColumn - mappingB.originalColumn; + if (cmp !== 0) { + return cmp; + } + + return strcmp(mappingA.name, mappingB.name); + } + exports.compareByGeneratedPositionsInflated = compareByGeneratedPositionsInflated; +} + +},{}],607:[function(_dereq_,module,exports){ +/* + * Copyright 2009-2011 Mozilla Foundation and contributors + * Licensed under the New BSD license. See LICENSE.txt or: + * http://opensource.org/licenses/BSD-3-Clause + */ +exports.SourceMapGenerator = _dereq_(604).SourceMapGenerator; +exports.SourceMapConsumer = _dereq_(603).SourceMapConsumer; +exports.SourceNode = _dereq_(605).SourceNode; + +},{"603":603,"604":604,"605":605}],608:[function(_dereq_,module,exports){ +'use strict'; +module.exports = function toFastProperties(obj) { + /*jshint -W027*/ + function f() {} + f.prototype = obj; + new f(); + return; + eval(obj); +}; + +},{}],609:[function(_dereq_,module,exports){ +'use strict'; +module.exports = function (str) { + var tail = str.length; + + while (/[\s\uFEFF\u00A0]/.test(str[tail - 1])) { + tail--; + } + + return str.slice(0, tail); +}; + +},{}],610:[function(_dereq_,module,exports){ +(function (process){ +var Module = _dereq_(3); + +var resolve = module.exports = function (loc, _require) { + try { + return (_require || _dereq_).resolve(loc); + } catch (err) { + return null; + } +}; + +var relativeMod; + +resolve.relative = function (loc) { + // we're in the browser, probably + if (typeof Module === "object") return null; + + if (!relativeMod) { + relativeMod = new Module; + relativeMod.paths = Module._nodeModulePaths(process.cwd()); + } + + try { + return Module._resolveFilename(loc, relativeMod); + } catch (err) { + return null; + } +}; + +}).call(this,_dereq_(10)) +},{"10":10,"3":3}],611:[function(_dereq_,module,exports){ +module.exports={ + "name": "babel-core", + "version": "5.8.35", + "description": "A compiler for writing next generation JavaScript", + "author": "Sebastian McKenzie ", + "homepage": "https://babeljs.io/", + "license": "MIT", + "repository": "babel/babel", + "browser": { + "./lib/api/register/node.js": "./lib/api/register/browser.js" + }, + "keywords": [ + "6to5", + "babel", + "classes", + "const", + "es6", + "harmony", + "let", + "modules", + "transpile", + "transpiler", + "var" + ], + "scripts": { + "bench": "make bench", + "test": "make test" + }, + "dependencies": { + "babel-plugin-constant-folding": "^1.0.1", + "babel-plugin-dead-code-elimination": "^1.0.2", + "babel-plugin-eval": "^1.0.1", + "babel-plugin-inline-environment-variables": "^1.0.1", + "babel-plugin-jscript": "^1.0.4", + "babel-plugin-member-expression-literals": "^1.0.1", + "babel-plugin-property-literals": "^1.0.1", + "babel-plugin-proto-to-assign": "^1.0.3", + "babel-plugin-react-constant-elements": "^1.0.3", + "babel-plugin-react-display-name": "^1.0.3", + "babel-plugin-remove-console": "^1.0.1", + "babel-plugin-remove-debugger": "^1.0.1", + "babel-plugin-runtime": "^1.0.7", + "babel-plugin-undeclared-variables-check": "^1.0.2", + "babel-plugin-undefined-to-void": "^1.1.6", + "babylon": "^5.8.35", + "bluebird": "^2.9.33", + "chalk": "^1.0.0", + "convert-source-map": "^1.1.0", + "core-js": "^1.0.0", + "debug": "^2.1.1", + "detect-indent": "^3.0.0", + "esutils": "^2.0.0", + "fs-readdir-recursive": "^0.1.0", + "globals": "^6.4.0", + "home-or-tmp": "^1.0.0", + "is-integer": "^1.0.4", + "js-tokens": "1.0.1", + "json5": "^0.4.0", + "line-numbers": "0.2.0", + "lodash": "^3.10.0", + "minimatch": "^2.0.3", + "output-file-sync": "^1.1.0", + "path-exists": "^1.0.0", + "path-is-absolute": "^1.0.0", + "private": "^0.1.6", + "regenerator": "0.8.40", + "regexpu": "^1.3.0", + "repeating": "^1.1.2", + "resolve": "^1.1.6", + "shebang-regex": "^1.0.0", + "slash": "^1.0.0", + "source-map": "^0.5.0", + "source-map-support": "^0.2.10", + "to-fast-properties": "^1.0.0", + "trim-right": "^1.0.0", + "try-resolve": "^1.0.0" + } +} +},{}],612:[function(_dereq_,module,exports){ +module.exports={"abstract-expression-call":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"PROPERTY"},"property":{"type":"MemberExpression","object":{"type":"Identifier","name":"Symbol"},"property":{"type":"Identifier","name":"referenceGet"},"computed":false},"computed":true},"arguments":[{"type":"Identifier","name":"OBJECT"}]},"property":{"type":"Identifier","name":"call"},"computed":false},"arguments":[{"type":"Identifier","name":"OBJECT"}]}}]},"abstract-expression-delete":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"PROPERTY"},"property":{"type":"MemberExpression","object":{"type":"Identifier","name":"Symbol"},"property":{"type":"Identifier","name":"referenceDelete"},"computed":false},"computed":true},"arguments":[{"type":"Identifier","name":"OBJECT"}]}}]},"abstract-expression-get":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"PROPERTY"},"property":{"type":"MemberExpression","object":{"type":"Identifier","name":"Symbol"},"property":{"type":"Identifier","name":"referenceGet"},"computed":false},"computed":true},"arguments":[{"type":"Identifier","name":"OBJECT"}]}}]},"abstract-expression-set":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"PROPERTY"},"property":{"type":"MemberExpression","object":{"type":"Identifier","name":"Symbol"},"property":{"type":"Identifier","name":"referenceSet"},"computed":false},"computed":true},"arguments":[{"type":"Identifier","name":"OBJECT"},{"type":"Identifier","name":"VALUE"}]}}]},"array-comprehension-container":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"CallExpression","callee":{"type":"FunctionExpression","id":null,"generator":false,"expression":false,"params":[],"body":{"type":"BlockStatement","body":[{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"KEY"},"init":{"type":"ArrayExpression","elements":[]}}],"kind":"var"},{"type":"ReturnStatement","argument":{"type":"Identifier","name":"KEY"}}]},"parenthesizedExpression":true},"arguments":[]}}]},"array-from":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"Array"},"property":{"type":"Identifier","name":"from"},"computed":false},"arguments":[{"type":"Identifier","name":"VALUE"}]}}]},"array-push":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"KEY"},"property":{"type":"Identifier","name":"push"},"computed":false},"arguments":[{"type":"Identifier","name":"STATEMENT"}]}}]},"call":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"OBJECT"},"property":{"type":"Identifier","name":"call"},"computed":false},"arguments":[{"type":"Identifier","name":"CONTEXT"}]}}]},"class-decorator":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"AssignmentExpression","operator":"=","left":{"type":"Identifier","name":"CLASS_REF"},"right":{"type":"LogicalExpression","left":{"type":"CallExpression","callee":{"type":"Identifier","name":"DECORATOR"},"arguments":[{"type":"Identifier","name":"CLASS_REF"}]},"operator":"||","right":{"type":"Identifier","name":"CLASS_REF"}}}}]},"class-derived-default-constructor":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"FunctionExpression","id":null,"generator":false,"expression":false,"params":[],"body":{"type":"BlockStatement","body":[{"type":"ExpressionStatement","expression":{"type":"CallExpression","callee":{"type":"Super"},"arguments":[{"type":"SpreadElement","argument":{"type":"Identifier","name":"arguments"}}]}}]},"parenthesizedExpression":true}}]},"default-parameter-assign":{"type":"Program","body":[{"type":"IfStatement","test":{"type":"BinaryExpression","left":{"type":"Identifier","name":"VARIABLE_NAME"},"operator":"===","right":{"type":"Identifier","name":"undefined"}},"consequent":{"type":"ExpressionStatement","expression":{"type":"AssignmentExpression","operator":"=","left":{"type":"Identifier","name":"VARIABLE_NAME"},"right":{"type":"Identifier","name":"DEFAULT_VALUE"}}},"alternate":null}]},"default-parameter":{"type":"Program","body":[{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"VARIABLE_NAME"},"init":{"type":"ConditionalExpression","test":{"type":"LogicalExpression","left":{"type":"BinaryExpression","left":{"type":"MemberExpression","object":{"type":"Identifier","name":"ARGUMENTS"},"property":{"type":"Identifier","name":"length"},"computed":false},"operator":"<=","right":{"type":"Identifier","name":"ARGUMENT_KEY"}},"operator":"||","right":{"type":"BinaryExpression","left":{"type":"MemberExpression","object":{"type":"Identifier","name":"ARGUMENTS"},"property":{"type":"Identifier","name":"ARGUMENT_KEY"},"computed":true},"operator":"===","right":{"type":"Identifier","name":"undefined"}}},"consequent":{"type":"Identifier","name":"DEFAULT_VALUE"},"alternate":{"type":"MemberExpression","object":{"type":"Identifier","name":"ARGUMENTS"},"property":{"type":"Identifier","name":"ARGUMENT_KEY"},"computed":true}}}],"kind":"let"}]},"exports-assign":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"AssignmentExpression","operator":"=","left":{"type":"MemberExpression","object":{"type":"Identifier","name":"exports"},"property":{"type":"Identifier","name":"KEY"},"computed":false},"right":{"type":"Identifier","name":"VALUE"}}}]},"exports-default-assign":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"AssignmentExpression","operator":"=","left":{"type":"MemberExpression","object":{"type":"Identifier","name":"module"},"property":{"type":"Identifier","name":"exports"},"computed":false},"right":{"type":"Identifier","name":"VALUE"}}}]},"exports-from-assign":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"Object"},"property":{"type":"Identifier","name":"defineProperty"},"computed":false},"arguments":[{"type":"Identifier","name":"exports"},{"type":"Identifier","name":"ID"},{"type":"ObjectExpression","properties":[{"type":"Property","method":false,"shorthand":false,"computed":false,"key":{"type":"Identifier","name":"enumerable"},"value":{"type":"Literal","value":true},"kind":"init"},{"type":"Property","method":false,"shorthand":false,"computed":false,"key":{"type":"Identifier","name":"get"},"value":{"type":"FunctionExpression","id":{"type":"Identifier","name":"get"},"generator":false,"expression":false,"params":[],"body":{"type":"BlockStatement","body":[{"type":"ReturnStatement","argument":{"type":"Identifier","name":"INIT"}}]}},"kind":"init"}]}]}}]},"exports-module-declaration-loose":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"AssignmentExpression","operator":"=","left":{"type":"MemberExpression","object":{"type":"Identifier","name":"exports"},"property":{"type":"Identifier","name":"__esModule"},"computed":false},"right":{"type":"Literal","value":true}}}]},"exports-module-declaration":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"Object"},"property":{"type":"Identifier","name":"defineProperty"},"computed":false},"arguments":[{"type":"Identifier","name":"exports"},{"type":"Literal","value":"__esModule"},{"type":"ObjectExpression","properties":[{"type":"Property","method":false,"shorthand":false,"computed":false,"key":{"type":"Identifier","name":"value"},"value":{"type":"Literal","value":true},"kind":"init"}]}]}}]},"for-of-array":{"type":"Program","body":[{"type":"ForStatement","init":{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"KEY"},"init":{"type":"Literal","value":0}}],"kind":"var"},"test":{"type":"BinaryExpression","left":{"type":"Identifier","name":"KEY"},"operator":"<","right":{"type":"MemberExpression","object":{"type":"Identifier","name":"ARR"},"property":{"type":"Identifier","name":"length"},"computed":false}},"update":{"type":"UpdateExpression","operator":"++","prefix":false,"argument":{"type":"Identifier","name":"KEY"}},"body":{"type":"ExpressionStatement","expression":{"type":"Identifier","name":"BODY"}}}]},"for-of-loose":{"type":"Program","body":[{"type":"ForStatement","init":{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"LOOP_OBJECT"},"init":{"type":"Identifier","name":"OBJECT"}},{"type":"VariableDeclarator","id":{"type":"Identifier","name":"IS_ARRAY"},"init":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"Array"},"property":{"type":"Identifier","name":"isArray"},"computed":false},"arguments":[{"type":"Identifier","name":"LOOP_OBJECT"}]}},{"type":"VariableDeclarator","id":{"type":"Identifier","name":"INDEX"},"init":{"type":"Literal","value":0}},{"type":"VariableDeclarator","id":{"type":"Identifier","name":"LOOP_OBJECT"},"init":{"type":"ConditionalExpression","test":{"type":"Identifier","name":"IS_ARRAY"},"consequent":{"type":"Identifier","name":"LOOP_OBJECT"},"alternate":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"LOOP_OBJECT"},"property":{"type":"MemberExpression","object":{"type":"Identifier","name":"Symbol"},"property":{"type":"Identifier","name":"iterator"},"computed":false},"computed":true},"arguments":[]}}}],"kind":"var"},"test":null,"update":null,"body":{"type":"BlockStatement","body":[{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"ID"},"init":null}],"kind":"var"},{"type":"IfStatement","test":{"type":"Identifier","name":"IS_ARRAY"},"consequent":{"type":"BlockStatement","body":[{"type":"IfStatement","test":{"type":"BinaryExpression","left":{"type":"Identifier","name":"INDEX"},"operator":">=","right":{"type":"MemberExpression","object":{"type":"Identifier","name":"LOOP_OBJECT"},"property":{"type":"Identifier","name":"length"},"computed":false}},"consequent":{"type":"BreakStatement","label":null},"alternate":null},{"type":"ExpressionStatement","expression":{"type":"AssignmentExpression","operator":"=","left":{"type":"Identifier","name":"ID"},"right":{"type":"MemberExpression","object":{"type":"Identifier","name":"LOOP_OBJECT"},"property":{"type":"UpdateExpression","operator":"++","prefix":false,"argument":{"type":"Identifier","name":"INDEX"}},"computed":true}}}]},"alternate":{"type":"BlockStatement","body":[{"type":"ExpressionStatement","expression":{"type":"AssignmentExpression","operator":"=","left":{"type":"Identifier","name":"INDEX"},"right":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"LOOP_OBJECT"},"property":{"type":"Identifier","name":"next"},"computed":false},"arguments":[]}}},{"type":"IfStatement","test":{"type":"MemberExpression","object":{"type":"Identifier","name":"INDEX"},"property":{"type":"Identifier","name":"done"},"computed":false},"consequent":{"type":"BreakStatement","label":null},"alternate":null},{"type":"ExpressionStatement","expression":{"type":"AssignmentExpression","operator":"=","left":{"type":"Identifier","name":"ID"},"right":{"type":"MemberExpression","object":{"type":"Identifier","name":"INDEX"},"property":{"type":"Identifier","name":"value"},"computed":false}}}]}}]}}]},"for-of":{"type":"Program","body":[{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"ITERATOR_COMPLETION"},"init":{"type":"Literal","value":true}}],"kind":"var"},{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"ITERATOR_HAD_ERROR_KEY"},"init":{"type":"Literal","value":false}}],"kind":"var"},{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"ITERATOR_ERROR_KEY"},"init":{"type":"Identifier","name":"undefined"}}],"kind":"var"},{"type":"TryStatement","block":{"type":"BlockStatement","body":[{"type":"ForStatement","init":{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"ITERATOR_KEY"},"init":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"OBJECT"},"property":{"type":"MemberExpression","object":{"type":"Identifier","name":"Symbol"},"property":{"type":"Identifier","name":"iterator"},"computed":false},"computed":true},"arguments":[]}},{"type":"VariableDeclarator","id":{"type":"Identifier","name":"STEP_KEY"},"init":null}],"kind":"var"},"test":{"type":"UnaryExpression","operator":"!","prefix":true,"argument":{"type":"AssignmentExpression","operator":"=","left":{"type":"Identifier","name":"ITERATOR_COMPLETION"},"right":{"type":"MemberExpression","object":{"type":"AssignmentExpression","operator":"=","left":{"type":"Identifier","name":"STEP_KEY"},"right":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"ITERATOR_KEY"},"property":{"type":"Identifier","name":"next"},"computed":false},"arguments":[]},"parenthesizedExpression":true},"property":{"type":"Identifier","name":"done"},"computed":false},"parenthesizedExpression":true}},"update":{"type":"AssignmentExpression","operator":"=","left":{"type":"Identifier","name":"ITERATOR_COMPLETION"},"right":{"type":"Literal","value":true}},"body":{"type":"BlockStatement","body":[]}}]},"handler":{"type":"CatchClause","param":{"type":"Identifier","name":"err"},"body":{"type":"BlockStatement","body":[{"type":"ExpressionStatement","expression":{"type":"AssignmentExpression","operator":"=","left":{"type":"Identifier","name":"ITERATOR_HAD_ERROR_KEY"},"right":{"type":"Literal","value":true}}},{"type":"ExpressionStatement","expression":{"type":"AssignmentExpression","operator":"=","left":{"type":"Identifier","name":"ITERATOR_ERROR_KEY"},"right":{"type":"Identifier","name":"err"}}}]}},"guardedHandlers":[],"finalizer":{"type":"BlockStatement","body":[{"type":"TryStatement","block":{"type":"BlockStatement","body":[{"type":"IfStatement","test":{"type":"LogicalExpression","left":{"type":"UnaryExpression","operator":"!","prefix":true,"argument":{"type":"Identifier","name":"ITERATOR_COMPLETION"}},"operator":"&&","right":{"type":"MemberExpression","object":{"type":"Identifier","name":"ITERATOR_KEY"},"property":{"type":"Literal","value":"return"},"computed":true}},"consequent":{"type":"BlockStatement","body":[{"type":"ExpressionStatement","expression":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"ITERATOR_KEY"},"property":{"type":"Literal","value":"return"},"computed":true},"arguments":[]}}]},"alternate":null}]},"handler":null,"guardedHandlers":[],"finalizer":{"type":"BlockStatement","body":[{"type":"IfStatement","test":{"type":"Identifier","name":"ITERATOR_HAD_ERROR_KEY"},"consequent":{"type":"BlockStatement","body":[{"type":"ThrowStatement","argument":{"type":"Identifier","name":"ITERATOR_ERROR_KEY"}}]},"alternate":null}]}}]}}]},"helper-async-to-generator":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"FunctionExpression","id":null,"generator":false,"expression":false,"params":[{"type":"Identifier","name":"fn"}],"body":{"type":"BlockStatement","body":[{"type":"ReturnStatement","argument":{"type":"FunctionExpression","id":null,"generator":false,"expression":false,"params":[],"body":{"type":"BlockStatement","body":[{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"gen"},"init":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"fn"},"property":{"type":"Identifier","name":"apply"},"computed":false},"arguments":[{"type":"ThisExpression"},{"type":"Identifier","name":"arguments"}]}}],"kind":"var"},{"type":"ReturnStatement","argument":{"type":"NewExpression","callee":{"type":"Identifier","name":"Promise"},"arguments":[{"type":"FunctionExpression","id":null,"generator":false,"expression":false,"params":[{"type":"Identifier","name":"resolve"},{"type":"Identifier","name":"reject"}],"body":{"type":"BlockStatement","body":[{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"callNext"},"init":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"step"},"property":{"type":"Identifier","name":"bind"},"computed":false},"arguments":[{"type":"Literal","value":null,"rawValue":null},{"type":"Literal","value":"next"}]}}],"kind":"var"},{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"callThrow"},"init":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"step"},"property":{"type":"Identifier","name":"bind"},"computed":false},"arguments":[{"type":"Literal","value":null,"rawValue":null},{"type":"Literal","value":"throw"}]}}],"kind":"var"},{"type":"FunctionDeclaration","id":{"type":"Identifier","name":"step"},"generator":false,"expression":false,"params":[{"type":"Identifier","name":"key"},{"type":"Identifier","name":"arg"}],"body":{"type":"BlockStatement","body":[{"type":"TryStatement","block":{"type":"BlockStatement","body":[{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"info"},"init":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"gen"},"property":{"type":"Identifier","name":"key"},"computed":true},"arguments":[{"type":"Identifier","name":"arg"}]}}],"kind":"var"},{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"value"},"init":{"type":"MemberExpression","object":{"type":"Identifier","name":"info"},"property":{"type":"Identifier","name":"value"},"computed":false}}],"kind":"var"}]},"handler":{"type":"CatchClause","param":{"type":"Identifier","name":"error"},"body":{"type":"BlockStatement","body":[{"type":"ExpressionStatement","expression":{"type":"CallExpression","callee":{"type":"Identifier","name":"reject"},"arguments":[{"type":"Identifier","name":"error"}]}},{"type":"ReturnStatement","argument":null}]}},"guardedHandlers":[],"finalizer":null},{"type":"IfStatement","test":{"type":"MemberExpression","object":{"type":"Identifier","name":"info"},"property":{"type":"Identifier","name":"done"},"computed":false},"consequent":{"type":"BlockStatement","body":[{"type":"ExpressionStatement","expression":{"type":"CallExpression","callee":{"type":"Identifier","name":"resolve"},"arguments":[{"type":"Identifier","name":"value"}]}}]},"alternate":{"type":"BlockStatement","body":[{"type":"ExpressionStatement","expression":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"Promise"},"property":{"type":"Identifier","name":"resolve"},"computed":false},"arguments":[{"type":"Identifier","name":"value"}]},"property":{"type":"Identifier","name":"then"},"computed":false},"arguments":[{"type":"Identifier","name":"callNext"},{"type":"Identifier","name":"callThrow"}]}}]}}]}},{"type":"ExpressionStatement","expression":{"type":"CallExpression","callee":{"type":"Identifier","name":"callNext"},"arguments":[]}}]}}]}}]}}}]},"parenthesizedExpression":true}}]},"helper-bind":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"MemberExpression","object":{"type":"MemberExpression","object":{"type":"Identifier","name":"Function"},"property":{"type":"Identifier","name":"prototype"},"computed":false},"property":{"type":"Identifier","name":"bind"},"computed":false}}]},"helper-class-call-check":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"FunctionExpression","id":null,"generator":false,"expression":false,"params":[{"type":"Identifier","name":"instance"},{"type":"Identifier","name":"Constructor"}],"body":{"type":"BlockStatement","body":[{"type":"IfStatement","test":{"type":"UnaryExpression","operator":"!","prefix":true,"argument":{"type":"BinaryExpression","left":{"type":"Identifier","name":"instance"},"operator":"instanceof","right":{"type":"Identifier","name":"Constructor"},"parenthesizedExpression":true}},"consequent":{"type":"BlockStatement","body":[{"type":"ThrowStatement","argument":{"type":"NewExpression","callee":{"type":"Identifier","name":"TypeError"},"arguments":[{"type":"Literal","value":"Cannot call a class as a function"}]}}]},"alternate":null}]},"parenthesizedExpression":true}}]},"helper-create-class":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"CallExpression","callee":{"type":"FunctionExpression","id":null,"generator":false,"expression":false,"params":[],"body":{"type":"BlockStatement","body":[{"type":"FunctionDeclaration","id":{"type":"Identifier","name":"defineProperties"},"generator":false,"expression":false,"params":[{"type":"Identifier","name":"target"},{"type":"Identifier","name":"props"}],"body":{"type":"BlockStatement","body":[{"type":"ForStatement","init":{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"i"},"init":{"type":"Literal","value":0}}],"kind":"var"},"test":{"type":"BinaryExpression","left":{"type":"Identifier","name":"i"},"operator":"<","right":{"type":"MemberExpression","object":{"type":"Identifier","name":"props"},"property":{"type":"Identifier","name":"length"},"computed":false}},"update":{"type":"UpdateExpression","operator":"++","prefix":false,"argument":{"type":"Identifier","name":"i"}},"body":{"type":"BlockStatement","body":[{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"descriptor"},"init":{"type":"MemberExpression","object":{"type":"Identifier","name":"props"},"property":{"type":"Identifier","name":"i"},"computed":true}}],"kind":"var"},{"type":"ExpressionStatement","expression":{"type":"AssignmentExpression","operator":"=","left":{"type":"MemberExpression","object":{"type":"Identifier","name":"descriptor"},"property":{"type":"Identifier","name":"enumerable"},"computed":false},"right":{"type":"LogicalExpression","left":{"type":"MemberExpression","object":{"type":"Identifier","name":"descriptor"},"property":{"type":"Identifier","name":"enumerable"},"computed":false},"operator":"||","right":{"type":"Literal","value":false}}}},{"type":"ExpressionStatement","expression":{"type":"AssignmentExpression","operator":"=","left":{"type":"MemberExpression","object":{"type":"Identifier","name":"descriptor"},"property":{"type":"Identifier","name":"configurable"},"computed":false},"right":{"type":"Literal","value":true}}},{"type":"IfStatement","test":{"type":"BinaryExpression","left":{"type":"Literal","value":"value"},"operator":"in","right":{"type":"Identifier","name":"descriptor"}},"consequent":{"type":"ExpressionStatement","expression":{"type":"AssignmentExpression","operator":"=","left":{"type":"MemberExpression","object":{"type":"Identifier","name":"descriptor"},"property":{"type":"Identifier","name":"writable"},"computed":false},"right":{"type":"Literal","value":true}}},"alternate":null},{"type":"ExpressionStatement","expression":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"Object"},"property":{"type":"Identifier","name":"defineProperty"},"computed":false},"arguments":[{"type":"Identifier","name":"target"},{"type":"MemberExpression","object":{"type":"Identifier","name":"descriptor"},"property":{"type":"Identifier","name":"key"},"computed":false},{"type":"Identifier","name":"descriptor"}]}}]}}]}},{"type":"ReturnStatement","argument":{"type":"FunctionExpression","id":null,"generator":false,"expression":false,"params":[{"type":"Identifier","name":"Constructor"},{"type":"Identifier","name":"protoProps"},{"type":"Identifier","name":"staticProps"}],"body":{"type":"BlockStatement","body":[{"type":"IfStatement","test":{"type":"Identifier","name":"protoProps"},"consequent":{"type":"ExpressionStatement","expression":{"type":"CallExpression","callee":{"type":"Identifier","name":"defineProperties"},"arguments":[{"type":"MemberExpression","object":{"type":"Identifier","name":"Constructor"},"property":{"type":"Identifier","name":"prototype"},"computed":false},{"type":"Identifier","name":"protoProps"}]}},"alternate":null},{"type":"IfStatement","test":{"type":"Identifier","name":"staticProps"},"consequent":{"type":"ExpressionStatement","expression":{"type":"CallExpression","callee":{"type":"Identifier","name":"defineProperties"},"arguments":[{"type":"Identifier","name":"Constructor"},{"type":"Identifier","name":"staticProps"}]}},"alternate":null},{"type":"ReturnStatement","argument":{"type":"Identifier","name":"Constructor"}}]}}}]},"parenthesizedExpression":true},"arguments":[]}}]},"helper-create-decorated-class":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"CallExpression","callee":{"type":"FunctionExpression","id":null,"generator":false,"expression":false,"params":[],"body":{"type":"BlockStatement","body":[{"type":"FunctionDeclaration","id":{"type":"Identifier","name":"defineProperties"},"generator":false,"expression":false,"params":[{"type":"Identifier","name":"target"},{"type":"Identifier","name":"descriptors"},{"type":"Identifier","name":"initializers"}],"body":{"type":"BlockStatement","body":[{"type":"ForStatement","init":{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"i"},"init":{"type":"Literal","value":0}}],"kind":"var"},"test":{"type":"BinaryExpression","left":{"type":"Identifier","name":"i"},"operator":"<","right":{"type":"MemberExpression","object":{"type":"Identifier","name":"descriptors"},"property":{"type":"Identifier","name":"length"},"computed":false}},"update":{"type":"UpdateExpression","operator":"++","prefix":false,"argument":{"type":"Identifier","name":"i"}},"body":{"type":"BlockStatement","body":[{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"descriptor"},"init":{"type":"MemberExpression","object":{"type":"Identifier","name":"descriptors"},"property":{"type":"Identifier","name":"i"},"computed":true}}],"kind":"var"},{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"decorators"},"init":{"type":"MemberExpression","object":{"type":"Identifier","name":"descriptor"},"property":{"type":"Identifier","name":"decorators"},"computed":false}}],"kind":"var"},{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"key"},"init":{"type":"MemberExpression","object":{"type":"Identifier","name":"descriptor"},"property":{"type":"Identifier","name":"key"},"computed":false}}],"kind":"var"},{"type":"ExpressionStatement","expression":{"type":"UnaryExpression","operator":"delete","prefix":true,"argument":{"type":"MemberExpression","object":{"type":"Identifier","name":"descriptor","leadingComments":null},"property":{"type":"Identifier","name":"key"},"computed":false,"leadingComments":null},"leadingComments":null}},{"type":"ExpressionStatement","expression":{"type":"UnaryExpression","operator":"delete","prefix":true,"argument":{"type":"MemberExpression","object":{"type":"Identifier","name":"descriptor"},"property":{"type":"Identifier","name":"decorators"},"computed":false}}},{"type":"ExpressionStatement","expression":{"type":"AssignmentExpression","operator":"=","left":{"type":"MemberExpression","object":{"type":"Identifier","name":"descriptor"},"property":{"type":"Identifier","name":"enumerable"},"computed":false},"right":{"type":"LogicalExpression","left":{"type":"MemberExpression","object":{"type":"Identifier","name":"descriptor"},"property":{"type":"Identifier","name":"enumerable"},"computed":false},"operator":"||","right":{"type":"Literal","value":false}}}},{"type":"ExpressionStatement","expression":{"type":"AssignmentExpression","operator":"=","left":{"type":"MemberExpression","object":{"type":"Identifier","name":"descriptor"},"property":{"type":"Identifier","name":"configurable"},"computed":false},"right":{"type":"Literal","value":true}}},{"type":"IfStatement","test":{"type":"LogicalExpression","left":{"type":"BinaryExpression","left":{"type":"Literal","value":"value"},"operator":"in","right":{"type":"Identifier","name":"descriptor"}},"operator":"||","right":{"type":"MemberExpression","object":{"type":"Identifier","name":"descriptor"},"property":{"type":"Identifier","name":"initializer"},"computed":false}},"consequent":{"type":"ExpressionStatement","expression":{"type":"AssignmentExpression","operator":"=","left":{"type":"MemberExpression","object":{"type":"Identifier","name":"descriptor"},"property":{"type":"Identifier","name":"writable"},"computed":false},"right":{"type":"Literal","value":true}}},"alternate":null},{"type":"IfStatement","test":{"type":"Identifier","name":"decorators"},"consequent":{"type":"BlockStatement","body":[{"type":"ForStatement","init":{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"f"},"init":{"type":"Literal","value":0}}],"kind":"var"},"test":{"type":"BinaryExpression","left":{"type":"Identifier","name":"f"},"operator":"<","right":{"type":"MemberExpression","object":{"type":"Identifier","name":"decorators"},"property":{"type":"Identifier","name":"length"},"computed":false}},"update":{"type":"UpdateExpression","operator":"++","prefix":false,"argument":{"type":"Identifier","name":"f"}},"body":{"type":"BlockStatement","body":[{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"decorator"},"init":{"type":"MemberExpression","object":{"type":"Identifier","name":"decorators"},"property":{"type":"Identifier","name":"f"},"computed":true}}],"kind":"var"},{"type":"IfStatement","test":{"type":"BinaryExpression","left":{"type":"UnaryExpression","operator":"typeof","prefix":true,"argument":{"type":"Identifier","name":"decorator"}},"operator":"===","right":{"type":"Literal","value":"function"}},"consequent":{"type":"BlockStatement","body":[{"type":"ExpressionStatement","expression":{"type":"AssignmentExpression","operator":"=","left":{"type":"Identifier","name":"descriptor"},"right":{"type":"LogicalExpression","left":{"type":"CallExpression","callee":{"type":"Identifier","name":"decorator"},"arguments":[{"type":"Identifier","name":"target"},{"type":"Identifier","name":"key"},{"type":"Identifier","name":"descriptor"}]},"operator":"||","right":{"type":"Identifier","name":"descriptor"}}}}]},"alternate":{"type":"BlockStatement","body":[{"type":"ThrowStatement","argument":{"type":"NewExpression","callee":{"type":"Identifier","name":"TypeError"},"arguments":[{"type":"BinaryExpression","left":{"type":"BinaryExpression","left":{"type":"BinaryExpression","left":{"type":"Literal","value":"The decorator for method "},"operator":"+","right":{"type":"MemberExpression","object":{"type":"Identifier","name":"descriptor"},"property":{"type":"Identifier","name":"key"},"computed":false}},"operator":"+","right":{"type":"Literal","value":" is of the invalid type "}},"operator":"+","right":{"type":"UnaryExpression","operator":"typeof","prefix":true,"argument":{"type":"Identifier","name":"decorator"}}}]}}]}}]}},{"type":"IfStatement","test":{"type":"BinaryExpression","left":{"type":"MemberExpression","object":{"type":"Identifier","name":"descriptor"},"property":{"type":"Identifier","name":"initializer"},"computed":false},"operator":"!==","right":{"type":"Identifier","name":"undefined"}},"consequent":{"type":"BlockStatement","body":[{"type":"ExpressionStatement","expression":{"type":"AssignmentExpression","operator":"=","left":{"type":"MemberExpression","object":{"type":"Identifier","name":"initializers"},"property":{"type":"Identifier","name":"key"},"computed":true},"right":{"type":"Identifier","name":"descriptor"}}},{"type":"ContinueStatement","label":null}]},"alternate":null}]},"alternate":null},{"type":"ExpressionStatement","expression":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"Object"},"property":{"type":"Identifier","name":"defineProperty"},"computed":false},"arguments":[{"type":"Identifier","name":"target"},{"type":"Identifier","name":"key"},{"type":"Identifier","name":"descriptor"}]}}]}}]}},{"type":"ReturnStatement","argument":{"type":"FunctionExpression","id":null,"generator":false,"expression":false,"params":[{"type":"Identifier","name":"Constructor"},{"type":"Identifier","name":"protoProps"},{"type":"Identifier","name":"staticProps"},{"type":"Identifier","name":"protoInitializers"},{"type":"Identifier","name":"staticInitializers"}],"body":{"type":"BlockStatement","body":[{"type":"IfStatement","test":{"type":"Identifier","name":"protoProps"},"consequent":{"type":"ExpressionStatement","expression":{"type":"CallExpression","callee":{"type":"Identifier","name":"defineProperties"},"arguments":[{"type":"MemberExpression","object":{"type":"Identifier","name":"Constructor"},"property":{"type":"Identifier","name":"prototype"},"computed":false},{"type":"Identifier","name":"protoProps"},{"type":"Identifier","name":"protoInitializers"}]}},"alternate":null},{"type":"IfStatement","test":{"type":"Identifier","name":"staticProps"},"consequent":{"type":"ExpressionStatement","expression":{"type":"CallExpression","callee":{"type":"Identifier","name":"defineProperties"},"arguments":[{"type":"Identifier","name":"Constructor"},{"type":"Identifier","name":"staticProps"},{"type":"Identifier","name":"staticInitializers"}]}},"alternate":null},{"type":"ReturnStatement","argument":{"type":"Identifier","name":"Constructor"}}]}}}]},"parenthesizedExpression":true},"arguments":[]}}]},"helper-create-decorated-object":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"FunctionExpression","id":null,"generator":false,"expression":false,"params":[{"type":"Identifier","name":"descriptors"}],"body":{"type":"BlockStatement","body":[{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"target"},"init":{"type":"ObjectExpression","properties":[]}}],"kind":"var"},{"type":"ForStatement","init":{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"i"},"init":{"type":"Literal","value":0}}],"kind":"var"},"test":{"type":"BinaryExpression","left":{"type":"Identifier","name":"i"},"operator":"<","right":{"type":"MemberExpression","object":{"type":"Identifier","name":"descriptors"},"property":{"type":"Identifier","name":"length"},"computed":false}},"update":{"type":"UpdateExpression","operator":"++","prefix":false,"argument":{"type":"Identifier","name":"i"}},"body":{"type":"BlockStatement","body":[{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"descriptor"},"init":{"type":"MemberExpression","object":{"type":"Identifier","name":"descriptors"},"property":{"type":"Identifier","name":"i"},"computed":true}}],"kind":"var"},{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"decorators"},"init":{"type":"MemberExpression","object":{"type":"Identifier","name":"descriptor"},"property":{"type":"Identifier","name":"decorators"},"computed":false}}],"kind":"var"},{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"key"},"init":{"type":"MemberExpression","object":{"type":"Identifier","name":"descriptor"},"property":{"type":"Identifier","name":"key"},"computed":false}}],"kind":"var"},{"type":"ExpressionStatement","expression":{"type":"UnaryExpression","operator":"delete","prefix":true,"argument":{"type":"MemberExpression","object":{"type":"Identifier","name":"descriptor","leadingComments":null},"property":{"type":"Identifier","name":"key"},"computed":false,"leadingComments":null},"leadingComments":null}},{"type":"ExpressionStatement","expression":{"type":"UnaryExpression","operator":"delete","prefix":true,"argument":{"type":"MemberExpression","object":{"type":"Identifier","name":"descriptor"},"property":{"type":"Identifier","name":"decorators"},"computed":false}}},{"type":"ExpressionStatement","expression":{"type":"AssignmentExpression","operator":"=","left":{"type":"MemberExpression","object":{"type":"Identifier","name":"descriptor"},"property":{"type":"Identifier","name":"enumerable"},"computed":false},"right":{"type":"Literal","value":true}}},{"type":"ExpressionStatement","expression":{"type":"AssignmentExpression","operator":"=","left":{"type":"MemberExpression","object":{"type":"Identifier","name":"descriptor"},"property":{"type":"Identifier","name":"configurable"},"computed":false},"right":{"type":"Literal","value":true}}},{"type":"IfStatement","test":{"type":"LogicalExpression","left":{"type":"BinaryExpression","left":{"type":"Literal","value":"value"},"operator":"in","right":{"type":"Identifier","name":"descriptor"}},"operator":"||","right":{"type":"MemberExpression","object":{"type":"Identifier","name":"descriptor"},"property":{"type":"Identifier","name":"initializer"},"computed":false}},"consequent":{"type":"ExpressionStatement","expression":{"type":"AssignmentExpression","operator":"=","left":{"type":"MemberExpression","object":{"type":"Identifier","name":"descriptor"},"property":{"type":"Identifier","name":"writable"},"computed":false},"right":{"type":"Literal","value":true}}},"alternate":null},{"type":"IfStatement","test":{"type":"Identifier","name":"decorators"},"consequent":{"type":"BlockStatement","body":[{"type":"ForStatement","init":{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"f"},"init":{"type":"Literal","value":0}}],"kind":"var"},"test":{"type":"BinaryExpression","left":{"type":"Identifier","name":"f"},"operator":"<","right":{"type":"MemberExpression","object":{"type":"Identifier","name":"decorators"},"property":{"type":"Identifier","name":"length"},"computed":false}},"update":{"type":"UpdateExpression","operator":"++","prefix":false,"argument":{"type":"Identifier","name":"f"}},"body":{"type":"BlockStatement","body":[{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"decorator"},"init":{"type":"MemberExpression","object":{"type":"Identifier","name":"decorators"},"property":{"type":"Identifier","name":"f"},"computed":true}}],"kind":"var"},{"type":"IfStatement","test":{"type":"BinaryExpression","left":{"type":"UnaryExpression","operator":"typeof","prefix":true,"argument":{"type":"Identifier","name":"decorator"}},"operator":"===","right":{"type":"Literal","value":"function"}},"consequent":{"type":"BlockStatement","body":[{"type":"ExpressionStatement","expression":{"type":"AssignmentExpression","operator":"=","left":{"type":"Identifier","name":"descriptor"},"right":{"type":"LogicalExpression","left":{"type":"CallExpression","callee":{"type":"Identifier","name":"decorator"},"arguments":[{"type":"Identifier","name":"target"},{"type":"Identifier","name":"key"},{"type":"Identifier","name":"descriptor"}]},"operator":"||","right":{"type":"Identifier","name":"descriptor"}}}}]},"alternate":{"type":"BlockStatement","body":[{"type":"ThrowStatement","argument":{"type":"NewExpression","callee":{"type":"Identifier","name":"TypeError"},"arguments":[{"type":"BinaryExpression","left":{"type":"BinaryExpression","left":{"type":"BinaryExpression","left":{"type":"Literal","value":"The decorator for method "},"operator":"+","right":{"type":"MemberExpression","object":{"type":"Identifier","name":"descriptor"},"property":{"type":"Identifier","name":"key"},"computed":false}},"operator":"+","right":{"type":"Literal","value":" is of the invalid type "}},"operator":"+","right":{"type":"UnaryExpression","operator":"typeof","prefix":true,"argument":{"type":"Identifier","name":"decorator"}}}]}}]}}]}}]},"alternate":null},{"type":"IfStatement","test":{"type":"MemberExpression","object":{"type":"Identifier","name":"descriptor"},"property":{"type":"Identifier","name":"initializer"},"computed":false},"consequent":{"type":"BlockStatement","body":[{"type":"ExpressionStatement","expression":{"type":"AssignmentExpression","operator":"=","left":{"type":"MemberExpression","object":{"type":"Identifier","name":"descriptor"},"property":{"type":"Identifier","name":"value"},"computed":false},"right":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"MemberExpression","object":{"type":"Identifier","name":"descriptor"},"property":{"type":"Identifier","name":"initializer"},"computed":false},"property":{"type":"Identifier","name":"call"},"computed":false},"arguments":[{"type":"Identifier","name":"target"}]}}}]},"alternate":null},{"type":"ExpressionStatement","expression":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"Object"},"property":{"type":"Identifier","name":"defineProperty"},"computed":false},"arguments":[{"type":"Identifier","name":"target"},{"type":"Identifier","name":"key"},{"type":"Identifier","name":"descriptor"}]}}]}},{"type":"ReturnStatement","argument":{"type":"Identifier","name":"target"}}]},"parenthesizedExpression":true}}]},"helper-default-props":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"FunctionExpression","id":null,"generator":false,"expression":false,"params":[{"type":"Identifier","name":"defaultProps"},{"type":"Identifier","name":"props"}],"body":{"type":"BlockStatement","body":[{"type":"IfStatement","test":{"type":"Identifier","name":"defaultProps"},"consequent":{"type":"BlockStatement","body":[{"type":"ForInStatement","left":{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"propName"},"init":null}],"kind":"var"},"right":{"type":"Identifier","name":"defaultProps"},"body":{"type":"BlockStatement","body":[{"type":"IfStatement","test":{"type":"BinaryExpression","left":{"type":"UnaryExpression","operator":"typeof","prefix":true,"argument":{"type":"MemberExpression","object":{"type":"Identifier","name":"props"},"property":{"type":"Identifier","name":"propName"},"computed":true}},"operator":"===","right":{"type":"Literal","value":"undefined"}},"consequent":{"type":"BlockStatement","body":[{"type":"ExpressionStatement","expression":{"type":"AssignmentExpression","operator":"=","left":{"type":"MemberExpression","object":{"type":"Identifier","name":"props"},"property":{"type":"Identifier","name":"propName"},"computed":true},"right":{"type":"MemberExpression","object":{"type":"Identifier","name":"defaultProps"},"property":{"type":"Identifier","name":"propName"},"computed":true}}}]},"alternate":null}]}}]},"alternate":null},{"type":"ReturnStatement","argument":{"type":"Identifier","name":"props"}}]},"parenthesizedExpression":true}}]},"helper-defaults":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"FunctionExpression","id":null,"generator":false,"expression":false,"params":[{"type":"Identifier","name":"obj"},{"type":"Identifier","name":"defaults"}],"body":{"type":"BlockStatement","body":[{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"keys"},"init":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"Object"},"property":{"type":"Identifier","name":"getOwnPropertyNames"},"computed":false},"arguments":[{"type":"Identifier","name":"defaults"}]}}],"kind":"var"},{"type":"ForStatement","init":{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"i"},"init":{"type":"Literal","value":0}}],"kind":"var"},"test":{"type":"BinaryExpression","left":{"type":"Identifier","name":"i"},"operator":"<","right":{"type":"MemberExpression","object":{"type":"Identifier","name":"keys"},"property":{"type":"Identifier","name":"length"},"computed":false}},"update":{"type":"UpdateExpression","operator":"++","prefix":false,"argument":{"type":"Identifier","name":"i"}},"body":{"type":"BlockStatement","body":[{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"key"},"init":{"type":"MemberExpression","object":{"type":"Identifier","name":"keys"},"property":{"type":"Identifier","name":"i"},"computed":true}}],"kind":"var"},{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"value"},"init":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"Object"},"property":{"type":"Identifier","name":"getOwnPropertyDescriptor"},"computed":false},"arguments":[{"type":"Identifier","name":"defaults"},{"type":"Identifier","name":"key"}]}}],"kind":"var"},{"type":"IfStatement","test":{"type":"LogicalExpression","left":{"type":"LogicalExpression","left":{"type":"Identifier","name":"value"},"operator":"&&","right":{"type":"MemberExpression","object":{"type":"Identifier","name":"value"},"property":{"type":"Identifier","name":"configurable"},"computed":false}},"operator":"&&","right":{"type":"BinaryExpression","left":{"type":"MemberExpression","object":{"type":"Identifier","name":"obj"},"property":{"type":"Identifier","name":"key"},"computed":true},"operator":"===","right":{"type":"Identifier","name":"undefined"}}},"consequent":{"type":"BlockStatement","body":[{"type":"ExpressionStatement","expression":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"Object"},"property":{"type":"Identifier","name":"defineProperty"},"computed":false},"arguments":[{"type":"Identifier","name":"obj"},{"type":"Identifier","name":"key"},{"type":"Identifier","name":"value"}]}}]},"alternate":null}]}},{"type":"ReturnStatement","argument":{"type":"Identifier","name":"obj"}}]},"parenthesizedExpression":true}}]},"helper-define-decorated-property-descriptor":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"FunctionExpression","id":null,"generator":false,"expression":false,"params":[{"type":"Identifier","name":"target"},{"type":"Identifier","name":"key"},{"type":"Identifier","name":"descriptors"}],"body":{"type":"BlockStatement","body":[{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"_descriptor"},"init":{"type":"MemberExpression","object":{"type":"Identifier","name":"descriptors"},"property":{"type":"Identifier","name":"key"},"computed":true}}],"kind":"var"},{"type":"IfStatement","test":{"type":"UnaryExpression","operator":"!","prefix":true,"argument":{"type":"Identifier","name":"_descriptor"}},"consequent":{"type":"ReturnStatement","argument":null,"leadingComments":null,"trailingComments":null},"alternate":null},{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"descriptor","leadingComments":null},"init":{"type":"ObjectExpression","properties":[]},"leadingComments":null}],"kind":"var"},{"type":"ForInStatement","left":{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"_key"},"init":null}],"kind":"var"},"right":{"type":"Identifier","name":"_descriptor"},"body":{"type":"ExpressionStatement","expression":{"type":"AssignmentExpression","operator":"=","left":{"type":"MemberExpression","object":{"type":"Identifier","name":"descriptor"},"property":{"type":"Identifier","name":"_key"},"computed":true},"right":{"type":"MemberExpression","object":{"type":"Identifier","name":"_descriptor"},"property":{"type":"Identifier","name":"_key"},"computed":true}},"trailingComments":null}},{"type":"ExpressionStatement","expression":{"type":"AssignmentExpression","operator":"=","left":{"type":"MemberExpression","object":{"type":"Identifier","name":"descriptor","leadingComments":null},"property":{"type":"Identifier","name":"value"},"computed":false,"leadingComments":null},"right":{"type":"ConditionalExpression","test":{"type":"MemberExpression","object":{"type":"Identifier","name":"descriptor"},"property":{"type":"Identifier","name":"initializer"},"computed":false},"consequent":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"MemberExpression","object":{"type":"Identifier","name":"descriptor"},"property":{"type":"Identifier","name":"initializer"},"computed":false},"property":{"type":"Identifier","name":"call"},"computed":false},"arguments":[{"type":"Identifier","name":"target"}]},"alternate":{"type":"Identifier","name":"undefined"}},"leadingComments":null}},{"type":"ExpressionStatement","expression":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"Object"},"property":{"type":"Identifier","name":"defineProperty"},"computed":false},"arguments":[{"type":"Identifier","name":"target"},{"type":"Identifier","name":"key"},{"type":"Identifier","name":"descriptor"}]}}]},"parenthesizedExpression":true}}]},"helper-define-property":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"FunctionExpression","id":null,"generator":false,"expression":false,"params":[{"type":"Identifier","name":"obj"},{"type":"Identifier","name":"key"},{"type":"Identifier","name":"value"}],"body":{"type":"BlockStatement","body":[{"type":"IfStatement","test":{"type":"BinaryExpression","left":{"type":"Identifier","name":"key","leadingComments":null},"operator":"in","right":{"type":"Identifier","name":"obj"},"leadingComments":null},"consequent":{"type":"BlockStatement","body":[{"type":"ExpressionStatement","expression":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"Object"},"property":{"type":"Identifier","name":"defineProperty"},"computed":false},"arguments":[{"type":"Identifier","name":"obj"},{"type":"Identifier","name":"key"},{"type":"ObjectExpression","properties":[{"type":"Property","method":false,"shorthand":false,"computed":false,"key":{"type":"Identifier","name":"value"},"value":{"type":"Identifier","name":"value"},"kind":"init"},{"type":"Property","method":false,"shorthand":false,"computed":false,"key":{"type":"Identifier","name":"enumerable"},"value":{"type":"Literal","value":true},"kind":"init"},{"type":"Property","method":false,"shorthand":false,"computed":false,"key":{"type":"Identifier","name":"configurable"},"value":{"type":"Literal","value":true},"kind":"init"},{"type":"Property","method":false,"shorthand":false,"computed":false,"key":{"type":"Identifier","name":"writable"},"value":{"type":"Literal","value":true},"kind":"init"}]}]}}]},"alternate":{"type":"BlockStatement","body":[{"type":"ExpressionStatement","expression":{"type":"AssignmentExpression","operator":"=","left":{"type":"MemberExpression","object":{"type":"Identifier","name":"obj"},"property":{"type":"Identifier","name":"key"},"computed":true},"right":{"type":"Identifier","name":"value"}}}]}},{"type":"ReturnStatement","argument":{"type":"Identifier","name":"obj"}}]},"parenthesizedExpression":true}}]},"helper-extends":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"LogicalExpression","left":{"type":"MemberExpression","object":{"type":"Identifier","name":"Object"},"property":{"type":"Identifier","name":"assign"},"computed":false},"operator":"||","right":{"type":"FunctionExpression","id":null,"generator":false,"expression":false,"params":[{"type":"Identifier","name":"target"}],"body":{"type":"BlockStatement","body":[{"type":"ForStatement","init":{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"i"},"init":{"type":"Literal","value":1}}],"kind":"var"},"test":{"type":"BinaryExpression","left":{"type":"Identifier","name":"i"},"operator":"<","right":{"type":"MemberExpression","object":{"type":"Identifier","name":"arguments"},"property":{"type":"Identifier","name":"length"},"computed":false}},"update":{"type":"UpdateExpression","operator":"++","prefix":false,"argument":{"type":"Identifier","name":"i"}},"body":{"type":"BlockStatement","body":[{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"source"},"init":{"type":"MemberExpression","object":{"type":"Identifier","name":"arguments"},"property":{"type":"Identifier","name":"i"},"computed":true}}],"kind":"var"},{"type":"ForInStatement","left":{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"key"},"init":null}],"kind":"var"},"right":{"type":"Identifier","name":"source"},"body":{"type":"BlockStatement","body":[{"type":"IfStatement","test":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"MemberExpression","object":{"type":"MemberExpression","object":{"type":"Identifier","name":"Object"},"property":{"type":"Identifier","name":"prototype"},"computed":false},"property":{"type":"Identifier","name":"hasOwnProperty"},"computed":false},"property":{"type":"Identifier","name":"call"},"computed":false},"arguments":[{"type":"Identifier","name":"source"},{"type":"Identifier","name":"key"}]},"consequent":{"type":"BlockStatement","body":[{"type":"ExpressionStatement","expression":{"type":"AssignmentExpression","operator":"=","left":{"type":"MemberExpression","object":{"type":"Identifier","name":"target"},"property":{"type":"Identifier","name":"key"},"computed":true},"right":{"type":"MemberExpression","object":{"type":"Identifier","name":"source"},"property":{"type":"Identifier","name":"key"},"computed":true}}}]},"alternate":null}]}}]}},{"type":"ReturnStatement","argument":{"type":"Identifier","name":"target"}}]}}}}]},"helper-get":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"FunctionExpression","id":{"type":"Identifier","name":"get"},"generator":false,"expression":false,"params":[{"type":"Identifier","name":"object"},{"type":"Identifier","name":"property"},{"type":"Identifier","name":"receiver"}],"body":{"type":"BlockStatement","body":[{"type":"IfStatement","test":{"type":"BinaryExpression","left":{"type":"Identifier","name":"object"},"operator":"===","right":{"type":"Literal","value":null,"rawValue":null}},"consequent":{"type":"ExpressionStatement","expression":{"type":"AssignmentExpression","operator":"=","left":{"type":"Identifier","name":"object"},"right":{"type":"MemberExpression","object":{"type":"Identifier","name":"Function"},"property":{"type":"Identifier","name":"prototype"},"computed":false}}},"alternate":null},{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"desc"},"init":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"Object"},"property":{"type":"Identifier","name":"getOwnPropertyDescriptor"},"computed":false},"arguments":[{"type":"Identifier","name":"object"},{"type":"Identifier","name":"property"}]}}],"kind":"var"},{"type":"IfStatement","test":{"type":"BinaryExpression","left":{"type":"Identifier","name":"desc"},"operator":"===","right":{"type":"Identifier","name":"undefined"}},"consequent":{"type":"BlockStatement","body":[{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"parent"},"init":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"Object"},"property":{"type":"Identifier","name":"getPrototypeOf"},"computed":false},"arguments":[{"type":"Identifier","name":"object"}]}}],"kind":"var"},{"type":"IfStatement","test":{"type":"BinaryExpression","left":{"type":"Identifier","name":"parent"},"operator":"===","right":{"type":"Literal","value":null,"rawValue":null}},"consequent":{"type":"BlockStatement","body":[{"type":"ReturnStatement","argument":{"type":"Identifier","name":"undefined"}}]},"alternate":{"type":"BlockStatement","body":[{"type":"ReturnStatement","argument":{"type":"CallExpression","callee":{"type":"Identifier","name":"get"},"arguments":[{"type":"Identifier","name":"parent"},{"type":"Identifier","name":"property"},{"type":"Identifier","name":"receiver"}]}}]}}]},"alternate":{"type":"IfStatement","test":{"type":"BinaryExpression","left":{"type":"Literal","value":"value"},"operator":"in","right":{"type":"Identifier","name":"desc"}},"consequent":{"type":"BlockStatement","body":[{"type":"ReturnStatement","argument":{"type":"MemberExpression","object":{"type":"Identifier","name":"desc"},"property":{"type":"Identifier","name":"value"},"computed":false}}]},"alternate":{"type":"BlockStatement","body":[{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"getter"},"init":{"type":"MemberExpression","object":{"type":"Identifier","name":"desc"},"property":{"type":"Identifier","name":"get"},"computed":false}}],"kind":"var"},{"type":"IfStatement","test":{"type":"BinaryExpression","left":{"type":"Identifier","name":"getter"},"operator":"===","right":{"type":"Identifier","name":"undefined"}},"consequent":{"type":"BlockStatement","body":[{"type":"ReturnStatement","argument":{"type":"Identifier","name":"undefined"}}]},"alternate":null},{"type":"ReturnStatement","argument":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"getter"},"property":{"type":"Identifier","name":"call"},"computed":false},"arguments":[{"type":"Identifier","name":"receiver"}]}}]}}}]},"parenthesizedExpression":true}}]},"helper-has-own":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"MemberExpression","object":{"type":"MemberExpression","object":{"type":"Identifier","name":"Object"},"property":{"type":"Identifier","name":"prototype"},"computed":false},"property":{"type":"Identifier","name":"hasOwnProperty"},"computed":false}}]},"helper-inherits":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"FunctionExpression","id":null,"generator":false,"expression":false,"params":[{"type":"Identifier","name":"subClass"},{"type":"Identifier","name":"superClass"}],"body":{"type":"BlockStatement","body":[{"type":"IfStatement","test":{"type":"LogicalExpression","left":{"type":"BinaryExpression","left":{"type":"UnaryExpression","operator":"typeof","prefix":true,"argument":{"type":"Identifier","name":"superClass"}},"operator":"!==","right":{"type":"Literal","value":"function"}},"operator":"&&","right":{"type":"BinaryExpression","left":{"type":"Identifier","name":"superClass"},"operator":"!==","right":{"type":"Literal","value":null,"rawValue":null}}},"consequent":{"type":"BlockStatement","body":[{"type":"ThrowStatement","argument":{"type":"NewExpression","callee":{"type":"Identifier","name":"TypeError"},"arguments":[{"type":"BinaryExpression","left":{"type":"Literal","value":"Super expression must either be null or a function, not "},"operator":"+","right":{"type":"UnaryExpression","operator":"typeof","prefix":true,"argument":{"type":"Identifier","name":"superClass"}}}]}}]},"alternate":null},{"type":"ExpressionStatement","expression":{"type":"AssignmentExpression","operator":"=","left":{"type":"MemberExpression","object":{"type":"Identifier","name":"subClass"},"property":{"type":"Identifier","name":"prototype"},"computed":false},"right":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"Object"},"property":{"type":"Identifier","name":"create"},"computed":false},"arguments":[{"type":"LogicalExpression","left":{"type":"Identifier","name":"superClass"},"operator":"&&","right":{"type":"MemberExpression","object":{"type":"Identifier","name":"superClass"},"property":{"type":"Identifier","name":"prototype"},"computed":false}},{"type":"ObjectExpression","properties":[{"type":"Property","method":false,"shorthand":false,"computed":false,"key":{"type":"Identifier","name":"constructor"},"value":{"type":"ObjectExpression","properties":[{"type":"Property","method":false,"shorthand":false,"computed":false,"key":{"type":"Identifier","name":"value"},"value":{"type":"Identifier","name":"subClass"},"kind":"init"},{"type":"Property","method":false,"shorthand":false,"computed":false,"key":{"type":"Identifier","name":"enumerable"},"value":{"type":"Literal","value":false},"kind":"init"},{"type":"Property","method":false,"shorthand":false,"computed":false,"key":{"type":"Identifier","name":"writable"},"value":{"type":"Literal","value":true},"kind":"init"},{"type":"Property","method":false,"shorthand":false,"computed":false,"key":{"type":"Identifier","name":"configurable"},"value":{"type":"Literal","value":true},"kind":"init"}]},"kind":"init"}]}]}}},{"type":"IfStatement","test":{"type":"Identifier","name":"superClass"},"consequent":{"type":"ExpressionStatement","expression":{"type":"ConditionalExpression","test":{"type":"MemberExpression","object":{"type":"Identifier","name":"Object"},"property":{"type":"Identifier","name":"setPrototypeOf"},"computed":false},"consequent":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"Object"},"property":{"type":"Identifier","name":"setPrototypeOf"},"computed":false},"arguments":[{"type":"Identifier","name":"subClass"},{"type":"Identifier","name":"superClass"}]},"alternate":{"type":"AssignmentExpression","operator":"=","left":{"type":"MemberExpression","object":{"type":"Identifier","name":"subClass"},"property":{"type":"Identifier","name":"__proto__"},"computed":false},"right":{"type":"Identifier","name":"superClass"}}}},"alternate":null}]},"parenthesizedExpression":true}}]},"helper-instanceof":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"FunctionExpression","id":null,"generator":false,"expression":false,"params":[{"type":"Identifier","name":"left"},{"type":"Identifier","name":"right"}],"body":{"type":"BlockStatement","body":[{"type":"IfStatement","test":{"type":"LogicalExpression","left":{"type":"BinaryExpression","left":{"type":"Identifier","name":"right"},"operator":"!=","right":{"type":"Literal","value":null,"rawValue":null}},"operator":"&&","right":{"type":"MemberExpression","object":{"type":"Identifier","name":"right"},"property":{"type":"MemberExpression","object":{"type":"Identifier","name":"Symbol"},"property":{"type":"Identifier","name":"hasInstance"},"computed":false},"computed":true}},"consequent":{"type":"BlockStatement","body":[{"type":"ReturnStatement","argument":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"right"},"property":{"type":"MemberExpression","object":{"type":"Identifier","name":"Symbol"},"property":{"type":"Identifier","name":"hasInstance"},"computed":false},"computed":true},"arguments":[{"type":"Identifier","name":"left"}]}}]},"alternate":{"type":"BlockStatement","body":[{"type":"ReturnStatement","argument":{"type":"BinaryExpression","left":{"type":"Identifier","name":"left"},"operator":"instanceof","right":{"type":"Identifier","name":"right"}}}]}}]},"parenthesizedExpression":true}}]},"helper-interop-export-wildcard":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"FunctionExpression","id":null,"generator":false,"expression":false,"params":[{"type":"Identifier","name":"obj"},{"type":"Identifier","name":"defaults"}],"body":{"type":"BlockStatement","body":[{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"newObj"},"init":{"type":"CallExpression","callee":{"type":"Identifier","name":"defaults"},"arguments":[{"type":"ObjectExpression","properties":[]},{"type":"Identifier","name":"obj"}]}}],"kind":"var"},{"type":"ExpressionStatement","expression":{"type":"UnaryExpression","operator":"delete","prefix":true,"argument":{"type":"MemberExpression","object":{"type":"Identifier","name":"newObj"},"property":{"type":"Literal","value":"default"},"computed":true}}},{"type":"ReturnStatement","argument":{"type":"Identifier","name":"newObj"}}]},"parenthesizedExpression":true}}]},"helper-interop-require-default":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"FunctionExpression","id":null,"generator":false,"expression":false,"params":[{"type":"Identifier","name":"obj"}],"body":{"type":"BlockStatement","body":[{"type":"ReturnStatement","argument":{"type":"ConditionalExpression","test":{"type":"LogicalExpression","left":{"type":"Identifier","name":"obj"},"operator":"&&","right":{"type":"MemberExpression","object":{"type":"Identifier","name":"obj"},"property":{"type":"Identifier","name":"__esModule"},"computed":false}},"consequent":{"type":"Identifier","name":"obj"},"alternate":{"type":"ObjectExpression","properties":[{"type":"Property","method":false,"shorthand":false,"computed":false,"key":{"type":"Literal","value":"default"},"value":{"type":"Identifier","name":"obj"},"kind":"init"}]}}}]},"parenthesizedExpression":true}}]},"helper-interop-require-wildcard":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"FunctionExpression","id":null,"generator":false,"expression":false,"params":[{"type":"Identifier","name":"obj"}],"body":{"type":"BlockStatement","body":[{"type":"IfStatement","test":{"type":"LogicalExpression","left":{"type":"Identifier","name":"obj"},"operator":"&&","right":{"type":"MemberExpression","object":{"type":"Identifier","name":"obj"},"property":{"type":"Identifier","name":"__esModule"},"computed":false}},"consequent":{"type":"BlockStatement","body":[{"type":"ReturnStatement","argument":{"type":"Identifier","name":"obj"}}]},"alternate":{"type":"BlockStatement","body":[{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"newObj"},"init":{"type":"ObjectExpression","properties":[]}}],"kind":"var"},{"type":"IfStatement","test":{"type":"BinaryExpression","left":{"type":"Identifier","name":"obj"},"operator":"!=","right":{"type":"Literal","value":null,"rawValue":null}},"consequent":{"type":"BlockStatement","body":[{"type":"ForInStatement","left":{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"key"},"init":null}],"kind":"var"},"right":{"type":"Identifier","name":"obj"},"body":{"type":"BlockStatement","body":[{"type":"IfStatement","test":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"MemberExpression","object":{"type":"MemberExpression","object":{"type":"Identifier","name":"Object"},"property":{"type":"Identifier","name":"prototype"},"computed":false},"property":{"type":"Identifier","name":"hasOwnProperty"},"computed":false},"property":{"type":"Identifier","name":"call"},"computed":false},"arguments":[{"type":"Identifier","name":"obj"},{"type":"Identifier","name":"key"}]},"consequent":{"type":"ExpressionStatement","expression":{"type":"AssignmentExpression","operator":"=","left":{"type":"MemberExpression","object":{"type":"Identifier","name":"newObj"},"property":{"type":"Identifier","name":"key"},"computed":true},"right":{"type":"MemberExpression","object":{"type":"Identifier","name":"obj"},"property":{"type":"Identifier","name":"key"},"computed":true}}},"alternate":null}]}}]},"alternate":null},{"type":"ExpressionStatement","expression":{"type":"AssignmentExpression","operator":"=","left":{"type":"MemberExpression","object":{"type":"Identifier","name":"newObj"},"property":{"type":"Literal","value":"default"},"computed":true},"right":{"type":"Identifier","name":"obj"}}},{"type":"ReturnStatement","argument":{"type":"Identifier","name":"newObj"}}]}}]},"parenthesizedExpression":true}}]},"helper-interop-require":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"FunctionExpression","id":null,"generator":false,"expression":false,"params":[{"type":"Identifier","name":"obj"}],"body":{"type":"BlockStatement","body":[{"type":"ReturnStatement","argument":{"type":"ConditionalExpression","test":{"type":"LogicalExpression","left":{"type":"Identifier","name":"obj"},"operator":"&&","right":{"type":"MemberExpression","object":{"type":"Identifier","name":"obj"},"property":{"type":"Identifier","name":"__esModule"},"computed":false}},"consequent":{"type":"MemberExpression","object":{"type":"Identifier","name":"obj"},"property":{"type":"Literal","value":"default"},"computed":true},"alternate":{"type":"Identifier","name":"obj"}}}]},"parenthesizedExpression":true}}]},"helper-new-arrow-check":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"FunctionExpression","id":null,"generator":false,"expression":false,"params":[{"type":"Identifier","name":"innerThis"},{"type":"Identifier","name":"boundThis"}],"body":{"type":"BlockStatement","body":[{"type":"IfStatement","test":{"type":"BinaryExpression","left":{"type":"Identifier","name":"innerThis"},"operator":"!==","right":{"type":"Identifier","name":"boundThis"}},"consequent":{"type":"BlockStatement","body":[{"type":"ThrowStatement","argument":{"type":"NewExpression","callee":{"type":"Identifier","name":"TypeError"},"arguments":[{"type":"Literal","value":"Cannot instantiate an arrow function"}]}}]},"alternate":null}]},"parenthesizedExpression":true}}]},"helper-object-destructuring-empty":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"FunctionExpression","id":null,"generator":false,"expression":false,"params":[{"type":"Identifier","name":"obj"}],"body":{"type":"BlockStatement","body":[{"type":"IfStatement","test":{"type":"BinaryExpression","left":{"type":"Identifier","name":"obj"},"operator":"==","right":{"type":"Literal","value":null,"rawValue":null}},"consequent":{"type":"ThrowStatement","argument":{"type":"NewExpression","callee":{"type":"Identifier","name":"TypeError"},"arguments":[{"type":"Literal","value":"Cannot destructure undefined"}]}},"alternate":null}]},"parenthesizedExpression":true}}]},"helper-object-without-properties":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"FunctionExpression","id":null,"generator":false,"expression":false,"params":[{"type":"Identifier","name":"obj"},{"type":"Identifier","name":"keys"}],"body":{"type":"BlockStatement","body":[{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"target"},"init":{"type":"ObjectExpression","properties":[]}}],"kind":"var"},{"type":"ForInStatement","left":{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"i"},"init":null}],"kind":"var"},"right":{"type":"Identifier","name":"obj"},"body":{"type":"BlockStatement","body":[{"type":"IfStatement","test":{"type":"BinaryExpression","left":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"keys"},"property":{"type":"Identifier","name":"indexOf"},"computed":false},"arguments":[{"type":"Identifier","name":"i"}]},"operator":">=","right":{"type":"Literal","value":0}},"consequent":{"type":"ContinueStatement","label":null},"alternate":null},{"type":"IfStatement","test":{"type":"UnaryExpression","operator":"!","prefix":true,"argument":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"MemberExpression","object":{"type":"MemberExpression","object":{"type":"Identifier","name":"Object"},"property":{"type":"Identifier","name":"prototype"},"computed":false},"property":{"type":"Identifier","name":"hasOwnProperty"},"computed":false},"property":{"type":"Identifier","name":"call"},"computed":false},"arguments":[{"type":"Identifier","name":"obj"},{"type":"Identifier","name":"i"}]}},"consequent":{"type":"ContinueStatement","label":null},"alternate":null},{"type":"ExpressionStatement","expression":{"type":"AssignmentExpression","operator":"=","left":{"type":"MemberExpression","object":{"type":"Identifier","name":"target"},"property":{"type":"Identifier","name":"i"},"computed":true},"right":{"type":"MemberExpression","object":{"type":"Identifier","name":"obj"},"property":{"type":"Identifier","name":"i"},"computed":true}}}]}},{"type":"ReturnStatement","argument":{"type":"Identifier","name":"target"}}]},"parenthesizedExpression":true}}]},"helper-self-global":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"ConditionalExpression","test":{"type":"BinaryExpression","left":{"type":"UnaryExpression","operator":"typeof","prefix":true,"argument":{"type":"Identifier","name":"global"}},"operator":"===","right":{"type":"Literal","value":"undefined"}},"consequent":{"type":"Identifier","name":"self"},"alternate":{"type":"Identifier","name":"global"}}}]},"helper-set":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"FunctionExpression","id":{"type":"Identifier","name":"set"},"generator":false,"expression":false,"params":[{"type":"Identifier","name":"object"},{"type":"Identifier","name":"property"},{"type":"Identifier","name":"value"},{"type":"Identifier","name":"receiver"}],"body":{"type":"BlockStatement","body":[{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"desc"},"init":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"Object"},"property":{"type":"Identifier","name":"getOwnPropertyDescriptor"},"computed":false},"arguments":[{"type":"Identifier","name":"object"},{"type":"Identifier","name":"property"}]}}],"kind":"var"},{"type":"IfStatement","test":{"type":"BinaryExpression","left":{"type":"Identifier","name":"desc"},"operator":"===","right":{"type":"Identifier","name":"undefined"}},"consequent":{"type":"BlockStatement","body":[{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"parent"},"init":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"Object"},"property":{"type":"Identifier","name":"getPrototypeOf"},"computed":false},"arguments":[{"type":"Identifier","name":"object"}]}}],"kind":"var"},{"type":"IfStatement","test":{"type":"BinaryExpression","left":{"type":"Identifier","name":"parent"},"operator":"!==","right":{"type":"Literal","value":null,"rawValue":null}},"consequent":{"type":"BlockStatement","body":[{"type":"ExpressionStatement","expression":{"type":"CallExpression","callee":{"type":"Identifier","name":"set"},"arguments":[{"type":"Identifier","name":"parent"},{"type":"Identifier","name":"property"},{"type":"Identifier","name":"value"},{"type":"Identifier","name":"receiver"}]}}]},"alternate":null}]},"alternate":{"type":"IfStatement","test":{"type":"LogicalExpression","left":{"type":"BinaryExpression","left":{"type":"Literal","value":"value"},"operator":"in","right":{"type":"Identifier","name":"desc"}},"operator":"&&","right":{"type":"MemberExpression","object":{"type":"Identifier","name":"desc"},"property":{"type":"Identifier","name":"writable"},"computed":false}},"consequent":{"type":"BlockStatement","body":[{"type":"ExpressionStatement","expression":{"type":"AssignmentExpression","operator":"=","left":{"type":"MemberExpression","object":{"type":"Identifier","name":"desc"},"property":{"type":"Identifier","name":"value"},"computed":false},"right":{"type":"Identifier","name":"value"}}}]},"alternate":{"type":"BlockStatement","body":[{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"setter"},"init":{"type":"MemberExpression","object":{"type":"Identifier","name":"desc"},"property":{"type":"Identifier","name":"set"},"computed":false}}],"kind":"var"},{"type":"IfStatement","test":{"type":"BinaryExpression","left":{"type":"Identifier","name":"setter"},"operator":"!==","right":{"type":"Identifier","name":"undefined"}},"consequent":{"type":"BlockStatement","body":[{"type":"ExpressionStatement","expression":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"setter"},"property":{"type":"Identifier","name":"call"},"computed":false},"arguments":[{"type":"Identifier","name":"receiver"},{"type":"Identifier","name":"value"}]}}]},"alternate":null}]}}},{"type":"ReturnStatement","argument":{"type":"Identifier","name":"value"}}]},"parenthesizedExpression":true}}]},"helper-slice":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"MemberExpression","object":{"type":"MemberExpression","object":{"type":"Identifier","name":"Array"},"property":{"type":"Identifier","name":"prototype"},"computed":false},"property":{"type":"Identifier","name":"slice"},"computed":false}}]},"helper-sliced-to-array-loose":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"FunctionExpression","id":null,"generator":false,"expression":false,"params":[{"type":"Identifier","name":"arr"},{"type":"Identifier","name":"i"}],"body":{"type":"BlockStatement","body":[{"type":"IfStatement","test":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"Array"},"property":{"type":"Identifier","name":"isArray"},"computed":false},"arguments":[{"type":"Identifier","name":"arr"}]},"consequent":{"type":"BlockStatement","body":[{"type":"ReturnStatement","argument":{"type":"Identifier","name":"arr"}}]},"alternate":{"type":"IfStatement","test":{"type":"BinaryExpression","left":{"type":"MemberExpression","object":{"type":"Identifier","name":"Symbol"},"property":{"type":"Identifier","name":"iterator"},"computed":false},"operator":"in","right":{"type":"CallExpression","callee":{"type":"Identifier","name":"Object"},"arguments":[{"type":"Identifier","name":"arr"}]}},"consequent":{"type":"BlockStatement","body":[{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"_arr"},"init":{"type":"ArrayExpression","elements":[]}}],"kind":"var"},{"type":"ForStatement","init":{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"_iterator"},"init":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"arr"},"property":{"type":"MemberExpression","object":{"type":"Identifier","name":"Symbol"},"property":{"type":"Identifier","name":"iterator"},"computed":false},"computed":true},"arguments":[]}},{"type":"VariableDeclarator","id":{"type":"Identifier","name":"_step"},"init":null}],"kind":"var"},"test":{"type":"UnaryExpression","operator":"!","prefix":true,"argument":{"type":"MemberExpression","object":{"type":"AssignmentExpression","operator":"=","left":{"type":"Identifier","name":"_step"},"right":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"_iterator"},"property":{"type":"Identifier","name":"next"},"computed":false},"arguments":[]},"parenthesizedExpression":true},"property":{"type":"Identifier","name":"done"},"computed":false}},"update":null,"body":{"type":"BlockStatement","body":[{"type":"ExpressionStatement","expression":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"_arr"},"property":{"type":"Identifier","name":"push"},"computed":false},"arguments":[{"type":"MemberExpression","object":{"type":"Identifier","name":"_step"},"property":{"type":"Identifier","name":"value"},"computed":false}]}},{"type":"IfStatement","test":{"type":"LogicalExpression","left":{"type":"Identifier","name":"i"},"operator":"&&","right":{"type":"BinaryExpression","left":{"type":"MemberExpression","object":{"type":"Identifier","name":"_arr"},"property":{"type":"Identifier","name":"length"},"computed":false},"operator":"===","right":{"type":"Identifier","name":"i"}}},"consequent":{"type":"BreakStatement","label":null},"alternate":null}]}},{"type":"ReturnStatement","argument":{"type":"Identifier","name":"_arr"}}]},"alternate":{"type":"BlockStatement","body":[{"type":"ThrowStatement","argument":{"type":"NewExpression","callee":{"type":"Identifier","name":"TypeError"},"arguments":[{"type":"Literal","value":"Invalid attempt to destructure non-iterable instance"}]}}]}}}]},"parenthesizedExpression":true}}]},"helper-sliced-to-array":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"CallExpression","callee":{"type":"FunctionExpression","id":null,"generator":false,"expression":false,"params":[],"body":{"type":"BlockStatement","body":[{"type":"FunctionDeclaration","id":{"type":"Identifier","name":"sliceIterator","leadingComments":null},"generator":false,"expression":false,"params":[{"type":"Identifier","name":"arr"},{"type":"Identifier","name":"i"}],"body":{"type":"BlockStatement","body":[{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"_arr","leadingComments":null},"init":{"type":"ArrayExpression","elements":[]},"leadingComments":null}],"kind":"var"},{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"_n"},"init":{"type":"Literal","value":true}}],"kind":"var"},{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"_d"},"init":{"type":"Literal","value":false}}],"kind":"var"},{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"_e"},"init":{"type":"Identifier","name":"undefined"}}],"kind":"var"},{"type":"TryStatement","block":{"type":"BlockStatement","body":[{"type":"ForStatement","init":{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"_i"},"init":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"arr"},"property":{"type":"MemberExpression","object":{"type":"Identifier","name":"Symbol"},"property":{"type":"Identifier","name":"iterator"},"computed":false},"computed":true},"arguments":[]}},{"type":"VariableDeclarator","id":{"type":"Identifier","name":"_s"},"init":null}],"kind":"var"},"test":{"type":"UnaryExpression","operator":"!","prefix":true,"argument":{"type":"AssignmentExpression","operator":"=","left":{"type":"Identifier","name":"_n"},"right":{"type":"MemberExpression","object":{"type":"AssignmentExpression","operator":"=","left":{"type":"Identifier","name":"_s"},"right":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"_i"},"property":{"type":"Identifier","name":"next"},"computed":false},"arguments":[]},"parenthesizedExpression":true},"property":{"type":"Identifier","name":"done"},"computed":false},"parenthesizedExpression":true}},"update":{"type":"AssignmentExpression","operator":"=","left":{"type":"Identifier","name":"_n"},"right":{"type":"Literal","value":true}},"body":{"type":"BlockStatement","body":[{"type":"ExpressionStatement","expression":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"_arr"},"property":{"type":"Identifier","name":"push"},"computed":false},"arguments":[{"type":"MemberExpression","object":{"type":"Identifier","name":"_s"},"property":{"type":"Identifier","name":"value"},"computed":false}]}},{"type":"IfStatement","test":{"type":"LogicalExpression","left":{"type":"Identifier","name":"i"},"operator":"&&","right":{"type":"BinaryExpression","left":{"type":"MemberExpression","object":{"type":"Identifier","name":"_arr"},"property":{"type":"Identifier","name":"length"},"computed":false},"operator":"===","right":{"type":"Identifier","name":"i"}}},"consequent":{"type":"BreakStatement","label":null},"alternate":null}]}}]},"handler":{"type":"CatchClause","param":{"type":"Identifier","name":"err"},"body":{"type":"BlockStatement","body":[{"type":"ExpressionStatement","expression":{"type":"AssignmentExpression","operator":"=","left":{"type":"Identifier","name":"_d"},"right":{"type":"Literal","value":true}}},{"type":"ExpressionStatement","expression":{"type":"AssignmentExpression","operator":"=","left":{"type":"Identifier","name":"_e"},"right":{"type":"Identifier","name":"err"}}}]}},"guardedHandlers":[],"finalizer":{"type":"BlockStatement","body":[{"type":"TryStatement","block":{"type":"BlockStatement","body":[{"type":"IfStatement","test":{"type":"LogicalExpression","left":{"type":"UnaryExpression","operator":"!","prefix":true,"argument":{"type":"Identifier","name":"_n"}},"operator":"&&","right":{"type":"MemberExpression","object":{"type":"Identifier","name":"_i"},"property":{"type":"Literal","value":"return"},"computed":true}},"consequent":{"type":"ExpressionStatement","expression":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"_i"},"property":{"type":"Literal","value":"return"},"computed":true},"arguments":[]}},"alternate":null}]},"handler":null,"guardedHandlers":[],"finalizer":{"type":"BlockStatement","body":[{"type":"IfStatement","test":{"type":"Identifier","name":"_d"},"consequent":{"type":"ThrowStatement","argument":{"type":"Identifier","name":"_e"}},"alternate":null}]}}]}},{"type":"ReturnStatement","argument":{"type":"Identifier","name":"_arr"}}]}},{"type":"ReturnStatement","argument":{"type":"FunctionExpression","id":null,"generator":false,"expression":false,"params":[{"type":"Identifier","name":"arr"},{"type":"Identifier","name":"i"}],"body":{"type":"BlockStatement","body":[{"type":"IfStatement","test":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"Array"},"property":{"type":"Identifier","name":"isArray"},"computed":false},"arguments":[{"type":"Identifier","name":"arr"}]},"consequent":{"type":"BlockStatement","body":[{"type":"ReturnStatement","argument":{"type":"Identifier","name":"arr"}}]},"alternate":{"type":"IfStatement","test":{"type":"BinaryExpression","left":{"type":"MemberExpression","object":{"type":"Identifier","name":"Symbol"},"property":{"type":"Identifier","name":"iterator"},"computed":false},"operator":"in","right":{"type":"CallExpression","callee":{"type":"Identifier","name":"Object"},"arguments":[{"type":"Identifier","name":"arr"}]}},"consequent":{"type":"BlockStatement","body":[{"type":"ReturnStatement","argument":{"type":"CallExpression","callee":{"type":"Identifier","name":"sliceIterator"},"arguments":[{"type":"Identifier","name":"arr"},{"type":"Identifier","name":"i"}]}}]},"alternate":{"type":"BlockStatement","body":[{"type":"ThrowStatement","argument":{"type":"NewExpression","callee":{"type":"Identifier","name":"TypeError"},"arguments":[{"type":"Literal","value":"Invalid attempt to destructure non-iterable instance"}]}}]}}}]}}}]},"parenthesizedExpression":true},"arguments":[]}}]},"helper-tagged-template-literal-loose":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"FunctionExpression","id":null,"generator":false,"expression":false,"params":[{"type":"Identifier","name":"strings"},{"type":"Identifier","name":"raw"}],"body":{"type":"BlockStatement","body":[{"type":"ExpressionStatement","expression":{"type":"AssignmentExpression","operator":"=","left":{"type":"MemberExpression","object":{"type":"Identifier","name":"strings"},"property":{"type":"Identifier","name":"raw"},"computed":false},"right":{"type":"Identifier","name":"raw"}}},{"type":"ReturnStatement","argument":{"type":"Identifier","name":"strings"}}]},"parenthesizedExpression":true}}]},"helper-tagged-template-literal":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"FunctionExpression","id":null,"generator":false,"expression":false,"params":[{"type":"Identifier","name":"strings"},{"type":"Identifier","name":"raw"}],"body":{"type":"BlockStatement","body":[{"type":"ReturnStatement","argument":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"Object"},"property":{"type":"Identifier","name":"freeze"},"computed":false},"arguments":[{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"Object"},"property":{"type":"Identifier","name":"defineProperties"},"computed":false},"arguments":[{"type":"Identifier","name":"strings"},{"type":"ObjectExpression","properties":[{"type":"Property","method":false,"shorthand":false,"computed":false,"key":{"type":"Identifier","name":"raw"},"value":{"type":"ObjectExpression","properties":[{"type":"Property","method":false,"shorthand":false,"computed":false,"key":{"type":"Identifier","name":"value"},"value":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"Object"},"property":{"type":"Identifier","name":"freeze"},"computed":false},"arguments":[{"type":"Identifier","name":"raw"}]},"kind":"init"}]},"kind":"init"}]}]}]}}]},"parenthesizedExpression":true}}]},"helper-temporal-assert-defined":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"FunctionExpression","id":null,"generator":false,"expression":false,"params":[{"type":"Identifier","name":"val"},{"type":"Identifier","name":"name"},{"type":"Identifier","name":"undef"}],"body":{"type":"BlockStatement","body":[{"type":"IfStatement","test":{"type":"BinaryExpression","left":{"type":"Identifier","name":"val"},"operator":"===","right":{"type":"Identifier","name":"undef"}},"consequent":{"type":"BlockStatement","body":[{"type":"ThrowStatement","argument":{"type":"NewExpression","callee":{"type":"Identifier","name":"ReferenceError"},"arguments":[{"type":"BinaryExpression","left":{"type":"Identifier","name":"name"},"operator":"+","right":{"type":"Literal","value":" is not defined - temporal dead zone"}}]}}]},"alternate":null},{"type":"ReturnStatement","argument":{"type":"Literal","value":true}}]},"parenthesizedExpression":true}}]},"helper-temporal-undefined":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"ObjectExpression","properties":[],"parenthesizedExpression":true}}]},"helper-to-array":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"FunctionExpression","id":null,"generator":false,"expression":false,"params":[{"type":"Identifier","name":"arr"}],"body":{"type":"BlockStatement","body":[{"type":"ReturnStatement","argument":{"type":"ConditionalExpression","test":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"Array"},"property":{"type":"Identifier","name":"isArray"},"computed":false},"arguments":[{"type":"Identifier","name":"arr"}]},"consequent":{"type":"Identifier","name":"arr"},"alternate":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"Array"},"property":{"type":"Identifier","name":"from"},"computed":false},"arguments":[{"type":"Identifier","name":"arr"}]}}}]},"parenthesizedExpression":true}}]},"helper-to-consumable-array":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"FunctionExpression","id":null,"generator":false,"expression":false,"params":[{"type":"Identifier","name":"arr"}],"body":{"type":"BlockStatement","body":[{"type":"IfStatement","test":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"Array"},"property":{"type":"Identifier","name":"isArray"},"computed":false},"arguments":[{"type":"Identifier","name":"arr"}]},"consequent":{"type":"BlockStatement","body":[{"type":"ForStatement","init":{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"i"},"init":{"type":"Literal","value":0}},{"type":"VariableDeclarator","id":{"type":"Identifier","name":"arr2"},"init":{"type":"CallExpression","callee":{"type":"Identifier","name":"Array"},"arguments":[{"type":"MemberExpression","object":{"type":"Identifier","name":"arr"},"property":{"type":"Identifier","name":"length"},"computed":false}]}}],"kind":"var"},"test":{"type":"BinaryExpression","left":{"type":"Identifier","name":"i"},"operator":"<","right":{"type":"MemberExpression","object":{"type":"Identifier","name":"arr"},"property":{"type":"Identifier","name":"length"},"computed":false}},"update":{"type":"UpdateExpression","operator":"++","prefix":false,"argument":{"type":"Identifier","name":"i"}},"body":{"type":"ExpressionStatement","expression":{"type":"AssignmentExpression","operator":"=","left":{"type":"MemberExpression","object":{"type":"Identifier","name":"arr2"},"property":{"type":"Identifier","name":"i"},"computed":true},"right":{"type":"MemberExpression","object":{"type":"Identifier","name":"arr"},"property":{"type":"Identifier","name":"i"},"computed":true}}}},{"type":"ReturnStatement","argument":{"type":"Identifier","name":"arr2"}}]},"alternate":{"type":"BlockStatement","body":[{"type":"ReturnStatement","argument":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"Array"},"property":{"type":"Identifier","name":"from"},"computed":false},"arguments":[{"type":"Identifier","name":"arr"}]}}]}}]},"parenthesizedExpression":true}}]},"helper-typeof-react-element":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"LogicalExpression","left":{"type":"LogicalExpression","left":{"type":"LogicalExpression","left":{"type":"BinaryExpression","left":{"type":"UnaryExpression","operator":"typeof","prefix":true,"argument":{"type":"Identifier","name":"Symbol"}},"operator":"===","right":{"type":"Literal","value":"function"}},"operator":"&&","right":{"type":"MemberExpression","object":{"type":"Identifier","name":"Symbol"},"property":{"type":"Literal","value":"for"},"computed":true}},"operator":"&&","right":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"Symbol"},"property":{"type":"Literal","value":"for"},"computed":true},"arguments":[{"type":"Literal","value":"react.element"}]}},"operator":"||","right":{"type":"Literal","value":60103}}}]},"helper-typeof":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"FunctionExpression","id":null,"generator":false,"expression":false,"params":[{"type":"Identifier","name":"obj"}],"body":{"type":"BlockStatement","body":[{"type":"ReturnStatement","argument":{"type":"ConditionalExpression","test":{"type":"LogicalExpression","left":{"type":"Identifier","name":"obj"},"operator":"&&","right":{"type":"BinaryExpression","left":{"type":"MemberExpression","object":{"type":"Identifier","name":"obj"},"property":{"type":"Identifier","name":"constructor"},"computed":false},"operator":"===","right":{"type":"Identifier","name":"Symbol"}}},"consequent":{"type":"Literal","value":"symbol"},"alternate":{"type":"UnaryExpression","operator":"typeof","prefix":true,"argument":{"type":"Identifier","name":"obj"}}}}]},"parenthesizedExpression":true}}]},"let-scoping-return":{"type":"Program","body":[{"type":"IfStatement","test":{"type":"BinaryExpression","left":{"type":"UnaryExpression","operator":"typeof","prefix":true,"argument":{"type":"Identifier","name":"RETURN"}},"operator":"===","right":{"type":"Literal","value":"object"}},"consequent":{"type":"ReturnStatement","argument":{"type":"MemberExpression","object":{"type":"Identifier","name":"RETURN"},"property":{"type":"Identifier","name":"v"},"computed":false}},"alternate":null}]},"named-function":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"CallExpression","callee":{"type":"FunctionExpression","id":null,"generator":false,"expression":false,"params":[],"body":{"type":"BlockStatement","body":[{"type":"FunctionDeclaration","id":{"type":"Identifier","name":"GET_OUTER_ID"},"generator":false,"expression":false,"params":[],"body":{"type":"BlockStatement","body":[{"type":"ReturnStatement","argument":{"type":"Identifier","name":"FUNCTION_ID"}}]}},{"type":"ReturnStatement","argument":{"type":"Identifier","name":"FUNCTION"}}]},"parenthesizedExpression":true},"arguments":[]}}]},"property-method-assignment-wrapper-generator":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"CallExpression","callee":{"type":"FunctionExpression","id":null,"generator":false,"expression":false,"params":[{"type":"Identifier","name":"FUNCTION_KEY"}],"body":{"type":"BlockStatement","body":[{"type":"FunctionDeclaration","id":{"type":"Identifier","name":"FUNCTION_ID"},"generator":true,"expression":false,"params":[],"body":{"type":"BlockStatement","body":[{"type":"ReturnStatement","argument":{"type":"YieldExpression","delegate":true,"argument":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"FUNCTION_KEY"},"property":{"type":"Identifier","name":"apply"},"computed":false},"arguments":[{"type":"ThisExpression"},{"type":"Identifier","name":"arguments"}]}}}]}},{"type":"ExpressionStatement","expression":{"type":"AssignmentExpression","operator":"=","left":{"type":"MemberExpression","object":{"type":"Identifier","name":"FUNCTION_ID"},"property":{"type":"Identifier","name":"toString"},"computed":false},"right":{"type":"FunctionExpression","id":null,"generator":false,"expression":false,"params":[],"body":{"type":"BlockStatement","body":[{"type":"ReturnStatement","argument":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"FUNCTION_KEY"},"property":{"type":"Identifier","name":"toString"},"computed":false},"arguments":[]}}]}}}},{"type":"ReturnStatement","argument":{"type":"Identifier","name":"FUNCTION_ID"}}]},"parenthesizedExpression":true},"arguments":[{"type":"Identifier","name":"FUNCTION"}]}}]},"property-method-assignment-wrapper":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"CallExpression","callee":{"type":"FunctionExpression","id":null,"generator":false,"expression":false,"params":[{"type":"Identifier","name":"FUNCTION_KEY"}],"body":{"type":"BlockStatement","body":[{"type":"FunctionDeclaration","id":{"type":"Identifier","name":"FUNCTION_ID"},"generator":false,"expression":false,"params":[],"body":{"type":"BlockStatement","body":[{"type":"ReturnStatement","argument":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"FUNCTION_KEY"},"property":{"type":"Identifier","name":"apply"},"computed":false},"arguments":[{"type":"ThisExpression"},{"type":"Identifier","name":"arguments"}]}}]}},{"type":"ExpressionStatement","expression":{"type":"AssignmentExpression","operator":"=","left":{"type":"MemberExpression","object":{"type":"Identifier","name":"FUNCTION_ID"},"property":{"type":"Identifier","name":"toString"},"computed":false},"right":{"type":"FunctionExpression","id":null,"generator":false,"expression":false,"params":[],"body":{"type":"BlockStatement","body":[{"type":"ReturnStatement","argument":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"FUNCTION_KEY"},"property":{"type":"Identifier","name":"toString"},"computed":false},"arguments":[]}}]}}}},{"type":"ReturnStatement","argument":{"type":"Identifier","name":"FUNCTION_ID"}}]},"parenthesizedExpression":true},"arguments":[{"type":"Identifier","name":"FUNCTION"}]}}]},"prototype-identifier":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"MemberExpression","object":{"type":"Identifier","name":"CLASS_NAME"},"property":{"type":"Identifier","name":"prototype"},"computed":false}}]},"require-assign-key":{"type":"Program","body":[{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"VARIABLE_NAME"},"init":{"type":"MemberExpression","object":{"type":"CallExpression","callee":{"type":"Identifier","name":"require"},"arguments":[{"type":"Identifier","name":"MODULE_NAME"}]},"property":{"type":"Identifier","name":"KEY"},"computed":false}}],"kind":"var"}]},"require":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"CallExpression","callee":{"type":"Identifier","name":"require"},"arguments":[{"type":"Identifier","name":"MODULE_NAME"}]}}]},"rest":{"type":"Program","body":[{"type":"ForStatement","init":{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"LEN"},"init":{"type":"MemberExpression","object":{"type":"Identifier","name":"ARGUMENTS"},"property":{"type":"Identifier","name":"length"},"computed":false}},{"type":"VariableDeclarator","id":{"type":"Identifier","name":"ARRAY"},"init":{"type":"CallExpression","callee":{"type":"Identifier","name":"Array"},"arguments":[{"type":"Identifier","name":"ARRAY_LEN"}]}},{"type":"VariableDeclarator","id":{"type":"Identifier","name":"KEY"},"init":{"type":"Identifier","name":"START"}}],"kind":"var"},"test":{"type":"BinaryExpression","left":{"type":"Identifier","name":"KEY"},"operator":"<","right":{"type":"Identifier","name":"LEN"}},"update":{"type":"UpdateExpression","operator":"++","prefix":false,"argument":{"type":"Identifier","name":"KEY"}},"body":{"type":"BlockStatement","body":[{"type":"ExpressionStatement","expression":{"type":"AssignmentExpression","operator":"=","left":{"type":"MemberExpression","object":{"type":"Identifier","name":"ARRAY"},"property":{"type":"Identifier","name":"ARRAY_KEY"},"computed":true},"right":{"type":"MemberExpression","object":{"type":"Identifier","name":"ARGUMENTS"},"property":{"type":"Identifier","name":"KEY"},"computed":true}}}]}}]},"self-contained-helpers-head":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"AssignmentExpression","operator":"=","left":{"type":"MemberExpression","object":{"type":"Identifier","name":"exports"},"property":{"type":"Literal","value":"default"},"computed":true},"right":{"type":"Identifier","name":"HELPER"}}},{"type":"ExpressionStatement","expression":{"type":"AssignmentExpression","operator":"=","left":{"type":"MemberExpression","object":{"type":"Identifier","name":"exports"},"property":{"type":"Identifier","name":"__esModule"},"computed":false},"right":{"type":"Literal","value":true}}}]},"system":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"CallExpression","callee":{"type":"MemberExpression","object":{"type":"Identifier","name":"System"},"property":{"type":"Identifier","name":"register"},"computed":false},"arguments":[{"type":"Identifier","name":"MODULE_NAME"},{"type":"Identifier","name":"MODULE_DEPENDENCIES"},{"type":"FunctionExpression","id":null,"generator":false,"expression":false,"params":[{"type":"Identifier","name":"EXPORT_IDENTIFIER"}],"body":{"type":"BlockStatement","body":[{"type":"ReturnStatement","argument":{"type":"ObjectExpression","properties":[{"type":"Property","method":false,"shorthand":false,"computed":false,"key":{"type":"Identifier","name":"setters"},"value":{"type":"Identifier","name":"SETTERS"},"kind":"init"},{"type":"Property","method":false,"shorthand":false,"computed":false,"key":{"type":"Identifier","name":"execute"},"value":{"type":"Identifier","name":"EXECUTE"},"kind":"init"}]}}]}}]}}]},"tail-call-body":{"type":"Program","body":[{"type":"BlockStatement","body":[{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"AGAIN_ID"},"init":{"type":"Literal","value":true}}],"kind":"var"},{"type":"LabeledStatement","body":{"type":"WhileStatement","test":{"type":"Identifier","name":"AGAIN_ID"},"body":{"type":"ExpressionStatement","expression":{"type":"Identifier","name":"BLOCK"}}},"label":{"type":"Identifier","name":"FUNCTION_ID"}}]}]},"test-exports":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"BinaryExpression","left":{"type":"UnaryExpression","operator":"typeof","prefix":true,"argument":{"type":"Identifier","name":"exports"}},"operator":"!==","right":{"type":"Literal","value":"undefined"}}}]},"test-module":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"BinaryExpression","left":{"type":"UnaryExpression","operator":"typeof","prefix":true,"argument":{"type":"Identifier","name":"module"}},"operator":"!==","right":{"type":"Literal","value":"undefined"}}}]},"umd-commonjs-strict":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"CallExpression","callee":{"type":"FunctionExpression","id":null,"generator":false,"expression":false,"params":[{"type":"Identifier","name":"root"},{"type":"Identifier","name":"factory"}],"body":{"type":"BlockStatement","body":[{"type":"IfStatement","test":{"type":"LogicalExpression","left":{"type":"BinaryExpression","left":{"type":"UnaryExpression","operator":"typeof","prefix":true,"argument":{"type":"Identifier","name":"define"}},"operator":"===","right":{"type":"Literal","value":"function"}},"operator":"&&","right":{"type":"MemberExpression","object":{"type":"Identifier","name":"define"},"property":{"type":"Identifier","name":"amd"},"computed":false}},"consequent":{"type":"BlockStatement","body":[{"type":"ExpressionStatement","expression":{"type":"CallExpression","callee":{"type":"Identifier","name":"define"},"arguments":[{"type":"Identifier","name":"AMD_ARGUMENTS"},{"type":"Identifier","name":"factory"}]}}]},"alternate":{"type":"IfStatement","test":{"type":"BinaryExpression","left":{"type":"UnaryExpression","operator":"typeof","prefix":true,"argument":{"type":"Identifier","name":"exports"}},"operator":"===","right":{"type":"Literal","value":"object"}},"consequent":{"type":"BlockStatement","body":[{"type":"ExpressionStatement","expression":{"type":"CallExpression","callee":{"type":"Identifier","name":"factory"},"arguments":[{"type":"Identifier","name":"COMMON_ARGUMENTS"}]}}]},"alternate":{"type":"BlockStatement","body":[{"type":"ExpressionStatement","expression":{"type":"CallExpression","callee":{"type":"Identifier","name":"factory"},"arguments":[{"type":"Identifier","name":"BROWSER_ARGUMENTS"}]}}]}}}]},"parenthesizedExpression":true},"arguments":[{"type":"Identifier","name":"UMD_ROOT"},{"type":"FunctionExpression","id":null,"generator":false,"expression":false,"params":[{"type":"Identifier","name":"FACTORY_PARAMETERS"}],"body":{"type":"BlockStatement","body":[{"type":"ExpressionStatement","expression":{"type":"Identifier","name":"FACTORY_BODY"}}]}}]}}]},"umd-runner-body":{"type":"Program","body":[{"type":"ExpressionStatement","expression":{"type":"FunctionExpression","id":null,"generator":false,"expression":false,"params":[{"type":"Identifier","name":"global"},{"type":"Identifier","name":"factory"}],"body":{"type":"BlockStatement","body":[{"type":"IfStatement","test":{"type":"LogicalExpression","left":{"type":"BinaryExpression","left":{"type":"UnaryExpression","operator":"typeof","prefix":true,"argument":{"type":"Identifier","name":"define"}},"operator":"===","right":{"type":"Literal","value":"function"}},"operator":"&&","right":{"type":"MemberExpression","object":{"type":"Identifier","name":"define"},"property":{"type":"Identifier","name":"amd"},"computed":false}},"consequent":{"type":"BlockStatement","body":[{"type":"ExpressionStatement","expression":{"type":"CallExpression","callee":{"type":"Identifier","name":"define"},"arguments":[{"type":"Identifier","name":"AMD_ARGUMENTS"},{"type":"Identifier","name":"factory"}]}}]},"alternate":{"type":"IfStatement","test":{"type":"Identifier","name":"COMMON_TEST"},"consequent":{"type":"BlockStatement","body":[{"type":"ExpressionStatement","expression":{"type":"CallExpression","callee":{"type":"Identifier","name":"factory"},"arguments":[{"type":"Identifier","name":"COMMON_ARGUMENTS"}]}}]},"alternate":{"type":"BlockStatement","body":[{"type":"VariableDeclaration","declarations":[{"type":"VariableDeclarator","id":{"type":"Identifier","name":"mod"},"init":{"type":"ObjectExpression","properties":[{"type":"Property","method":false,"shorthand":false,"computed":false,"key":{"type":"Identifier","name":"exports"},"value":{"type":"ObjectExpression","properties":[]},"kind":"init"}]}}],"kind":"var"},{"type":"ExpressionStatement","expression":{"type":"CallExpression","callee":{"type":"Identifier","name":"factory"},"arguments":[{"type":"MemberExpression","object":{"type":"Identifier","name":"mod"},"property":{"type":"Identifier","name":"exports"},"computed":false},{"type":"Identifier","name":"BROWSER_ARGUMENTS"}]}},{"type":"ExpressionStatement","expression":{"type":"AssignmentExpression","operator":"=","left":{"type":"MemberExpression","object":{"type":"Identifier","name":"global"},"property":{"type":"Identifier","name":"GLOBAL_ARG"},"computed":false},"right":{"type":"MemberExpression","object":{"type":"Identifier","name":"mod"},"property":{"type":"Identifier","name":"exports"},"computed":false}}}]}}}]},"parenthesizedExpression":true}}]}} +},{}],613:[function(_dereq_,module,exports){ +"use strict"; + +exports.__esModule = true; +exports.parse = parse; +// istanbul ignore next + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } + +var _parser = _dereq_(617); + +var _parser2 = _interopRequireDefault(_parser); + +_dereq_(622); + +_dereq_(621); + +_dereq_(619); + +_dereq_(616); + +_dereq_(620); + +_dereq_(618); + +_dereq_(615); + +var _tokenizerTypes = _dereq_(629); + +_dereq_(627); + +_dereq_(626); + +var _pluginsFlow = _dereq_(623); + +var _pluginsFlow2 = _interopRequireDefault(_pluginsFlow); + +var _pluginsJsx = _dereq_(624); + +var _pluginsJsx2 = _interopRequireDefault(_pluginsJsx); + +_parser.plugins.flow = _pluginsFlow2["default"]; +_parser.plugins.jsx = _pluginsJsx2["default"]; + +function parse(input, options) { + return new _parser2["default"](options, input).parse(); +} + +exports.tokTypes = _tokenizerTypes.types; +},{"615":615,"616":616,"617":617,"618":618,"619":619,"620":620,"621":621,"622":622,"623":623,"624":624,"626":626,"627":627,"629":629}],614:[function(_dereq_,module,exports){ +// A second optional argument can be given to further configure +// the parser process. These options are recognized: + +"use strict"; + +exports.__esModule = true; +exports.getOptions = getOptions; +var defaultOptions = { + // Source type ("script" or "module") for different semantics + sourceType: "script", + // By default, reserved words are not enforced. Disable + // `allowReserved` to enforce them. When this option has the + // value "never", reserved words and keywords can also not be + // used as property names. + allowReserved: true, + // When enabled, a return at the top level is not considered an + // error. + allowReturnOutsideFunction: false, + // When enabled, import/export statements are not constrained to + // appearing at the top of the program. + allowImportExportEverywhere: false, + plugins: {}, + // Babel-specific options + features: {}, + strictMode: null +}; + +exports.defaultOptions = defaultOptions; +// Interpret and default an options object + +function getOptions(opts) { + var options = {}; + for (var key in defaultOptions) { + options[key] = opts && key in opts ? opts[key] : defaultOptions[key]; + } + return options; +} +},{}],615:[function(_dereq_,module,exports){ +/** + * Based on the comment attachment algorithm used in espree and estraverse. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +"use strict"; + +// istanbul ignore next + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } + +var _index = _dereq_(617); + +var _index2 = _interopRequireDefault(_index); + +function last(stack) { + return stack[stack.length - 1]; +} + +var pp = _index2["default"].prototype; + +pp.addComment = function (comment) { + this.state.trailingComments.push(comment); + this.state.leadingComments.push(comment); +}; + +pp.processComment = function (node) { + if (node.type === "Program" && node.body.length > 0) return; + + var stack = this.state.commentStack; + + var lastChild, trailingComments, i; + + if (this.state.trailingComments.length > 0) { + // If the first comment in trailingComments comes after the + // current node, then we're good - all comments in the array will + // come after the node and so it's safe to add them as official + // trailingComments. + if (this.state.trailingComments[0].start >= node.end) { + trailingComments = this.state.trailingComments; + this.state.trailingComments = []; + } else { + // Otherwise, if the first comment doesn't come after the + // current node, that means we have a mix of leading and trailing + // comments in the array and that leadingComments contains the + // same items as trailingComments. Reset trailingComments to + // zero items and we'll handle this by evaluating leadingComments + // later. + this.state.trailingComments.length = 0; + } + } else { + var lastInStack = last(stack); + if (stack.length > 0 && lastInStack.trailingComments && lastInStack.trailingComments[0].start >= node.end) { + trailingComments = lastInStack.trailingComments; + lastInStack.trailingComments = null; + } + } + + // Eating the stack. + while (stack.length > 0 && last(stack).start >= node.start) { + lastChild = stack.pop(); + } + + if (lastChild) { + if (lastChild.leadingComments) { + if (lastChild !== node && last(lastChild.leadingComments).end <= node.start) { + node.leadingComments = lastChild.leadingComments; + lastChild.leadingComments = null; + } else { + // A leading comment for an anonymous class had been stolen by its first MethodDefinition, + // so this takes back the leading comment. + // See also: https://github.com/eslint/espree/issues/158 + for (i = lastChild.leadingComments.length - 2; i >= 0; --i) { + if (lastChild.leadingComments[i].end <= node.start) { + node.leadingComments = lastChild.leadingComments.splice(0, i + 1); + break; + } + } + } + } + } else if (this.state.leadingComments.length > 0) { + if (last(this.state.leadingComments).end <= node.start) { + node.leadingComments = this.state.leadingComments; + this.state.leadingComments = []; + } else { + // https://github.com/eslint/espree/issues/2 + // + // In special cases, such as return (without a value) and + // debugger, all comments will end up as leadingComments and + // will otherwise be eliminated. This step runs when the + // commentStack is empty and there are comments left + // in leadingComments. + // + // This loop figures out the stopping point between the actual + // leading and trailing comments by finding the location of the + // first comment that comes after the given node. + for (i = 0; i < this.state.leadingComments.length; i++) { + if (this.state.leadingComments[i].end > node.start) { + break; + } + } + + // Split the array based on the location of the first comment + // that comes after the node. Keep in mind that this could + // result in an empty array, and if so, the array must be + // deleted. + node.leadingComments = this.state.leadingComments.slice(0, i); + if (node.leadingComments.length === 0) { + node.leadingComments = null; + } + + // Similarly, trailing comments are attached later. The variable + // must be reset to null if there are no trailing comments. + trailingComments = this.state.leadingComments.slice(i); + if (trailingComments.length === 0) { + trailingComments = null; + } + } + } + + if (trailingComments) { + if (trailingComments.length && trailingComments[0].start >= node.start && last(trailingComments).end <= node.end) { + node.innerComments = trailingComments; + } else { + node.trailingComments = trailingComments; + } + } + + stack.push(node); +}; +},{"617":617}],616:[function(_dereq_,module,exports){ +// A recursive descent parser operates by defining functions for all +// syntactic elements, and recursively calling those, each function +// advancing the input stream and returning an AST node. Precedence +// of constructs (for example, the fact that `!x[1]` means `!(x[1])` +// instead of `(!x)[1]` is handled by the fact that the parser +// function that parses unary prefix operators is called first, and +// in turn calls the function that parses `[]` subscripts — that +// way, it'll receive the node for `x[1]` already parsed, and wraps +// *that* in the unary operator node. +// +// Acorn uses an [operator precedence parser][opp] to handle binary +// operator precedence, because it is much more compact than using +// the technique outlined above, which uses different, nesting +// functions to specify precedence, for all of the ten binary +// precedence levels that JavaScript defines. +// +// [opp]: http://en.wikipedia.org/wiki/Operator-precedence_parser + +"use strict"; + +// istanbul ignore next + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } + +var _tokenizerTypes = _dereq_(629); + +var _index = _dereq_(617); + +var _index2 = _interopRequireDefault(_index); + +var _utilIdentifier = _dereq_(630); + +var pp = _index2["default"].prototype; + +// Check if property name clashes with already added. +// Object/class getters and setters are not allowed to clash — +// either with each other or with an init property — and in +// strict mode, init properties are also not allowed to be repeated. + +pp.checkPropClash = function (prop, propHash) { + if (prop.computed || prop.method || prop.shorthand) return; + + var key = prop.key, + name = undefined; + switch (key.type) { + case "Identifier": + name = key.name;break; + case "Literal": + name = String(key.value);break; + default: + return; + } + + var kind = prop.kind; + if (name === "__proto__" && kind === "init") { + if (propHash.proto) this.raise(key.start, "Redefinition of __proto__ property"); + propHash.proto = true; + } +}; + +// ### Expression parsing + +// These nest, from the most general expression type at the top to +// 'atomic', nondivisible expression types at the bottom. Most of +// the functions will simply let the function (s) below them parse, +// and, *if* the syntactic construct they handle is present, wrap +// the AST node that the inner parser gave them in another node. + +// Parse a full expression. The optional arguments are used to +// forbid the `in` operator (in for loops initalization expressions) +// and provide reference for storing '=' operator inside shorthand +// property assignment in contexts where both object expression +// and object pattern might appear (so it's possible to raise +// delayed syntax error at correct position). + +pp.parseExpression = function (noIn, refShorthandDefaultPos) { + var startPos = this.state.start, + startLoc = this.state.startLoc; + var expr = this.parseMaybeAssign(noIn, refShorthandDefaultPos); + if (this.match(_tokenizerTypes.types.comma)) { + var node = this.startNodeAt(startPos, startLoc); + node.expressions = [expr]; + while (this.eat(_tokenizerTypes.types.comma)) { + node.expressions.push(this.parseMaybeAssign(noIn, refShorthandDefaultPos)); + } + this.toReferencedList(node.expressions); + return this.finishNode(node, "SequenceExpression"); + } + return expr; +}; + +// Parse an assignment expression. This includes applications of +// operators like `+=`. + +pp.parseMaybeAssign = function (noIn, refShorthandDefaultPos, afterLeftParse) { + if (this.match(_tokenizerTypes.types._yield) && this.state.inGenerator) { + return this.parseYield(); + } + + var failOnShorthandAssign = undefined; + if (!refShorthandDefaultPos) { + refShorthandDefaultPos = { start: 0 }; + failOnShorthandAssign = true; + } else { + failOnShorthandAssign = false; + } + var startPos = this.state.start, + startLoc = this.state.startLoc; + if (this.match(_tokenizerTypes.types.parenL) || this.match(_tokenizerTypes.types.name)) { + this.state.potentialArrowAt = this.state.start; + } + var left = this.parseMaybeConditional(noIn, refShorthandDefaultPos); + if (afterLeftParse) left = afterLeftParse.call(this, left, startPos, startLoc); + if (this.state.type.isAssign) { + var node = this.startNodeAt(startPos, startLoc); + node.operator = this.state.value; + node.left = this.match(_tokenizerTypes.types.eq) ? this.toAssignable(left) : left; + refShorthandDefaultPos.start = 0; // reset because shorthand default was used correctly + this.checkLVal(left); + if (left.parenthesizedExpression) { + var errorMsg = undefined; + if (left.type === "ObjectPattern") { + errorMsg = "`({a}) = 0` use `({a} = 0)`"; + } else if (left.type === "ArrayPattern") { + errorMsg = "`([a]) = 0` use `([a] = 0)`"; + } + if (errorMsg) { + this.raise(left.start, "You're trying to assign to a parenthesized expression, eg. instead of " + errorMsg); + } + } + this.next(); + node.right = this.parseMaybeAssign(noIn); + return this.finishNode(node, "AssignmentExpression"); + } else if (failOnShorthandAssign && refShorthandDefaultPos.start) { + this.unexpected(refShorthandDefaultPos.start); + } + return left; +}; + +// Parse a ternary conditional (`?:`) operator. + +pp.parseMaybeConditional = function (noIn, refShorthandDefaultPos) { + var startPos = this.state.start, + startLoc = this.state.startLoc; + var expr = this.parseExprOps(noIn, refShorthandDefaultPos); + if (refShorthandDefaultPos && refShorthandDefaultPos.start) return expr; + if (this.eat(_tokenizerTypes.types.question)) { + var node = this.startNodeAt(startPos, startLoc); + node.test = expr; + node.consequent = this.parseMaybeAssign(); + this.expect(_tokenizerTypes.types.colon); + node.alternate = this.parseMaybeAssign(noIn); + return this.finishNode(node, "ConditionalExpression"); + } + return expr; +}; + +// Start the precedence parser. + +pp.parseExprOps = function (noIn, refShorthandDefaultPos) { + var startPos = this.state.start, + startLoc = this.state.startLoc; + var expr = this.parseMaybeUnary(refShorthandDefaultPos); + if (refShorthandDefaultPos && refShorthandDefaultPos.start) { + return expr; + } else { + return this.parseExprOp(expr, startPos, startLoc, -1, noIn); + } +}; + +// Parse binary operators with the operator precedence parsing +// algorithm. `left` is the left-hand side of the operator. +// `minPrec` provides context that allows the function to stop and +// defer further parser to one of its callers when it encounters an +// operator that has a lower precedence than the set it is parsing. + +pp.parseExprOp = function (left, leftStartPos, leftStartLoc, minPrec, noIn) { + var prec = this.state.type.binop; + if (prec != null && (!noIn || !this.match(_tokenizerTypes.types._in))) { + if (prec > minPrec) { + var node = this.startNodeAt(leftStartPos, leftStartLoc); + node.left = left; + node.operator = this.state.value; + var op = this.state.type; + this.next(); + var startPos = this.state.start, + startLoc = this.state.startLoc; + node.right = this.parseExprOp(this.parseMaybeUnary(), startPos, startLoc, op.rightAssociative ? prec - 1 : prec, noIn); + this.finishNode(node, op === _tokenizerTypes.types.logicalOR || op === _tokenizerTypes.types.logicalAND ? "LogicalExpression" : "BinaryExpression"); + return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec, noIn); + } + } + return left; +}; + +// Parse unary operators, both prefix and postfix. + +pp.parseMaybeUnary = function (refShorthandDefaultPos) { + if (this.state.type.prefix) { + var node = this.startNode(), + update = this.match(_tokenizerTypes.types.incDec); + node.operator = this.state.value; + node.prefix = true; + this.next(); + node.argument = this.parseMaybeUnary(); + if (refShorthandDefaultPos && refShorthandDefaultPos.start) this.unexpected(refShorthandDefaultPos.start); + if (update) { + this.checkLVal(node.argument); + } else if (this.strict && node.operator === "delete" && node.argument.type === "Identifier") { + this.raise(node.start, "Deleting local variable in strict mode"); + } + return this.finishNode(node, update ? "UpdateExpression" : "UnaryExpression"); + } + + var startPos = this.state.start, + startLoc = this.state.startLoc; + var expr = this.parseExprSubscripts(refShorthandDefaultPos); + if (refShorthandDefaultPos && refShorthandDefaultPos.start) return expr; + while (this.state.type.postfix && !this.canInsertSemicolon()) { + var node = this.startNodeAt(startPos, startLoc); + node.operator = this.state.value; + node.prefix = false; + node.argument = expr; + this.checkLVal(expr); + this.next(); + expr = this.finishNode(node, "UpdateExpression"); + } + return expr; +}; + +// Parse call, dot, and `[]`-subscript expressions. + +pp.parseExprSubscripts = function (refShorthandDefaultPos) { + var startPos = this.state.start, + startLoc = this.state.startLoc; + var expr = this.parseExprAtom(refShorthandDefaultPos); + if (refShorthandDefaultPos && refShorthandDefaultPos.start) { + return expr; + } else { + return this.parseSubscripts(expr, startPos, startLoc); + } +}; + +pp.parseSubscripts = function (base, startPos, startLoc, noCalls) { + for (;;) { + if (!noCalls && this.eat(_tokenizerTypes.types.doubleColon)) { + var node = this.startNodeAt(startPos, startLoc); + node.object = base; + node.callee = this.parseNoCallExpr(); + return this.parseSubscripts(this.finishNode(node, "BindExpression"), startPos, startLoc, noCalls); + } else if (this.eat(_tokenizerTypes.types.dot)) { + var node = this.startNodeAt(startPos, startLoc); + node.object = base; + node.property = this.parseIdent(true); + node.computed = false; + base = this.finishNode(node, "MemberExpression"); + } else if (this.eat(_tokenizerTypes.types.bracketL)) { + var node = this.startNodeAt(startPos, startLoc); + node.object = base; + node.property = this.parseExpression(); + node.computed = true; + this.expect(_tokenizerTypes.types.bracketR); + base = this.finishNode(node, "MemberExpression"); + } else if (!noCalls && this.match(_tokenizerTypes.types.parenL)) { + var possibleAsync = base.type === "Identifier" && base.name === "async" && !this.canInsertSemicolon(); + this.next(); + + var node = this.startNodeAt(startPos, startLoc); + node.callee = base; + node.arguments = this.parseExprList(_tokenizerTypes.types.parenR, this.options.features["es7.trailingFunctionCommas"]); + base = this.finishNode(node, "CallExpression"); + + if (possibleAsync && (this.match(_tokenizerTypes.types.colon) || this.match(_tokenizerTypes.types.arrow))) { + base = this.parseAsyncArrowFromCallExpression(this.startNodeAt(startPos, startLoc), node); + } else { + this.toReferencedList(node.arguments); + } + } else if (this.match(_tokenizerTypes.types.backQuote)) { + var node = this.startNodeAt(startPos, startLoc); + node.tag = base; + node.quasi = this.parseTemplate(); + base = this.finishNode(node, "TaggedTemplateExpression"); + } else { + return base; + } + } +}; + +pp.parseAsyncArrowFromCallExpression = function (node, call) { + if (!this.options.features["es7.asyncFunctions"]) this.unexpected(); + this.expect(_tokenizerTypes.types.arrow); + return this.parseArrowExpression(node, call.arguments, true); +}; + +// Parse a no-call expression (like argument of `new` or `::` operators). + +pp.parseNoCallExpr = function () { + var startPos = this.state.start, + startLoc = this.state.startLoc; + return this.parseSubscripts(this.parseExprAtom(), startPos, startLoc, true); +}; + +// Parse an atomic expression — either a single token that is an +// expression, an expression started by a keyword like `function` or +// `new`, or an expression wrapped in punctuation like `()`, `[]`, +// or `{}`. + +pp.parseExprAtom = function (refShorthandDefaultPos) { + var node = undefined, + canBeArrow = this.state.potentialArrowAt === this.state.start; + switch (this.state.type) { + case _tokenizerTypes.types._super: + if (!this.state.inFunction) this.raise(this.state.start, "'super' outside of function or class"); + case _tokenizerTypes.types._this: + var type = this.match(_tokenizerTypes.types._this) ? "ThisExpression" : "Super"; + node = this.startNode(); + this.next(); + return this.finishNode(node, type); + + case _tokenizerTypes.types._yield: + if (this.state.inGenerator) this.unexpected(); + + case _tokenizerTypes.types._do: + if (this.options.features["es7.doExpressions"]) { + var _node = this.startNode(); + this.next(); + var oldInFunction = this.state.inFunction; + var oldLabels = this.state.labels; + this.state.labels = []; + this.state.inFunction = false; + _node.body = this.parseBlock(); + this.state.inFunction = oldInFunction; + this.state.labels = oldLabels; + return this.finishNode(_node, "DoExpression"); + } + + case _tokenizerTypes.types.name: + node = this.startNode(); + var id = this.parseIdent(true); + + if (this.options.features["es7.asyncFunctions"]) { + if (id.name === "await") { + if (this.inAsync) return this.parseAwait(node); + } else if (id.name === "async" && this.match(_tokenizerTypes.types._function) && !this.canInsertSemicolon()) { + this.next(); + return this.parseFunction(node, false, false, true); + } else if (canBeArrow && id.name === "async" && this.match(_tokenizerTypes.types.name)) { + var params = [this.parseIdent()]; + this.expect(_tokenizerTypes.types.arrow); + // var foo = bar => {}; + return this.parseArrowExpression(node, params, true); + } + } + + if (canBeArrow && !this.canInsertSemicolon() && this.eat(_tokenizerTypes.types.arrow)) { + return this.parseArrowExpression(node, [id]); + } + + return id; + + case _tokenizerTypes.types.regexp: + var value = this.state.value; + node = this.parseLiteral(value.value); + node.regex = { pattern: value.pattern, flags: value.flags }; + return node; + + case _tokenizerTypes.types.num:case _tokenizerTypes.types.string: + return this.parseLiteral(this.state.value); + + case _tokenizerTypes.types._null:case _tokenizerTypes.types._true:case _tokenizerTypes.types._false: + node = this.startNode(); + node.rawValue = node.value = this.match(_tokenizerTypes.types._null) ? null : this.match(_tokenizerTypes.types._true); + node.raw = this.state.type.keyword; + this.next(); + return this.finishNode(node, "Literal"); + + case _tokenizerTypes.types.parenL: + return this.parseParenAndDistinguishExpression(null, null, canBeArrow); + + case _tokenizerTypes.types.bracketL: + node = this.startNode(); + this.next(); + // check whether this is array comprehension or regular array + if (this.options.features["es7.comprehensions"] && this.match(_tokenizerTypes.types._for)) { + return this.parseComprehension(node, false); + } + node.elements = this.parseExprList(_tokenizerTypes.types.bracketR, true, true, refShorthandDefaultPos); + this.toReferencedList(node.elements); + return this.finishNode(node, "ArrayExpression"); + + case _tokenizerTypes.types.braceL: + return this.parseObj(false, refShorthandDefaultPos); + + case _tokenizerTypes.types._function: + node = this.startNode(); + this.next(); + return this.parseFunction(node, false); + + case _tokenizerTypes.types.at: + this.parseDecorators(); + + case _tokenizerTypes.types._class: + node = this.startNode(); + this.takeDecorators(node); + return this.parseClass(node, false); + + case _tokenizerTypes.types._new: + return this.parseNew(); + + case _tokenizerTypes.types.backQuote: + return this.parseTemplate(); + + case _tokenizerTypes.types.doubleColon: + node = this.startNode(); + this.next(); + node.object = null; + var callee = node.callee = this.parseNoCallExpr(); + if (callee.type === "MemberExpression") { + return this.finishNode(node, "BindExpression"); + } else { + this.raise(callee.start, "Binding should be performed on object property."); + } + + default: + this.unexpected(); + } +}; + +pp.parseLiteral = function (value) { + var node = this.startNode(); + node.rawValue = node.value = value; + node.raw = this.input.slice(this.state.start, this.state.end); + this.next(); + return this.finishNode(node, "Literal"); +}; + +pp.parseParenExpression = function () { + this.expect(_tokenizerTypes.types.parenL); + var val = this.parseExpression(); + this.expect(_tokenizerTypes.types.parenR); + return val; +}; + +pp.parseParenAndDistinguishExpression = function (startPos, startLoc, canBeArrow, isAsync) { + startPos = startPos || this.state.start; + startLoc = startLoc || this.state.startLoc; + var val = undefined; + this.next(); + + if (this.options.features["es7.comprehensions"] && this.match(_tokenizerTypes.types._for)) { + return this.parseComprehension(this.startNodeAt(startPos, startLoc), true); + } + + var innerStartPos = this.state.start, + innerStartLoc = this.state.startLoc; + var exprList = [], + first = true; + var refShorthandDefaultPos = { start: 0 }, + spreadStart = undefined, + innerParenStart = undefined, + optionalCommaStart = undefined; + while (!this.match(_tokenizerTypes.types.parenR)) { + if (first) { + first = false; + } else { + this.expect(_tokenizerTypes.types.comma); + if (this.match(_tokenizerTypes.types.parenR) && this.options.features["es7.trailingFunctionCommas"]) { + optionalCommaStart = this.state.start; + break; + } + } + + if (this.match(_tokenizerTypes.types.ellipsis)) { + var spreadNodeStartPos = this.state.start, + spreadNodeStartLoc = this.state.startLoc; + spreadStart = this.state.start; + exprList.push(this.parseParenItem(this.parseRest(), spreadNodeStartLoc, spreadNodeStartPos)); + break; + } else { + if (this.match(_tokenizerTypes.types.parenL) && !innerParenStart) { + innerParenStart = this.state.start; + } + exprList.push(this.parseMaybeAssign(false, refShorthandDefaultPos, this.parseParenItem)); + } + } + var innerEndPos = this.state.start; + var innerEndLoc = this.state.startLoc; + this.expect(_tokenizerTypes.types.parenR); + + if (canBeArrow && !this.canInsertSemicolon() && this.eat(_tokenizerTypes.types.arrow)) { + if (innerParenStart) this.unexpected(innerParenStart); + return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList, isAsync); + } + + if (!exprList.length) { + if (isAsync) { + return; + } else { + this.unexpected(this.state.lastTokStart); + } + } + if (optionalCommaStart) this.unexpected(optionalCommaStart); + if (spreadStart) this.unexpected(spreadStart); + if (refShorthandDefaultPos.start) this.unexpected(refShorthandDefaultPos.start); + + if (exprList.length > 1) { + val = this.startNodeAt(innerStartPos, innerStartLoc); + val.expressions = exprList; + this.toReferencedList(val.expressions); + this.finishNodeAt(val, "SequenceExpression", innerEndPos, innerEndLoc); + } else { + val = exprList[0]; + } + + val.parenthesizedExpression = true; + return val; +}; + +pp.parseParenItem = function (node) { + return node; +}; + +// New's precedence is slightly tricky. It must allow its argument +// to be a `[]` or dot subscript expression, but not a call — at +// least, not without wrapping it in parentheses. Thus, it uses the + +pp.parseNew = function () { + var node = this.startNode(); + var meta = this.parseIdent(true); + + if (this.eat(_tokenizerTypes.types.dot)) { + node.meta = meta; + node.property = this.parseIdent(true); + + if (node.property.name !== "target") { + this.raise(node.property.start, "The only valid meta property for new is new.target"); + } + + return this.finishNode(node, "MetaProperty"); + } + + node.callee = this.parseNoCallExpr(); + + if (this.eat(_tokenizerTypes.types.parenL)) { + node.arguments = this.parseExprList(_tokenizerTypes.types.parenR, this.options.features["es7.trailingFunctionCommas"]); + this.toReferencedList(node.arguments); + } else { + node.arguments = []; + } + + return this.finishNode(node, "NewExpression"); +}; + +// Parse template expression. + +pp.parseTemplateElement = function () { + var elem = this.startNode(); + elem.value = { + raw: this.input.slice(this.state.start, this.state.end).replace(/\r\n?/g, "\n"), + cooked: this.state.value + }; + this.next(); + elem.tail = this.match(_tokenizerTypes.types.backQuote); + return this.finishNode(elem, "TemplateElement"); +}; + +pp.parseTemplate = function () { + var node = this.startNode(); + this.next(); + node.expressions = []; + var curElt = this.parseTemplateElement(); + node.quasis = [curElt]; + while (!curElt.tail) { + this.expect(_tokenizerTypes.types.dollarBraceL); + node.expressions.push(this.parseExpression()); + this.expect(_tokenizerTypes.types.braceR); + node.quasis.push(curElt = this.parseTemplateElement()); + } + this.next(); + return this.finishNode(node, "TemplateLiteral"); +}; + +// Parse an object literal or binding pattern. + +pp.parseObj = function (isPattern, refShorthandDefaultPos) { + var node = this.startNode(), + first = true, + propHash = Object.create(null); + node.properties = []; + var decorators = []; + this.next(); + while (!this.eat(_tokenizerTypes.types.braceR)) { + if (first) { + first = false; + } else { + this.expect(_tokenizerTypes.types.comma); + if (this.eat(_tokenizerTypes.types.braceR)) break; + } + + while (this.match(_tokenizerTypes.types.at)) { + decorators.push(this.parseDecorator()); + } + + var prop = this.startNode(), + isGenerator = false, + isAsync = false, + startPos = undefined, + startLoc = undefined; + if (decorators.length) { + prop.decorators = decorators; + decorators = []; + } + if (this.options.features["es7.objectRestSpread"] && this.match(_tokenizerTypes.types.ellipsis)) { + prop = this.parseSpread(); + prop.type = "SpreadProperty"; + node.properties.push(prop); + continue; + } + prop.method = false; + prop.shorthand = false; + if (isPattern || refShorthandDefaultPos) { + startPos = this.state.start; + startLoc = this.state.startLoc; + } + if (!isPattern) { + isGenerator = this.eat(_tokenizerTypes.types.star); + } + if (!isPattern && this.options.features["es7.asyncFunctions"] && this.isContextual("async")) { + if (isGenerator) this.unexpected(); + var asyncId = this.parseIdent(); + if (this.match(_tokenizerTypes.types.colon) || this.match(_tokenizerTypes.types.parenL) || this.match(_tokenizerTypes.types.braceR)) { + prop.key = asyncId; + } else { + isAsync = true; + this.parsePropertyName(prop); + } + } else { + this.parsePropertyName(prop); + } + this.parseObjPropValue(prop, startPos, startLoc, isGenerator, isAsync, isPattern, refShorthandDefaultPos); + this.checkPropClash(prop, propHash); + node.properties.push(this.finishNode(prop, "Property")); + } + if (decorators.length) { + this.raise(this.state.start, "You have trailing decorators with no property"); + } + return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression"); +}; + +pp.parseObjPropValue = function (prop, startPos, startLoc, isGenerator, isAsync, isPattern, refShorthandDefaultPos) { + if (this.eat(_tokenizerTypes.types.colon)) { + prop.value = isPattern ? this.parseMaybeDefault(this.state.start, this.state.startLoc) : this.parseMaybeAssign(false, refShorthandDefaultPos); + prop.kind = "init"; + } else if (this.match(_tokenizerTypes.types.parenL)) { + if (isPattern) this.unexpected(); + prop.kind = "init"; + prop.method = true; + prop.value = this.parseMethod(isGenerator, isAsync); + } else if (!prop.computed && prop.key.type === "Identifier" && (prop.key.name === "get" || prop.key.name === "set") && !this.match(_tokenizerTypes.types.comma) && !this.match(_tokenizerTypes.types.braceR)) { + if (isGenerator || isAsync || isPattern) this.unexpected(); + prop.kind = prop.key.name; + this.parsePropertyName(prop); + prop.value = this.parseMethod(false); + var paramCount = prop.kind === "get" ? 0 : 1; + if (prop.value.params.length !== paramCount) { + var start = prop.value.start; + if (prop.kind === "get") this.raise(start, "getter should have no params");else this.raise(start, "setter should have exactly one param"); + } + } else if (!prop.computed && prop.key.type === "Identifier") { + prop.kind = "init"; + if (isPattern) { + if (this.isKeyword(prop.key.name) || this.strict && (_utilIdentifier.reservedWords.strictBind(prop.key.name) || _utilIdentifier.reservedWords.strict(prop.key.name)) || !this.options.allowReserved && this.isReservedWord(prop.key.name)) this.raise(prop.key.start, "Binding " + prop.key.name); + prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key.__clone()); + } else if (this.match(_tokenizerTypes.types.eq) && refShorthandDefaultPos) { + if (!refShorthandDefaultPos.start) refShorthandDefaultPos.start = this.state.start; + prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key.__clone()); + } else { + prop.value = prop.key.__clone(); + } + prop.shorthand = true; + } else { + this.unexpected(); + } +}; + +pp.parsePropertyName = function (prop) { + if (this.eat(_tokenizerTypes.types.bracketL)) { + prop.computed = true; + prop.key = this.parseMaybeAssign(); + this.expect(_tokenizerTypes.types.bracketR); + return prop.key; + } else { + prop.computed = false; + return prop.key = this.match(_tokenizerTypes.types.num) || this.match(_tokenizerTypes.types.string) ? this.parseExprAtom() : this.parseIdent(true); + } +}; + +// Initialize empty function node. + +pp.initFunction = function (node, isAsync) { + node.id = null; + node.generator = false; + node.expression = false; + if (this.options.features["es7.asyncFunctions"]) { + node.async = !!isAsync; + } +}; + +// Parse object or class method. + +pp.parseMethod = function (isGenerator, isAsync) { + var node = this.startNode(); + this.initFunction(node, isAsync); + this.expect(_tokenizerTypes.types.parenL); + node.params = this.parseBindingList(_tokenizerTypes.types.parenR, false, this.options.features["es7.trailingFunctionCommas"]); + node.generator = isGenerator; + this.parseFunctionBody(node); + return this.finishNode(node, "FunctionExpression"); +}; + +// Parse arrow function expression with given parameters. + +pp.parseArrowExpression = function (node, params, isAsync) { + this.initFunction(node, isAsync); + node.params = this.toAssignableList(params, true); + this.parseFunctionBody(node, true); + return this.finishNode(node, "ArrowFunctionExpression"); +}; + +// Parse function body and check parameters. + +pp.parseFunctionBody = function (node, allowExpression) { + var isExpression = allowExpression && !this.match(_tokenizerTypes.types.braceL); + + var oldInAsync = this.inAsync; + this.inAsync = node.async; + if (isExpression) { + node.body = this.parseMaybeAssign(); + node.expression = true; + } else { + // Start a new scope with regard to labels and the `inFunction` + // flag (restore them to their old value afterwards). + var oldInFunc = this.state.inFunction, + oldInGen = this.state.inGenerator, + oldLabels = this.state.labels; + this.state.inFunction = true;this.state.inGenerator = node.generator;this.state.labels = []; + node.body = this.parseBlock(true); + node.expression = false; + this.state.inFunction = oldInFunc;this.state.inGenerator = oldInGen;this.state.labels = oldLabels; + } + this.inAsync = oldInAsync; + + // If this is a strict mode function, verify that argument names + // are not repeated, and it does not try to bind the words `eval` + // or `arguments`. + if (this.strict || !isExpression && node.body.body.length && this.isUseStrict(node.body.body[0])) { + var nameHash = Object.create(null), + oldStrict = this.strict; + this.strict = true; + if (node.id) { + this.checkLVal(node.id, true); + } + var _arr = node.params; + for (var _i = 0; _i < _arr.length; _i++) { + var param = _arr[_i]; + this.checkLVal(param, true, nameHash); + } + this.strict = oldStrict; + } +}; + +// Parses a comma-separated list of expressions, and returns them as +// an array. `close` is the token type that ends the list, and +// `allowEmpty` can be turned on to allow subsequent commas with +// nothing in between them to be parsed as `null` (which is needed +// for array literals). + +pp.parseExprList = function (close, allowTrailingComma, allowEmpty, refShorthandDefaultPos) { + var elts = [], + first = true; + while (!this.eat(close)) { + if (first) { + first = false; + } else { + this.expect(_tokenizerTypes.types.comma); + if (allowTrailingComma && this.eat(close)) break; + } + + elts.push(this.parseExprListItem(allowEmpty, refShorthandDefaultPos)); + } + return elts; +}; + +pp.parseExprListItem = function (allowEmpty, refShorthandDefaultPos) { + var elt = undefined; + if (allowEmpty && this.match(_tokenizerTypes.types.comma)) { + elt = null; + } else if (this.match(_tokenizerTypes.types.ellipsis)) { + elt = this.parseSpread(refShorthandDefaultPos); + } else { + elt = this.parseMaybeAssign(false, refShorthandDefaultPos); + } + return elt; +}; + +// Parse the next token as an identifier. If `liberal` is true (used +// when parsing properties), it will also convert keywords into +// identifiers. + +pp.parseIdent = function (liberal) { + var node = this.startNode(); + if (this.match(_tokenizerTypes.types.name)) { + if (!liberal && (!this.options.allowReserved && this.isReservedWord(this.state.value) || this.strict && _utilIdentifier.reservedWords.strict(this.state.value))) this.raise(this.state.start, "The keyword '" + this.state.value + "' is reserved"); + node.name = this.state.value; + } else if (liberal && this.state.type.keyword) { + node.name = this.state.type.keyword; + } else { + this.unexpected(); + } + this.next(); + return this.finishNode(node, "Identifier"); +}; + +// Parses await expression inside async function. + +pp.parseAwait = function (node) { + if (this.eat(_tokenizerTypes.types.semi) || this.canInsertSemicolon()) { + this.unexpected(); + } + node.all = this.eat(_tokenizerTypes.types.star); + node.argument = this.parseMaybeUnary(); + return this.finishNode(node, "AwaitExpression"); +}; + +// Parses yield expression inside generator. + +pp.parseYield = function () { + var node = this.startNode(); + this.next(); + if (this.match(_tokenizerTypes.types.semi) || this.canInsertSemicolon() || !this.match(_tokenizerTypes.types.star) && !this.state.type.startsExpr) { + node.delegate = false; + node.argument = null; + } else { + node.delegate = this.eat(_tokenizerTypes.types.star); + node.argument = this.parseMaybeAssign(); + } + return this.finishNode(node, "YieldExpression"); +}; + +// Parses array and generator comprehensions. + +pp.parseComprehension = function (node, isGenerator) { + node.blocks = []; + while (this.match(_tokenizerTypes.types._for)) { + var block = this.startNode(); + this.next(); + this.expect(_tokenizerTypes.types.parenL); + block.left = this.parseBindingAtom(); + this.checkLVal(block.left, true); + this.expectContextual("of"); + block.right = this.parseExpression(); + this.expect(_tokenizerTypes.types.parenR); + node.blocks.push(this.finishNode(block, "ComprehensionBlock")); + } + node.filter = this.eat(_tokenizerTypes.types._if) ? this.parseParenExpression() : null; + node.body = this.parseExpression(); + this.expect(isGenerator ? _tokenizerTypes.types.parenR : _tokenizerTypes.types.bracketR); + node.generator = isGenerator; + return this.finishNode(node, "ComprehensionExpression"); +}; +},{"617":617,"629":629,"630":630}],617:[function(_dereq_,module,exports){ +"use strict"; + +exports.__esModule = true; +// istanbul ignore next + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } + +// istanbul ignore next + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +// istanbul ignore next + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var _utilIdentifier = _dereq_(630); + +var _options = _dereq_(614); + +var _tokenizer = _dereq_(627); + +var _tokenizer2 = _interopRequireDefault(_tokenizer); + +// Registered plugins + +var plugins = {}; + +exports.plugins = plugins; + +var Parser = (function (_Tokenizer) { + _inherits(Parser, _Tokenizer); + + function Parser(options, input) { + _classCallCheck(this, Parser); + + _Tokenizer.call(this, input); + + this.options = _options.getOptions(options); + this.isKeyword = _utilIdentifier.isKeyword; + this.isReservedWord = _utilIdentifier.reservedWords[6]; + this.input = input; + this.loadPlugins(this.options.plugins); + + // Figure out if it's a module code. + this.inModule = this.options.sourceType === "module"; + this.strict = this.options.strictMode === false ? false : this.inModule; + + // If enabled, skip leading hashbang line. + if (this.state.pos === 0 && this.input[0] === "#" && this.input[1] === "!") { + this.skipLineComment(2); + } + } + + Parser.prototype.extend = function extend(name, f) { + this[name] = f(this[name]); + }; + + Parser.prototype.loadPlugins = function loadPlugins(plugins) { + for (var _name in plugins) { + var plugin = exports.plugins[_name]; + if (!plugin) throw new Error("Plugin '" + _name + "' not found"); + plugin(this, plugins[_name]); + } + }; + + Parser.prototype.parse = function parse() { + var file = this.startNode(); + var program = this.startNode(); + this.nextToken(); + return this.parseTopLevel(file, program); + }; + + return Parser; +})(_tokenizer2["default"]); + +exports["default"] = Parser; +},{"614":614,"627":627,"630":630}],618:[function(_dereq_,module,exports){ +"use strict"; + +// istanbul ignore next + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } + +var _utilLocation = _dereq_(631); + +var _index = _dereq_(617); + +var _index2 = _interopRequireDefault(_index); + +var pp = _index2["default"].prototype; + +// This function is used to raise exceptions on parse errors. It +// takes an offset integer (into the current `input`) to indicate +// the location of the error, attaches the position to the end +// of the error message, and then raises a `SyntaxError` with that +// message. + +pp.raise = function (pos, message) { + var loc = _utilLocation.getLineInfo(this.input, pos); + message += " (" + loc.line + ":" + loc.column + ")"; + var err = new SyntaxError(message); + err.pos = pos; + err.loc = loc; + throw err; +}; +},{"617":617,"631":631}],619:[function(_dereq_,module,exports){ +"use strict"; + +// istanbul ignore next + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } + +var _tokenizerTypes = _dereq_(629); + +var _index = _dereq_(617); + +var _index2 = _interopRequireDefault(_index); + +var _utilIdentifier = _dereq_(630); + +var pp = _index2["default"].prototype; + +// Convert existing expression atom to assignable pattern +// if possible. + +pp.toAssignable = function (node, isBinding) { + if (node) { + switch (node.type) { + case "Identifier": + case "ObjectPattern": + case "ArrayPattern": + case "AssignmentPattern": + break; + + case "ObjectExpression": + node.type = "ObjectPattern"; + var _arr = node.properties; + for (var _i = 0; _i < _arr.length; _i++) { + var prop = _arr[_i]; + if (prop.type === "SpreadProperty") continue; + if (prop.kind !== "init") this.raise(prop.key.start, "Object pattern can't contain getter or setter"); + this.toAssignable(prop.value, isBinding); + } + break; + + case "ArrayExpression": + node.type = "ArrayPattern"; + this.toAssignableList(node.elements, isBinding); + break; + + case "AssignmentExpression": + if (node.operator === "=") { + node.type = "AssignmentPattern"; + delete node.operator; + } else { + this.raise(node.left.end, "Only '=' operator can be used for specifying default value."); + } + break; + + case "MemberExpression": + if (!isBinding) break; + + default: + this.raise(node.start, "Assigning to rvalue"); + } + } + return node; +}; + +// Convert list of expression atoms to binding list. + +pp.toAssignableList = function (exprList, isBinding) { + var end = exprList.length; + if (end) { + var last = exprList[end - 1]; + if (last && last.type === "RestElement") { + --end; + } else if (last && last.type === "SpreadElement") { + last.type = "RestElement"; + var arg = last.argument; + this.toAssignable(arg, isBinding); + if (arg.type !== "Identifier" && arg.type !== "MemberExpression" && arg.type !== "ArrayPattern") { + this.unexpected(arg.start); + } + --end; + } + } + for (var i = 0; i < end; i++) { + var elt = exprList[i]; + if (elt) this.toAssignable(elt, isBinding); + } + return exprList; +}; + +// Convert list of expression atoms to a list of + +pp.toReferencedList = function (exprList) { + return exprList; +}; + +// Parses spread element. + +pp.parseSpread = function (refShorthandDefaultPos) { + var node = this.startNode(); + this.next(); + node.argument = this.parseMaybeAssign(refShorthandDefaultPos); + return this.finishNode(node, "SpreadElement"); +}; + +pp.parseRest = function () { + var node = this.startNode(); + this.next(); + node.argument = this.match(_tokenizerTypes.types.name) || this.match(_tokenizerTypes.types.bracketL) ? this.parseBindingAtom() : this.unexpected(); + return this.finishNode(node, "RestElement"); +}; + +// Parses lvalue (assignable) atom. + +pp.parseBindingAtom = function () { + switch (this.state.type) { + case _tokenizerTypes.types.name: + return this.parseIdent(); + + case _tokenizerTypes.types.bracketL: + var node = this.startNode(); + this.next(); + node.elements = this.parseBindingList(_tokenizerTypes.types.bracketR, true, true); + return this.finishNode(node, "ArrayPattern"); + + case _tokenizerTypes.types.braceL: + return this.parseObj(true); + + default: + this.unexpected(); + } +}; + +pp.parseBindingList = function (close, allowEmpty, allowTrailingComma) { + var elts = [], + first = true; + while (!this.eat(close)) { + if (first) first = false;else this.expect(_tokenizerTypes.types.comma); + if (allowEmpty && this.match(_tokenizerTypes.types.comma)) { + elts.push(null); + } else if (allowTrailingComma && this.eat(close)) { + break; + } else if (this.match(_tokenizerTypes.types.ellipsis)) { + elts.push(this.parseAssignableListItemTypes(this.parseRest())); + this.expect(close); + break; + } else { + var left = this.parseMaybeDefault(); + this.parseAssignableListItemTypes(left); + elts.push(this.parseMaybeDefault(null, null, left)); + } + } + return elts; +}; + +pp.parseAssignableListItemTypes = function (param) { + return param; +}; + +// Parses assignment pattern around given atom if possible. + +pp.parseMaybeDefault = function (startPos, startLoc, left) { + startLoc = startLoc || this.state.startLoc; + startPos = startPos || this.state.start; + left = left || this.parseBindingAtom(); + if (!this.eat(_tokenizerTypes.types.eq)) return left; + + var node = this.startNodeAt(startPos, startLoc); + node.left = left; + node.right = this.parseMaybeAssign(); + return this.finishNode(node, "AssignmentPattern"); +}; + +// Verify that a node is an lval — something that can be assigned +// to. + +pp.checkLVal = function (expr, isBinding, checkClashes) { + switch (expr.type) { + case "Identifier": + if (this.strict && (_utilIdentifier.reservedWords.strictBind(expr.name) || _utilIdentifier.reservedWords.strict(expr.name))) this.raise(expr.start, (isBinding ? "Binding " : "Assigning to ") + expr.name + " in strict mode"); + if (checkClashes) { + if (checkClashes[expr.name]) { + this.raise(expr.start, "Argument name clash in strict mode"); + } else { + checkClashes[expr.name] = true; + } + } + break; + + case "MemberExpression": + if (isBinding) this.raise(expr.start, (isBinding ? "Binding" : "Assigning to") + " member expression"); + break; + + case "ObjectPattern": + var _arr2 = expr.properties; + + for (var _i2 = 0; _i2 < _arr2.length; _i2++) { + var prop = _arr2[_i2]; + if (prop.type === "Property") prop = prop.value; + this.checkLVal(prop, isBinding, checkClashes); + } + break; + + case "ArrayPattern": + var _arr3 = expr.elements; + + for (var _i3 = 0; _i3 < _arr3.length; _i3++) { + var elem = _arr3[_i3]; + if (elem) this.checkLVal(elem, isBinding, checkClashes); + } + break; + + case "AssignmentPattern": + this.checkLVal(expr.left, isBinding, checkClashes); + break; + + case "SpreadProperty": + case "RestElement": + this.checkLVal(expr.argument, isBinding, checkClashes); + break; + + default: + this.raise(expr.start, (isBinding ? "Binding" : "Assigning to") + " rvalue"); + } +}; +},{"617":617,"629":629,"630":630}],620:[function(_dereq_,module,exports){ +"use strict"; + +exports.__esModule = true; +// istanbul ignore next + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } + +// istanbul ignore next + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var _index = _dereq_(617); + +var _index2 = _interopRequireDefault(_index); + +var _utilLocation = _dereq_(631); + +// Start an AST node, attaching a start offset. + +var pp = _index2["default"].prototype; + +var Node = (function () { + function Node(parser, pos, loc) { + _classCallCheck(this, Node); + + this.type = ""; + this.start = pos; + this.end = 0; + this.loc = new _utilLocation.SourceLocation(loc); + } + + Node.prototype.__clone = function __clone() { + var node2 = new Node(); + for (var key in this) node2[key] = this[key]; + return node2; + }; + + return Node; +})(); + +exports.Node = Node; + +pp.startNode = function () { + return new Node(this, this.state.start, this.state.startLoc); +}; + +pp.startNodeAt = function (pos, loc) { + return new Node(this, pos, loc); +}; + +function finishNodeAt(node, type, pos, loc) { + node.type = type; + node.end = pos; + node.loc.end = loc; + this.processComment(node); + return node; +} + +// Finish an AST node, adding `type` and `end` properties. + +pp.finishNode = function (node, type) { + return finishNodeAt.call(this, node, type, this.state.lastTokEnd, this.state.lastTokEndLoc); +}; + +// Finish node at given position + +pp.finishNodeAt = function (node, type, pos, loc) { + return finishNodeAt.call(this, node, type, pos, loc); +}; +},{"617":617,"631":631}],621:[function(_dereq_,module,exports){ +"use strict"; + +// istanbul ignore next + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } + +var _tokenizerTypes = _dereq_(629); + +var _index = _dereq_(617); + +var _index2 = _interopRequireDefault(_index); + +var _utilWhitespace = _dereq_(632); + +var pp = _index2["default"].prototype; + +// ### Statement parsing + +// Parse a program. Initializes the parser, reads any number of +// statements, and wraps them in a Program node. Optionally takes a +// `program` argument. If present, the statements will be appended +// to its body instead of creating a new node. + +pp.parseTopLevel = function (file, program) { + program.sourceType = this.options.sourceType; + program.body = []; + + var first = true; + while (!this.match(_tokenizerTypes.types.eof)) { + var stmt = this.parseStatement(true, true); + program.body.push(stmt); + if (first) { + if (this.isUseStrict(stmt)) this.setStrict(true); + first = false; + } + } + this.next(); + + file.program = this.finishNode(program, "Program"); + file.comments = this.state.comments; + file.tokens = this.state.tokens; + + return this.finishNode(file, "File"); +}; + +var loopLabel = { kind: "loop" }, + switchLabel = { kind: "switch" }; + +// Parse a single statement. +// +// If expecting a statement and finding a slash operator, parse a +// regular expression literal. This is to handle cases like +// `if (foo) /blah/.exec(foo)`, where looking at the previous token +// does not help. + +pp.parseStatement = function (declaration, topLevel) { + if (this.match(_tokenizerTypes.types.at)) { + this.parseDecorators(true); + } + + var starttype = this.state.type, + node = this.startNode(); + + // Most types of statements are recognized by the keyword they + // start with. Many are trivial to parse, some require a bit of + // complexity. + + switch (starttype) { + case _tokenizerTypes.types._break:case _tokenizerTypes.types._continue: + return this.parseBreakContinueStatement(node, starttype.keyword); + case _tokenizerTypes.types._debugger: + return this.parseDebuggerStatement(node); + case _tokenizerTypes.types._do: + return this.parseDoStatement(node); + case _tokenizerTypes.types._for: + return this.parseForStatement(node); + case _tokenizerTypes.types._function: + if (!declaration) this.unexpected(); + return this.parseFunctionStatement(node); + + case _tokenizerTypes.types._class: + if (!declaration) this.unexpected(); + this.takeDecorators(node); + return this.parseClass(node, true); + + case _tokenizerTypes.types._if: + return this.parseIfStatement(node); + case _tokenizerTypes.types._return: + return this.parseReturnStatement(node); + case _tokenizerTypes.types._switch: + return this.parseSwitchStatement(node); + case _tokenizerTypes.types._throw: + return this.parseThrowStatement(node); + case _tokenizerTypes.types._try: + return this.parseTryStatement(node); + case _tokenizerTypes.types._let:case _tokenizerTypes.types._const: + if (!declaration) this.unexpected(); // NOTE: falls through to _var + case _tokenizerTypes.types._var: + return this.parseVarStatement(node, starttype); + case _tokenizerTypes.types._while: + return this.parseWhileStatement(node); + case _tokenizerTypes.types._with: + return this.parseWithStatement(node); + case _tokenizerTypes.types.braceL: + return this.parseBlock(); + case _tokenizerTypes.types.semi: + return this.parseEmptyStatement(node); + case _tokenizerTypes.types._export: + case _tokenizerTypes.types._import: + if (!this.options.allowImportExportEverywhere) { + if (!topLevel) this.raise(this.state.start, "'import' and 'export' may only appear at the top level"); + + if (!this.inModule) this.raise(this.state.start, "'import' and 'export' may appear only with 'sourceType: module'"); + } + return starttype === _tokenizerTypes.types._import ? this.parseImport(node) : this.parseExport(node); + + case _tokenizerTypes.types.name: + if (this.options.features["es7.asyncFunctions"] && this.state.value === "async") { + // peek ahead and see if next token is a function + var state = this.state.clone(); + this.next(); + if (this.match(_tokenizerTypes.types._function) && !this.canInsertSemicolon()) { + this.expect(_tokenizerTypes.types._function); + return this.parseFunction(node, true, false, true); + } else { + this.state = state; + } + } + + // If the statement does not start with a statement keyword or a + // brace, it's an ExpressionStatement or LabeledStatement. We + // simply start parsing an expression, and afterwards, if the + // next token is a colon and the expression was a simple + // Identifier node, we switch to interpreting it as a label. + default: + var maybeName = this.state.value, + expr = this.parseExpression(); + + if (starttype === _tokenizerTypes.types.name && expr.type === "Identifier" && this.eat(_tokenizerTypes.types.colon)) { + return this.parseLabeledStatement(node, maybeName, expr); + } else { + return this.parseExpressionStatement(node, expr); + } + } +}; + +pp.takeDecorators = function (node) { + if (this.state.decorators.length) { + node.decorators = this.state.decorators; + this.state.decorators = []; + } +}; + +pp.parseDecorators = function (allowExport) { + while (this.match(_tokenizerTypes.types.at)) { + this.state.decorators.push(this.parseDecorator()); + } + + if (allowExport && this.match(_tokenizerTypes.types._export)) { + return; + } + + if (!this.match(_tokenizerTypes.types._class)) { + this.raise(this.state.start, "Leading decorators must be attached to a class declaration"); + } +}; + +pp.parseDecorator = function () { + if (!this.options.features["es7.decorators"]) { + this.unexpected(); + } + var node = this.startNode(); + this.next(); + node.expression = this.parseMaybeAssign(); + return this.finishNode(node, "Decorator"); +}; + +pp.parseBreakContinueStatement = function (node, keyword) { + var isBreak = keyword === "break"; + this.next(); + + if (this.eat(_tokenizerTypes.types.semi) || this.canInsertSemicolon()) { + node.label = null; + } else if (!this.match(_tokenizerTypes.types.name)) { + this.unexpected(); + } else { + node.label = this.parseIdent(); + this.semicolon(); + } + + // Verify that there is an actual destination to break or + // continue to. + for (var i = 0; i < this.state.labels.length; ++i) { + var lab = this.state.labels[i]; + if (node.label == null || lab.name === node.label.name) { + if (lab.kind != null && (isBreak || lab.kind === "loop")) break; + if (node.label && isBreak) break; + } + } + if (i === this.state.labels.length) this.raise(node.start, "Unsyntactic " + keyword); + return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement"); +}; + +pp.parseDebuggerStatement = function (node) { + this.next(); + this.semicolon(); + return this.finishNode(node, "DebuggerStatement"); +}; + +pp.parseDoStatement = function (node) { + this.next(); + this.state.labels.push(loopLabel); + node.body = this.parseStatement(false); + this.state.labels.pop(); + this.expect(_tokenizerTypes.types._while); + node.test = this.parseParenExpression(); + this.eat(_tokenizerTypes.types.semi); + return this.finishNode(node, "DoWhileStatement"); +}; + +// Disambiguating between a `for` and a `for`/`in` or `for`/`of` +// loop is non-trivial. Basically, we have to parse the init `var` +// statement or expression, disallowing the `in` operator (see +// the second parameter to `parseExpression`), and then check +// whether the next token is `in` or `of`. When there is no init +// part (semicolon immediately after the opening parenthesis), it +// is a regular `for` loop. + +pp.parseForStatement = function (node) { + this.next(); + this.state.labels.push(loopLabel); + this.expect(_tokenizerTypes.types.parenL); + + if (this.match(_tokenizerTypes.types.semi)) { + return this.parseFor(node, null); + } + + if (this.match(_tokenizerTypes.types._var) || this.match(_tokenizerTypes.types._let) || this.match(_tokenizerTypes.types._const)) { + var _init = this.startNode(), + varKind = this.state.type; + this.next(); + this.parseVar(_init, true, varKind); + this.finishNode(_init, "VariableDeclaration"); + if ((this.match(_tokenizerTypes.types._in) || this.isContextual("of")) && _init.declarations.length === 1 && !(varKind !== _tokenizerTypes.types._var && _init.declarations[0].init)) return this.parseForIn(node, _init); + return this.parseFor(node, _init); + } + + var refShorthandDefaultPos = { start: 0 }; + var init = this.parseExpression(true, refShorthandDefaultPos); + if (this.match(_tokenizerTypes.types._in) || this.isContextual("of")) { + this.toAssignable(init); + this.checkLVal(init); + return this.parseForIn(node, init); + } else if (refShorthandDefaultPos.start) { + this.unexpected(refShorthandDefaultPos.start); + } + return this.parseFor(node, init); +}; + +pp.parseFunctionStatement = function (node) { + this.next(); + return this.parseFunction(node, true); +}; + +pp.parseIfStatement = function (node) { + this.next(); + node.test = this.parseParenExpression(); + node.consequent = this.parseStatement(false); + node.alternate = this.eat(_tokenizerTypes.types._else) ? this.parseStatement(false) : null; + return this.finishNode(node, "IfStatement"); +}; + +pp.parseReturnStatement = function (node) { + if (!this.state.inFunction && !this.options.allowReturnOutsideFunction) { + this.raise(this.state.start, "'return' outside of function"); + } + + this.next(); + + // In `return` (and `break`/`continue`), the keywords with + // optional arguments, we eagerly look for a semicolon or the + // possibility to insert one. + + if (this.eat(_tokenizerTypes.types.semi) || this.canInsertSemicolon()) { + node.argument = null; + } else { + node.argument = this.parseExpression(); + this.semicolon(); + } + + return this.finishNode(node, "ReturnStatement"); +}; + +pp.parseSwitchStatement = function (node) { + this.next(); + node.discriminant = this.parseParenExpression(); + node.cases = []; + this.expect(_tokenizerTypes.types.braceL); + this.state.labels.push(switchLabel); + + // Statements under must be grouped (by label) in SwitchCase + // nodes. `cur` is used to keep the node that we are currently + // adding statements to. + + for (var cur, sawDefault; !this.match(_tokenizerTypes.types.braceR);) { + if (this.match(_tokenizerTypes.types._case) || this.match(_tokenizerTypes.types._default)) { + var isCase = this.match(_tokenizerTypes.types._case); + if (cur) this.finishNode(cur, "SwitchCase"); + node.cases.push(cur = this.startNode()); + cur.consequent = []; + this.next(); + if (isCase) { + cur.test = this.parseExpression(); + } else { + if (sawDefault) this.raise(this.state.lastTokStart, "Multiple default clauses"); + sawDefault = true; + cur.test = null; + } + this.expect(_tokenizerTypes.types.colon); + } else { + if (!cur) this.unexpected(); + cur.consequent.push(this.parseStatement(true)); + } + } + if (cur) this.finishNode(cur, "SwitchCase"); + this.next(); // Closing brace + this.state.labels.pop(); + return this.finishNode(node, "SwitchStatement"); +}; + +pp.parseThrowStatement = function (node) { + this.next(); + if (_utilWhitespace.lineBreak.test(this.input.slice(this.state.lastTokEnd, this.state.start))) this.raise(this.state.lastTokEnd, "Illegal newline after throw"); + node.argument = this.parseExpression(); + this.semicolon(); + return this.finishNode(node, "ThrowStatement"); +}; + +// Reused empty array added for node fields that are always empty. + +var empty = []; + +pp.parseTryStatement = function (node) { + this.next(); + node.block = this.parseBlock(); + node.handler = null; + if (this.match(_tokenizerTypes.types._catch)) { + var clause = this.startNode(); + this.next(); + this.expect(_tokenizerTypes.types.parenL); + clause.param = this.parseBindingAtom(); + this.checkLVal(clause.param, true); + this.expect(_tokenizerTypes.types.parenR); + clause.body = this.parseBlock(); + node.handler = this.finishNode(clause, "CatchClause"); + } + + node.guardedHandlers = empty; + node.finalizer = this.eat(_tokenizerTypes.types._finally) ? this.parseBlock() : null; + + if (!node.handler && !node.finalizer) { + this.raise(node.start, "Missing catch or finally clause"); + } + + return this.finishNode(node, "TryStatement"); +}; + +pp.parseVarStatement = function (node, kind) { + this.next(); + this.parseVar(node, false, kind); + this.semicolon(); + return this.finishNode(node, "VariableDeclaration"); +}; + +pp.parseWhileStatement = function (node) { + this.next(); + node.test = this.parseParenExpression(); + this.state.labels.push(loopLabel); + node.body = this.parseStatement(false); + this.state.labels.pop(); + return this.finishNode(node, "WhileStatement"); +}; + +pp.parseWithStatement = function (node) { + if (this.strict) this.raise(this.state.start, "'with' in strict mode"); + this.next(); + node.object = this.parseParenExpression(); + node.body = this.parseStatement(false); + return this.finishNode(node, "WithStatement"); +}; + +pp.parseEmptyStatement = function (node) { + this.next(); + return this.finishNode(node, "EmptyStatement"); +}; + +pp.parseLabeledStatement = function (node, maybeName, expr) { + var _arr = this.state.labels; + + for (var _i = 0; _i < _arr.length; _i++) { + var label = _arr[_i]; + if (label.name === maybeName) { + this.raise(expr.start, "Label '" + maybeName + "' is already declared"); + } + } + + var kind = this.state.type.isLoop ? "loop" : this.match(_tokenizerTypes.types._switch) ? "switch" : null; + for (var i = this.state.labels.length - 1; i >= 0; i--) { + var label = this.state.labels[i]; + if (label.statementStart === node.start) { + label.statementStart = this.state.start; + label.kind = kind; + } else { + break; + } + } + + this.state.labels.push({ name: maybeName, kind: kind, statementStart: this.state.start }); + node.body = this.parseStatement(true); + this.state.labels.pop(); + node.label = expr; + return this.finishNode(node, "LabeledStatement"); +}; + +pp.parseExpressionStatement = function (node, expr) { + node.expression = expr; + this.semicolon(); + return this.finishNode(node, "ExpressionStatement"); +}; + +// Parse a semicolon-enclosed block of statements, handling `"use +// strict"` declarations when `allowStrict` is true (used for +// function bodies). + +pp.parseBlock = function (allowStrict) { + var node = this.startNode(), + first = true, + oldStrict = undefined; + node.body = []; + this.expect(_tokenizerTypes.types.braceL); + while (!this.eat(_tokenizerTypes.types.braceR)) { + var stmt = this.parseStatement(true); + node.body.push(stmt); + if (first && allowStrict && this.isUseStrict(stmt)) { + oldStrict = this.strict; + this.setStrict(this.strict = true); + } + first = false; + } + if (oldStrict === false) this.setStrict(false); + return this.finishNode(node, "BlockStatement"); +}; + +// Parse a regular `for` loop. The disambiguation code in +// `parseStatement` will already have parsed the init statement or +// expression. + +pp.parseFor = function (node, init) { + node.init = init; + this.expect(_tokenizerTypes.types.semi); + node.test = this.match(_tokenizerTypes.types.semi) ? null : this.parseExpression(); + this.expect(_tokenizerTypes.types.semi); + node.update = this.match(_tokenizerTypes.types.parenR) ? null : this.parseExpression(); + this.expect(_tokenizerTypes.types.parenR); + node.body = this.parseStatement(false); + this.state.labels.pop(); + return this.finishNode(node, "ForStatement"); +}; + +// Parse a `for`/`in` and `for`/`of` loop, which are almost +// same from parser's perspective. + +pp.parseForIn = function (node, init) { + var type = this.match(_tokenizerTypes.types._in) ? "ForInStatement" : "ForOfStatement"; + this.next(); + node.left = init; + node.right = this.parseExpression(); + this.expect(_tokenizerTypes.types.parenR); + node.body = this.parseStatement(false); + this.state.labels.pop(); + return this.finishNode(node, type); +}; + +// Parse a list of variable declarations. + +pp.parseVar = function (node, isFor, kind) { + node.declarations = []; + node.kind = kind.keyword; + for (;;) { + var decl = this.startNode(); + this.parseVarHead(decl); + if (this.eat(_tokenizerTypes.types.eq)) { + decl.init = this.parseMaybeAssign(isFor); + } else if (kind === _tokenizerTypes.types._const && !(this.match(_tokenizerTypes.types._in) || this.isContextual("of"))) { + this.unexpected(); + } else if (decl.id.type !== "Identifier" && !(isFor && (this.match(_tokenizerTypes.types._in) || this.isContextual("of")))) { + this.raise(this.state.lastTokEnd, "Complex binding patterns require an initialization value"); + } else { + decl.init = null; + } + node.declarations.push(this.finishNode(decl, "VariableDeclarator")); + if (!this.eat(_tokenizerTypes.types.comma)) break; + } + return node; +}; + +pp.parseVarHead = function (decl) { + decl.id = this.parseBindingAtom(); + this.checkLVal(decl.id, true); +}; + +// Parse a function declaration or literal (depending on the +// `isStatement` parameter). + +pp.parseFunction = function (node, isStatement, allowExpressionBody, isAsync) { + this.initFunction(node, isAsync); + node.generator = this.eat(_tokenizerTypes.types.star); + + if (isStatement || this.match(_tokenizerTypes.types.name)) { + node.id = this.parseIdent(); + } + + this.parseFunctionParams(node); + this.parseFunctionBody(node, allowExpressionBody); + return this.finishNode(node, isStatement ? "FunctionDeclaration" : "FunctionExpression"); +}; + +pp.parseFunctionParams = function (node) { + this.expect(_tokenizerTypes.types.parenL); + node.params = this.parseBindingList(_tokenizerTypes.types.parenR, false, this.options.features["es7.trailingFunctionCommas"]); +}; + +// Parse a class declaration or literal (depending on the +// `isStatement` parameter). + +pp.parseClass = function (node, isStatement) { + this.next(); + this.parseClassId(node, isStatement); + this.parseClassSuper(node); + var classBody = this.startNode(); + var hadConstructor = false; + classBody.body = []; + this.expect(_tokenizerTypes.types.braceL); + var decorators = []; + while (!this.eat(_tokenizerTypes.types.braceR)) { + if (this.eat(_tokenizerTypes.types.semi)) continue; + if (this.match(_tokenizerTypes.types.at)) { + decorators.push(this.parseDecorator()); + continue; + } + var method = this.startNode(); + if (decorators.length) { + method.decorators = decorators; + decorators = []; + } + var isMaybeStatic = this.match(_tokenizerTypes.types.name) && this.state.value === "static"; + var isGenerator = this.eat(_tokenizerTypes.types.star), + isAsync = false; + this.parsePropertyName(method); + method["static"] = isMaybeStatic && !this.match(_tokenizerTypes.types.parenL); + if (method["static"]) { + if (isGenerator) this.unexpected(); + isGenerator = this.eat(_tokenizerTypes.types.star); + this.parsePropertyName(method); + } + if (!isGenerator && method.key.type === "Identifier" && !method.computed && this.isClassProperty()) { + classBody.body.push(this.parseClassProperty(method)); + continue; + } + if (this.options.features["es7.asyncFunctions"] && !this.match(_tokenizerTypes.types.parenL) && !method.computed && method.key.type === "Identifier" && method.key.name === "async") { + isAsync = true; + this.parsePropertyName(method); + } + var isGetSet = false; + method.kind = "method"; + if (!method.computed) { + var key = method.key; + + if (!isAsync && !isGenerator && key.type === "Identifier" && !this.match(_tokenizerTypes.types.parenL) && (key.name === "get" || key.name === "set")) { + isGetSet = true; + method.kind = key.name; + key = this.parsePropertyName(method); + } + if (!method["static"] && (key.type === "Identifier" && key.name === "constructor" || key.type === "Literal" && key.value === "constructor")) { + if (hadConstructor) this.raise(key.start, "Duplicate constructor in the same class"); + if (isGetSet) this.raise(key.start, "Constructor can't have get/set modifier"); + if (isGenerator) this.raise(key.start, "Constructor can't be a generator"); + if (isAsync) this.raise(key.start, "Constructor can't be an async function"); + method.kind = "constructor"; + hadConstructor = true; + } + } + if (method.kind === "constructor" && method.decorators) { + this.raise(method.start, "You can't attach decorators to a class constructor"); + } + this.parseClassMethod(classBody, method, isGenerator, isAsync); + if (isGetSet) { + var paramCount = method.kind === "get" ? 0 : 1; + if (method.value.params.length !== paramCount) { + var start = method.value.start; + if (method.kind === "get") { + this.raise(start, "getter should have no params"); + } else { + this.raise(start, "setter should have exactly one param"); + } + } + } + } + + if (decorators.length) { + this.raise(this.state.start, "You have trailing decorators with no method"); + } + + node.body = this.finishNode(classBody, "ClassBody"); + return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression"); +}; + +pp.isClassProperty = function () { + return this.match(_tokenizerTypes.types.eq) || this.match(_tokenizerTypes.types.semi) || this.canInsertSemicolon(); +}; + +pp.parseClassProperty = function (node) { + if (this.match(_tokenizerTypes.types.eq)) { + if (!this.options.features["es7.classProperties"]) this.unexpected(); + this.next(); + node.value = this.parseMaybeAssign(); + } else { + node.value = null; + } + this.semicolon(); + return this.finishNode(node, "ClassProperty"); +}; + +pp.parseClassMethod = function (classBody, method, isGenerator, isAsync) { + method.value = this.parseMethod(isGenerator, isAsync); + classBody.body.push(this.finishNode(method, "MethodDefinition")); +}; + +pp.parseClassId = function (node, isStatement) { + node.id = this.match(_tokenizerTypes.types.name) ? this.parseIdent() : isStatement ? this.unexpected() : null; +}; + +pp.parseClassSuper = function (node) { + node.superClass = this.eat(_tokenizerTypes.types._extends) ? this.parseExprSubscripts() : null; +}; + +// Parses module export declaration. + +pp.parseExport = function (node) { + this.next(); + // export * from '...' + if (this.match(_tokenizerTypes.types.star)) { + var specifier = this.startNode(); + this.next(); + if (this.options.features["es7.exportExtensions"] && this.eatContextual("as")) { + specifier.exported = this.parseIdent(); + node.specifiers = [this.finishNode(specifier, "ExportNamespaceSpecifier")]; + this.parseExportSpecifiersMaybe(node); + this.parseExportFrom(node, true); + } else { + this.parseExportFrom(node, true); + return this.finishNode(node, "ExportAllDeclaration"); + } + } else if (this.options.features["es7.exportExtensions"] && this.isExportDefaultSpecifier()) { + var specifier = this.startNode(); + specifier.exported = this.parseIdent(true); + node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")]; + if (this.match(_tokenizerTypes.types.comma) && this.lookahead().type === _tokenizerTypes.types.star) { + this.expect(_tokenizerTypes.types.comma); + var _specifier = this.startNode(); + this.expect(_tokenizerTypes.types.star); + this.expectContextual("as"); + _specifier.exported = this.parseIdent(); + node.specifiers.push(this.finishNode(_specifier, "ExportNamespaceSpecifier")); + } else { + this.parseExportSpecifiersMaybe(node); + } + this.parseExportFrom(node, true); + } else if (this.eat(_tokenizerTypes.types._default)) { + // export default ... + var possibleDeclaration = this.match(_tokenizerTypes.types._function) || this.match(_tokenizerTypes.types._class); + var expr = this.parseMaybeAssign(); + var needsSemi = true; + if (possibleDeclaration) { + needsSemi = false; + if (expr.id) { + expr.type = expr.type === "FunctionExpression" ? "FunctionDeclaration" : "ClassDeclaration"; + } + } + node.declaration = expr; + if (needsSemi) this.semicolon(); + this.checkExport(node); + return this.finishNode(node, "ExportDefaultDeclaration"); + } else if (this.state.type.keyword || this.shouldParseExportDeclaration()) { + node.specifiers = []; + node.source = null; + node.declaration = this.parseExportDeclaration(node); + } else { + // export { x, y as z } [from '...'] + node.declaration = null; + node.specifiers = this.parseExportSpecifiers(); + this.parseExportFrom(node); + } + this.checkExport(node); + return this.finishNode(node, "ExportNamedDeclaration"); +}; + +pp.parseExportDeclaration = function () { + return this.parseStatement(true); +}; + +pp.isExportDefaultSpecifier = function () { + if (this.match(_tokenizerTypes.types.name)) { + return this.state.value !== "type" && this.state.value !== "async" && this.state.value !== "interface"; + } + + if (!this.match(_tokenizerTypes.types._default)) { + return false; + } + + var lookahead = this.lookahead(); + return lookahead.type === _tokenizerTypes.types.comma || lookahead.type === _tokenizerTypes.types.name && lookahead.value === "from"; +}; + +pp.parseExportSpecifiersMaybe = function (node) { + if (this.eat(_tokenizerTypes.types.comma)) { + node.specifiers = node.specifiers.concat(this.parseExportSpecifiers()); + } +}; + +pp.parseExportFrom = function (node, expect) { + if (this.eatContextual("from")) { + node.source = this.match(_tokenizerTypes.types.string) ? this.parseExprAtom() : this.unexpected(); + this.checkExport(node); + } else { + if (expect) { + this.unexpected(); + } else { + node.source = null; + } + } + + this.semicolon(); +}; + +pp.shouldParseExportDeclaration = function () { + return this.options.features["es7.asyncFunctions"] && this.isContextual("async"); +}; + +pp.checkExport = function (node) { + if (this.state.decorators.length) { + var isClass = node.declaration && (node.declaration.type === "ClassDeclaration" || node.declaration.type === "ClassExpression"); + if (!node.declaration || !isClass) { + this.raise(node.start, "You can only use decorators on an export when exporting a class"); + } + this.takeDecorators(node.declaration); + } +}; + +// Parses a comma-separated list of module exports. + +pp.parseExportSpecifiers = function () { + var nodes = [], + first = true; + // export { x, y as z } [from '...'] + this.expect(_tokenizerTypes.types.braceL); + + while (!this.eat(_tokenizerTypes.types.braceR)) { + if (first) { + first = false; + } else { + this.expect(_tokenizerTypes.types.comma); + if (this.eat(_tokenizerTypes.types.braceR)) break; + } + + var node = this.startNode(); + node.local = this.parseIdent(this.match(_tokenizerTypes.types._default)); + node.exported = this.eatContextual("as") ? this.parseIdent(true) : node.local.__clone(); + nodes.push(this.finishNode(node, "ExportSpecifier")); + } + + return nodes; +}; + +// Parses import declaration. + +pp.parseImport = function (node) { + this.next(); + + // import '...' + if (this.match(_tokenizerTypes.types.string)) { + node.specifiers = []; + node.source = this.parseExprAtom(); + } else { + node.specifiers = []; + this.parseImportSpecifiers(node); + this.expectContextual("from"); + node.source = this.match(_tokenizerTypes.types.string) ? this.parseExprAtom() : this.unexpected(); + } + this.semicolon(); + return this.finishNode(node, "ImportDeclaration"); +}; + +// Parses a comma-separated list of module imports. + +pp.parseImportSpecifiers = function (node) { + var first = true; + if (this.match(_tokenizerTypes.types.name)) { + // import defaultObj, { x, y as z } from '...' + var startPos = this.state.start, + startLoc = this.state.startLoc; + node.specifiers.push(this.parseImportSpecifierDefault(this.parseIdent(), startPos, startLoc)); + if (!this.eat(_tokenizerTypes.types.comma)) return; + } + + if (this.match(_tokenizerTypes.types.star)) { + var specifier = this.startNode(); + this.next(); + this.expectContextual("as"); + specifier.local = this.parseIdent(); + this.checkLVal(specifier.local, true); + node.specifiers.push(this.finishNode(specifier, "ImportNamespaceSpecifier")); + return; + } + + this.expect(_tokenizerTypes.types.braceL); + while (!this.eat(_tokenizerTypes.types.braceR)) { + if (first) { + first = false; + } else { + this.expect(_tokenizerTypes.types.comma); + if (this.eat(_tokenizerTypes.types.braceR)) break; + } + + var specifier = this.startNode(); + specifier.imported = this.parseIdent(true); + specifier.local = this.eatContextual("as") ? this.parseIdent() : specifier.imported.__clone(); + this.checkLVal(specifier.local, true); + node.specifiers.push(this.finishNode(specifier, "ImportSpecifier")); + } +}; + +pp.parseImportSpecifierDefault = function (id, startPos, startLoc) { + var node = this.startNodeAt(startPos, startLoc); + node.local = id; + this.checkLVal(node.local, true); + return this.finishNode(node, "ImportDefaultSpecifier"); +}; +},{"617":617,"629":629,"632":632}],622:[function(_dereq_,module,exports){ +"use strict"; + +// istanbul ignore next + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } + +var _tokenizerTypes = _dereq_(629); + +var _index = _dereq_(617); + +var _index2 = _interopRequireDefault(_index); + +var _utilWhitespace = _dereq_(632); + +var pp = _index2["default"].prototype; + +// ## Parser utilities + +// Test whether a statement node is the string literal `"use strict"`. + +pp.isUseStrict = function (stmt) { + return stmt.type === "ExpressionStatement" && stmt.expression.type === "Literal" && stmt.expression.raw.slice(1, -1) === "use strict"; +}; + +// TODO + +pp.isRelational = function (op) { + return this.match(_tokenizerTypes.types.relational) && this.state.value === op; +}; + +// TODO + +pp.expectRelational = function (op) { + if (this.isRelational(op)) { + this.next(); + } else { + this.unexpected(); + } +}; + +// Tests whether parsed token is a contextual keyword. + +pp.isContextual = function (name) { + return this.match(_tokenizerTypes.types.name) && this.state.value === name; +}; + +// Consumes contextual keyword if possible. + +pp.eatContextual = function (name) { + return this.state.value === name && this.eat(_tokenizerTypes.types.name); +}; + +// Asserts that following token is given contextual keyword. + +pp.expectContextual = function (name) { + if (!this.eatContextual(name)) this.unexpected(); +}; + +// Test whether a semicolon can be inserted at the current position. + +pp.canInsertSemicolon = function () { + return this.match(_tokenizerTypes.types.eof) || this.match(_tokenizerTypes.types.braceR) || _utilWhitespace.lineBreak.test(this.input.slice(this.state.lastTokEnd, this.state.start)); +}; + +// Consume a semicolon, or, failing that, see if we are allowed to +// pretend that there is a semicolon at this position. + +pp.semicolon = function () { + if (!this.eat(_tokenizerTypes.types.semi) && !this.canInsertSemicolon()) this.unexpected(); +}; + +// Expect a token of a given type. If found, consume it, otherwise, +// raise an unexpected token error. + +pp.expect = function (type) { + return this.eat(type) || this.unexpected(); +}; + +// Raise an unexpected token error. + +pp.unexpected = function (pos) { + this.raise(pos != null ? pos : this.state.start, "Unexpected token"); +}; +},{"617":617,"629":629,"632":632}],623:[function(_dereq_,module,exports){ +"use strict"; + +exports.__esModule = true; +// istanbul ignore next + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } + +var _tokenizerTypes = _dereq_(629); + +var _parser = _dereq_(617); + +var _parser2 = _interopRequireDefault(_parser); + +var pp = _parser2["default"].prototype; + +pp.flowParseTypeInitialiser = function (tok) { + var oldInType = this.state.inType; + this.state.inType = true; + this.expect(tok || _tokenizerTypes.types.colon); + var type = this.flowParseType(); + this.state.inType = oldInType; + return type; +}; + +pp.flowParseDeclareClass = function (node) { + this.next(); + this.flowParseInterfaceish(node, true); + return this.finishNode(node, "DeclareClass"); +}; + +pp.flowParseDeclareFunction = function (node) { + this.next(); + + var id = node.id = this.parseIdent(); + + var typeNode = this.startNode(); + var typeContainer = this.startNode(); + + if (this.isRelational("<")) { + typeNode.typeParameters = this.flowParseTypeParameterDeclaration(); + } else { + typeNode.typeParameters = null; + } + + this.expect(_tokenizerTypes.types.parenL); + var tmp = this.flowParseFunctionTypeParams(); + typeNode.params = tmp.params; + typeNode.rest = tmp.rest; + this.expect(_tokenizerTypes.types.parenR); + typeNode.returnType = this.flowParseTypeInitialiser(); + + typeContainer.typeAnnotation = this.finishNode(typeNode, "FunctionTypeAnnotation"); + id.typeAnnotation = this.finishNode(typeContainer, "TypeAnnotation"); + + this.finishNode(id, id.type); + + this.semicolon(); + + return this.finishNode(node, "DeclareFunction"); +}; + +pp.flowParseDeclare = function (node) { + if (this.match(_tokenizerTypes.types._class)) { + return this.flowParseDeclareClass(node); + } else if (this.match(_tokenizerTypes.types._function)) { + return this.flowParseDeclareFunction(node); + } else if (this.match(_tokenizerTypes.types._var)) { + return this.flowParseDeclareVariable(node); + } else if (this.isContextual("module")) { + return this.flowParseDeclareModule(node); + } else if (this.isContextual("type")) { + return this.flowParseDeclareTypeAlias(node); + } else if (this.isContextual("interface")) { + return this.flowParseDeclareInterface(node); + } else { + this.unexpected(); + } +}; + +pp.flowParseDeclareVariable = function (node) { + this.next(); + node.id = this.flowParseTypeAnnotatableIdentifier(); + this.semicolon(); + return this.finishNode(node, "DeclareVariable"); +}; + +pp.flowParseDeclareModule = function (node) { + this.next(); + + if (this.match(_tokenizerTypes.types.string)) { + node.id = this.parseExprAtom(); + } else { + node.id = this.parseIdent(); + } + + var bodyNode = node.body = this.startNode(); + var body = bodyNode.body = []; + this.expect(_tokenizerTypes.types.braceL); + while (!this.match(_tokenizerTypes.types.braceR)) { + var node2 = this.startNode(); + + // todo: declare check + this.next(); + + body.push(this.flowParseDeclare(node2)); + } + this.expect(_tokenizerTypes.types.braceR); + + this.finishNode(bodyNode, "BlockStatement"); + return this.finishNode(node, "DeclareModule"); +}; + +pp.flowParseDeclareTypeAlias = function (node) { + this.next(); + this.flowParseTypeAlias(node); + return this.finishNode(node, "DeclareTypeAlias"); +}; + +pp.flowParseDeclareInterface = function (node) { + this.next(); + this.flowParseInterfaceish(node); + return this.finishNode(node, "DeclareInterface"); +}; + +// Interfaces + +pp.flowParseInterfaceish = function (node, allowStatic) { + node.id = this.parseIdent(); + + if (this.isRelational("<")) { + node.typeParameters = this.flowParseTypeParameterDeclaration(); + } else { + node.typeParameters = null; + } + + node["extends"] = []; + node.mixins = []; + + if (this.eat(_tokenizerTypes.types._extends)) { + do { + node["extends"].push(this.flowParseInterfaceExtends()); + } while (this.eat(_tokenizerTypes.types.comma)); + } + + if (this.isContextual("mixins")) { + this.next(); + do { + node.mixins.push(this.flowParseInterfaceExtends()); + } while (this.eat(_tokenizerTypes.types.comma)); + } + + node.body = this.flowParseObjectType(allowStatic); +}; + +pp.flowParseInterfaceExtends = function () { + var node = this.startNode(); + + node.id = this.parseIdent(); + if (this.isRelational("<")) { + node.typeParameters = this.flowParseTypeParameterInstantiation(); + } else { + node.typeParameters = null; + } + + return this.finishNode(node, "InterfaceExtends"); +}; + +pp.flowParseInterface = function (node) { + this.flowParseInterfaceish(node, false); + return this.finishNode(node, "InterfaceDeclaration"); +}; + +// Type aliases + +pp.flowParseTypeAlias = function (node) { + node.id = this.parseIdent(); + + if (this.isRelational("<")) { + node.typeParameters = this.flowParseTypeParameterDeclaration(); + } else { + node.typeParameters = null; + } + + node.right = this.flowParseTypeInitialiser(_tokenizerTypes.types.eq); + this.semicolon(); + + return this.finishNode(node, "TypeAlias"); +}; + +// Type annotations + +pp.flowParseTypeParameterDeclaration = function () { + var node = this.startNode(); + node.params = []; + + this.expectRelational("<"); + while (!this.isRelational(">")) { + node.params.push(this.flowParseTypeAnnotatableIdentifier()); + if (!this.isRelational(">")) { + this.expect(_tokenizerTypes.types.comma); + } + } + this.expectRelational(">"); + + return this.finishNode(node, "TypeParameterDeclaration"); +}; + +pp.flowParseTypeParameterInstantiation = function () { + var node = this.startNode(), + oldInType = this.state.inType; + node.params = []; + + this.state.inType = true; + + this.expectRelational("<"); + while (!this.isRelational(">")) { + node.params.push(this.flowParseType()); + if (!this.isRelational(">")) { + this.expect(_tokenizerTypes.types.comma); + } + } + this.expectRelational(">"); + + this.state.inType = oldInType; + + return this.finishNode(node, "TypeParameterInstantiation"); +}; + +pp.flowParseObjectPropertyKey = function () { + return this.match(_tokenizerTypes.types.num) || this.match(_tokenizerTypes.types.string) ? this.parseExprAtom() : this.parseIdent(true); +}; + +pp.flowParseObjectTypeIndexer = function (node, isStatic) { + node["static"] = isStatic; + + this.expect(_tokenizerTypes.types.bracketL); + node.id = this.flowParseObjectPropertyKey(); + node.key = this.flowParseTypeInitialiser(); + this.expect(_tokenizerTypes.types.bracketR); + node.value = this.flowParseTypeInitialiser(); + + this.flowObjectTypeSemicolon(); + return this.finishNode(node, "ObjectTypeIndexer"); +}; + +pp.flowParseObjectTypeMethodish = function (node) { + node.params = []; + node.rest = null; + node.typeParameters = null; + + if (this.isRelational("<")) { + node.typeParameters = this.flowParseTypeParameterDeclaration(); + } + + this.expect(_tokenizerTypes.types.parenL); + while (this.match(_tokenizerTypes.types.name)) { + node.params.push(this.flowParseFunctionTypeParam()); + if (!this.match(_tokenizerTypes.types.parenR)) { + this.expect(_tokenizerTypes.types.comma); + } + } + + if (this.eat(_tokenizerTypes.types.ellipsis)) { + node.rest = this.flowParseFunctionTypeParam(); + } + this.expect(_tokenizerTypes.types.parenR); + node.returnType = this.flowParseTypeInitialiser(); + + return this.finishNode(node, "FunctionTypeAnnotation"); +}; + +pp.flowParseObjectTypeMethod = function (startPos, startLoc, isStatic, key) { + var node = this.startNodeAt(startPos, startLoc); + node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(startPos, startLoc)); + node["static"] = isStatic; + node.key = key; + node.optional = false; + this.flowObjectTypeSemicolon(); + return this.finishNode(node, "ObjectTypeProperty"); +}; + +pp.flowParseObjectTypeCallProperty = function (node, isStatic) { + var valueNode = this.startNode(); + node["static"] = isStatic; + node.value = this.flowParseObjectTypeMethodish(valueNode); + this.flowObjectTypeSemicolon(); + return this.finishNode(node, "ObjectTypeCallProperty"); +}; + +pp.flowParseObjectType = function (allowStatic) { + var nodeStart = this.startNode(); + var node; + var propertyKey; + var isStatic; + + nodeStart.callProperties = []; + nodeStart.properties = []; + nodeStart.indexers = []; + + this.expect(_tokenizerTypes.types.braceL); + + while (!this.match(_tokenizerTypes.types.braceR)) { + var optional = false; + var startPos = this.state.start, + startLoc = this.state.startLoc; + node = this.startNode(); + if (allowStatic && this.isContextual("static")) { + this.next(); + isStatic = true; + } + + if (this.match(_tokenizerTypes.types.bracketL)) { + nodeStart.indexers.push(this.flowParseObjectTypeIndexer(node, isStatic)); + } else if (this.match(_tokenizerTypes.types.parenL) || this.isRelational("<")) { + nodeStart.callProperties.push(this.flowParseObjectTypeCallProperty(node, allowStatic)); + } else { + if (isStatic && this.match(_tokenizerTypes.types.colon)) { + propertyKey = this.parseIdent(); + } else { + propertyKey = this.flowParseObjectPropertyKey(); + } + if (this.isRelational("<") || this.match(_tokenizerTypes.types.parenL)) { + // This is a method property + nodeStart.properties.push(this.flowParseObjectTypeMethod(startPos, startLoc, isStatic, propertyKey)); + } else { + if (this.eat(_tokenizerTypes.types.question)) { + optional = true; + } + node.key = propertyKey; + node.value = this.flowParseTypeInitialiser(); + node.optional = optional; + node["static"] = isStatic; + this.flowObjectTypeSemicolon(); + nodeStart.properties.push(this.finishNode(node, "ObjectTypeProperty")); + } + } + } + + this.expect(_tokenizerTypes.types.braceR); + + return this.finishNode(nodeStart, "ObjectTypeAnnotation"); +}; + +pp.flowObjectTypeSemicolon = function () { + if (!this.eat(_tokenizerTypes.types.semi) && !this.eat(_tokenizerTypes.types.comma) && !this.match(_tokenizerTypes.types.braceR)) { + this.unexpected(); + } +}; + +pp.flowParseGenericType = function (startPos, startLoc, id) { + var node = this.startNodeAt(startPos, startLoc); + + node.typeParameters = null; + node.id = id; + + while (this.eat(_tokenizerTypes.types.dot)) { + var node2 = this.startNodeAt(startPos, startLoc); + node2.qualification = node.id; + node2.id = this.parseIdent(); + node.id = this.finishNode(node2, "QualifiedTypeIdentifier"); + } + + if (this.isRelational("<")) { + node.typeParameters = this.flowParseTypeParameterInstantiation(); + } + + return this.finishNode(node, "GenericTypeAnnotation"); +}; + +pp.flowParseTypeofType = function () { + var node = this.startNode(); + this.expect(_tokenizerTypes.types._typeof); + node.argument = this.flowParsePrimaryType(); + return this.finishNode(node, "TypeofTypeAnnotation"); +}; + +pp.flowParseTupleType = function () { + var node = this.startNode(); + node.types = []; + this.expect(_tokenizerTypes.types.bracketL); + // We allow trailing commas + while (this.state.pos < this.input.length && !this.match(_tokenizerTypes.types.bracketR)) { + node.types.push(this.flowParseType()); + if (this.match(_tokenizerTypes.types.bracketR)) break; + this.expect(_tokenizerTypes.types.comma); + } + this.expect(_tokenizerTypes.types.bracketR); + return this.finishNode(node, "TupleTypeAnnotation"); +}; + +pp.flowParseFunctionTypeParam = function () { + var optional = false; + var node = this.startNode(); + node.name = this.parseIdent(); + if (this.eat(_tokenizerTypes.types.question)) { + optional = true; + } + node.optional = optional; + node.typeAnnotation = this.flowParseTypeInitialiser(); + return this.finishNode(node, "FunctionTypeParam"); +}; + +pp.flowParseFunctionTypeParams = function () { + var ret = { params: [], rest: null }; + while (this.match(_tokenizerTypes.types.name)) { + ret.params.push(this.flowParseFunctionTypeParam()); + if (!this.match(_tokenizerTypes.types.parenR)) { + this.expect(_tokenizerTypes.types.comma); + } + } + if (this.eat(_tokenizerTypes.types.ellipsis)) { + ret.rest = this.flowParseFunctionTypeParam(); + } + return ret; +}; + +pp.flowIdentToTypeAnnotation = function (startPos, startLoc, node, id) { + switch (id.name) { + case "any": + return this.finishNode(node, "AnyTypeAnnotation"); + + case "void": + return this.finishNode(node, "VoidTypeAnnotation"); + + case "bool": + case "boolean": + return this.finishNode(node, "BooleanTypeAnnotation"); + + case "mixed": + return this.finishNode(node, "MixedTypeAnnotation"); + + case "number": + return this.finishNode(node, "NumberTypeAnnotation"); + + case "string": + return this.finishNode(node, "StringTypeAnnotation"); + + default: + return this.flowParseGenericType(startPos, startLoc, id); + } +}; + +// The parsing of types roughly parallels the parsing of expressions, and +// primary types are kind of like primary expressions...they're the +// primitives with which other types are constructed. +pp.flowParsePrimaryType = function () { + var startPos = this.state.start, + startLoc = this.state.startLoc; + var node = this.startNode(); + var tmp; + var type; + var isGroupedType = false; + + switch (this.state.type) { + case _tokenizerTypes.types.name: + return this.flowIdentToTypeAnnotation(startPos, startLoc, node, this.parseIdent()); + + case _tokenizerTypes.types.braceL: + return this.flowParseObjectType(); + + case _tokenizerTypes.types.bracketL: + return this.flowParseTupleType(); + + case _tokenizerTypes.types.relational: + if (this.state.value === "<") { + node.typeParameters = this.flowParseTypeParameterDeclaration(); + this.expect(_tokenizerTypes.types.parenL); + tmp = this.flowParseFunctionTypeParams(); + node.params = tmp.params; + node.rest = tmp.rest; + this.expect(_tokenizerTypes.types.parenR); + + this.expect(_tokenizerTypes.types.arrow); + + node.returnType = this.flowParseType(); + + return this.finishNode(node, "FunctionTypeAnnotation"); + } + + case _tokenizerTypes.types.parenL: + this.next(); + + // Check to see if this is actually a grouped type + if (!this.match(_tokenizerTypes.types.parenR) && !this.match(_tokenizerTypes.types.ellipsis)) { + if (this.match(_tokenizerTypes.types.name)) { + var token = this.lookahead().type; + isGroupedType = token !== _tokenizerTypes.types.question && token !== _tokenizerTypes.types.colon; + } else { + isGroupedType = true; + } + } + + if (isGroupedType) { + type = this.flowParseType(); + this.expect(_tokenizerTypes.types.parenR); + + // If we see a => next then someone was probably confused about + // function types, so we can provide a better error message + if (this.eat(_tokenizerTypes.types.arrow)) { + this.raise(node, "Unexpected token =>. It looks like " + "you are trying to write a function type, but you ended up " + "writing a grouped type followed by an =>, which is a syntax " + "error. Remember, function type parameters are named so function " + "types look like (name1: type1, name2: type2) => returnType. You " + "probably wrote (type1) => returnType"); + } + + return type; + } + + tmp = this.flowParseFunctionTypeParams(); + node.params = tmp.params; + node.rest = tmp.rest; + + this.expect(_tokenizerTypes.types.parenR); + + this.expect(_tokenizerTypes.types.arrow); + + node.returnType = this.flowParseType(); + node.typeParameters = null; + + return this.finishNode(node, "FunctionTypeAnnotation"); + + case _tokenizerTypes.types.string: + node.rawValue = node.value = this.state.value; + node.raw = this.input.slice(this.state.start, this.state.end); + this.next(); + return this.finishNode(node, "StringLiteralTypeAnnotation"); + + case _tokenizerTypes.types._true:case _tokenizerTypes.types._false: + node.value = this.match(_tokenizerTypes.types._true); + this.next(); + return this.finishNode(node, "BooleanLiteralTypeAnnotation"); + + case _tokenizerTypes.types.num: + node.rawValue = node.value = this.state.value; + node.raw = this.input.slice(this.state.start, this.state.end); + this.next(); + return this.finishNode(node, "NumberLiteralTypeAnnotation"); + + case _tokenizerTypes.types._null: + node.value = this.match(_tokenizerTypes.types._null); + this.next(); + return this.finishNode(node, "NullLiteralTypeAnnotation"); + + case _tokenizerTypes.types._this: + node.value = this.match(_tokenizerTypes.types._this); + this.next(); + return this.finishNode(node, "ThisTypeAnnotation"); + + default: + if (this.state.type.keyword === "typeof") { + return this.flowParseTypeofType(); + } + } + + this.unexpected(); +}; + +pp.flowParsePostfixType = function () { + var node = this.startNode(); + var type = node.elementType = this.flowParsePrimaryType(); + if (this.match(_tokenizerTypes.types.bracketL)) { + this.expect(_tokenizerTypes.types.bracketL); + this.expect(_tokenizerTypes.types.bracketR); + return this.finishNode(node, "ArrayTypeAnnotation"); + } else { + return type; + } +}; + +pp.flowParsePrefixType = function () { + var node = this.startNode(); + if (this.eat(_tokenizerTypes.types.question)) { + node.typeAnnotation = this.flowParsePrefixType(); + return this.finishNode(node, "NullableTypeAnnotation"); + } else { + return this.flowParsePostfixType(); + } +}; + +pp.flowParseIntersectionType = function () { + var node = this.startNode(); + var type = this.flowParsePrefixType(); + node.types = [type]; + while (this.eat(_tokenizerTypes.types.bitwiseAND)) { + node.types.push(this.flowParsePrefixType()); + } + return node.types.length === 1 ? type : this.finishNode(node, "IntersectionTypeAnnotation"); +}; + +pp.flowParseUnionType = function () { + var node = this.startNode(); + var type = this.flowParseIntersectionType(); + node.types = [type]; + while (this.eat(_tokenizerTypes.types.bitwiseOR)) { + node.types.push(this.flowParseIntersectionType()); + } + return node.types.length === 1 ? type : this.finishNode(node, "UnionTypeAnnotation"); +}; + +pp.flowParseType = function () { + var oldInType = this.state.inType; + this.state.inType = true; + var type = this.flowParseUnionType(); + this.state.inType = oldInType; + return type; +}; + +pp.flowParseTypeAnnotation = function () { + var node = this.startNode(); + node.typeAnnotation = this.flowParseTypeInitialiser(); + return this.finishNode(node, "TypeAnnotation"); +}; + +pp.flowParseTypeAnnotatableIdentifier = function (requireTypeAnnotation, canBeOptionalParam) { + var ident = this.parseIdent(); + var isOptionalParam = false; + + if (canBeOptionalParam && this.eat(_tokenizerTypes.types.question)) { + this.expect(_tokenizerTypes.types.question); + isOptionalParam = true; + } + + if (requireTypeAnnotation || this.match(_tokenizerTypes.types.colon)) { + ident.typeAnnotation = this.flowParseTypeAnnotation(); + this.finishNode(ident, ident.type); + } + + if (isOptionalParam) { + ident.optional = true; + this.finishNode(ident, ident.type); + } + + return ident; +}; + +exports["default"] = function (instance) { + // function name(): string {} + instance.extend("parseFunctionBody", function (inner) { + return function (node, allowExpression) { + if (this.match(_tokenizerTypes.types.colon) && !allowExpression) { + // if allowExpression is true then we're parsing an arrow function and if + // there's a return type then it's been handled elsewhere + node.returnType = this.flowParseTypeAnnotation(); + } + + return inner.call(this, node, allowExpression); + }; + }); + + instance.extend("parseStatement", function (inner) { + return function (declaration, topLevel) { + // strict mode handling of `interface` since it's a reserved word + if (this.strict && this.match(_tokenizerTypes.types.name) && this.state.value === "interface") { + var node = this.startNode(); + this.next(); + return this.flowParseInterface(node); + } else { + return inner.call(this, declaration, topLevel); + } + }; + }); + + instance.extend("parseExpressionStatement", function (inner) { + return function (node, expr) { + if (expr.type === "Identifier") { + if (expr.name === "declare") { + if (this.match(_tokenizerTypes.types._class) || this.match(_tokenizerTypes.types.name) || this.match(_tokenizerTypes.types._function) || this.match(_tokenizerTypes.types._var)) { + return this.flowParseDeclare(node); + } + } else if (this.match(_tokenizerTypes.types.name)) { + if (expr.name === "interface") { + return this.flowParseInterface(node); + } else if (expr.name === "type") { + return this.flowParseTypeAlias(node); + } + } + } + + return inner.call(this, node, expr); + }; + }); + + instance.extend("shouldParseExportDeclaration", function (inner) { + return function () { + return this.isContextual("type") || this.isContextual("interface") || inner.call(this); + }; + }); + + instance.extend("parseParenItem", function () { + return function (node, startLoc, startPos, forceArrow) { + if (this.match(_tokenizerTypes.types.colon)) { + var typeCastNode = this.startNodeAt(startLoc, startPos); + typeCastNode.expression = node; + typeCastNode.typeAnnotation = this.flowParseTypeAnnotation(); + + if (forceArrow && !this.match(_tokenizerTypes.types.arrow)) { + this.unexpected(); + } + + if (this.eat(_tokenizerTypes.types.arrow)) { + // ((lol): number => {}); + var func = this.parseArrowExpression(this.startNodeAt(startLoc, startPos), [node]); + func.returnType = typeCastNode.typeAnnotation; + return func; + } else { + return this.finishNode(typeCastNode, "TypeCastExpression"); + } + } else { + return node; + } + }; + }); + + instance.extend("parseExport", function (inner) { + return function (node) { + node = inner.call(this, node); + if (node.type === "ExportNamedDeclaration") { + node.exportKind = node.exportKind || "value"; + } + return node; + }; + }); + + instance.extend("parseExportDeclaration", function (inner) { + return function (node) { + if (this.isContextual("type")) { + node.exportKind = "type"; + + var declarationNode = this.startNode(); + this.next(); + + if (this.match(_tokenizerTypes.types.braceL)) { + // export type { foo, bar }; + node.specifiers = this.parseExportSpecifiers(); + this.parseExportFrom(node); + return null; + } else { + // export type Foo = Bar; + return this.flowParseTypeAlias(declarationNode); + } + } else if (this.isContextual("interface")) { + node.exportKind = "type"; + var _declarationNode = this.startNode(); + this.next(); + return this.flowParseInterface(_declarationNode); + } else { + return inner.call(this, node); + } + }; + }); + + instance.extend("parseClassId", function (inner) { + return function (node, isStatement) { + inner.call(this, node, isStatement); + if (this.isRelational("<")) { + node.typeParameters = this.flowParseTypeParameterDeclaration(); + } + }; + }); + + // don't consider `void` to be a keyword as then it'll use the void token type + // and set startExpr + instance.extend("isKeyword", function (inner) { + return function (name) { + if (this.state.inType && name === "void") { + return false; + } else { + return inner.call(this, name); + } + }; + }); + + instance.extend("readToken", function (inner) { + return function (code) { + if (this.state.inType && (code === 62 || code === 60)) { + return this.finishOp(_tokenizerTypes.types.relational, 1); + } else { + return inner.call(this, code); + } + }; + }); + + instance.extend("jsx_readToken", function (inner) { + return function () { + if (!this.state.inType) return inner.call(this); + }; + }); + + function typeCastToParameter(node) { + node.expression.typeAnnotation = node.typeAnnotation; + return node.expression; + } + + instance.extend("toAssignableList", function (inner) { + return function (exprList, isBinding) { + for (var i = 0; i < exprList.length; i++) { + var expr = exprList[i]; + if (expr && expr.type === "TypeCastExpression") { + exprList[i] = typeCastToParameter(expr); + } + } + return inner.call(this, exprList, isBinding); + }; + }); + + instance.extend("toReferencedList", function () { + return function (exprList) { + for (var i = 0; i < exprList.length; i++) { + var expr = exprList[i]; + if (expr && expr._exprListItem && expr.type === "TypeCastExpression") { + this.raise(expr.start, "Unexpected type cast"); + } + } + + return exprList; + }; + }); + + instance.extend("parseExprListItem", function (inner) { + return function (allowEmpty, refShorthandDefaultPos) { + var container = this.startNode(); + var node = inner.call(this, allowEmpty, refShorthandDefaultPos); + if (this.match(_tokenizerTypes.types.colon)) { + container._exprListItem = true; + container.expression = node; + container.typeAnnotation = this.flowParseTypeAnnotation(); + return this.finishNode(container, "TypeCastExpression"); + } else { + return node; + } + }; + }); + + instance.extend("parseClassProperty", function (inner) { + return function (node) { + if (this.match(_tokenizerTypes.types.colon)) { + node.typeAnnotation = this.flowParseTypeAnnotation(); + } + return inner.call(this, node); + }; + }); + + instance.extend("isClassProperty", function (inner) { + return function () { + return this.match(_tokenizerTypes.types.colon) || inner.call(this); + }; + }); + + instance.extend("parseClassMethod", function () { + return function (classBody, method, isGenerator, isAsync) { + var typeParameters; + if (this.isRelational("<")) { + typeParameters = this.flowParseTypeParameterDeclaration(); + } + method.value = this.parseMethod(isGenerator, isAsync); + method.value.typeParameters = typeParameters; + classBody.body.push(this.finishNode(method, "MethodDefinition")); + }; + }); + + instance.extend("parseClassSuper", function (inner) { + return function (node, isStatement) { + inner.call(this, node, isStatement); + if (node.superClass && this.isRelational("<")) { + node.superTypeParameters = this.flowParseTypeParameterInstantiation(); + } + if (this.isContextual("implements")) { + this.next(); + var implemented = node["implements"] = []; + do { + var _node = this.startNode(); + _node.id = this.parseIdent(); + if (this.isRelational("<")) { + _node.typeParameters = this.flowParseTypeParameterInstantiation(); + } else { + _node.typeParameters = null; + } + implemented.push(this.finishNode(_node, "ClassImplements")); + } while (this.eat(_tokenizerTypes.types.comma)); + } + }; + }); + + instance.extend("parseObjPropValue", function (inner) { + return function (prop) { + var typeParameters; + + // method shorthand + if (this.isRelational("<")) { + typeParameters = this.flowParseTypeParameterDeclaration(); + if (!this.match(_tokenizerTypes.types.parenL)) this.unexpected(); + } + + inner.apply(this, arguments); + + // add typeParameters if we found them + if (typeParameters) { + prop.value.typeParameters = typeParameters; + } + }; + }); + + instance.extend("parseAssignableListItemTypes", function () { + return function (param) { + if (this.eat(_tokenizerTypes.types.question)) { + param.optional = true; + } + if (this.match(_tokenizerTypes.types.colon)) { + param.typeAnnotation = this.flowParseTypeAnnotation(); + } + this.finishNode(param, param.type); + return param; + }; + }); + + instance.extend("parseImportSpecifiers", function (inner) { + return function (node) { + node.importKind = "value"; + + var kind = this.match(_tokenizerTypes.types._typeof) ? "typeof" : this.isContextual("type") ? "type" : null; + if (kind) { + var lh = this.lookahead(); + if (lh.type === _tokenizerTypes.types.name && lh.value !== "from" || lh.type === _tokenizerTypes.types.braceL || lh.type === _tokenizerTypes.types.star) { + this.next(); + node.importKind = kind; + } + } + + inner.call(this, node); + }; + }); + + // function foo() {} + instance.extend("parseFunctionParams", function (inner) { + return function (node) { + if (this.isRelational("<")) { + node.typeParameters = this.flowParseTypeParameterDeclaration(); + } + inner.call(this, node); + }; + }); + + // var foo: string = bar + instance.extend("parseVarHead", function (inner) { + return function (decl) { + inner.call(this, decl); + if (this.match(_tokenizerTypes.types.colon)) { + decl.id.typeAnnotation = this.flowParseTypeAnnotation(); + this.finishNode(decl.id, decl.id.type); + } + }; + }); + + // var foo = (async (): number => {}); + instance.extend("parseAsyncArrowFromCallExpression", function (inner) { + return function (node, call) { + if (this.match(_tokenizerTypes.types.colon)) { + node.returnType = this.flowParseTypeAnnotation(); + } + + return inner.call(this, node, call); + }; + }); + + instance.extend("parseParenAndDistinguishExpression", function (inner) { + return function (startPos, startLoc, canBeArrow, isAsync) { + startPos = startPos || this.state.start; + startLoc = startLoc || this.state.startLoc; + + if (this.lookahead().type === _tokenizerTypes.types.parenR) { + // var foo = (): number => {}; + this.expect(_tokenizerTypes.types.parenL); + this.expect(_tokenizerTypes.types.parenR); + + var node = this.startNodeAt(startPos, startLoc); + if (this.match(_tokenizerTypes.types.colon)) node.returnType = this.flowParseTypeAnnotation(); + this.expect(_tokenizerTypes.types.arrow); + return this.parseArrowExpression(node, [], isAsync); + } else { + // var foo = (foo): number => {}; + var node = inner.call(this, startPos, startLoc, canBeArrow, isAsync); + + if (this.match(_tokenizerTypes.types.colon)) { + var state = this.state.clone(); + try { + return this.parseParenItem(node, startPos, startLoc, true); + } catch (err) { + if (err instanceof SyntaxError) { + this.state = state; + return node; + } else { + throw err; + } + } + } else { + return node; + } + } + }; + }); +}; + +module.exports = exports["default"]; +},{"617":617,"629":629}],624:[function(_dereq_,module,exports){ +"use strict"; + +exports.__esModule = true; +// istanbul ignore next + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } + +var _xhtml = _dereq_(625); + +var _xhtml2 = _interopRequireDefault(_xhtml); + +var _tokenizerTypes = _dereq_(629); + +var _tokenizerContext = _dereq_(626); + +var _parser = _dereq_(617); + +var _parser2 = _interopRequireDefault(_parser); + +var _utilIdentifier = _dereq_(630); + +var _utilWhitespace = _dereq_(632); + +var HEX_NUMBER = /^[\da-fA-F]+$/; +var DECIMAL_NUMBER = /^\d+$/; + +_tokenizerContext.types.j_oTag = new _tokenizerContext.TokContext("...", true, true); + +_tokenizerTypes.types.jsxName = new _tokenizerTypes.TokenType("jsxName"); +_tokenizerTypes.types.jsxText = new _tokenizerTypes.TokenType("jsxText", { beforeExpr: true }); +_tokenizerTypes.types.jsxTagStart = new _tokenizerTypes.TokenType("jsxTagStart"); +_tokenizerTypes.types.jsxTagEnd = new _tokenizerTypes.TokenType("jsxTagEnd"); + +_tokenizerTypes.types.jsxTagStart.updateContext = function () { + this.state.context.push(_tokenizerContext.types.j_expr); // treat as beginning of JSX expression + this.state.context.push(_tokenizerContext.types.j_oTag); // start opening tag context + this.state.exprAllowed = false; +}; + +_tokenizerTypes.types.jsxTagEnd.updateContext = function (prevType) { + var out = this.state.context.pop(); + if (out === _tokenizerContext.types.j_oTag && prevType === _tokenizerTypes.types.slash || out === _tokenizerContext.types.j_cTag) { + this.state.context.pop(); + this.state.exprAllowed = this.curContext() === _tokenizerContext.types.j_expr; + } else { + this.state.exprAllowed = true; + } +}; + +var pp = _parser2["default"].prototype; + +// Reads inline JSX contents token. + +pp.jsxReadToken = function () { + var out = "", + chunkStart = this.state.pos; + for (;;) { + if (this.state.pos >= this.input.length) { + this.raise(this.state.start, "Unterminated JSX contents"); + } + + var ch = this.input.charCodeAt(this.state.pos); + + switch (ch) { + case 60: // "<" + case 123: + // "{" + if (this.state.pos === this.state.start) { + if (ch === 60 && this.state.exprAllowed) { + ++this.state.pos; + return this.finishToken(_tokenizerTypes.types.jsxTagStart); + } + return this.getTokenFromCode(ch); + } + out += this.input.slice(chunkStart, this.state.pos); + return this.finishToken(_tokenizerTypes.types.jsxText, out); + + case 38: + // "&" + out += this.input.slice(chunkStart, this.state.pos); + out += this.jsxReadEntity(); + chunkStart = this.state.pos; + break; + + default: + if (_utilWhitespace.isNewLine(ch)) { + out += this.input.slice(chunkStart, this.state.pos); + out += this.jsxReadNewLine(true); + chunkStart = this.state.pos; + } else { + ++this.state.pos; + } + } + } +}; + +pp.jsxReadNewLine = function (normalizeCRLF) { + var ch = this.input.charCodeAt(this.state.pos); + var out; + ++this.state.pos; + if (ch === 13 && this.input.charCodeAt(this.state.pos) === 10) { + ++this.state.pos; + out = normalizeCRLF ? "\n" : "\r\n"; + } else { + out = String.fromCharCode(ch); + } + ++this.state.curLine; + this.state.lineStart = this.state.pos; + + return out; +}; + +pp.jsxReadString = function (quote) { + var out = "", + chunkStart = ++this.state.pos; + for (;;) { + if (this.state.pos >= this.input.length) { + this.raise(this.state.start, "Unterminated string constant"); + } + + var ch = this.input.charCodeAt(this.state.pos); + if (ch === quote) break; + if (ch === 38) { + // "&" + out += this.input.slice(chunkStart, this.state.pos); + out += this.jsxReadEntity(); + chunkStart = this.state.pos; + } else if (_utilWhitespace.isNewLine(ch)) { + out += this.input.slice(chunkStart, this.state.pos); + out += this.jsxReadNewLine(false); + chunkStart = this.state.pos; + } else { + ++this.state.pos; + } + } + out += this.input.slice(chunkStart, this.state.pos++); + return this.finishToken(_tokenizerTypes.types.string, out); +}; + +pp.jsxReadEntity = function () { + var str = "", + count = 0, + entity; + var ch = this.input[this.state.pos]; + + var startPos = ++this.state.pos; + while (this.state.pos < this.input.length && count++ < 10) { + ch = this.input[this.state.pos++]; + if (ch === ";") { + if (str[0] === "#") { + if (str[1] === "x") { + str = str.substr(2); + if (HEX_NUMBER.test(str)) entity = String.fromCharCode(parseInt(str, 16)); + } else { + str = str.substr(1); + if (DECIMAL_NUMBER.test(str)) entity = String.fromCharCode(parseInt(str, 10)); + } + } else { + entity = _xhtml2["default"][str]; + } + break; + } + str += ch; + } + if (!entity) { + this.state.pos = startPos; + return "&"; + } + return entity; +}; + +// Read a JSX identifier (valid tag or attribute name). +// +// Optimized version since JSX identifiers can"t contain +// escape characters and so can be read as single slice. +// Also assumes that first character was already checked +// by isIdentifierStart in readToken. + +pp.jsxReadWord = function () { + var ch, + start = this.state.pos; + do { + ch = this.input.charCodeAt(++this.state.pos); + } while (_utilIdentifier.isIdentifierChar(ch) || ch === 45); // "-" + return this.finishToken(_tokenizerTypes.types.jsxName, this.input.slice(start, this.state.pos)); +}; + +// Transforms JSX element name to string. + +function getQualifiedJSXName(object) { + if (object.type === "JSXIdentifier") { + return object.name; + } + + if (object.type === "JSXNamespacedName") { + return object.namespace.name + ":" + object.name.name; + } + + if (object.type === "JSXMemberExpression") { + return getQualifiedJSXName(object.object) + "." + getQualifiedJSXName(object.property); + } +} + +// Parse next token as JSX identifier + +pp.jsxParseIdentifier = function () { + var node = this.startNode(); + if (this.match(_tokenizerTypes.types.jsxName)) { + node.name = this.state.value; + } else if (this.state.type.keyword) { + node.name = this.state.type.keyword; + } else { + this.unexpected(); + } + this.next(); + return this.finishNode(node, "JSXIdentifier"); +}; + +// Parse namespaced identifier. + +pp.jsxParseNamespacedName = function () { + var startPos = this.state.start, + startLoc = this.state.startLoc; + var name = this.jsxParseIdentifier(); + if (!this.eat(_tokenizerTypes.types.colon)) return name; + + var node = this.startNodeAt(startPos, startLoc); + node.namespace = name; + node.name = this.jsxParseIdentifier(); + return this.finishNode(node, "JSXNamespacedName"); +}; + +// Parses element name in any form - namespaced, member +// or single identifier. + +pp.jsxParseElementName = function () { + var startPos = this.state.start, + startLoc = this.state.startLoc; + var node = this.jsxParseNamespacedName(); + while (this.eat(_tokenizerTypes.types.dot)) { + var newNode = this.startNodeAt(startPos, startLoc); + newNode.object = node; + newNode.property = this.jsxParseIdentifier(); + node = this.finishNode(newNode, "JSXMemberExpression"); + } + return node; +}; + +// Parses any type of JSX attribute value. + +pp.jsxParseAttributeValue = function () { + var node; + switch (this.state.type) { + case _tokenizerTypes.types.braceL: + node = this.jsxParseExpressionContainer(); + if (node.expression.type === "JSXEmptyExpression") { + this.raise(node.start, "JSX attributes must only be assigned a non-empty expression"); + } else { + return node; + } + + case _tokenizerTypes.types.jsxTagStart: + case _tokenizerTypes.types.string: + node = this.parseExprAtom(); + node.rawValue = null; + return node; + + default: + this.raise(this.state.start, "JSX value should be either an expression or a quoted JSX text"); + } +}; + +// JSXEmptyExpression is unique type since it doesn"t actually parse anything, +// and so it should start at the end of last read token (left brace) and finish +// at the beginning of the next one (right brace). + +pp.jsxParseEmptyExpression = function () { + var tmp = this.state.start; + this.state.start = this.state.lastTokEnd; + this.state.lastTokEnd = tmp; + + tmp = this.state.startLoc; + this.state.startLoc = this.state.lastTokEndLoc; + this.state.lastTokEndLoc = tmp; + + return this.finishNode(this.startNode(), "JSXEmptyExpression"); +}; + +// Parses JSX expression enclosed into curly brackets. + +pp.jsxParseExpressionContainer = function () { + var node = this.startNode(); + this.next(); + if (this.match(_tokenizerTypes.types.braceR)) { + node.expression = this.jsxParseEmptyExpression(); + } else { + node.expression = this.parseExpression(); + } + this.expect(_tokenizerTypes.types.braceR); + return this.finishNode(node, "JSXExpressionContainer"); +}; + +// Parses following JSX attribute name-value pair. + +pp.jsxParseAttribute = function () { + var node = this.startNode(); + if (this.eat(_tokenizerTypes.types.braceL)) { + this.expect(_tokenizerTypes.types.ellipsis); + node.argument = this.parseMaybeAssign(); + this.expect(_tokenizerTypes.types.braceR); + return this.finishNode(node, "JSXSpreadAttribute"); + } + node.name = this.jsxParseNamespacedName(); + node.value = this.eat(_tokenizerTypes.types.eq) ? this.jsxParseAttributeValue() : null; + return this.finishNode(node, "JSXAttribute"); +}; + +// Parses JSX opening tag starting after "<". + +pp.jsxParseOpeningElementAt = function (startPos, startLoc) { + var node = this.startNodeAt(startPos, startLoc); + node.attributes = []; + node.name = this.jsxParseElementName(); + while (!this.match(_tokenizerTypes.types.slash) && !this.match(_tokenizerTypes.types.jsxTagEnd)) { + node.attributes.push(this.jsxParseAttribute()); + } + node.selfClosing = this.eat(_tokenizerTypes.types.slash); + this.expect(_tokenizerTypes.types.jsxTagEnd); + return this.finishNode(node, "JSXOpeningElement"); +}; + +// Parses JSX closing tag starting after ""); + } + } + + node.openingElement = openingElement; + node.closingElement = closingElement; + node.children = children; + if (this.match(_tokenizerTypes.types.relational) && this.state.value === "<") { + this.raise(this.state.start, "Adjacent JSX elements must be wrapped in an enclosing tag"); + } + return this.finishNode(node, "JSXElement"); +}; + +// Parses entire JSX element from current position. + +pp.jsxParseElement = function () { + var startPos = this.state.start, + startLoc = this.state.startLoc; + this.next(); + return this.jsxParseElementAt(startPos, startLoc); +}; + +exports["default"] = function (instance) { + instance.extend("parseExprAtom", function (inner) { + return function (refShortHandDefaultPos) { + if (this.match(_tokenizerTypes.types.jsxText)) { + var node = this.parseLiteral(this.state.value); + // https://github.com/babel/babel/issues/2078 + node.rawValue = null; + return node; + } else if (this.match(_tokenizerTypes.types.jsxTagStart)) { + return this.jsxParseElement(); + } else { + return inner.call(this, refShortHandDefaultPos); + } + }; + }); + + instance.extend("readToken", function (inner) { + return function (code) { + var context = this.curContext(); + + if (context === _tokenizerContext.types.j_expr) { + return this.jsxReadToken(); + } + + if (context === _tokenizerContext.types.j_oTag || context === _tokenizerContext.types.j_cTag) { + if (_utilIdentifier.isIdentifierStart(code)) { + return this.jsxReadWord(); + } + + if (code === 62) { + ++this.state.pos; + return this.finishToken(_tokenizerTypes.types.jsxTagEnd); + } + + if ((code === 34 || code === 39) && context === _tokenizerContext.types.j_oTag) { + return this.jsxReadString(code); + } + } + + if (code === 60 && this.state.exprAllowed) { + ++this.state.pos; + return this.finishToken(_tokenizerTypes.types.jsxTagStart); + } + + return inner.call(this, code); + }; + }); + + instance.extend("updateContext", function (inner) { + return function (prevType) { + if (this.match(_tokenizerTypes.types.braceL)) { + var curContext = this.curContext(); + if (curContext === _tokenizerContext.types.j_oTag) { + this.state.context.push(_tokenizerContext.types.b_expr); + } else if (curContext === _tokenizerContext.types.j_expr) { + this.state.context.push(_tokenizerContext.types.b_tmpl); + } else { + inner.call(this, prevType); + } + this.state.exprAllowed = true; + } else if (this.match(_tokenizerTypes.types.slash) && prevType === _tokenizerTypes.types.jsxTagStart) { + this.state.context.length -= 2; // do not consider JSX expr -> JSX open tag -> ... anymore + this.state.context.push(_tokenizerContext.types.j_cTag); // reconsider as closing tag context + this.state.exprAllowed = false; + } else { + return inner.call(this, prevType); + } + }; + }); +}; + +module.exports = exports["default"]; +},{"617":617,"625":625,"626":626,"629":629,"630":630,"632":632}],625:[function(_dereq_,module,exports){ +"use strict"; + +exports.__esModule = true; +exports["default"] = { + quot: "\"", + amp: "&", + apos: "'", + lt: "<", + gt: ">", + nbsp: " ", + iexcl: "¡", + cent: "¢", + pound: "£", + curren: "¤", + yen: "¥", + brvbar: "¦", + sect: "§", + uml: "¨", + copy: "©", + ordf: "ª", + laquo: "«", + not: "¬", + shy: "­", + reg: "®", + macr: "¯", + deg: "°", + plusmn: "±", + sup2: "²", + sup3: "³", + acute: "´", + micro: "µ", + para: "¶", + middot: "·", + cedil: "¸", + sup1: "¹", + ordm: "º", + raquo: "»", + frac14: "¼", + frac12: "½", + frac34: "¾", + iquest: "¿", + Agrave: "À", + Aacute: "Á", + Acirc: "Â", + Atilde: "Ã", + Auml: "Ä", + Aring: "Å", + AElig: "Æ", + Ccedil: "Ç", + Egrave: "È", + Eacute: "É", + Ecirc: "Ê", + Euml: "Ë", + Igrave: "Ì", + Iacute: "Í", + Icirc: "Î", + Iuml: "Ï", + ETH: "Ð", + Ntilde: "Ñ", + Ograve: "Ò", + Oacute: "Ó", + Ocirc: "Ô", + Otilde: "Õ", + Ouml: "Ö", + times: "×", + Oslash: "Ø", + Ugrave: "Ù", + Uacute: "Ú", + Ucirc: "Û", + Uuml: "Ü", + Yacute: "Ý", + THORN: "Þ", + szlig: "ß", + agrave: "à", + aacute: "á", + acirc: "â", + atilde: "ã", + auml: "ä", + aring: "å", + aelig: "æ", + ccedil: "ç", + egrave: "è", + eacute: "é", + ecirc: "ê", + euml: "ë", + igrave: "ì", + iacute: "í", + icirc: "î", + iuml: "ï", + eth: "ð", + ntilde: "ñ", + ograve: "ò", + oacute: "ó", + ocirc: "ô", + otilde: "õ", + ouml: "ö", + divide: "÷", + oslash: "ø", + ugrave: "ù", + uacute: "ú", + ucirc: "û", + uuml: "ü", + yacute: "ý", + thorn: "þ", + yuml: "ÿ", + OElig: "Œ", + oelig: "œ", + Scaron: "Š", + scaron: "š", + Yuml: "Ÿ", + fnof: "ƒ", + circ: "ˆ", + tilde: "˜", + Alpha: "Α", + Beta: "Β", + Gamma: "Γ", + Delta: "Δ", + Epsilon: "Ε", + Zeta: "Ζ", + Eta: "Η", + Theta: "Θ", + Iota: "Ι", + Kappa: "Κ", + Lambda: "Λ", + Mu: "Μ", + Nu: "Ν", + Xi: "Ξ", + Omicron: "Ο", + Pi: "Π", + Rho: "Ρ", + Sigma: "Σ", + Tau: "Τ", + Upsilon: "Υ", + Phi: "Φ", + Chi: "Χ", + Psi: "Ψ", + Omega: "Ω", + alpha: "α", + beta: "β", + gamma: "γ", + delta: "δ", + epsilon: "ε", + zeta: "ζ", + eta: "η", + theta: "θ", + iota: "ι", + kappa: "κ", + lambda: "λ", + mu: "μ", + nu: "ν", + xi: "ξ", + omicron: "ο", + pi: "π", + rho: "ρ", + sigmaf: "ς", + sigma: "σ", + tau: "τ", + upsilon: "υ", + phi: "φ", + chi: "χ", + psi: "ψ", + omega: "ω", + thetasym: "ϑ", + upsih: "ϒ", + piv: "ϖ", + ensp: " ", + emsp: " ", + thinsp: " ", + zwnj: "‌", + zwj: "‍", + lrm: "‎", + rlm: "‏", + ndash: "–", + mdash: "—", + lsquo: "‘", + rsquo: "’", + sbquo: "‚", + ldquo: "“", + rdquo: "”", + bdquo: "„", + dagger: "†", + Dagger: "‡", + bull: "•", + hellip: "…", + permil: "‰", + prime: "′", + Prime: "″", + lsaquo: "‹", + rsaquo: "›", + oline: "‾", + frasl: "⁄", + euro: "€", + image: "ℑ", + weierp: "℘", + real: "ℜ", + trade: "™", + alefsym: "ℵ", + larr: "←", + uarr: "↑", + rarr: "→", + darr: "↓", + harr: "↔", + crarr: "↵", + lArr: "⇐", + uArr: "⇑", + rArr: "⇒", + dArr: "⇓", + hArr: "⇔", + forall: "∀", + part: "∂", + exist: "∃", + empty: "∅", + nabla: "∇", + isin: "∈", + notin: "∉", + ni: "∋", + prod: "∏", + sum: "∑", + minus: "−", + lowast: "∗", + radic: "√", + prop: "∝", + infin: "∞", + ang: "∠", + and: "∧", + or: "∨", + cap: "∩", + cup: "∪", + "int": "∫", + there4: "∴", + sim: "∼", + cong: "≅", + asymp: "≈", + ne: "≠", + equiv: "≡", + le: "≤", + ge: "≥", + sub: "⊂", + sup: "⊃", + nsub: "⊄", + sube: "⊆", + supe: "⊇", + oplus: "⊕", + otimes: "⊗", + perp: "⊥", + sdot: "⋅", + lceil: "⌈", + rceil: "⌉", + lfloor: "⌊", + rfloor: "⌋", + lang: "〈", + rang: "〉", + loz: "◊", + spades: "♠", + clubs: "♣", + hearts: "♥", + diams: "♦" +}; +module.exports = exports["default"]; +},{}],626:[function(_dereq_,module,exports){ +// The algorithm used to determine whether a regexp can appear at a +// given point in the program is loosely based on sweet.js' approach. +// See https://github.com/mozilla/sweet.js/wiki/design + +"use strict"; + +exports.__esModule = true; +// istanbul ignore next + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var _types = _dereq_(629); + +var TokContext = function TokContext(token, isExpr, preserveSpace, override) { + _classCallCheck(this, TokContext); + + this.token = token; + this.isExpr = !!isExpr; + this.preserveSpace = !!preserveSpace; + this.override = override; +}; + +exports.TokContext = TokContext; +var types = { + b_stat: new TokContext("{", false), + b_expr: new TokContext("{", true), + b_tmpl: new TokContext("${", true), + p_stat: new TokContext("(", false), + p_expr: new TokContext("(", true), + q_tmpl: new TokContext("`", true, true, function (p) { + return p.readTmplToken(); + }), + f_expr: new TokContext("function", true) +}; + +exports.types = types; +// Token-specific context update code + +_types.types.parenR.updateContext = _types.types.braceR.updateContext = function () { + if (this.state.context.length === 1) { + this.state.exprAllowed = true; + return; + } + + var out = this.state.context.pop(); + if (out === types.b_stat && this.curContext() === types.f_expr) { + this.state.context.pop(); + this.state.exprAllowed = false; + } else if (out === types.b_tmpl) { + this.state.exprAllowed = true; + } else { + this.state.exprAllowed = !out.isExpr; + } +}; + +_types.types.braceL.updateContext = function (prevType) { + this.state.context.push(this.braceIsBlock(prevType) ? types.b_stat : types.b_expr); + this.state.exprAllowed = true; +}; + +_types.types.dollarBraceL.updateContext = function () { + this.state.context.push(types.b_tmpl); + this.state.exprAllowed = true; +}; + +_types.types.parenL.updateContext = function (prevType) { + var statementParens = prevType === _types.types._if || prevType === _types.types._for || prevType === _types.types._with || prevType === _types.types._while; + this.state.context.push(statementParens ? types.p_stat : types.p_expr); + this.state.exprAllowed = true; +}; + +_types.types.incDec.updateContext = function () { + // tokExprAllowed stays unchanged +}; + +_types.types._function.updateContext = function () { + if (this.curContext() !== types.b_stat) { + this.state.context.push(types.f_expr); + } + + this.state.exprAllowed = false; +}; + +_types.types.backQuote.updateContext = function () { + if (this.curContext() === types.q_tmpl) { + this.state.context.pop(); + } else { + this.state.context.push(types.q_tmpl); + } + this.state.exprAllowed = false; +}; +},{"629":629}],627:[function(_dereq_,module,exports){ +"use strict"; + +exports.__esModule = true; +// istanbul ignore next + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } + +// istanbul ignore next + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var _utilIdentifier = _dereq_(630); + +var _types = _dereq_(629); + +var _context = _dereq_(626); + +var _utilLocation = _dereq_(631); + +var _utilWhitespace = _dereq_(632); + +var _state = _dereq_(628); + +var _state2 = _interopRequireDefault(_state); + +// Object type used to represent tokens. Note that normally, tokens +// simply exist as properties on the parser object. This is only +// used for the onToken callback and the external tokenizer. + +var Token = function Token(state) { + _classCallCheck(this, Token); + + this.type = state.type; + this.value = state.value; + this.start = state.start; + this.end = state.end; + this.loc = new _utilLocation.SourceLocation(state.startLoc, state.endLoc); +} + +// ## Tokenizer + +// Are we running under Rhino? +/* global Packages */ +; + +exports.Token = Token; +var isRhino = typeof Packages === "object" && Object.prototype.toString.call(Packages) === "[object JavaPackage]"; + +// Parse a regular expression. Some context-awareness is necessary, +// since a '/' inside a '[]' set does not end the expression. + +function tryCreateRegexp(src, flags, throwErrorStart) { + try { + return new RegExp(src, flags); + } catch (e) { + if (throwErrorStart !== undefined) { + if (e instanceof SyntaxError) this.raise(throwErrorStart, "Error parsing regular expression: " + e.message); + this.raise(e); + } + } +} + +var regexpUnicodeSupport = !!tryCreateRegexp("￿", "u"); + +function codePointToString(code) { + // UTF-16 Decoding + if (code <= 0xFFFF) return String.fromCharCode(code); + return String.fromCharCode((code - 0x10000 >> 10) + 0xD800, (code - 0x10000 & 1023) + 0xDC00); +} + +var Tokenizer = (function () { + function Tokenizer(input) { + _classCallCheck(this, Tokenizer); + + this.state = new _state2["default"](); + this.state.init(input); + } + + // Move to the next token + + Tokenizer.prototype.next = function next() { + this.state.tokens.push(new Token(this.state)); + + this.state.lastTokEnd = this.state.end; + this.state.lastTokStart = this.state.start; + this.state.lastTokEndLoc = this.state.endLoc; + this.state.lastTokStartLoc = this.state.startLoc; + this.nextToken(); + }; + + // TODO + + Tokenizer.prototype.eat = function eat(type) { + if (this.match(type)) { + this.next(); + return true; + } else { + return false; + } + }; + + // TODO + + Tokenizer.prototype.match = function match(type) { + return this.state.type === type; + }; + + // TODO + + Tokenizer.prototype.lookahead = function lookahead() { + var old = this.state; + this.state = old.clone(); + this.next(); + var curr = this.state.clone(); + this.state = old; + return curr; + }; + + // Toggle strict mode. Re-reads the next number or string to please + // pedantic tests (`"use strict"; 010;` should fail). + + Tokenizer.prototype.setStrict = function setStrict(strict) { + this.strict = strict; + if (!this.match(_types.types.num) && !this.match(_types.types.string)) return; + this.state.pos = this.state.start; + while (this.state.pos < this.state.lineStart) { + this.state.lineStart = this.input.lastIndexOf("\n", this.state.lineStart - 2) + 1; + --this.state.curLine; + } + this.nextToken(); + }; + + Tokenizer.prototype.curContext = function curContext() { + return this.state.context[this.state.context.length - 1]; + }; + + // Read a single token, updating the parser object's token-related + // properties. + + Tokenizer.prototype.nextToken = function nextToken() { + var curContext = this.curContext(); + if (!curContext || !curContext.preserveSpace) this.skipSpace(); + + this.state.start = this.state.pos; + this.state.startLoc = this.state.curPosition(); + if (this.state.pos >= this.input.length) return this.finishToken(_types.types.eof); + + if (curContext.override) { + return curContext.override(this); + } else { + return this.readToken(this.fullCharCodeAtPos()); + } + }; + + Tokenizer.prototype.readToken = function readToken(code) { + // Identifier or keyword. '\uXXXX' sequences are allowed in + // identifiers, so '\' also dispatches to that. + if (_utilIdentifier.isIdentifierStart(code, true) || code === 92 /* '\' */) return this.readWord(); + + return this.getTokenFromCode(code); + }; + + Tokenizer.prototype.fullCharCodeAtPos = function fullCharCodeAtPos() { + var code = this.input.charCodeAt(this.state.pos); + if (code <= 0xd7ff || code >= 0xe000) return code; + + var next = this.input.charCodeAt(this.state.pos + 1); + return (code << 10) + next - 0x35fdc00; + }; + + Tokenizer.prototype.pushComment = function pushComment(block, text, start, end, startLoc, endLoc) { + var comment = { + type: block ? "CommentBlock" : "CommentLine", + value: text, + start: start, + end: end, + loc: new _utilLocation.SourceLocation(startLoc, endLoc), + range: [start, end] + }; + + this.state.tokens.push(comment); + this.state.comments.push(comment); + this.addComment(comment); + }; + + Tokenizer.prototype.skipBlockComment = function skipBlockComment() { + var startLoc = this.state.curPosition(); + var start = this.state.pos, + end = this.input.indexOf("*/", this.state.pos += 2); + if (end === -1) this.raise(this.state.pos - 2, "Unterminated comment"); + + this.state.pos = end + 2; + _utilWhitespace.lineBreakG.lastIndex = start; + var match = undefined; + while ((match = _utilWhitespace.lineBreakG.exec(this.input)) && match.index < this.state.pos) { + ++this.state.curLine; + this.state.lineStart = match.index + match[0].length; + } + + this.pushComment(true, this.input.slice(start + 2, end), start, this.state.pos, startLoc, this.state.curPosition()); + }; + + Tokenizer.prototype.skipLineComment = function skipLineComment(startSkip) { + var start = this.state.pos; + var startLoc = this.state.curPosition(); + var ch = this.input.charCodeAt(this.state.pos += startSkip); + while (this.state.pos < this.input.length && ch !== 10 && ch !== 13 && ch !== 8232 && ch !== 8233) { + ++this.state.pos; + ch = this.input.charCodeAt(this.state.pos); + } + + this.pushComment(false, this.input.slice(start + startSkip, this.state.pos), start, this.state.pos, startLoc, this.state.curPosition()); + }; + + // Called at the start of the parse and after every token. Skips + // whitespace and comments, and. + + Tokenizer.prototype.skipSpace = function skipSpace() { + loop: while (this.state.pos < this.input.length) { + var ch = this.input.charCodeAt(this.state.pos); + switch (ch) { + case 32:case 160: + // ' ' + ++this.state.pos; + break; + + case 13: + if (this.input.charCodeAt(this.state.pos + 1) === 10) { + ++this.state.pos; + } + + case 10:case 8232:case 8233: + ++this.state.pos; + ++this.state.curLine; + this.state.lineStart = this.state.pos; + break; + + case 47: + // '/' + switch (this.input.charCodeAt(this.state.pos + 1)) { + case 42: + // '*' + this.skipBlockComment(); + break; + + case 47: + this.skipLineComment(2); + break; + + default: + break loop; + } + break; + + default: + if (ch > 8 && ch < 14 || ch >= 5760 && _utilWhitespace.nonASCIIwhitespace.test(String.fromCharCode(ch))) { + ++this.state.pos; + } else { + break loop; + } + } + } + }; + + // Called at the end of every token. Sets `end`, `val`, and + // maintains `context` and `exprAllowed`, and skips the space after + // the token, so that the next one's `start` will point at the + // right position. + + Tokenizer.prototype.finishToken = function finishToken(type, val) { + this.state.end = this.state.pos; + this.state.endLoc = this.state.curPosition(); + var prevType = this.state.type; + this.state.type = type; + this.state.value = val; + + this.updateContext(prevType); + }; + + // ### Token reading + + // This is the function that is called to fetch the next token. It + // is somewhat obscure, because it works in character codes rather + // than characters, and because operator parsing has been inlined + // into it. + // + // All in the name of speed. + // + + Tokenizer.prototype.readToken_dot = function readToken_dot() { + var next = this.input.charCodeAt(this.state.pos + 1); + if (next >= 48 && next <= 57) { + return this.readNumber(true); + } + + var next2 = this.input.charCodeAt(this.state.pos + 2); + if (next === 46 && next2 === 46) { + // 46 = dot '.' + this.state.pos += 3; + return this.finishToken(_types.types.ellipsis); + } else { + ++this.state.pos; + return this.finishToken(_types.types.dot); + } + }; + + Tokenizer.prototype.readToken_slash = function readToken_slash() { + // '/' + if (this.state.exprAllowed) { + ++this.state.pos; + return this.readRegexp(); + } + + var next = this.input.charCodeAt(this.state.pos + 1); + if (next === 61) { + return this.finishOp(_types.types.assign, 2); + } else { + return this.finishOp(_types.types.slash, 1); + } + }; + + Tokenizer.prototype.readToken_mult_modulo = function readToken_mult_modulo(code) { + // '%*' + var type = code === 42 ? _types.types.star : _types.types.modulo; + var width = 1; + var next = this.input.charCodeAt(this.state.pos + 1); + + if (next === 42 && this.options.features["es7.exponentiationOperator"]) { + // '*' + width++; + next = this.input.charCodeAt(this.state.pos + 2); + type = _types.types.exponent; + } + + if (next === 61) { + width++; + type = _types.types.assign; + } + + return this.finishOp(type, width); + }; + + Tokenizer.prototype.readToken_pipe_amp = function readToken_pipe_amp(code) { + // '|&' + var next = this.input.charCodeAt(this.state.pos + 1); + if (next === code) return this.finishOp(code === 124 ? _types.types.logicalOR : _types.types.logicalAND, 2); + if (next === 61) return this.finishOp(_types.types.assign, 2); + return this.finishOp(code === 124 ? _types.types.bitwiseOR : _types.types.bitwiseAND, 1); + }; + + Tokenizer.prototype.readToken_caret = function readToken_caret() { + // '^' + var next = this.input.charCodeAt(this.state.pos + 1); + if (next === 61) { + return this.finishOp(_types.types.assign, 2); + } else { + return this.finishOp(_types.types.bitwiseXOR, 1); + } + }; + + Tokenizer.prototype.readToken_plus_min = function readToken_plus_min(code) { + // '+-' + var next = this.input.charCodeAt(this.state.pos + 1); + + if (next === code) { + if (next === 45 && this.input.charCodeAt(this.state.pos + 2) === 62 && _utilWhitespace.lineBreak.test(this.input.slice(this.state.lastTokEnd, this.state.pos))) { + // A `-->` line comment + this.skipLineComment(3); + this.skipSpace(); + return this.nextToken(); + } + return this.finishOp(_types.types.incDec, 2); + } + + if (next === 61) { + return this.finishOp(_types.types.assign, 2); + } else { + return this.finishOp(_types.types.plusMin, 1); + } + }; + + Tokenizer.prototype.readToken_lt_gt = function readToken_lt_gt(code) { + // '<>' + var next = this.input.charCodeAt(this.state.pos + 1); + var size = 1; + + if (next === code) { + size = code === 62 && this.input.charCodeAt(this.state.pos + 2) === 62 ? 3 : 2; + if (this.input.charCodeAt(this.state.pos + size) === 61) return this.finishOp(_types.types.assign, size + 1); + return this.finishOp(_types.types.bitShift, size); + } + + if (next === 33 && code === 60 && this.input.charCodeAt(this.state.pos + 2) === 45 && this.input.charCodeAt(this.state.pos + 3) === 45) { + if (this.inModule) this.unexpected(); + // ` + + + + + + + +
    +
    + +
    + +

    Index

    + +

    Classes

    + + +
    + +
    + + +

    + Class +

    + + + + + + + +

    Fields

    + + + + + + + +

    Methods

    + + + + + + + + +
    + +
    + +

    + Class Signal +

    + + +

    + + + + + + +
    Defined in: signals.js. + +

    + + + +
    +
    + Class Detail +
    + +
    + Signal() +
    + +
    +

    Custom event broadcaster +
    - inspired by Robert Penner's AS3 Signals.

    +
    Author: Miller Medeiros. +
    + + + + + + + + + + + + +
    + + + + +
    +
    + Field Detail +
    + +
    + +
    +
    +
    + + {boolean} + active + +
    +
    +

    If Signal is active and should broadcast events.

    + +

    IMPORTANT: Setting this property during a dispatch will only affect the next dispatch, if you want to stop the propagation of a signal use `halt()` instead.

    + + +
    + + + + + + + +
    + +
    + +
    +
    +
    + + {boolean} + memorize + +
    +
    +

    If Signal should keep record of previously dispatched parameters and +automatically execute listener during add()/addOnce() if Signal was +already dispatched before.

    + + +
    + + + + + + + +
    + +
    + +
    +
    +
    + + {String} + VERSION + +
    +
    +

    Signals Version Number

    + + +
    + + + + + + + +
    + +
    + + + + +
    +
    + Method Detail +
    + +
    + +
    +
    +
    + {SignalBinding} + add(listener, listenerContext, priority) + +
    +
    +

    Add a listener to the signal.

    + + +
    + + + + +
    +
    Parameters:
    + +
    + {Function} listener + +
    +
    Signal handler function.
    + +
    + {Object} listenerContext + Optional +
    +
    Context on which listener will be executed (object that should represent the `this` variable inside listener function).
    + +
    + {Number} priority + Optional +
    +
    The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0)
    + +
    + + + + + +
    +
    Returns:
    + +
    {SignalBinding} An Object representing the binding between the Signal and listener.
    + +
    + + + + +
    + +
    + +
    +
    +
    + {SignalBinding} + addOnce(listener, listenerContext, priority) + +
    +
    +

    Add listener to the signal that should be removed after first execution (will be executed only once).

    + + +
    + + + + +
    +
    Parameters:
    + +
    + {Function} listener + +
    +
    Signal handler function.
    + +
    + {Object} listenerContext + Optional +
    +
    Context on which listener will be executed (object that should represent the `this` variable inside listener function).
    + +
    + {Number} priority + Optional +
    +
    The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0)
    + +
    + + + + + +
    +
    Returns:
    + +
    {SignalBinding} An Object representing the binding between the Signal and listener.
    + +
    + + + + +
    + +
    + +
    +
    +
    + + dispatch(params) + +
    +
    +

    Dispatch/Broadcast Signal to all listeners added to the queue.

    + + +
    + + + + +
    +
    Parameters:
    + +
    + {...*} params + Optional +
    +
    Parameters that should be passed to each handler.
    + +
    + + + + + + + + +
    + +
    + +
    +
    +
    + + dispose() + +
    +
    +

    Remove all bindings from signal and destroy any reference to external objects (destroy Signal object).

    + +

    IMPORTANT: calling any method on the signal instance after calling dispose will throw errors.

    + + +
    + + + + + + + + + + + +
    + +
    + +
    +
    +
    + + forget() + +
    +
    +

    Forget memorized arguments.

    + + +
    + + + + + + + + + + +
    +
    See:
    + +
    Signal.memorize
    + +
    + + +
    + +
    + +
    +
    +
    + {number} + getNumListeners() + +
    +
    + + + +
    + + + + + + + + +
    +
    Returns:
    + +
    {number} Number of listeners attached to the Signal.
    + +
    + + + + +
    + +
    + +
    +
    +
    + + halt() + +
    +
    +

    Stop propagation of the event, blocking the dispatch to next listeners on the queue.

    + +

    IMPORTANT: should be called only during signal dispatch, calling it before/after dispatch won't affect signal broadcast.

    + + +
    + + + + + + + + + + +
    +
    See:
    + +
    Signal.prototype.disable
    + +
    + + +
    + +
    + +
    +
    +
    + {boolean} + has(listener, context) + +
    +
    +

    Check if listener was attached to Signal.

    + + +
    + + + + +
    +
    Parameters:
    + +
    + {Function} listener + +
    +
    + +
    + {Object} context + Optional +
    +
    + +
    + + + + + +
    +
    Returns:
    + +
    {boolean} if Signal has the specified listener.
    + +
    + + + + +
    + +
    + +
    +
    +
    + {Function} + remove(listener, context) + +
    +
    +

    Remove a single listener from the dispatch queue.

    + + +
    + + + + +
    +
    Parameters:
    + +
    + {Function} listener + +
    +
    Handler function that should be removed.
    + +
    + {Object} context + Optional +
    +
    Execution context (since you can add the same handler multiple times if executing in a different context).
    + +
    + + + + + +
    +
    Returns:
    + +
    {Function} Listener handler function.
    + +
    + + + + +
    + +
    + +
    +
    +
    + + removeAll() + +
    +
    +

    Remove all listeners from the Signal.

    + + +
    + + + + + + + + + + + +
    + +
    + +
    +
    +
    + {string} + toString() + +
    +
    + + + +
    + + + + + + + + +
    +
    Returns:
    + +
    {string} String representation of the object.
    + +
    + + + + +
    + +
    + + + + +
    +
    + + + +
    + + Documentation generated by JsDoc Toolkit 2.4.0 on Thu Nov 29 2012 17:48:56 GMT-0200 (BRST) + | template based on Steffen Siering jsdoc-simple. +
    + + diff --git a/jspm_packages/npm/signals@1.0.0/dist/docs/symbols/SignalBinding.html b/jspm_packages/npm/signals@1.0.0/dist/docs/symbols/SignalBinding.html new file mode 100644 index 0000000..e234c67 --- /dev/null +++ b/jspm_packages/npm/signals@1.0.0/dist/docs/symbols/SignalBinding.html @@ -0,0 +1,571 @@ + + + + + + + JsDoc Reference - SignalBinding + + + + + + + + + + + + + +
    +
    + +
    + +

    Index

    + +

    Classes

    + + +
    + +
    + + +

    + Class +

    + + + + + + + +

    Fields

    + + + + + + + +

    Methods

    + + + + + + + + +
    + +
    + +

    + Class SignalBinding +

    + + +

    + + + + + + +
    Defined in: signals.js. + +

    + + + +
    +
    + Class Detail +
    + +
    + SignalBinding(signal, listener, isOnce, listenerContext, priority) +
    + +
    +

    Object that represents a binding between a Signal and a listener function. +
    - This is an internal constructor and shouldn't be called by regular users. +
    - inspired by Joa Ebert AS3 SignalBinding and Robert Penner's Slot classes.

    +
    Author: Miller Medeiros. +
    + + + + + +
    +
    Parameters:
    + +
    + {Signal} signal + +
    +
    Reference to Signal object that listener is currently bound to.
    + +
    + {Function} listener + +
    +
    Handler function bound to the signal.
    + +
    + {boolean} isOnce + +
    +
    If binding should be executed just once.
    + +
    + {Object} listenerContext + Optional +
    +
    Context on which listener will be executed (object that should represent the `this` variable inside listener function).
    + +
    + {Number} priority + Optional +
    +
    The priority level of the event listener. (default = 0).
    + +
    + + + + + + + + +
    + + + + +
    +
    + Field Detail +
    + +
    + +
    +
    +
    + + {boolean} + active + +
    +
    +

    If binding is active and should be executed.

    + + +
    + + + + + + + +
    + +
    + +
    +
    +
    + + {Object|undefined|null} + context + +
    +
    +

    Context on which listener will be executed (object that should represent the this variable inside listener function).

    + + +
    + + + + + + + +
    + +
    + +
    +
    +
    + + {Array|null} + params + +
    +
    +

    Default parameters passed to listener during Signal.dispatch and SignalBinding.execute. (curried parameters)

    + + +
    + + + + + + + +
    + +
    + + + + +
    +
    + Method Detail +
    + +
    + +
    +
    +
    + {Function|null} + detach() + +
    +
    +

    Detach binding from signal. +- alias to: mySignal.remove(myBinding.getListener());

    + + +
    + + + + + + + + +
    +
    Returns:
    + +
    {Function|null} Handler function bound to the signal or `null` if binding was previously detached.
    + +
    + + + + +
    + +
    + +
    +
    +
    + {*} + execute(paramsArr) + +
    +
    +

    Call listener passing arbitrary parameters.

    + +

    If binding was added using `Signal.addOnce()` it will be automatically removed from signal dispatch queue, this method is used internally for the signal dispatch.

    + + +
    + + + + +
    +
    Parameters:
    + +
    + {Array} paramsArr + Optional +
    +
    Array of parameters that should be passed to the listener
    + +
    + + + + + +
    +
    Returns:
    + +
    {*} Value returned by the listener.
    + +
    + + + + +
    + +
    + +
    +
    +
    + {Function} + getListener() + +
    +
    + + + +
    + + + + + + + + +
    +
    Returns:
    + +
    {Function} Handler function bound to the signal.
    + +
    + + + + +
    + +
    + +
    +
    +
    + {Signal} + getSignal() + +
    +
    + + + +
    + + + + + + + + +
    +
    Returns:
    + +
    {Signal} Signal that listener is currently bound to.
    + +
    + + + + +
    + +
    + +
    +
    +
    + {Boolean} + isBound() + +
    +
    + + + +
    + + + + + + + + +
    +
    Returns:
    + +
    {Boolean} `true` if binding is still bound to the signal and have a listener.
    + +
    + + + + +
    + +
    + +
    +
    +
    + {boolean} + isOnce() + +
    +
    + + + +
    + + + + + + + + +
    +
    Returns:
    + +
    {boolean} If SignalBinding will only be executed once.
    + +
    + + + + +
    + +
    + +
    +
    +
    + {string} + toString() + +
    +
    + + + +
    + + + + + + + + +
    +
    Returns:
    + +
    {string} String representation of the object.
    + +
    + + + + +
    + +
    + + + + +
    +
    + + + +
    + + Documentation generated by JsDoc Toolkit 2.4.0 on Thu Nov 29 2012 17:48:56 GMT-0200 (BRST) + | template based on Steffen Siering jsdoc-simple. +
    + + diff --git a/jspm_packages/npm/signals@1.0.0/dist/docs/symbols/_global_.html b/jspm_packages/npm/signals@1.0.0/dist/docs/symbols/_global_.html new file mode 100644 index 0000000..b107d58 --- /dev/null +++ b/jspm_packages/npm/signals@1.0.0/dist/docs/symbols/_global_.html @@ -0,0 +1,108 @@ + + + + + + + JsDoc Reference - _global_ + + + + + + + + + + + + + +
    +
    + +
    + +

    Index

    + +

    Classes

    + + +
    + +
    + + + + + + + + + + + + + + + + + + +
    + +
    + +

    + Built-In Namespace _global_ +

    + + +

    + + + + + + +

    + + + + + + + + + + + + +
    +
    + + + +
    + + Documentation generated by JsDoc Toolkit 2.4.0 on Thu Nov 29 2012 17:48:56 GMT-0200 (BRST) + | template based on Steffen Siering jsdoc-simple. +
    + + diff --git a/jspm_packages/npm/signals@1.0.0/dist/docs/symbols/signals.html b/jspm_packages/npm/signals@1.0.0/dist/docs/symbols/signals.html new file mode 100644 index 0000000..3ef15e1 --- /dev/null +++ b/jspm_packages/npm/signals@1.0.0/dist/docs/symbols/signals.html @@ -0,0 +1,193 @@ + + + + + + + JsDoc Reference - signals + + + + + + + + + + + + + +
    +
    + +
    + +

    Index

    + +

    Classes

    + + +
    + +
    + + +

    + Namespace +

    + + + + + + + +

    Variables

    + + + + + + + + + + + + + +
    + +
    + +

    + Namespace signals +

    + + +

    + + + + + + +
    Defined in: signals.js. + +

    + + + +
    +
    + Namespace Detail +
    + +
    + signals +
    + +
    +

    Signals namespace

    + +
    + + + + + + + + + + + + +
    + + + + +
    +
    + Field Detail +
    + +
    + +
    +
    <static> +
    + + + signals.Signal + +
    +
    +

    Custom event broadcaster

    + + +
    + + + + + + +
    +
    See:
    + +
    Signal
    + +
    + + +
    + +
    + + + + + + + +
    +
    + + + +
    + + Documentation generated by JsDoc Toolkit 2.4.0 on Thu Nov 29 2012 17:48:56 GMT-0200 (BRST) + | template based on Steffen Siering jsdoc-simple. +
    + + diff --git a/jspm_packages/npm/signals@1.0.0/dist/docs/symbols/src/_Users_millermedeiros_Projects__open_source_js-signals_dist_signals.js.html b/jspm_packages/npm/signals@1.0.0/dist/docs/symbols/src/_Users_millermedeiros_Projects__open_source_js-signals_dist_signals.js.html new file mode 100644 index 0000000..3dec6f7 --- /dev/null +++ b/jspm_packages/npm/signals@1.0.0/dist/docs/symbols/src/_Users_millermedeiros_Projects__open_source_js-signals_dist_signals.js.html @@ -0,0 +1,453 @@ +
      1 /*jslint onevar:true, undef:true, newcap:true, regexp:true, bitwise:true, maxerr:50, indent:4, white:false, nomen:false, plusplus:false */
    +  2 /*global define:false, require:false, exports:false, module:false, signals:false */
    +  3 
    +  4 /** @license
    +  5  * JS Signals <http://millermedeiros.github.com/js-signals/>
    +  6  * Released under the MIT license
    +  7  * Author: Miller Medeiros
    +  8  * Version: 1.0.0 - Build: 268 (2012/11/29 05:48 PM)
    +  9  */
    + 10 
    + 11 (function(global){
    + 12 
    + 13     // SignalBinding -------------------------------------------------
    + 14     //================================================================
    + 15 
    + 16     /**
    + 17      * Object that represents a binding between a Signal and a listener function.
    + 18      * <br />- <strong>This is an internal constructor and shouldn't be called by regular users.</strong>
    + 19      * <br />- inspired by Joa Ebert AS3 SignalBinding and Robert Penner's Slot classes.
    + 20      * @author Miller Medeiros
    + 21      * @constructor
    + 22      * @internal
    + 23      * @name SignalBinding
    + 24      * @param {Signal} signal Reference to Signal object that listener is currently bound to.
    + 25      * @param {Function} listener Handler function bound to the signal.
    + 26      * @param {boolean} isOnce If binding should be executed just once.
    + 27      * @param {Object} [listenerContext] Context on which listener will be executed (object that should represent the `this` variable inside listener function).
    + 28      * @param {Number} [priority] The priority level of the event listener. (default = 0).
    + 29      */
    + 30     function SignalBinding(signal, listener, isOnce, listenerContext, priority) {
    + 31 
    + 32         /**
    + 33          * Handler function bound to the signal.
    + 34          * @type Function
    + 35          * @private
    + 36          */
    + 37         this._listener = listener;
    + 38 
    + 39         /**
    + 40          * If binding should be executed just once.
    + 41          * @type boolean
    + 42          * @private
    + 43          */
    + 44         this._isOnce = isOnce;
    + 45 
    + 46         /**
    + 47          * Context on which listener will be executed (object that should represent the `this` variable inside listener function).
    + 48          * @memberOf SignalBinding.prototype
    + 49          * @name context
    + 50          * @type Object|undefined|null
    + 51          */
    + 52         this.context = listenerContext;
    + 53 
    + 54         /**
    + 55          * Reference to Signal object that listener is currently bound to.
    + 56          * @type Signal
    + 57          * @private
    + 58          */
    + 59         this._signal = signal;
    + 60 
    + 61         /**
    + 62          * Listener priority
    + 63          * @type Number
    + 64          * @private
    + 65          */
    + 66         this._priority = priority || 0;
    + 67     }
    + 68 
    + 69     SignalBinding.prototype = {
    + 70 
    + 71         /**
    + 72          * If binding is active and should be executed.
    + 73          * @type boolean
    + 74          */
    + 75         active : true,
    + 76 
    + 77         /**
    + 78          * Default parameters passed to listener during `Signal.dispatch` and `SignalBinding.execute`. (curried parameters)
    + 79          * @type Array|null
    + 80          */
    + 81         params : null,
    + 82 
    + 83         /**
    + 84          * Call listener passing arbitrary parameters.
    + 85          * <p>If binding was added using `Signal.addOnce()` it will be automatically removed from signal dispatch queue, this method is used internally for the signal dispatch.</p>
    + 86          * @param {Array} [paramsArr] Array of parameters that should be passed to the listener
    + 87          * @return {*} Value returned by the listener.
    + 88          */
    + 89         execute : function (paramsArr) {
    + 90             var handlerReturn, params;
    + 91             if (this.active && !!this._listener) {
    + 92                 params = this.params? this.params.concat(paramsArr) : paramsArr;
    + 93                 handlerReturn = this._listener.apply(this.context, params);
    + 94                 if (this._isOnce) {
    + 95                     this.detach();
    + 96                 }
    + 97             }
    + 98             return handlerReturn;
    + 99         },
    +100 
    +101         /**
    +102          * Detach binding from signal.
    +103          * - alias to: mySignal.remove(myBinding.getListener());
    +104          * @return {Function|null} Handler function bound to the signal or `null` if binding was previously detached.
    +105          */
    +106         detach : function () {
    +107             return this.isBound()? this._signal.remove(this._listener, this.context) : null;
    +108         },
    +109 
    +110         /**
    +111          * @return {Boolean} `true` if binding is still bound to the signal and have a listener.
    +112          */
    +113         isBound : function () {
    +114             return (!!this._signal && !!this._listener);
    +115         },
    +116 
    +117         /**
    +118          * @return {boolean} If SignalBinding will only be executed once.
    +119          */
    +120         isOnce : function () {
    +121             return this._isOnce;
    +122         },
    +123 
    +124         /**
    +125          * @return {Function} Handler function bound to the signal.
    +126          */
    +127         getListener : function () {
    +128             return this._listener;
    +129         },
    +130 
    +131         /**
    +132          * @return {Signal} Signal that listener is currently bound to.
    +133          */
    +134         getSignal : function () {
    +135             return this._signal;
    +136         },
    +137 
    +138         /**
    +139          * Delete instance properties
    +140          * @private
    +141          */
    +142         _destroy : function () {
    +143             delete this._signal;
    +144             delete this._listener;
    +145             delete this.context;
    +146         },
    +147 
    +148         /**
    +149          * @return {string} String representation of the object.
    +150          */
    +151         toString : function () {
    +152             return '[SignalBinding isOnce:' + this._isOnce +', isBound:'+ this.isBound() +', active:' + this.active + ']';
    +153         }
    +154 
    +155     };
    +156 
    +157 
    +158 /*global SignalBinding:false*/
    +159 
    +160     // Signal --------------------------------------------------------
    +161     //================================================================
    +162 
    +163     function validateListener(listener, fnName) {
    +164         if (typeof listener !== 'function') {
    +165             throw new Error( 'listener is a required param of {fn}() and should be a Function.'.replace('{fn}', fnName) );
    +166         }
    +167     }
    +168 
    +169     /**
    +170      * Custom event broadcaster
    +171      * <br />- inspired by Robert Penner's AS3 Signals.
    +172      * @name Signal
    +173      * @author Miller Medeiros
    +174      * @constructor
    +175      */
    +176     function Signal() {
    +177         /**
    +178          * @type Array.<SignalBinding>
    +179          * @private
    +180          */
    +181         this._bindings = [];
    +182         this._prevParams = null;
    +183 
    +184         // enforce dispatch to aways work on same context (#47)
    +185         var self = this;
    +186         this.dispatch = function(){
    +187             Signal.prototype.dispatch.apply(self, arguments);
    +188         };
    +189     }
    +190 
    +191     Signal.prototype = {
    +192 
    +193         /**
    +194          * Signals Version Number
    +195          * @type String
    +196          * @const
    +197          */
    +198         VERSION : '1.0.0',
    +199 
    +200         /**
    +201          * If Signal should keep record of previously dispatched parameters and
    +202          * automatically execute listener during `add()`/`addOnce()` if Signal was
    +203          * already dispatched before.
    +204          * @type boolean
    +205          */
    +206         memorize : false,
    +207 
    +208         /**
    +209          * @type boolean
    +210          * @private
    +211          */
    +212         _shouldPropagate : true,
    +213 
    +214         /**
    +215          * If Signal is active and should broadcast events.
    +216          * <p><strong>IMPORTANT:</strong> Setting this property during a dispatch will only affect the next dispatch, if you want to stop the propagation of a signal use `halt()` instead.</p>
    +217          * @type boolean
    +218          */
    +219         active : true,
    +220 
    +221         /**
    +222          * @param {Function} listener
    +223          * @param {boolean} isOnce
    +224          * @param {Object} [listenerContext]
    +225          * @param {Number} [priority]
    +226          * @return {SignalBinding}
    +227          * @private
    +228          */
    +229         _registerListener : function (listener, isOnce, listenerContext, priority) {
    +230 
    +231             var prevIndex = this._indexOfListener(listener, listenerContext),
    +232                 binding;
    +233 
    +234             if (prevIndex !== -1) {
    +235                 binding = this._bindings[prevIndex];
    +236                 if (binding.isOnce() !== isOnce) {
    +237                     throw new Error('You cannot add'+ (isOnce? '' : 'Once') +'() then add'+ (!isOnce? '' : 'Once') +'() the same listener without removing the relationship first.');
    +238                 }
    +239             } else {
    +240                 binding = new SignalBinding(this, listener, isOnce, listenerContext, priority);
    +241                 this._addBinding(binding);
    +242             }
    +243 
    +244             if(this.memorize && this._prevParams){
    +245                 binding.execute(this._prevParams);
    +246             }
    +247 
    +248             return binding;
    +249         },
    +250 
    +251         /**
    +252          * @param {SignalBinding} binding
    +253          * @private
    +254          */
    +255         _addBinding : function (binding) {
    +256             //simplified insertion sort
    +257             var n = this._bindings.length;
    +258             do { --n; } while (this._bindings[n] && binding._priority <= this._bindings[n]._priority);
    +259             this._bindings.splice(n + 1, 0, binding);
    +260         },
    +261 
    +262         /**
    +263          * @param {Function} listener
    +264          * @return {number}
    +265          * @private
    +266          */
    +267         _indexOfListener : function (listener, context) {
    +268             var n = this._bindings.length,
    +269                 cur;
    +270             while (n--) {
    +271                 cur = this._bindings[n];
    +272                 if (cur._listener === listener && cur.context === context) {
    +273                     return n;
    +274                 }
    +275             }
    +276             return -1;
    +277         },
    +278 
    +279         /**
    +280          * Check if listener was attached to Signal.
    +281          * @param {Function} listener
    +282          * @param {Object} [context]
    +283          * @return {boolean} if Signal has the specified listener.
    +284          */
    +285         has : function (listener, context) {
    +286             return this._indexOfListener(listener, context) !== -1;
    +287         },
    +288 
    +289         /**
    +290          * Add a listener to the signal.
    +291          * @param {Function} listener Signal handler function.
    +292          * @param {Object} [listenerContext] Context on which listener will be executed (object that should represent the `this` variable inside listener function).
    +293          * @param {Number} [priority] The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0)
    +294          * @return {SignalBinding} An Object representing the binding between the Signal and listener.
    +295          */
    +296         add : function (listener, listenerContext, priority) {
    +297             validateListener(listener, 'add');
    +298             return this._registerListener(listener, false, listenerContext, priority);
    +299         },
    +300 
    +301         /**
    +302          * Add listener to the signal that should be removed after first execution (will be executed only once).
    +303          * @param {Function} listener Signal handler function.
    +304          * @param {Object} [listenerContext] Context on which listener will be executed (object that should represent the `this` variable inside listener function).
    +305          * @param {Number} [priority] The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0)
    +306          * @return {SignalBinding} An Object representing the binding between the Signal and listener.
    +307          */
    +308         addOnce : function (listener, listenerContext, priority) {
    +309             validateListener(listener, 'addOnce');
    +310             return this._registerListener(listener, true, listenerContext, priority);
    +311         },
    +312 
    +313         /**
    +314          * Remove a single listener from the dispatch queue.
    +315          * @param {Function} listener Handler function that should be removed.
    +316          * @param {Object} [context] Execution context (since you can add the same handler multiple times if executing in a different context).
    +317          * @return {Function} Listener handler function.
    +318          */
    +319         remove : function (listener, context) {
    +320             validateListener(listener, 'remove');
    +321 
    +322             var i = this._indexOfListener(listener, context);
    +323             if (i !== -1) {
    +324                 this._bindings[i]._destroy(); //no reason to a SignalBinding exist if it isn't attached to a signal
    +325                 this._bindings.splice(i, 1);
    +326             }
    +327             return listener;
    +328         },
    +329 
    +330         /**
    +331          * Remove all listeners from the Signal.
    +332          */
    +333         removeAll : function () {
    +334             var n = this._bindings.length;
    +335             while (n--) {
    +336                 this._bindings[n]._destroy();
    +337             }
    +338             this._bindings.length = 0;
    +339         },
    +340 
    +341         /**
    +342          * @return {number} Number of listeners attached to the Signal.
    +343          */
    +344         getNumListeners : function () {
    +345             return this._bindings.length;
    +346         },
    +347 
    +348         /**
    +349          * Stop propagation of the event, blocking the dispatch to next listeners on the queue.
    +350          * <p><strong>IMPORTANT:</strong> should be called only during signal dispatch, calling it before/after dispatch won't affect signal broadcast.</p>
    +351          * @see Signal.prototype.disable
    +352          */
    +353         halt : function () {
    +354             this._shouldPropagate = false;
    +355         },
    +356 
    +357         /**
    +358          * Dispatch/Broadcast Signal to all listeners added to the queue.
    +359          * @param {...*} [params] Parameters that should be passed to each handler.
    +360          */
    +361         dispatch : function (params) {
    +362             if (! this.active) {
    +363                 return;
    +364             }
    +365 
    +366             var paramsArr = Array.prototype.slice.call(arguments),
    +367                 n = this._bindings.length,
    +368                 bindings;
    +369 
    +370             if (this.memorize) {
    +371                 this._prevParams = paramsArr;
    +372             }
    +373 
    +374             if (! n) {
    +375                 //should come after memorize
    +376                 return;
    +377             }
    +378 
    +379             bindings = this._bindings.slice(); //clone array in case add/remove items during dispatch
    +380             this._shouldPropagate = true; //in case `halt` was called before dispatch or during the previous dispatch.
    +381 
    +382             //execute all callbacks until end of the list or until a callback returns `false` or stops propagation
    +383             //reverse loop since listeners with higher priority will be added at the end of the list
    +384             do { n--; } while (bindings[n] && this._shouldPropagate && bindings[n].execute(paramsArr) !== false);
    +385         },
    +386 
    +387         /**
    +388          * Forget memorized arguments.
    +389          * @see Signal.memorize
    +390          */
    +391         forget : function(){
    +392             this._prevParams = null;
    +393         },
    +394 
    +395         /**
    +396          * Remove all bindings from signal and destroy any reference to external objects (destroy Signal object).
    +397          * <p><strong>IMPORTANT:</strong> calling any method on the signal instance after calling dispose will throw errors.</p>
    +398          */
    +399         dispose : function () {
    +400             this.removeAll();
    +401             delete this._bindings;
    +402             delete this._prevParams;
    +403         },
    +404 
    +405         /**
    +406          * @return {string} String representation of the object.
    +407          */
    +408         toString : function () {
    +409             return '[Signal active:'+ this.active +' numListeners:'+ this.getNumListeners() +']';
    +410         }
    +411 
    +412     };
    +413 
    +414 
    +415     // Namespace -----------------------------------------------------
    +416     //================================================================
    +417 
    +418     /**
    +419      * Signals namespace
    +420      * @namespace
    +421      * @name signals
    +422      */
    +423     var signals = Signal;
    +424 
    +425     /**
    +426      * Custom event broadcaster
    +427      * @see Signal
    +428      */
    +429     // alias for backwards compatibility (see #gh-44)
    +430     signals.Signal = Signal;
    +431 
    +432 
    +433 
    +434     //exports to multiple environments
    +435     if(typeof define === 'function' && define.amd){ //AMD
    +436         define(function () { return signals; });
    +437     } else if (typeof module !== 'undefined' && module.exports){ //node
    +438         module.exports = signals;
    +439     } else { //browser
    +440         //use string because of Google closure compiler ADVANCED_MODE
    +441         /*jslint sub:true */
    +442         global['signals'] = signals;
    +443     }
    +444 
    +445 }(this));
    +446 
    \ No newline at end of file diff --git a/jspm_packages/npm/signals@1.0.0/dist/signals.js b/jspm_packages/npm/signals@1.0.0/dist/signals.js new file mode 100644 index 0000000..1b7a405 --- /dev/null +++ b/jspm_packages/npm/signals@1.0.0/dist/signals.js @@ -0,0 +1,447 @@ +/* */ +"format cjs"; +/*jslint onevar:true, undef:true, newcap:true, regexp:true, bitwise:true, maxerr:50, indent:4, white:false, nomen:false, plusplus:false */ +/*global define:false, require:false, exports:false, module:false, signals:false */ + +/** @license + * JS Signals + * Released under the MIT license + * Author: Miller Medeiros + * Version: 1.0.0 - Build: 268 (2012/11/29 05:48 PM) + */ + +(function(global){ + + // SignalBinding ------------------------------------------------- + //================================================================ + + /** + * Object that represents a binding between a Signal and a listener function. + *
    - This is an internal constructor and shouldn't be called by regular users. + *
    - inspired by Joa Ebert AS3 SignalBinding and Robert Penner's Slot classes. + * @author Miller Medeiros + * @constructor + * @internal + * @name SignalBinding + * @param {Signal} signal Reference to Signal object that listener is currently bound to. + * @param {Function} listener Handler function bound to the signal. + * @param {boolean} isOnce If binding should be executed just once. + * @param {Object} [listenerContext] Context on which listener will be executed (object that should represent the `this` variable inside listener function). + * @param {Number} [priority] The priority level of the event listener. (default = 0). + */ + function SignalBinding(signal, listener, isOnce, listenerContext, priority) { + + /** + * Handler function bound to the signal. + * @type Function + * @private + */ + this._listener = listener; + + /** + * If binding should be executed just once. + * @type boolean + * @private + */ + this._isOnce = isOnce; + + /** + * Context on which listener will be executed (object that should represent the `this` variable inside listener function). + * @memberOf SignalBinding.prototype + * @name context + * @type Object|undefined|null + */ + this.context = listenerContext; + + /** + * Reference to Signal object that listener is currently bound to. + * @type Signal + * @private + */ + this._signal = signal; + + /** + * Listener priority + * @type Number + * @private + */ + this._priority = priority || 0; + } + + SignalBinding.prototype = { + + /** + * If binding is active and should be executed. + * @type boolean + */ + active : true, + + /** + * Default parameters passed to listener during `Signal.dispatch` and `SignalBinding.execute`. (curried parameters) + * @type Array|null + */ + params : null, + + /** + * Call listener passing arbitrary parameters. + *

    If binding was added using `Signal.addOnce()` it will be automatically removed from signal dispatch queue, this method is used internally for the signal dispatch.

    + * @param {Array} [paramsArr] Array of parameters that should be passed to the listener + * @return {*} Value returned by the listener. + */ + execute : function (paramsArr) { + var handlerReturn, params; + if (this.active && !!this._listener) { + params = this.params? this.params.concat(paramsArr) : paramsArr; + handlerReturn = this._listener.apply(this.context, params); + if (this._isOnce) { + this.detach(); + } + } + return handlerReturn; + }, + + /** + * Detach binding from signal. + * - alias to: mySignal.remove(myBinding.getListener()); + * @return {Function|null} Handler function bound to the signal or `null` if binding was previously detached. + */ + detach : function () { + return this.isBound()? this._signal.remove(this._listener, this.context) : null; + }, + + /** + * @return {Boolean} `true` if binding is still bound to the signal and have a listener. + */ + isBound : function () { + return (!!this._signal && !!this._listener); + }, + + /** + * @return {boolean} If SignalBinding will only be executed once. + */ + isOnce : function () { + return this._isOnce; + }, + + /** + * @return {Function} Handler function bound to the signal. + */ + getListener : function () { + return this._listener; + }, + + /** + * @return {Signal} Signal that listener is currently bound to. + */ + getSignal : function () { + return this._signal; + }, + + /** + * Delete instance properties + * @private + */ + _destroy : function () { + delete this._signal; + delete this._listener; + delete this.context; + }, + + /** + * @return {string} String representation of the object. + */ + toString : function () { + return '[SignalBinding isOnce:' + this._isOnce +', isBound:'+ this.isBound() +', active:' + this.active + ']'; + } + + }; + + +/*global SignalBinding:false*/ + + // Signal -------------------------------------------------------- + //================================================================ + + function validateListener(listener, fnName) { + if (typeof listener !== 'function') { + throw new Error( 'listener is a required param of {fn}() and should be a Function.'.replace('{fn}', fnName) ); + } + } + + /** + * Custom event broadcaster + *
    - inspired by Robert Penner's AS3 Signals. + * @name Signal + * @author Miller Medeiros + * @constructor + */ + function Signal() { + /** + * @type Array. + * @private + */ + this._bindings = []; + this._prevParams = null; + + // enforce dispatch to aways work on same context (#47) + var self = this; + this.dispatch = function(){ + Signal.prototype.dispatch.apply(self, arguments); + }; + } + + Signal.prototype = { + + /** + * Signals Version Number + * @type String + * @const + */ + VERSION : '1.0.0', + + /** + * If Signal should keep record of previously dispatched parameters and + * automatically execute listener during `add()`/`addOnce()` if Signal was + * already dispatched before. + * @type boolean + */ + memorize : false, + + /** + * @type boolean + * @private + */ + _shouldPropagate : true, + + /** + * If Signal is active and should broadcast events. + *

    IMPORTANT: Setting this property during a dispatch will only affect the next dispatch, if you want to stop the propagation of a signal use `halt()` instead.

    + * @type boolean + */ + active : true, + + /** + * @param {Function} listener + * @param {boolean} isOnce + * @param {Object} [listenerContext] + * @param {Number} [priority] + * @return {SignalBinding} + * @private + */ + _registerListener : function (listener, isOnce, listenerContext, priority) { + + var prevIndex = this._indexOfListener(listener, listenerContext), + binding; + + if (prevIndex !== -1) { + binding = this._bindings[prevIndex]; + if (binding.isOnce() !== isOnce) { + throw new Error('You cannot add'+ (isOnce? '' : 'Once') +'() then add'+ (!isOnce? '' : 'Once') +'() the same listener without removing the relationship first.'); + } + } else { + binding = new SignalBinding(this, listener, isOnce, listenerContext, priority); + this._addBinding(binding); + } + + if(this.memorize && this._prevParams){ + binding.execute(this._prevParams); + } + + return binding; + }, + + /** + * @param {SignalBinding} binding + * @private + */ + _addBinding : function (binding) { + //simplified insertion sort + var n = this._bindings.length; + do { --n; } while (this._bindings[n] && binding._priority <= this._bindings[n]._priority); + this._bindings.splice(n + 1, 0, binding); + }, + + /** + * @param {Function} listener + * @return {number} + * @private + */ + _indexOfListener : function (listener, context) { + var n = this._bindings.length, + cur; + while (n--) { + cur = this._bindings[n]; + if (cur._listener === listener && cur.context === context) { + return n; + } + } + return -1; + }, + + /** + * Check if listener was attached to Signal. + * @param {Function} listener + * @param {Object} [context] + * @return {boolean} if Signal has the specified listener. + */ + has : function (listener, context) { + return this._indexOfListener(listener, context) !== -1; + }, + + /** + * Add a listener to the signal. + * @param {Function} listener Signal handler function. + * @param {Object} [listenerContext] Context on which listener will be executed (object that should represent the `this` variable inside listener function). + * @param {Number} [priority] The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0) + * @return {SignalBinding} An Object representing the binding between the Signal and listener. + */ + add : function (listener, listenerContext, priority) { + validateListener(listener, 'add'); + return this._registerListener(listener, false, listenerContext, priority); + }, + + /** + * Add listener to the signal that should be removed after first execution (will be executed only once). + * @param {Function} listener Signal handler function. + * @param {Object} [listenerContext] Context on which listener will be executed (object that should represent the `this` variable inside listener function). + * @param {Number} [priority] The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0) + * @return {SignalBinding} An Object representing the binding between the Signal and listener. + */ + addOnce : function (listener, listenerContext, priority) { + validateListener(listener, 'addOnce'); + return this._registerListener(listener, true, listenerContext, priority); + }, + + /** + * Remove a single listener from the dispatch queue. + * @param {Function} listener Handler function that should be removed. + * @param {Object} [context] Execution context (since you can add the same handler multiple times if executing in a different context). + * @return {Function} Listener handler function. + */ + remove : function (listener, context) { + validateListener(listener, 'remove'); + + var i = this._indexOfListener(listener, context); + if (i !== -1) { + this._bindings[i]._destroy(); //no reason to a SignalBinding exist if it isn't attached to a signal + this._bindings.splice(i, 1); + } + return listener; + }, + + /** + * Remove all listeners from the Signal. + */ + removeAll : function () { + var n = this._bindings.length; + while (n--) { + this._bindings[n]._destroy(); + } + this._bindings.length = 0; + }, + + /** + * @return {number} Number of listeners attached to the Signal. + */ + getNumListeners : function () { + return this._bindings.length; + }, + + /** + * Stop propagation of the event, blocking the dispatch to next listeners on the queue. + *

    IMPORTANT: should be called only during signal dispatch, calling it before/after dispatch won't affect signal broadcast.

    + * @see Signal.prototype.disable + */ + halt : function () { + this._shouldPropagate = false; + }, + + /** + * Dispatch/Broadcast Signal to all listeners added to the queue. + * @param {...*} [params] Parameters that should be passed to each handler. + */ + dispatch : function (params) { + if (! this.active) { + return; + } + + var paramsArr = Array.prototype.slice.call(arguments), + n = this._bindings.length, + bindings; + + if (this.memorize) { + this._prevParams = paramsArr; + } + + if (! n) { + //should come after memorize + return; + } + + bindings = this._bindings.slice(); //clone array in case add/remove items during dispatch + this._shouldPropagate = true; //in case `halt` was called before dispatch or during the previous dispatch. + + //execute all callbacks until end of the list or until a callback returns `false` or stops propagation + //reverse loop since listeners with higher priority will be added at the end of the list + do { n--; } while (bindings[n] && this._shouldPropagate && bindings[n].execute(paramsArr) !== false); + }, + + /** + * Forget memorized arguments. + * @see Signal.memorize + */ + forget : function(){ + this._prevParams = null; + }, + + /** + * Remove all bindings from signal and destroy any reference to external objects (destroy Signal object). + *

    IMPORTANT: calling any method on the signal instance after calling dispose will throw errors.

    + */ + dispose : function () { + this.removeAll(); + delete this._bindings; + delete this._prevParams; + }, + + /** + * @return {string} String representation of the object. + */ + toString : function () { + return '[Signal active:'+ this.active +' numListeners:'+ this.getNumListeners() +']'; + } + + }; + + + // Namespace ----------------------------------------------------- + //================================================================ + + /** + * Signals namespace + * @namespace + * @name signals + */ + var signals = Signal; + + /** + * Custom event broadcaster + * @see Signal + */ + // alias for backwards compatibility (see #gh-44) + signals.Signal = Signal; + + + + //exports to multiple environments + if(typeof define === 'function' && define.amd){ //AMD + define(function () { return signals; }); + } else if (typeof module !== 'undefined' && module.exports){ //node + module.exports = signals; + } else { //browser + //use string because of Google closure compiler ADVANCED_MODE + /*jslint sub:true */ + global['signals'] = signals; + } + +}(this)); diff --git a/jspm_packages/npm/signals@1.0.0/dist/signals.min.js b/jspm_packages/npm/signals@1.0.0/dist/signals.min.js new file mode 100644 index 0000000..a91d03f --- /dev/null +++ b/jspm_packages/npm/signals@1.0.0/dist/signals.min.js @@ -0,0 +1,16 @@ +/* */ +"format cjs"; +/* + + JS Signals + Released under the MIT license + Author: Miller Medeiros + Version: 1.0.0 - Build: 268 (2012/11/29 05:48 PM) +*/ +(function(i){function h(a,b,c,d,e){this._listener=b;this._isOnce=c;this.context=d;this._signal=a;this._priority=e||0}function g(a,b){if(typeof a!=="function")throw Error("listener is a required param of {fn}() and should be a Function.".replace("{fn}",b));}function e(){this._bindings=[];this._prevParams=null;var a=this;this.dispatch=function(){e.prototype.dispatch.apply(a,arguments)}}h.prototype={active:!0,params:null,execute:function(a){var b;this.active&&this._listener&&(a=this.params?this.params.concat(a): +a,b=this._listener.apply(this.context,a),this._isOnce&&this.detach());return b},detach:function(){return this.isBound()?this._signal.remove(this._listener,this.context):null},isBound:function(){return!!this._signal&&!!this._listener},isOnce:function(){return this._isOnce},getListener:function(){return this._listener},getSignal:function(){return this._signal},_destroy:function(){delete this._signal;delete this._listener;delete this.context},toString:function(){return"[SignalBinding isOnce:"+this._isOnce+ +", isBound:"+this.isBound()+", active:"+this.active+"]"}};e.prototype={VERSION:"1.0.0",memorize:!1,_shouldPropagate:!0,active:!0,_registerListener:function(a,b,c,d){var e=this._indexOfListener(a,c);if(e!==-1){if(a=this._bindings[e],a.isOnce()!==b)throw Error("You cannot add"+(b?"":"Once")+"() then add"+(!b?"":"Once")+"() the same listener without removing the relationship first.");}else a=new h(this,a,b,c,d),this._addBinding(a);this.memorize&&this._prevParams&&a.execute(this._prevParams);return a}, +_addBinding:function(a){var b=this._bindings.length;do--b;while(this._bindings[b]&&a._priority<=this._bindings[b]._priority);this._bindings.splice(b+1,0,a)},_indexOfListener:function(a,b){for(var c=this._bindings.length,d;c--;)if(d=this._bindings[c],d._listener===a&&d.context===b)return c;return-1},has:function(a,b){return this._indexOfListener(a,b)!==-1},add:function(a,b,c){g(a,"add");return this._registerListener(a,!1,b,c)},addOnce:function(a,b,c){g(a,"addOnce");return this._registerListener(a, +!0,b,c)},remove:function(a,b){g(a,"remove");var c=this._indexOfListener(a,b);c!==-1&&(this._bindings[c]._destroy(),this._bindings.splice(c,1));return a},removeAll:function(){for(var a=this._bindings.length;a--;)this._bindings[a]._destroy();this._bindings.length=0},getNumListeners:function(){return this._bindings.length},halt:function(){this._shouldPropagate=!1},dispatch:function(a){if(this.active){var b=Array.prototype.slice.call(arguments),c=this._bindings.length,d;if(this.memorize)this._prevParams= +b;if(c){d=this._bindings.slice();this._shouldPropagate=!0;do c--;while(d[c]&&this._shouldPropagate&&d[c].execute(b)!==!1)}}},forget:function(){this._prevParams=null},dispose:function(){this.removeAll();delete this._bindings;delete this._prevParams},toString:function(){return"[Signal active:"+this.active+" numListeners:"+this.getNumListeners()+"]"}};var f=e;f.Signal=e;typeof define==="function"&&define.amd?define(function(){return f}):typeof module!=="undefined"&&module.exports?module.exports=f:i.signals= +f})(this); \ No newline at end of file diff --git a/jspm_packages/npm/signals@1.0.0/package.json b/jspm_packages/npm/signals@1.0.0/package.json new file mode 100644 index 0000000..e1ba0a9 --- /dev/null +++ b/jspm_packages/npm/signals@1.0.0/package.json @@ -0,0 +1,28 @@ +{ + "name" : "signals", + "description" : "Custom Event/Messaging System", + "keywords" : ["js-signals", "signals", "pub/sub", "event", "publish", "subscribe", "observer"], + "homepage" : "http://millermedeiros.github.com/js-signals/", + "version" : "1.0.0", + "author" : { + "name" : "Miller Medeiros", + "url" : "http://blog.millermedeiros.com/" + }, + "repository" : { + "type" : "git", + "url" : "https://github.com/millermedeiros/js-signals.git" + }, + "main" : "dist/signals.js", + "bugs" : { + "url" : "https://github.com/millermedeiros/js-signals/issues" + }, + "directories" : { + "doc" : "./dist/docs" + }, + "licenses" : [ + { + "type" : "MIT", + "url" : "http://www.opensource.org/licenses/mit-license.php" + } + ] +} diff --git a/jspm_packages/npm/signals@1.0.0/updateDocs.sh b/jspm_packages/npm/signals@1.0.0/updateDocs.sh new file mode 100644 index 0000000..9bb3487 --- /dev/null +++ b/jspm_packages/npm/signals@1.0.0/updateDocs.sh @@ -0,0 +1,12 @@ +# update docs on gh-pages branch + +git checkout gh-pages +rm -r docs/ +git checkout master dist/docs/ +mkdir docs/ +mv dist/docs/* docs/. +rm -r dist/ +git add -A +git commit +git checkout master + diff --git a/jspm_packages/npm/util@0.10.3.js b/jspm_packages/npm/util@0.10.3.js new file mode 100644 index 0000000..78b8116 --- /dev/null +++ b/jspm_packages/npm/util@0.10.3.js @@ -0,0 +1 @@ +module.exports = require("npm:util@0.10.3/util.js"); \ No newline at end of file diff --git a/jspm_packages/npm/util@0.10.3/.jspm-hash b/jspm_packages/npm/util@0.10.3/.jspm-hash new file mode 100644 index 0000000..fc61500 --- /dev/null +++ b/jspm_packages/npm/util@0.10.3/.jspm-hash @@ -0,0 +1 @@ +7afb1afe50805246489e3db7fe0ed379336ac0f999914b932bd37a50b983c5e7c90ae93bjspm-npm@0.260.16.1 \ No newline at end of file diff --git a/jspm_packages/npm/util@0.10.3/.npmignore b/jspm_packages/npm/util@0.10.3/.npmignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/jspm_packages/npm/util@0.10.3/.npmignore @@ -0,0 +1 @@ +node_modules diff --git a/jspm_packages/npm/util@0.10.3/.travis.yml b/jspm_packages/npm/util@0.10.3/.travis.yml new file mode 100644 index 0000000..ded625c --- /dev/null +++ b/jspm_packages/npm/util@0.10.3/.travis.yml @@ -0,0 +1,8 @@ +language: node_js +node_js: +- '0.8' +- '0.10' +env: + global: + - secure: AdUubswCR68/eGD+WWjwTHgFbelwQGnNo81j1IOaUxKw+zgFPzSnFEEtDw7z98pWgg7p9DpCnyzzSnSllP40wq6AG19OwyUJjSLoZK57fp+r8zwTQwWiSqUgMu2YSMmKJPIO/aoSGpRQXT+L1nRrHoUJXgFodyIZgz40qzJeZjc= + - secure: heQuxPVsQ7jBbssoVKimXDpqGjQFiucm6W5spoujmspjDG7oEcHD9ANo9++LoRPrsAmNx56SpMK5fNfVmYediw6SvhXm4Mxt56/fYCrLDBtgGG+1neCeffAi8z1rO8x48m77hcQ6YhbUL5R9uBimUjMX92fZcygAt8Rg804zjFo= diff --git a/jspm_packages/npm/util@0.10.3/.zuul.yml b/jspm_packages/npm/util@0.10.3/.zuul.yml new file mode 100644 index 0000000..2105010 --- /dev/null +++ b/jspm_packages/npm/util@0.10.3/.zuul.yml @@ -0,0 +1,10 @@ +ui: mocha-qunit +browsers: + - name: chrome + version: 27..latest + - name: firefox + version: latest + - name: safari + version: latest + - name: ie + version: 9..latest diff --git a/jspm_packages/npm/util@0.10.3/LICENSE b/jspm_packages/npm/util@0.10.3/LICENSE new file mode 100644 index 0000000..e3d4e69 --- /dev/null +++ b/jspm_packages/npm/util@0.10.3/LICENSE @@ -0,0 +1,18 @@ +Copyright Joyent, Inc. and other Node contributors. All rights reserved. +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to +deal in the Software without restriction, including without limitation the +rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +IN THE SOFTWARE. diff --git a/jspm_packages/npm/util@0.10.3/README.md b/jspm_packages/npm/util@0.10.3/README.md new file mode 100644 index 0000000..1c473d2 --- /dev/null +++ b/jspm_packages/npm/util@0.10.3/README.md @@ -0,0 +1,15 @@ +# util + +[![Build Status](https://travis-ci.org/defunctzombie/node-util.png?branch=master)](https://travis-ci.org/defunctzombie/node-util) + +node.js [util](http://nodejs.org/api/util.html) module as a module + +## install via [npm](npmjs.org) + +```shell +npm install util +``` + +## browser support + +This module also works in modern browsers. If you need legacy browser support you will need to polyfill ES5 features. diff --git a/jspm_packages/npm/util@0.10.3/package.json b/jspm_packages/npm/util@0.10.3/package.json new file mode 100644 index 0000000..738d0a8 --- /dev/null +++ b/jspm_packages/npm/util@0.10.3/package.json @@ -0,0 +1,31 @@ +{ + "author": { + "name": "Joyent", + "url": "http://www.joyent.com" + }, + "name": "util", + "description": "Node.JS util module", + "keywords": [ + "util" + ], + "version": "0.10.3", + "homepage": "https://github.com/defunctzombie/node-util", + "repository": { + "type": "git", + "url": "git://github.com/defunctzombie/node-util" + }, + "main": "./util.js", + "scripts": { + "test": "node test/node/*.js && zuul test/browser/*.js" + }, + "dependencies": { + "inherits": "2.0.1" + }, + "license": "MIT", + "devDependencies": { + "zuul": "~1.0.9" + }, + "browser": { + "./support/isBuffer.js": "./support/isBufferBrowser.js" + } +} diff --git a/jspm_packages/npm/util@0.10.3/support/isBuffer.js b/jspm_packages/npm/util@0.10.3/support/isBuffer.js new file mode 100644 index 0000000..5003347 --- /dev/null +++ b/jspm_packages/npm/util@0.10.3/support/isBuffer.js @@ -0,0 +1,6 @@ +/* */ +(function(Buffer) { + module.exports = function isBuffer(arg) { + return arg instanceof Buffer; + }; +})(require('buffer').Buffer); diff --git a/jspm_packages/npm/util@0.10.3/support/isBufferBrowser.js b/jspm_packages/npm/util@0.10.3/support/isBufferBrowser.js new file mode 100644 index 0000000..73d1ff9 --- /dev/null +++ b/jspm_packages/npm/util@0.10.3/support/isBufferBrowser.js @@ -0,0 +1,7 @@ +/* */ +module.exports = function isBuffer(arg) { + return arg && typeof arg === 'object' + && typeof arg.copy === 'function' + && typeof arg.fill === 'function' + && typeof arg.readUInt8 === 'function'; +} \ No newline at end of file diff --git a/jspm_packages/npm/util@0.10.3/test/browser/inspect.js b/jspm_packages/npm/util@0.10.3/test/browser/inspect.js new file mode 100644 index 0000000..9f3e38a --- /dev/null +++ b/jspm_packages/npm/util@0.10.3/test/browser/inspect.js @@ -0,0 +1,18 @@ +/* */ +var assert = require('assert'); +var util = require('../../util'); +suite('inspect'); +test('util.inspect - test for sparse array', function() { + var a = ['foo', 'bar', 'baz']; + assert.equal(util.inspect(a), '[ \'foo\', \'bar\', \'baz\' ]'); + delete a[1]; + assert.equal(util.inspect(a), '[ \'foo\', , \'baz\' ]'); + assert.equal(util.inspect(a, true), '[ \'foo\', , \'baz\', [length]: 3 ]'); + assert.equal(util.inspect(new Array(5)), '[ , , , , ]'); +}); +test('util.inspect - exceptions should print the error message, not \'{}\'', function() { + assert.equal(util.inspect(new Error()), '[Error]'); + assert.equal(util.inspect(new Error('FAIL')), '[Error: FAIL]'); + assert.equal(util.inspect(new TypeError('FAIL')), '[TypeError: FAIL]'); + assert.equal(util.inspect(new SyntaxError('FAIL')), '[SyntaxError: FAIL]'); +}); diff --git a/jspm_packages/npm/util@0.10.3/test/browser/is.js b/jspm_packages/npm/util@0.10.3/test/browser/is.js new file mode 100644 index 0000000..93fb171 --- /dev/null +++ b/jspm_packages/npm/util@0.10.3/test/browser/is.js @@ -0,0 +1,77 @@ +/* */ +(function(Buffer) { + var assert = require('assert'); + var util = require('../../util'); + suite('is'); + test('util.isArray', function() { + assert.equal(true, util.isArray([])); + assert.equal(true, util.isArray(Array())); + assert.equal(true, util.isArray(new Array())); + assert.equal(true, util.isArray(new Array(5))); + assert.equal(true, util.isArray(new Array('with', 'some', 'entries'))); + assert.equal(false, util.isArray({})); + assert.equal(false, util.isArray({push: function() {}})); + assert.equal(false, util.isArray(/regexp/)); + assert.equal(false, util.isArray(new Error())); + assert.equal(false, util.isArray(Object.create(Array.prototype))); + }); + test('util.isRegExp', function() { + assert.equal(true, util.isRegExp(/regexp/)); + assert.equal(true, util.isRegExp(RegExp())); + assert.equal(true, util.isRegExp(new RegExp())); + assert.equal(false, util.isRegExp({})); + assert.equal(false, util.isRegExp([])); + assert.equal(false, util.isRegExp(new Date())); + assert.equal(false, util.isRegExp(Object.create(RegExp.prototype))); + }); + test('util.isDate', function() { + assert.equal(true, util.isDate(new Date())); + assert.equal(true, util.isDate(new Date(0))); + assert.equal(false, util.isDate(Date())); + assert.equal(false, util.isDate({})); + assert.equal(false, util.isDate([])); + assert.equal(false, util.isDate(new Error())); + assert.equal(false, util.isDate(Object.create(Date.prototype))); + }); + test('util.isError', function() { + assert.equal(true, util.isError(new Error())); + assert.equal(true, util.isError(new TypeError())); + assert.equal(true, util.isError(new SyntaxError())); + assert.equal(false, util.isError({})); + assert.equal(false, util.isError({ + name: 'Error', + message: '' + })); + assert.equal(false, util.isError([])); + assert.equal(true, util.isError(Object.create(Error.prototype))); + }); + test('util._extend', function() { + assert.deepEqual(util._extend({a: 1}), {a: 1}); + assert.deepEqual(util._extend({a: 1}, []), {a: 1}); + assert.deepEqual(util._extend({a: 1}, null), {a: 1}); + assert.deepEqual(util._extend({a: 1}, true), {a: 1}); + assert.deepEqual(util._extend({a: 1}, false), {a: 1}); + assert.deepEqual(util._extend({a: 1}, {b: 2}), { + a: 1, + b: 2 + }); + assert.deepEqual(util._extend({ + a: 1, + b: 2 + }, {b: 3}), { + a: 1, + b: 3 + }); + }); + test('util.isBuffer', function() { + assert.equal(true, util.isBuffer(new Buffer(4))); + assert.equal(true, util.isBuffer(Buffer(4))); + assert.equal(true, util.isBuffer(new Buffer(4))); + assert.equal(true, util.isBuffer(new Buffer([1, 2, 3, 4]))); + assert.equal(false, util.isBuffer({})); + assert.equal(false, util.isBuffer([])); + assert.equal(false, util.isBuffer(new Error())); + assert.equal(false, util.isRegExp(new Date())); + assert.equal(true, util.isBuffer(Object.create(Buffer.prototype))); + }); +})(require('buffer').Buffer); diff --git a/jspm_packages/npm/util@0.10.3/test/node/debug.js b/jspm_packages/npm/util@0.10.3/test/node/debug.js new file mode 100644 index 0000000..1d4d79c --- /dev/null +++ b/jspm_packages/npm/util@0.10.3/test/node/debug.js @@ -0,0 +1,54 @@ +/* */ +(function(process) { + var assert = require('assert'); + var util = require('../../util'); + if (process.argv[2] === 'child') + child(); + else + parent(); + function parent() { + test('foo,tud,bar', true); + test('foo,tud', true); + test('tud,bar', true); + test('tud', true); + test('foo,bar', false); + test('', false); + } + function test(environ, shouldWrite) { + var expectErr = ''; + if (shouldWrite) { + expectErr = 'TUD %PID%: this { is: \'a\' } /debugging/\n' + 'TUD %PID%: number=1234 string=asdf obj={"foo":"bar"}\n'; + } + var expectOut = 'ok\n'; + var didTest = false; + var spawn = require('child_process').spawn; + var child = spawn(process.execPath, [__filename, 'child'], {env: {NODE_DEBUG: environ}}); + expectErr = expectErr.split('%PID%').join(child.pid); + var err = ''; + child.stderr.setEncoding('utf8'); + child.stderr.on('data', function(c) { + err += c; + }); + var out = ''; + child.stdout.setEncoding('utf8'); + child.stdout.on('data', function(c) { + out += c; + }); + child.on('close', function(c) { + assert(!c); + assert.equal(err, expectErr); + assert.equal(out, expectOut); + didTest = true; + console.log('ok %j %j', environ, shouldWrite); + }); + process.on('exit', function() { + assert(didTest); + }); + } + function child() { + var debug = util.debuglog('tud'); + debug('this', {is: 'a'}, /debugging/); + debug('number=%d string=%s obj=%j', 1234, 'asdf', {foo: 'bar'}); + console.log('ok'); + } +})(require('process')); diff --git a/jspm_packages/npm/util@0.10.3/test/node/format.js b/jspm_packages/npm/util@0.10.3/test/node/format.js new file mode 100644 index 0000000..1921156 --- /dev/null +++ b/jspm_packages/npm/util@0.10.3/test/node/format.js @@ -0,0 +1,50 @@ +/* */ +var assert = require('assert'); +var util = require('../../util'); +assert.equal(util.format(), ''); +assert.equal(util.format(''), ''); +assert.equal(util.format([]), '[]'); +assert.equal(util.format({}), '{}'); +assert.equal(util.format(null), 'null'); +assert.equal(util.format(true), 'true'); +assert.equal(util.format(false), 'false'); +assert.equal(util.format('test'), 'test'); +assert.equal(util.format('foo', 'bar', 'baz'), 'foo bar baz'); +assert.equal(util.format('%d', 42.0), '42'); +assert.equal(util.format('%d', 42), '42'); +assert.equal(util.format('%s', 42), '42'); +assert.equal(util.format('%j', 42), '42'); +assert.equal(util.format('%d', '42.0'), '42'); +assert.equal(util.format('%d', '42'), '42'); +assert.equal(util.format('%s', '42'), '42'); +assert.equal(util.format('%j', '42'), '"42"'); +assert.equal(util.format('%%s%s', 'foo'), '%sfoo'); +assert.equal(util.format('%s'), '%s'); +assert.equal(util.format('%s', undefined), 'undefined'); +assert.equal(util.format('%s', 'foo'), 'foo'); +assert.equal(util.format('%s:%s'), '%s:%s'); +assert.equal(util.format('%s:%s', undefined), 'undefined:%s'); +assert.equal(util.format('%s:%s', 'foo'), 'foo:%s'); +assert.equal(util.format('%s:%s', 'foo', 'bar'), 'foo:bar'); +assert.equal(util.format('%s:%s', 'foo', 'bar', 'baz'), 'foo:bar baz'); +assert.equal(util.format('%%%s%%', 'hi'), '%hi%'); +assert.equal(util.format('%%%s%%%%', 'hi'), '%hi%%'); +(function() { + var o = {}; + o.o = o; + assert.equal(util.format('%j', o), '[Circular]'); +})(); +assert.equal(util.format(new Error('foo')), '[Error: foo]'); +function CustomError(msg) { + Error.call(this); + Object.defineProperty(this, 'message', { + value: msg, + enumerable: false + }); + Object.defineProperty(this, 'name', { + value: 'CustomError', + enumerable: false + }); +} +util.inherits(CustomError, Error); +assert.equal(util.format(new CustomError('bar')), '[CustomError: bar]'); diff --git a/jspm_packages/npm/util@0.10.3/test/node/inspect.js b/jspm_packages/npm/util@0.10.3/test/node/inspect.js new file mode 100644 index 0000000..1655aa4 --- /dev/null +++ b/jspm_packages/npm/util@0.10.3/test/node/inspect.js @@ -0,0 +1,139 @@ +/* */ +var assert = require('assert'); +var util = require('../../util'); +var Date2 = require('vm').runInNewContext('Date'); +var d = new Date2(); +var orig = util.inspect(d); +Date2.prototype.foo = 'bar'; +var after = util.inspect(d); +assert.equal(orig, after); +var a = ['foo', 'bar', 'baz']; +assert.equal(util.inspect(a), '[ \'foo\', \'bar\', \'baz\' ]'); +delete a[1]; +assert.equal(util.inspect(a), '[ \'foo\', , \'baz\' ]'); +assert.equal(util.inspect(a, true), '[ \'foo\', , \'baz\', [length]: 3 ]'); +assert.equal(util.inspect(new Array(5)), '[ , , , , ]'); +var getter = Object.create(null, {a: {get: function() { + return 'aaa'; + }}}); +var setter = Object.create(null, {b: {set: function() {}}}); +var getterAndSetter = Object.create(null, {c: { + get: function() { + return 'ccc'; + }, + set: function() {} + }}); +assert.equal(util.inspect(getter, true), '{ [a]: [Getter] }'); +assert.equal(util.inspect(setter, true), '{ [b]: [Setter] }'); +assert.equal(util.inspect(getterAndSetter, true), '{ [c]: [Getter/Setter] }'); +assert.equal(util.inspect(new Error()), '[Error]'); +assert.equal(util.inspect(new Error('FAIL')), '[Error: FAIL]'); +assert.equal(util.inspect(new TypeError('FAIL')), '[TypeError: FAIL]'); +assert.equal(util.inspect(new SyntaxError('FAIL')), '[SyntaxError: FAIL]'); +try { + undef(); +} catch (e) { + assert.equal(util.inspect(e), '[ReferenceError: undef is not defined]'); +} +var ex = util.inspect(new Error('FAIL'), true); +assert.ok(ex.indexOf('[Error: FAIL]') != -1); +assert.ok(ex.indexOf('[stack]') != -1); +assert.ok(ex.indexOf('[message]') != -1); +assert.equal(util.inspect(Object.create(Date.prototype)), '{}'); +assert.doesNotThrow(function() { + var d = new Date(); + d.toUTCString = null; + util.inspect(d); +}); +assert.doesNotThrow(function() { + var r = /regexp/; + r.toString = null; + util.inspect(r); +}); +assert.doesNotThrow(function() { + util.inspect([{inspect: function() { + return 123; + }}]); +}); +var x = {inspect: util.inspect}; +assert.ok(util.inspect(x).indexOf('inspect') != -1); +function test_color_style(style, input, implicit) { + var color_name = util.inspect.styles[style]; + var color = ['', '']; + if (util.inspect.colors[color_name]) + color = util.inspect.colors[color_name]; + var without_color = util.inspect(input, false, 0, false); + var with_color = util.inspect(input, false, 0, true); + var expect = '\u001b[' + color[0] + 'm' + without_color + '\u001b[' + color[1] + 'm'; + assert.equal(with_color, expect, 'util.inspect color for style ' + style); +} +test_color_style('special', function() {}); +test_color_style('number', 123.456); +test_color_style('boolean', true); +test_color_style('undefined', undefined); +test_color_style('null', null); +test_color_style('string', 'test string'); +test_color_style('date', new Date); +test_color_style('regexp', /regexp/); +assert.doesNotThrow(function() { + util.inspect({hasOwnProperty: null}); +}); +var subject = { + foo: 'bar', + hello: 31, + a: {b: {c: {d: 0}}} +}; +Object.defineProperty(subject, 'hidden', { + enumerable: false, + value: null +}); +assert(util.inspect(subject, {showHidden: false}).indexOf('hidden') === -1); +assert(util.inspect(subject, {showHidden: true}).indexOf('hidden') !== -1); +assert(util.inspect(subject, {colors: false}).indexOf('\u001b[32m') === -1); +assert(util.inspect(subject, {colors: true}).indexOf('\u001b[32m') !== -1); +assert(util.inspect(subject, {depth: 2}).indexOf('c: [Object]') !== -1); +assert(util.inspect(subject, {depth: 0}).indexOf('a: [Object]') !== -1); +assert(util.inspect(subject, {depth: null}).indexOf('{ d: 0 }') !== -1); +subject = {inspect: function() { + return 123; + }}; +assert(util.inspect(subject, {customInspect: true}).indexOf('123') !== -1); +assert(util.inspect(subject, {customInspect: true}).indexOf('inspect') === -1); +assert(util.inspect(subject, {customInspect: false}).indexOf('123') === -1); +assert(util.inspect(subject, {customInspect: false}).indexOf('inspect') !== -1); +subject.inspect = function() { + return {foo: 'bar'}; +}; +assert.equal(util.inspect(subject), '{ foo: \'bar\' }'); +subject.inspect = function(depth, opts) { + assert.strictEqual(opts.customInspectOptions, true); +}; +util.inspect(subject, {customInspectOptions: true}); +function test_lines(input) { + var count_lines = function(str) { + return (str.match(/\n/g) || []).length; + }; + var without_color = util.inspect(input); + var with_color = util.inspect(input, {colors: true}); + assert.equal(count_lines(without_color), count_lines(with_color)); +} +test_lines([1, 2, 3, 4, 5, 6, 7]); +test_lines(function() { + var big_array = []; + for (var i = 0; i < 100; i++) { + big_array.push(i); + } + return big_array; +}()); +test_lines({ + foo: 'bar', + baz: 35, + b: {a: 35} +}); +test_lines({ + foo: 'bar', + baz: 35, + b: {a: 35}, + very_long_key: 'very_long_value', + even_longer_key: ['with even longer value in array'] +}); diff --git a/jspm_packages/npm/util@0.10.3/test/node/log.js b/jspm_packages/npm/util@0.10.3/test/node/log.js new file mode 100644 index 0000000..bf1fa61 --- /dev/null +++ b/jspm_packages/npm/util@0.10.3/test/node/log.js @@ -0,0 +1,50 @@ +/* */ +(function(process) { + var assert = require('assert'); + var util = require('../../util'); + assert.ok(process.stdout.writable); + assert.ok(process.stderr.writable); + var stdout_write = global.process.stdout.write; + var strings = []; + global.process.stdout.write = function(string) { + strings.push(string); + }; + console._stderr = process.stdout; + var tests = [{ + input: 'foo', + output: 'foo' + }, { + input: undefined, + output: 'undefined' + }, { + input: null, + output: 'null' + }, { + input: false, + output: 'false' + }, { + input: 42, + output: '42' + }, { + input: function() {}, + output: '[Function]' + }, { + input: parseInt('not a number', 10), + output: 'NaN' + }, { + input: {answer: 42}, + output: '{ answer: 42 }' + }, { + input: [1, 2, 3], + output: '[ 1, 2, 3 ]' + }]; + tests.forEach(function(test) { + util.log(test.input); + var result = strings.shift().trim(), + re = (/[0-9]{1,2} [A-Z][a-z]{2} [0-9]{2}:[0-9]{2}:[0-9]{2} - (.+)$/), + match = re.exec(result); + assert.ok(match); + assert.equal(match[1], test.output); + }); + global.process.stdout.write = stdout_write; +})(require('process')); diff --git a/jspm_packages/npm/util@0.10.3/test/node/util.js b/jspm_packages/npm/util@0.10.3/test/node/util.js new file mode 100644 index 0000000..52ec9c7 --- /dev/null +++ b/jspm_packages/npm/util@0.10.3/test/node/util.js @@ -0,0 +1,61 @@ +/* */ +var assert = require('assert'); +var context = require('vm').runInNewContext; +var util = require('../../util'); +assert.equal(true, util.isArray([])); +assert.equal(true, util.isArray(Array())); +assert.equal(true, util.isArray(new Array())); +assert.equal(true, util.isArray(new Array(5))); +assert.equal(true, util.isArray(new Array('with', 'some', 'entries'))); +assert.equal(true, util.isArray(context('Array')())); +assert.equal(false, util.isArray({})); +assert.equal(false, util.isArray({push: function() {}})); +assert.equal(false, util.isArray(/regexp/)); +assert.equal(false, util.isArray(new Error)); +assert.equal(false, util.isArray(Object.create(Array.prototype))); +assert.equal(true, util.isRegExp(/regexp/)); +assert.equal(true, util.isRegExp(RegExp())); +assert.equal(true, util.isRegExp(new RegExp())); +assert.equal(true, util.isRegExp(context('RegExp')())); +assert.equal(false, util.isRegExp({})); +assert.equal(false, util.isRegExp([])); +assert.equal(false, util.isRegExp(new Date())); +assert.equal(false, util.isRegExp(Object.create(RegExp.prototype))); +assert.equal(true, util.isDate(new Date())); +assert.equal(true, util.isDate(new Date(0))); +assert.equal(true, util.isDate(new (context('Date')))); +assert.equal(false, util.isDate(Date())); +assert.equal(false, util.isDate({})); +assert.equal(false, util.isDate([])); +assert.equal(false, util.isDate(new Error)); +assert.equal(false, util.isDate(Object.create(Date.prototype))); +assert.equal(true, util.isError(new Error)); +assert.equal(true, util.isError(new TypeError)); +assert.equal(true, util.isError(new SyntaxError)); +assert.equal(true, util.isError(new (context('Error')))); +assert.equal(true, util.isError(new (context('TypeError')))); +assert.equal(true, util.isError(new (context('SyntaxError')))); +assert.equal(false, util.isError({})); +assert.equal(false, util.isError({ + name: 'Error', + message: '' +})); +assert.equal(false, util.isError([])); +assert.equal(true, util.isError(Object.create(Error.prototype))); +assert.ok(util.isObject({}) === true); +assert.deepEqual(util._extend({a: 1}), {a: 1}); +assert.deepEqual(util._extend({a: 1}, []), {a: 1}); +assert.deepEqual(util._extend({a: 1}, null), {a: 1}); +assert.deepEqual(util._extend({a: 1}, true), {a: 1}); +assert.deepEqual(util._extend({a: 1}, false), {a: 1}); +assert.deepEqual(util._extend({a: 1}, {b: 2}), { + a: 1, + b: 2 +}); +assert.deepEqual(util._extend({ + a: 1, + b: 2 +}, {b: 3}), { + a: 1, + b: 3 +}); diff --git a/jspm_packages/npm/util@0.10.3/util.js b/jspm_packages/npm/util@0.10.3/util.js new file mode 100644 index 0000000..e11db0e --- /dev/null +++ b/jspm_packages/npm/util@0.10.3/util.js @@ -0,0 +1,424 @@ +/* */ +(function(process) { + var formatRegExp = /%[sdj%]/g; + exports.format = function(f) { + if (!isString(f)) { + var objects = []; + for (var i = 0; i < arguments.length; i++) { + objects.push(inspect(arguments[i])); + } + return objects.join(' '); + } + var i = 1; + var args = arguments; + var len = args.length; + var str = String(f).replace(formatRegExp, function(x) { + if (x === '%%') + return '%'; + if (i >= len) + return x; + switch (x) { + case '%s': + return String(args[i++]); + case '%d': + return Number(args[i++]); + case '%j': + try { + return JSON.stringify(args[i++]); + } catch (_) { + return '[Circular]'; + } + default: + return x; + } + }); + for (var x = args[i]; i < len; x = args[++i]) { + if (isNull(x) || !isObject(x)) { + str += ' ' + x; + } else { + str += ' ' + inspect(x); + } + } + return str; + }; + exports.deprecate = function(fn, msg) { + if (isUndefined(global.process)) { + return function() { + return exports.deprecate(fn, msg).apply(this, arguments); + }; + } + if (process.noDeprecation === true) { + return fn; + } + var warned = false; + function deprecated() { + if (!warned) { + if (process.throwDeprecation) { + throw new Error(msg); + } else if (process.traceDeprecation) { + console.trace(msg); + } else { + console.error(msg); + } + warned = true; + } + return fn.apply(this, arguments); + } + return deprecated; + }; + var debugs = {}; + var debugEnviron; + exports.debuglog = function(set) { + if (isUndefined(debugEnviron)) + debugEnviron = process.env.NODE_DEBUG || ''; + set = set.toUpperCase(); + if (!debugs[set]) { + if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) { + var pid = process.pid; + debugs[set] = function() { + var msg = exports.format.apply(exports, arguments); + console.error('%s %d: %s', set, pid, msg); + }; + } else { + debugs[set] = function() {}; + } + } + return debugs[set]; + }; + function inspect(obj, opts) { + var ctx = { + seen: [], + stylize: stylizeNoColor + }; + if (arguments.length >= 3) + ctx.depth = arguments[2]; + if (arguments.length >= 4) + ctx.colors = arguments[3]; + if (isBoolean(opts)) { + ctx.showHidden = opts; + } else if (opts) { + exports._extend(ctx, opts); + } + if (isUndefined(ctx.showHidden)) + ctx.showHidden = false; + if (isUndefined(ctx.depth)) + ctx.depth = 2; + if (isUndefined(ctx.colors)) + ctx.colors = false; + if (isUndefined(ctx.customInspect)) + ctx.customInspect = true; + if (ctx.colors) + ctx.stylize = stylizeWithColor; + return formatValue(ctx, obj, ctx.depth); + } + exports.inspect = inspect; + inspect.colors = { + 'bold': [1, 22], + 'italic': [3, 23], + 'underline': [4, 24], + 'inverse': [7, 27], + 'white': [37, 39], + 'grey': [90, 39], + 'black': [30, 39], + 'blue': [34, 39], + 'cyan': [36, 39], + 'green': [32, 39], + 'magenta': [35, 39], + 'red': [31, 39], + 'yellow': [33, 39] + }; + inspect.styles = { + 'special': 'cyan', + 'number': 'yellow', + 'boolean': 'yellow', + 'undefined': 'grey', + 'null': 'bold', + 'string': 'green', + 'date': 'magenta', + 'regexp': 'red' + }; + function stylizeWithColor(str, styleType) { + var style = inspect.styles[styleType]; + if (style) { + return '\u001b[' + inspect.colors[style][0] + 'm' + str + '\u001b[' + inspect.colors[style][1] + 'm'; + } else { + return str; + } + } + function stylizeNoColor(str, styleType) { + return str; + } + function arrayToHash(array) { + var hash = {}; + array.forEach(function(val, idx) { + hash[val] = true; + }); + return hash; + } + function formatValue(ctx, value, recurseTimes) { + if (ctx.customInspect && value && isFunction(value.inspect) && value.inspect !== exports.inspect && !(value.constructor && value.constructor.prototype === value)) { + var ret = value.inspect(recurseTimes, ctx); + if (!isString(ret)) { + ret = formatValue(ctx, ret, recurseTimes); + } + return ret; + } + var primitive = formatPrimitive(ctx, value); + if (primitive) { + return primitive; + } + var keys = Object.keys(value); + var visibleKeys = arrayToHash(keys); + if (ctx.showHidden) { + keys = Object.getOwnPropertyNames(value); + } + if (isError(value) && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) { + return formatError(value); + } + if (keys.length === 0) { + if (isFunction(value)) { + var name = value.name ? ': ' + value.name : ''; + return ctx.stylize('[Function' + name + ']', 'special'); + } + if (isRegExp(value)) { + return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); + } + if (isDate(value)) { + return ctx.stylize(Date.prototype.toString.call(value), 'date'); + } + if (isError(value)) { + return formatError(value); + } + } + var base = '', + array = false, + braces = ['{', '}']; + if (isArray(value)) { + array = true; + braces = ['[', ']']; + } + if (isFunction(value)) { + var n = value.name ? ': ' + value.name : ''; + base = ' [Function' + n + ']'; + } + if (isRegExp(value)) { + base = ' ' + RegExp.prototype.toString.call(value); + } + if (isDate(value)) { + base = ' ' + Date.prototype.toUTCString.call(value); + } + if (isError(value)) { + base = ' ' + formatError(value); + } + if (keys.length === 0 && (!array || value.length == 0)) { + return braces[0] + base + braces[1]; + } + if (recurseTimes < 0) { + if (isRegExp(value)) { + return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); + } else { + return ctx.stylize('[Object]', 'special'); + } + } + ctx.seen.push(value); + var output; + if (array) { + output = formatArray(ctx, value, recurseTimes, visibleKeys, keys); + } else { + output = keys.map(function(key) { + return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array); + }); + } + ctx.seen.pop(); + return reduceToSingleString(output, base, braces); + } + function formatPrimitive(ctx, value) { + if (isUndefined(value)) + return ctx.stylize('undefined', 'undefined'); + if (isString(value)) { + var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '').replace(/'/g, "\\'").replace(/\\"/g, '"') + '\''; + return ctx.stylize(simple, 'string'); + } + if (isNumber(value)) + return ctx.stylize('' + value, 'number'); + if (isBoolean(value)) + return ctx.stylize('' + value, 'boolean'); + if (isNull(value)) + return ctx.stylize('null', 'null'); + } + function formatError(value) { + return '[' + Error.prototype.toString.call(value) + ']'; + } + function formatArray(ctx, value, recurseTimes, visibleKeys, keys) { + var output = []; + for (var i = 0, + l = value.length; i < l; ++i) { + if (hasOwnProperty(value, String(i))) { + output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, String(i), true)); + } else { + output.push(''); + } + } + keys.forEach(function(key) { + if (!key.match(/^\d+$/)) { + output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, key, true)); + } + }); + return output; + } + function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) { + var name, + str, + desc; + desc = Object.getOwnPropertyDescriptor(value, key) || {value: value[key]}; + if (desc.get) { + if (desc.set) { + str = ctx.stylize('[Getter/Setter]', 'special'); + } else { + str = ctx.stylize('[Getter]', 'special'); + } + } else { + if (desc.set) { + str = ctx.stylize('[Setter]', 'special'); + } + } + if (!hasOwnProperty(visibleKeys, key)) { + name = '[' + key + ']'; + } + if (!str) { + if (ctx.seen.indexOf(desc.value) < 0) { + if (isNull(recurseTimes)) { + str = formatValue(ctx, desc.value, null); + } else { + str = formatValue(ctx, desc.value, recurseTimes - 1); + } + if (str.indexOf('\n') > -1) { + if (array) { + str = str.split('\n').map(function(line) { + return ' ' + line; + }).join('\n').substr(2); + } else { + str = '\n' + str.split('\n').map(function(line) { + return ' ' + line; + }).join('\n'); + } + } + } else { + str = ctx.stylize('[Circular]', 'special'); + } + } + if (isUndefined(name)) { + if (array && key.match(/^\d+$/)) { + return str; + } + name = JSON.stringify('' + key); + if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) { + name = name.substr(1, name.length - 2); + name = ctx.stylize(name, 'name'); + } else { + name = name.replace(/'/g, "\\'").replace(/\\"/g, '"').replace(/(^"|"$)/g, "'"); + name = ctx.stylize(name, 'string'); + } + } + return name + ': ' + str; + } + function reduceToSingleString(output, base, braces) { + var numLinesEst = 0; + var length = output.reduce(function(prev, cur) { + numLinesEst++; + if (cur.indexOf('\n') >= 0) + numLinesEst++; + return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1; + }, 0); + if (length > 60) { + return braces[0] + (base === '' ? '' : base + '\n ') + ' ' + output.join(',\n ') + ' ' + braces[1]; + } + return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1]; + } + function isArray(ar) { + return Array.isArray(ar); + } + exports.isArray = isArray; + function isBoolean(arg) { + return typeof arg === 'boolean'; + } + exports.isBoolean = isBoolean; + function isNull(arg) { + return arg === null; + } + exports.isNull = isNull; + function isNullOrUndefined(arg) { + return arg == null; + } + exports.isNullOrUndefined = isNullOrUndefined; + function isNumber(arg) { + return typeof arg === 'number'; + } + exports.isNumber = isNumber; + function isString(arg) { + return typeof arg === 'string'; + } + exports.isString = isString; + function isSymbol(arg) { + return typeof arg === 'symbol'; + } + exports.isSymbol = isSymbol; + function isUndefined(arg) { + return arg === void 0; + } + exports.isUndefined = isUndefined; + function isRegExp(re) { + return isObject(re) && objectToString(re) === '[object RegExp]'; + } + exports.isRegExp = isRegExp; + function isObject(arg) { + return typeof arg === 'object' && arg !== null; + } + exports.isObject = isObject; + function isDate(d) { + return isObject(d) && objectToString(d) === '[object Date]'; + } + exports.isDate = isDate; + function isError(e) { + return isObject(e) && (objectToString(e) === '[object Error]' || e instanceof Error); + } + exports.isError = isError; + function isFunction(arg) { + return typeof arg === 'function'; + } + exports.isFunction = isFunction; + function isPrimitive(arg) { + return arg === null || typeof arg === 'boolean' || typeof arg === 'number' || typeof arg === 'string' || typeof arg === 'symbol' || typeof arg === 'undefined'; + } + exports.isPrimitive = isPrimitive; + exports.isBuffer = require('./support/isBufferBrowser'); + function objectToString(o) { + return Object.prototype.toString.call(o); + } + function pad(n) { + return n < 10 ? '0' + n.toString(10) : n.toString(10); + } + var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; + function timestamp() { + var d = new Date(); + var time = [pad(d.getHours()), pad(d.getMinutes()), pad(d.getSeconds())].join(':'); + return [d.getDate(), months[d.getMonth()], time].join(' '); + } + exports.log = function() { + console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments)); + }; + exports.inherits = require('inherits'); + exports._extend = function(origin, add) { + if (!add || !isObject(add)) + return origin; + var keys = Object.keys(add); + var i = keys.length; + while (i--) { + origin[keys[i]] = add[keys[i]]; + } + return origin; + }; + function hasOwnProperty(obj, prop) { + return Object.prototype.hasOwnProperty.call(obj, prop); + } +})(require('process')); diff --git a/jspm_packages/npm/whatwg-fetch@0.7.0.js b/jspm_packages/npm/whatwg-fetch@0.7.0.js new file mode 100644 index 0000000..7ee009a --- /dev/null +++ b/jspm_packages/npm/whatwg-fetch@0.7.0.js @@ -0,0 +1 @@ +module.exports = require("npm:whatwg-fetch@0.7.0/fetch.js"); \ No newline at end of file diff --git a/jspm_packages/npm/whatwg-fetch@0.7.0/.jshintrc b/jspm_packages/npm/whatwg-fetch@0.7.0/.jshintrc new file mode 100644 index 0000000..604e4aa --- /dev/null +++ b/jspm_packages/npm/whatwg-fetch@0.7.0/.jshintrc @@ -0,0 +1,21 @@ +{ + "curly": true, + "eqeqeq": true, + "es3": true, + "immed": true, + "indent": 2, + "latedef": true, + "newcap": true, + "noarg": true, + "quotmark": true, + "undef": true, + "unused": true, + "strict": true, + "trailing": true, + "asi": true, + "boss": true, + "esnext": true, + "eqnull": true, + "browser": true, + "worker": true +} diff --git a/jspm_packages/npm/whatwg-fetch@0.7.0/.jspm-hash b/jspm_packages/npm/whatwg-fetch@0.7.0/.jspm-hash new file mode 100644 index 0000000..3ccf03b --- /dev/null +++ b/jspm_packages/npm/whatwg-fetch@0.7.0/.jspm-hash @@ -0,0 +1 @@ +538fee9896768dcec6634bbdda583c8f78fed80699914b932bd37a50b983c5e7c90ae93bjspm-npm@0.260.16.1 \ No newline at end of file diff --git a/jspm_packages/npm/whatwg-fetch@0.7.0/.npmignore b/jspm_packages/npm/whatwg-fetch@0.7.0/.npmignore new file mode 100644 index 0000000..c346b13 --- /dev/null +++ b/jspm_packages/npm/whatwg-fetch@0.7.0/.npmignore @@ -0,0 +1,2 @@ +bower_components/ +node_modules/ diff --git a/jspm_packages/npm/whatwg-fetch@0.7.0/.travis.yml b/jspm_packages/npm/whatwg-fetch@0.7.0/.travis.yml new file mode 100644 index 0000000..ecbdd57 --- /dev/null +++ b/jspm_packages/npm/whatwg-fetch@0.7.0/.travis.yml @@ -0,0 +1,11 @@ +language: node_js +script: make test +deploy: + provider: npm + email: matt@mattandre.ws + api_key: + secure: FcQZz0HCJhrz8FZyyfkuXj4cwoBP+PeQ7LzOVU1bG7v3kX7Z33n8glD+32QScT2Uu369exdjkk3mzCaCMsfZTTvRm9STnuJIrPtdB2/FwfaWiyJiB1oZ2UCd5UQM0zMiQrtg+gR8FUBBgi3GICOkzAqTbso+C7P2IJtvpP9RTTI= + on: + all_branches: true + tags: true + repo: github/fetch diff --git a/jspm_packages/npm/whatwg-fetch@0.7.0/LICENSE b/jspm_packages/npm/whatwg-fetch@0.7.0/LICENSE new file mode 100644 index 0000000..8ef3658 --- /dev/null +++ b/jspm_packages/npm/whatwg-fetch@0.7.0/LICENSE @@ -0,0 +1,20 @@ +Copyright (c) 2014 GitHub, Inc. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/jspm_packages/npm/whatwg-fetch@0.7.0/MAINTAINING.md b/jspm_packages/npm/whatwg-fetch@0.7.0/MAINTAINING.md new file mode 100644 index 0000000..0082ab3 --- /dev/null +++ b/jspm_packages/npm/whatwg-fetch@0.7.0/MAINTAINING.md @@ -0,0 +1,29 @@ +# Maintaining + +## Releasing a new version + +This project follows [semver](http://semver.org/). So if you are making a bug +fix, only increment the patch level "1.0.x". If any new files are added, a +minor version "1.x.x" bump is in order. + +### Make a release commit + +To prepare the release commit: + +1. Edit the [bower.json](https://github.com/github/fetch/blob/master/bower.json) +`version` value. +2. Change the npm [package.json](https://github.com/github/fetch/blob/master/package.json) +`version` value to match. +3. Make a single commit with the description as "Fetch 1.x.x". +4. Finally, tag the commit with `v1.x.x`. + +``` +$ git pull +$ vim bower.json +$ vim package.json +$ git add bower.json package.json +$ git commit -m "Fetch 1.x.x" +$ git tag v1.x.x +$ git push +$ git push --tags +``` diff --git a/jspm_packages/npm/whatwg-fetch@0.7.0/Makefile b/jspm_packages/npm/whatwg-fetch@0.7.0/Makefile new file mode 100644 index 0000000..b8ce6aa --- /dev/null +++ b/jspm_packages/npm/whatwg-fetch@0.7.0/Makefile @@ -0,0 +1,18 @@ +build: node_modules/ bower_components/ + +test: node_modules/ build lint + ./test/run.sh + +lint: node_modules/ + ./node_modules/.bin/jshint *.js test/*.js + +bower_components/: node_modules/ + ./node_modules/.bin/bower install + +node_modules/: + npm install + +clean: + rm -rf ./bower_components ./node_modules + +.PHONY: build clean lint test diff --git a/jspm_packages/npm/whatwg-fetch@0.7.0/README.md b/jspm_packages/npm/whatwg-fetch@0.7.0/README.md new file mode 100644 index 0000000..bea9a22 --- /dev/null +++ b/jspm_packages/npm/whatwg-fetch@0.7.0/README.md @@ -0,0 +1,159 @@ +# window.fetch polyfill + +The global `fetch` function is an easier way to make web requests and handle +responses than using an XMLHttpRequest. This polyfill is written as closely as +possible to the standard Fetch specification at https://fetch.spec.whatwg.org. + +## Installation + +Available on [Bower](http://bower.io) as **fetch**. + +```sh +$ bower install fetch +``` + +You'll also need a Promise polyfill for older browsers. + +```sh +$ bower install es6-promise +``` + +This can also be installed with `npm`. + +```sh +$ npm install whatwg-fetch --save +``` + +## Usage + +The `fetch` function supports any HTTP method. We'll focus on GET and POST +example requests. + +### HTML + +```javascript +fetch('/users.html') + .then(function(response) { + return response.text() + }).then(function(body) { + document.body.innerHTML = body + }) +``` + +### JSON + +```javascript +fetch('/users.json') + .then(function(response) { + return response.json() + }).then(function(json) { + console.log('parsed json', json) + }).catch(function(ex) { + console.log('parsing failed', ex) + }) +``` + +### Response metadata + +```javascript +fetch('/users.json').then(function(response) { + console.log(response.headers.get('Content-Type')) + console.log(response.headers.get('Date')) + console.log(response.status) + console.log(response.statusText) +}) +``` + +### Post form + +```javascript +var form = document.querySelector('form') + +fetch('/query', { + method: 'post', + body: new FormData(form) +}) +``` + +### Post JSON + +```javascript +fetch('/users', { + method: 'post', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + name: 'Hubot', + login: 'hubot', + }) +}) +``` + +### File upload + +```javascript +var input = document.querySelector('input[type="file"]') + +var form = new FormData() +form.append('file', input.files[0]) +form.append('user', 'hubot') + +fetch('/avatars', { + method: 'post', + body: form +}) +``` + +### Success and error handlers + +This causes `fetch` to behave like jQuery's `$.ajax` by rejecting the `Promise` +on HTTP failure status codes like 404, 500, etc. The response `Promise` is +resolved only on successful, 200 level, status codes. + +```javascript +function status(response) { + if (response.status >= 200 && response.status < 300) { + return Promise.resolve(response) + } else { + return Promise.reject(new Error(response.statusText)) + } +} + +function json(response) { + return response.json() +} + +fetch('/users') + .then(status) + .then(json) + .then(function(json) { + console.log('request succeeded with json response', json) + }).catch(function(error) { + console.log('request failed', error) + }) +``` + +### Response URL caveat + +The `Response` object has a URL attribute for the final responded resource. +Usually this is the same as the `Request` url, but in the case of a redirect, +its all transparent. Newer versions of XHR include a `responseURL` attribute +that returns this value. But not every browser supports this. The compromise +requires setting a special server side header to tell the browser what URL it +just requested (yeah, I know browsers). + +``` ruby +response.headers['X-Request-URL'] = request.url +``` + +If you want `response.url` to be reliable, you'll want to set this header. The +day that you ditch this polyfill and use native fetch only, you can remove the +header hack. + +## Browser Support + +![Chrome](https://raw.github.com/alrra/browser-logos/master/chrome/chrome_48x48.png) | ![Firefox](https://raw.github.com/alrra/browser-logos/master/firefox/firefox_48x48.png) | ![IE](https://raw.github.com/alrra/browser-logos/master/internet-explorer/internet-explorer_48x48.png) | ![Opera](https://raw.github.com/alrra/browser-logos/master/opera/opera_48x48.png) | ![Safari](https://raw.github.com/alrra/browser-logos/master/safari/safari_48x48.png) +--- | --- | --- | --- | --- | +Latest ✔ | Latest ✔ | 9+ ✔ | Latest ✔ | 6.1+ ✔ | diff --git a/jspm_packages/npm/whatwg-fetch@0.7.0/bower.json b/jspm_packages/npm/whatwg-fetch@0.7.0/bower.json new file mode 100644 index 0000000..740a9ab --- /dev/null +++ b/jspm_packages/npm/whatwg-fetch@0.7.0/bower.json @@ -0,0 +1,16 @@ +{ + "name": "fetch", + "version": "0.7.0", + "main": "fetch.js", + "devDependencies": { + "es6-promise": "1.0.0" + }, + "ignore": [ + ".*", + "*.md", + "examples/", + "Makefile", + "package.json", + "test/" + ] +} diff --git a/jspm_packages/npm/whatwg-fetch@0.7.0/examples/index.html b/jspm_packages/npm/whatwg-fetch@0.7.0/examples/index.html new file mode 100644 index 0000000..399b505 --- /dev/null +++ b/jspm_packages/npm/whatwg-fetch@0.7.0/examples/index.html @@ -0,0 +1,22 @@ + + + + + + + + + + diff --git a/jspm_packages/npm/whatwg-fetch@0.7.0/fetch.js b/jspm_packages/npm/whatwg-fetch@0.7.0/fetch.js new file mode 100644 index 0000000..428a755 --- /dev/null +++ b/jspm_packages/npm/whatwg-fetch@0.7.0/fetch.js @@ -0,0 +1,326 @@ +/* */ +"format cjs"; +(function() { + 'use strict'; + + if (self.fetch) { + return + } + + function Headers(headers) { + this.map = {} + + var self = this + if (headers instanceof Headers) { + headers.forEach(function(name, values) { + values.forEach(function(value) { + self.append(name, value) + }) + }) + + } else if (headers) { + Object.getOwnPropertyNames(headers).forEach(function(name) { + self.append(name, headers[name]) + }) + } + } + + Headers.prototype.append = function(name, value) { + name = name.toLowerCase() + var list = this.map[name] + if (!list) { + list = [] + this.map[name] = list + } + list.push(value) + } + + Headers.prototype['delete'] = function(name) { + delete this.map[name.toLowerCase()] + } + + Headers.prototype.get = function(name) { + var values = this.map[name.toLowerCase()] + return values ? values[0] : null + } + + Headers.prototype.getAll = function(name) { + return this.map[name.toLowerCase()] || [] + } + + Headers.prototype.has = function(name) { + return this.map.hasOwnProperty(name.toLowerCase()) + } + + Headers.prototype.set = function(name, value) { + this.map[name.toLowerCase()] = [value] + } + + // Instead of iterable for now. + Headers.prototype.forEach = function(callback) { + var self = this + Object.getOwnPropertyNames(this.map).forEach(function(name) { + callback(name, self.map[name]) + }) + } + + function consumed(body) { + if (body.bodyUsed) { + return Promise.reject(new TypeError('Already read')) + } + body.bodyUsed = true + } + + function fileReaderReady(reader) { + return new Promise(function(resolve, reject) { + reader.onload = function() { + resolve(reader.result) + } + reader.onerror = function() { + reject(reader.error) + } + }) + } + + function readBlobAsArrayBuffer(blob) { + var reader = new FileReader() + reader.readAsArrayBuffer(blob) + return fileReaderReady(reader) + } + + function readBlobAsText(blob) { + var reader = new FileReader() + reader.readAsText(blob) + return fileReaderReady(reader) + } + + var support = { + blob: 'FileReader' in self && 'Blob' in self && (function() { + try { + new Blob(); + return true + } catch(e) { + return false + } + })(), + formData: 'FormData' in self + } + + function Body() { + this.bodyUsed = false + + if (support.blob) { + this._initBody = function(body) { + this._bodyInit = body + if (typeof body === 'string') { + this._bodyText = body + } else if (support.blob && Blob.prototype.isPrototypeOf(body)) { + this._bodyBlob = body + } else if (support.formData && FormData.prototype.isPrototypeOf(body)) { + this._bodyFormData = body + } else if (!body) { + this._bodyText = '' + } else { + throw new Error('unsupported BodyInit type') + } + } + + this.blob = function() { + var rejected = consumed(this) + if (rejected) { + return rejected + } + + if (this._bodyBlob) { + return Promise.resolve(this._bodyBlob) + } else if (this._bodyFormData) { + throw new Error('could not read FormData body as blob') + } else { + return Promise.resolve(new Blob([this._bodyText])) + } + } + + this.arrayBuffer = function() { + return this.blob().then(readBlobAsArrayBuffer) + } + + this.text = function() { + var rejected = consumed(this) + if (rejected) { + return rejected + } + + if (this._bodyBlob) { + return readBlobAsText(this._bodyBlob) + } else if (this._bodyFormData) { + throw new Error('could not read FormData body as text') + } else { + return Promise.resolve(this._bodyText) + } + } + } else { + this._initBody = function(body) { + this._bodyInit = body + if (typeof body === 'string') { + this._bodyText = body + } else if (support.formData && FormData.prototype.isPrototypeOf(body)) { + this._bodyFormData = body + } else if (!body) { + this._bodyText = '' + } else { + throw new Error('unsupported BodyInit type') + } + } + + this.text = function() { + var rejected = consumed(this) + return rejected ? rejected : Promise.resolve(this._bodyText) + } + } + + if (support.formData) { + this.formData = function() { + return this.text().then(decode) + } + } + + this.json = function() { + return this.text().then(JSON.parse) + } + + return this + } + + // HTTP methods whose capitalization should be normalized + var methods = ['DELETE', 'GET', 'HEAD', 'OPTIONS', 'POST', 'PUT'] + + function normalizeMethod(method) { + var upcased = method.toUpperCase() + return (methods.indexOf(upcased) > -1) ? upcased : method + } + + function Request(url, options) { + options = options || {} + this.url = url + + this.credentials = options.credentials || 'omit' + this.headers = new Headers(options.headers) + this.method = normalizeMethod(options.method || 'GET') + this.mode = options.mode || null + this.referrer = null + + if ((this.method === 'GET' || this.method === 'HEAD') && options.body) { + throw new TypeError('Body not allowed for GET or HEAD requests') + } + this._initBody(options.body) + } + + function decode(body) { + var form = new FormData() + body.trim().split('&').forEach(function(bytes) { + if (bytes) { + var split = bytes.split('=') + var name = split.shift().replace(/\+/g, ' ') + var value = split.join('=').replace(/\+/g, ' ') + form.append(decodeURIComponent(name), decodeURIComponent(value)) + } + }) + return form + } + + function headers(xhr) { + var head = new Headers() + var pairs = xhr.getAllResponseHeaders().trim().split('\n') + pairs.forEach(function(header) { + var split = header.trim().split(':') + var key = split.shift().trim() + var value = split.join(':').trim() + head.append(key, value) + }) + return head + } + + Request.prototype.fetch = function() { + var self = this + + return new Promise(function(resolve, reject) { + var xhr = new XMLHttpRequest() + if (self.credentials === 'cors') { + xhr.withCredentials = true; + } + + function responseURL() { + if ('responseURL' in xhr) { + return xhr.responseURL + } + + // Avoid security warnings on getResponseHeader when not allowed by CORS + if (/^X-Request-URL:/m.test(xhr.getAllResponseHeaders())) { + return xhr.getResponseHeader('X-Request-URL') + } + + return; + } + + xhr.onload = function() { + var status = (xhr.status === 1223) ? 204 : xhr.status + if (status < 100 || status > 599) { + reject(new TypeError('Network request failed')) + return + } + var options = { + status: status, + statusText: xhr.statusText, + headers: headers(xhr), + url: responseURL() + } + var body = 'response' in xhr ? xhr.response : xhr.responseText; + resolve(new Response(body, options)) + } + + xhr.onerror = function() { + reject(new TypeError('Network request failed')) + } + + xhr.open(self.method, self.url, true) + if ('responseType' in xhr && support.blob) { + xhr.responseType = 'blob' + } + + self.headers.forEach(function(name, values) { + values.forEach(function(value) { + xhr.setRequestHeader(name, value) + }) + }) + + xhr.send(typeof self._bodyInit === 'undefined' ? null : self._bodyInit) + }) + } + + Body.call(Request.prototype) + + function Response(bodyInit, options) { + if (!options) { + options = {} + } + + this._initBody(bodyInit) + this.type = 'default' + this.url = null + this.status = options.status + this.statusText = options.statusText + this.headers = options.headers + this.url = options.url || '' + } + + Body.call(Response.prototype) + + self.Headers = Headers; + self.Request = Request; + self.Response = Response; + + self.fetch = function (url, options) { + return new Request(url, options).fetch() + } + self.fetch.polyfill = true +})(); diff --git a/jspm_packages/npm/whatwg-fetch@0.7.0/package.json b/jspm_packages/npm/whatwg-fetch@0.7.0/package.json new file mode 100644 index 0000000..32a198f --- /dev/null +++ b/jspm_packages/npm/whatwg-fetch@0.7.0/package.json @@ -0,0 +1,20 @@ +{ + "name": "whatwg-fetch", + "version": "0.7.0", + "main": "fetch.js", + "repository": "github/fetch", + "licenses": [ + { + "type": "MIT", + "url": "https://github.com/github/fetch/blob/master/LICENSE" + } + ], + "devDependencies": { + "bower": "1.3.8", + "chai": "1.10.0", + "jshint": "2.5.2", + "mocha-phantomjs": "3.5.2", + "mocha": "2.1.0", + "phantomjs": "1.9.13" + } +} diff --git a/jspm_packages/npm/whatwg-fetch@0.7.0/test/.jshintrc b/jspm_packages/npm/whatwg-fetch@0.7.0/test/.jshintrc new file mode 100644 index 0000000..2fa08ad --- /dev/null +++ b/jspm_packages/npm/whatwg-fetch@0.7.0/test/.jshintrc @@ -0,0 +1,32 @@ +{ + "curly": true, + "eqeqeq": true, + "immed": true, + "indent": 2, + "latedef": true, + "newcap": true, + "noarg": true, + "quotmark": true, + "undef": true, + "unused": true, + "trailing": true, + "asi": true, + "boss": true, + "esnext": true, + "sub": true, + "eqnull": true, + "browser": true, + "worker": true, + "globals": { + "fetch": false, + "Headers": false, + "Request": false, + "Response": false, + "mocha": false, + "chai": false, + "suite": false, + "setup": false, + "test": false, + "assert": false + } +} diff --git a/jspm_packages/npm/whatwg-fetch@0.7.0/test/.npmignore b/jspm_packages/npm/whatwg-fetch@0.7.0/test/.npmignore new file mode 100644 index 0000000..e6011a5 --- /dev/null +++ b/jspm_packages/npm/whatwg-fetch@0.7.0/test/.npmignore @@ -0,0 +1 @@ +server.pid diff --git a/jspm_packages/npm/whatwg-fetch@0.7.0/test/run.sh b/jspm_packages/npm/whatwg-fetch@0.7.0/test/run.sh new file mode 100755 index 0000000..15e07a4 --- /dev/null +++ b/jspm_packages/npm/whatwg-fetch@0.7.0/test/run.sh @@ -0,0 +1,15 @@ +#!/bin/bash +set -e + +port=3900 + +# Find next available port +while lsof -i :$((++port)) >/dev/null; do true; done + +# Spin a test server in the background +node ./test/server.js $port &>/dev/null & +server_pid=$! +trap "kill $server_pid" INT EXIT + +node ./node_modules/.bin/mocha-phantomjs -s localToRemoteUrlAccessEnabled=true -s webSecurityEnabled=false "http://localhost:$port/test/test.html" +node ./node_modules/.bin/mocha-phantomjs -s localToRemoteUrlAccessEnabled=true -s webSecurityEnabled=false "http://localhost:$port/test/test-worker.html" diff --git a/jspm_packages/npm/whatwg-fetch@0.7.0/test/server.js b/jspm_packages/npm/whatwg-fetch@0.7.0/test/server.js new file mode 100755 index 0000000..873090d --- /dev/null +++ b/jspm_packages/npm/whatwg-fetch@0.7.0/test/server.js @@ -0,0 +1,143 @@ +/* */ +(function(Buffer, process) { + var port = Number(process.argv[2] || 3000); + var fs = require('fs'); + var http = require('http'); + var url = require('url'); + var querystring = require('querystring'); + var routes = { + '/request': function(res, req) { + res.writeHead(200, {'Content-Type': 'application/json'}); + var data = ''; + req.on('data', function(c) { + data += c; + }); + req.on('end', function() { + res.end(JSON.stringify({ + method: req.method, + url: req.url, + headers: req.headers, + data: data + })); + }); + }, + '/hello': function(res, req) { + res.writeHead(200, { + 'Content-Type': 'text/plain', + 'X-Request-URL': 'http://' + req.headers.host + req.url + }); + res.end('hi'); + }, + '/hello/utf8': function(res) { + res.writeHead(200, {'Content-Type': 'text/plain; charset=utf-8'}); + var buf = new Buffer([104, 101, 108, 108, 111]); + res.end(buf); + }, + '/hello/utf16le': function(res) { + res.writeHead(200, {'Content-Type': 'text/plain; charset=utf-16le'}); + var buf = new Buffer([104, 0, 101, 0, 108, 0, 108, 0, 111, 0]); + res.end(buf); + }, + '/binary': function(res) { + res.writeHead(200, {'Content-Type': 'application/octet-stream'}); + var buf = new Buffer(256); + for (var i = 0; i < 256; i++) { + buf[i] = i; + } + res.end(buf); + }, + '/redirect/301': function(res) { + res.writeHead(301, {'Location': '/hello'}); + res.end(); + }, + '/redirect/302': function(res) { + res.writeHead(302, {'Location': '/hello'}); + res.end(); + }, + '/redirect/303': function(res) { + res.writeHead(303, {'Location': '/hello'}); + res.end(); + }, + '/redirect/307': function(res) { + res.writeHead(307, {'Location': '/hello'}); + res.end(); + }, + '/redirect/308': function(res) { + res.writeHead(308, {'Location': '/hello'}); + res.end(); + }, + '/boom': function(res) { + res.writeHead(500, {'Content-Type': 'text/plain'}); + res.end('boom'); + }, + '/empty': function(res) { + res.writeHead(204); + res.end(); + }, + '/error': function(res) { + res.destroy(); + }, + '/form': function(res) { + res.writeHead(200, {'Content-Type': 'text/plain'}); + res.end('number=1&space=one+two&empty=&encoded=a%2Bb&'); + }, + '/json': function(res) { + res.writeHead(200, {'Content-Type': 'application/json'}); + res.end(JSON.stringify({ + name: 'Hubot', + login: 'hubot' + })); + }, + '/json-error': function(res) { + res.writeHead(200, {'Content-Type': 'application/json'}); + res.end('not json {'); + }, + '/cookie': function(res, req) { + var setCookie, + cookie; + var params = querystring.parse(url.parse(req.url).query); + if (params.name && params.value) { + setCookie = [params.name, params.value].join('='); + } + if (params.name) { + cookie = querystring.parse(req.headers['cookie'], '; ')[params.name]; + } + res.writeHead(200, { + 'Content-Type': 'text/plain', + 'Set-Cookie': setCookie + }); + res.end(cookie); + }, + '/headers': function(res) { + res.writeHead(200, { + 'Date': 'Mon, 13 Oct 2014 21:02:27 GMT', + 'Content-Type': 'text/html; charset=utf-8' + }); + res.end(); + } + }; + var types = { + js: 'application/javascript', + css: 'text/css', + html: 'text/html', + txt: 'text/plain' + }; + http.createServer(function(req, res) { + var pathname = url.parse(req.url).pathname; + var route = routes[pathname]; + if (route) { + route(res, req); + } else { + fs.readFile(__dirname + '/..' + pathname, function(err, data) { + if (err) { + res.writeHead(404, {'Content-Type': types.txt}); + res.end('Not Found'); + } else { + var ext = (pathname.match(/\.([^\/]+)$/) || [])[1]; + res.writeHead(200, {'Content-Type': types[ext] || types.txt}); + res.end(data); + } + }); + } + }).listen(port); +})(require('buffer').Buffer, require('process')); diff --git a/jspm_packages/npm/whatwg-fetch@0.7.0/test/test-worker.html b/jspm_packages/npm/whatwg-fetch@0.7.0/test/test-worker.html new file mode 100644 index 0000000..6ff9dd5 --- /dev/null +++ b/jspm_packages/npm/whatwg-fetch@0.7.0/test/test-worker.html @@ -0,0 +1,43 @@ + + + + + Fetch Worker Tests + + + +
    + + + + + diff --git a/jspm_packages/npm/whatwg-fetch@0.7.0/test/test.html b/jspm_packages/npm/whatwg-fetch@0.7.0/test/test.html new file mode 100644 index 0000000..228f319 --- /dev/null +++ b/jspm_packages/npm/whatwg-fetch@0.7.0/test/test.html @@ -0,0 +1,30 @@ + + + + + Fetch Tests + + + +
    + + + + + + + + + + + + diff --git a/jspm_packages/npm/whatwg-fetch@0.7.0/test/test.js b/jspm_packages/npm/whatwg-fetch@0.7.0/test/test.js new file mode 100644 index 0000000..c2cf198 --- /dev/null +++ b/jspm_packages/npm/whatwg-fetch@0.7.0/test/test.js @@ -0,0 +1,593 @@ +/* */ +"format cjs"; +function readBlobAsText(blob) { + return new Promise(function(resolve, reject) { + var reader = new FileReader() + reader.onload = function() { + resolve(reader.result) + } + reader.onerror = function() { + reject(reader.error) + } + reader.readAsText(blob) + }) +} + +function readBlobAsBytes(blob) { + return new Promise(function(resolve, reject) { + var reader = new FileReader() + reader.onload = function() { + var view = new Uint8Array(reader.result) + resolve(Array.prototype.slice.call(view)) + } + reader.onerror = function() { + reject(reader.error) + } + reader.readAsArrayBuffer(blob) + }) +} + +test('resolves promise on 500 error', function() { + return fetch('/boom').then(function(response) { + assert.equal(response.status, 500) + return response.text() + }).then(function(body) { + assert.equal(body, 'boom') + }) +}) + +test('rejects promise for network error', function() { + return fetch('/error').then(function(response) { + assert(false, 'HTTP status ' + response.status + ' was treated as success') + }).catch(function(error) { + assert(error instanceof TypeError, 'Rejected with Error') + }) +}) + +// https://fetch.spec.whatwg.org/#headers-class +suite('Headers', function() { + test('headers are case insensitve', function() { + var headers = new Headers({'Accept': 'application/json'}) + assert.equal(headers.get('ACCEPT'), 'application/json') + assert.equal(headers.get('Accept'), 'application/json') + assert.equal(headers.get('accept'), 'application/json') + }) +}) + +// https://fetch.spec.whatwg.org/#request-class +suite('Request', function() { + test('sends request headers', function() { + return fetch('/request', { + headers: { + 'Accept': 'application/json', + 'X-Test': '42' + } + }).then(function(response) { + return response.json() + }).then(function(json) { + assert.equal(json.headers['accept'], 'application/json') + assert.equal(json.headers['x-test'], '42') + }) + }) + + test('construct with url', function() { + var request = new Request('https://fetch.spec.whatwg.org/') + assert.equal(request.url, 'https://fetch.spec.whatwg.org/') + }) + + // https://fetch.spec.whatwg.org/#concept-bodyinit-extract + suite('BodyInit extract', function() { + ;(Request.prototype.blob ? suite : suite.skip)('type Blob', function() { + test('consume as blob', function() { + var request = new Request(null, {method: 'POST', body: new Blob(['hello'])}) + return request.blob().then(readBlobAsText).then(function(text) { + assert.equal(text, 'hello') + }) + }) + + test('consume as text', function() { + var request = new Request(null, {method: 'POST', body: new Blob(['hello'])}) + return request.text().then(function(text) { + assert.equal(text, 'hello') + }) + }) + }) + + suite('type USVString', function() { + test('consume as text', function() { + var request = new Request(null, {method: 'POST', body: 'hello'}) + return request.text().then(function(text) { + assert.equal(text, 'hello') + }) + }) + + ;(Request.prototype.blob ? test : test.skip)('consume as blob', function() { + var request = new Request(null, {method: 'POST', body: 'hello'}) + return request.blob().then(readBlobAsText).then(function(text) { + assert.equal(text, 'hello') + }) + }) + }) + }) +}) + +// https://fetch.spec.whatwg.org/#response-class +suite('Response', function() { + // https://fetch.spec.whatwg.org/#concept-bodyinit-extract + suite('BodyInit extract', function() { + ;(Response.prototype.blob ? suite : suite.skip)('type Blob', function() { + test('consume as blob', function() { + var response = new Response(new Blob(['hello'])) + return response.blob().then(readBlobAsText).then(function(text) { + assert.equal(text, 'hello') + }) + }) + + test('consume as text', function() { + var response = new Response(new Blob(['hello'])) + return response.text().then(function(text) { + assert.equal(text, 'hello') + }) + }) + }) + + suite('type USVString', function() { + test('consume as text', function() { + var response = new Response('hello') + return response.text().then(function(text) { + assert.equal(text, 'hello') + }) + }) + + ;(Response.prototype.blob ? test : test.skip)('consume as blob', function() { + var response = new Response('hello') + return response.blob().then(readBlobAsText).then(function(text) { + assert.equal(text, 'hello') + }) + }) + }) + }) + + test('populates response body', function() { + return fetch('/hello').then(function(response) { + assert.equal(response.status, 200) + return response.text() + }).then(function(body) { + assert.equal(body, 'hi') + }) + }) + + test('parses response headers', function() { + return fetch('/headers?' + new Date().getTime()).then(function(response) { + assert.equal(response.headers.get('Date'), 'Mon, 13 Oct 2014 21:02:27 GMT') + assert.equal(response.headers.get('Content-Type'), 'text/html; charset=utf-8') + }) + }) +}) + +// https://fetch.spec.whatwg.org/#body-mixin +suite('Body mixin', function() { + ;(Response.prototype.arrayBuffer ? suite : suite.skip)('arrayBuffer', function() { + test('resolves arrayBuffer promise', function() { + return fetch('/hello').then(function(response) { + return response.arrayBuffer() + }).then(function(buf) { + assert(buf instanceof ArrayBuffer, 'buf is an ArrayBuffer instance') + assert.equal(buf.byteLength, 2) + }) + }) + + test('arrayBuffer handles binary data', function() { + return fetch('/binary').then(function(response) { + return response.arrayBuffer() + }).then(function(buf) { + assert(buf instanceof ArrayBuffer, 'buf is an ArrayBuffer instance') + assert.equal(buf.byteLength, 256, 'buf.byteLength is correct') + var view = new Uint8Array(buf) + for (var i = 0; i < 256; i++) { + assert.equal(view[i], i) + } + }) + }) + + test('arrayBuffer handles utf-8 data', function() { + return fetch('/hello/utf8').then(function(response) { + return response.arrayBuffer() + }).then(function(buf) { + assert(buf instanceof ArrayBuffer, 'buf is an ArrayBuffer instance') + assert.equal(buf.byteLength, 5, 'buf.byteLength is correct') + var octets = Array.prototype.slice.call(new Uint8Array(buf)) + assert.deepEqual(octets, [104, 101, 108, 108, 111]) + }) + }) + + test('arrayBuffer handles utf-16le data', function() { + return fetch('/hello/utf16le').then(function(response) { + return response.arrayBuffer() + }).then(function(buf) { + assert(buf instanceof ArrayBuffer, 'buf is an ArrayBuffer instance') + assert.equal(buf.byteLength, 10, 'buf.byteLength is correct') + var octets = Array.prototype.slice.call(new Uint8Array(buf)) + assert.deepEqual(octets, [104, 0, 101, 0, 108, 0, 108, 0, 111, 0]) + }) + }) + + test('rejects arrayBuffer promise after body is consumed', function() { + return fetch('/hello').then(function(response) { + assert(response.arrayBuffer, 'Body does not implement arrayBuffer') + assert.equal(response.bodyUsed, false) + response.blob() + assert.equal(response.bodyUsed, true) + return response.arrayBuffer() + }).catch(function(error) { + assert(error instanceof TypeError, 'Promise rejected after body consumed') + }) + }) + }) + + ;(Response.prototype.blob ? suite : suite.skip)('blob', function() { + test('resolves blob promise', function() { + return fetch('/hello').then(function(response) { + return response.blob() + }).then(function(blob) { + assert(blob instanceof Blob, 'blob is a Blob instance') + assert.equal(blob.size, 2) + }) + }) + + test('blob handles binary data', function() { + return fetch('/binary').then(function(response) { + return response.blob() + }).then(function(blob) { + assert(blob instanceof Blob, 'blob is a Blob instance') + assert.equal(blob.size, 256, 'blob.size is correct') + }) + }) + + test('blob handles utf-8 data', function() { + return fetch('/hello/utf8').then(function(response) { + return response.blob() + }).then(readBlobAsBytes).then(function(octets) { + assert.equal(octets.length, 5, 'blob.size is correct') + assert.deepEqual(octets, [104, 101, 108, 108, 111]) + }) + }) + + test('blob handles utf-16le data', function() { + return fetch('/hello/utf16le').then(function(response) { + return response.blob() + }).then(readBlobAsBytes).then(function(octets) { + assert.equal(octets.length, 10, 'blob.size is correct') + assert.deepEqual(octets, [104, 0, 101, 0, 108, 0, 108, 0, 111, 0]) + }) + }) + + test('rejects blob promise after body is consumed', function() { + return fetch('/hello').then(function(response) { + assert(response.blob, 'Body does not implement blob') + assert.equal(response.bodyUsed, false) + response.text() + assert.equal(response.bodyUsed, true) + return response.blob() + }).catch(function(error) { + assert(error instanceof TypeError, 'Promise rejected after body consumed') + }) + }) + }) + + ;(Response.prototype.formData ? suite : suite.skip)('formData', function() { + test('post sets content-type header', function() { + return fetch('/request', { + method: 'post', + body: new FormData() + }).then(function(response) { + return response.json() + }).then(function(json) { + assert.equal(json.method, 'POST') + assert(/^multipart\/form-data;/.test(json.headers['content-type'])) + }) + }) + + test('rejects formData promise after body is consumed', function() { + return fetch('/json').then(function(response) { + assert(response.formData, 'Body does not implement formData') + response.formData() + return response.formData() + }).catch(function(error) { + assert(error instanceof TypeError, 'Promise rejected after body consumed') + }) + }) + + test('parses form encoded response', function() { + return fetch('/form').then(function(response) { + return response.formData() + }).then(function(form) { + assert(form instanceof FormData, 'Parsed a FormData object') + }) + }) + }) + + suite('json', function() { + test('parses json response', function() { + return fetch('/json').then(function(response) { + return response.json() + }).then(function(json) { + assert.equal(json.name, 'Hubot') + assert.equal(json.login, 'hubot') + }) + }) + + test('rejects json promise after body is consumed', function() { + return fetch('/json').then(function(response) { + assert(response.json, 'Body does not implement json') + assert.equal(response.bodyUsed, false) + response.text() + assert.equal(response.bodyUsed, true) + return response.json() + }).catch(function(error) { + assert(error instanceof TypeError, 'Promise rejected after body consumed') + }) + }) + + test('handles json parse error', function() { + return fetch('/json-error').then(function(response) { + return response.json() + }).catch(function(error) { + assert(error instanceof Error, 'JSON exception is an Error instance') + assert(error.message, 'JSON exception has an error message') + }) + }) + }) + + suite('text', function() { + test('handles 204 No Content response', function() { + return fetch('/empty').then(function(response) { + assert.equal(response.status, 204) + return response.text() + }).then(function(body) { + assert.equal(body, '') + }) + }) + + test('resolves text promise', function() { + return fetch('/hello').then(function(response) { + return response.text() + }).then(function(text) { + assert.equal(text, 'hi') + }) + }) + + test('rejects text promise after body is consumed', function() { + return fetch('/hello').then(function(response) { + assert(response.text, 'Body does not implement text') + assert.equal(response.bodyUsed, false) + response.text() + assert.equal(response.bodyUsed, true) + return response.text() + }).catch(function(error) { + assert(error instanceof TypeError, 'Promise rejected after body consumed') + }) + }) + }) +}) + +// https://fetch.spec.whatwg.org/#methods +suite('Methods', function() { + test('supports HTTP GET', function() { + return fetch('/request', { + method: 'get', + }).then(function(response) { + return response.json() + }).then(function(request) { + assert.equal(request.method, 'GET') + assert.equal(request.data, '') + }) + }) + + test('GET with body throws TypeError', function() { + assert.throw(function() { + new Request('', { + method: 'get', + body: 'invalid' + }) + }, TypeError) + }) + + test('HEAD with body throws TypeError', function() { + assert.throw(function() { + new Request('', { + method: 'head', + body: 'invalid' + }) + }, TypeError) + }) + + test('supports HTTP POST', function() { + return fetch('/request', { + method: 'post', + body: 'name=Hubot' + }).then(function(response) { + return response.json() + }).then(function(request) { + assert.equal(request.method, 'POST') + assert.equal(request.data, 'name=Hubot') + }) + }) + + test('supports HTTP PUT', function() { + return fetch('/request', { + method: 'put', + body: 'name=Hubot' + }).then(function(response) { + return response.json() + }).then(function(request) { + assert.equal(request.method, 'PUT') + assert.equal(request.data, 'name=Hubot') + }) + }) + + var patchSupported = !/PhantomJS/.test(navigator.userAgent) + + ;(patchSupported ? test : test.skip)('supports HTTP PATCH', function() { + return fetch('/request', { + method: 'PATCH', + body: 'name=Hubot' + }).then(function(response) { + return response.json() + }).then(function(request) { + assert.equal(request.method, 'PATCH') + assert.equal(request.data, 'name=Hubot') + }) + }) + + test('supports HTTP DELETE', function() { + return fetch('/request', { + method: 'delete', + }).then(function(response) { + return response.json() + }).then(function(request) { + assert.equal(request.method, 'DELETE') + assert.equal(request.data, '') + }) + }) +}) + +// https://fetch.spec.whatwg.org/#atomic-http-redirect-handling +suite('Atomic HTTP redirect handling', function() { + test('handles 301 redirect response', function() { + return fetch('/redirect/301').then(function(response) { + assert.equal(response.status, 200) + assert.match(response.url, /\/hello/) + return response.text() + }).then(function(body) { + assert.equal(body, 'hi') + }) + }) + + test('handles 302 redirect response', function() { + return fetch('/redirect/302').then(function(response) { + assert.equal(response.status, 200) + assert.match(response.url, /\/hello/) + return response.text() + }).then(function(body) { + assert.equal(body, 'hi') + }) + }) + + test('handles 303 redirect response', function() { + return fetch('/redirect/303').then(function(response) { + assert.equal(response.status, 200) + assert.match(response.url, /\/hello/) + return response.text() + }).then(function(body) { + assert.equal(body, 'hi') + }) + }) + + test('handles 307 redirect response', function() { + return fetch('/redirect/307').then(function(response) { + assert.equal(response.status, 200) + assert.match(response.url, /\/hello/) + return response.text() + }).then(function(body) { + assert.equal(body, 'hi') + }) + }) + + var permanentRedirectSupported = !/PhantomJS|Trident/.test(navigator.userAgent) + + ;(permanentRedirectSupported ? test : test.skip)('handles 308 redirect response', function() { + return fetch('/redirect/308').then(function(response) { + assert.equal(response.status, 200) + assert.match(response.url, /\/hello/) + return response.text() + }).then(function(body) { + assert.equal(body, 'hi') + }) + }) +}) + +// https://fetch.spec.whatwg.org/#concept-request-credentials-mode +suite('credentials mode', function() { + var omitSupported = !self.fetch.polyfill + + setup(function() { + return fetch('/cookie?name=foo&value=reset', {credentials: 'same-origin'}); + }) + + ;(omitSupported ? suite : suite.skip)('omit', function() { + test('request credentials defaults to omit', function() { + var request = new Request('') + assert.equal(request.credentials, 'omit') + }) + + test('does not accept cookies with implicit omit credentials', function() { + return fetch('/cookie?name=foo&value=bar').then(function() { + return fetch('/cookie?name=foo', {credentials: 'same-origin'}); + }).then(function(response) { + return response.text() + }).then(function(data) { + assert.equal(data, 'reset') + }) + }) + + test('does not accept cookies with omit credentials', function() { + return fetch('/cookie?name=foo&value=bar', {credentials: 'omit'}).then(function() { + return fetch('/cookie?name=foo', {credentials: 'same-origin'}); + }).then(function(response) { + return response.text() + }).then(function(data) { + assert.equal(data, 'reset') + }) + }) + + test('does not send cookies with implicit omit credentials', function() { + return fetch('/cookie?name=foo&value=bar', {credentials: 'same-origin'}).then(function() { + return fetch('/cookie?name=foo'); + }).then(function(response) { + return response.text() + }).then(function(data) { + assert.equal(data, '') + }) + }) + + test('does not send cookies with omit credentials', function() { + return fetch('/cookie?name=foo&value=bar').then(function() { + return fetch('/cookie?name=foo', {credentials: 'omit'}) + }).then(function(response) { + return response.text() + }).then(function(data) { + assert.equal(data, '') + }) + }) + }) + + suite('same-origin', function() { + test('request credentials uses inits member', function() { + var request = new Request('', {credentials: 'same-origin'}) + assert.equal(request.credentials, 'same-origin') + }) + + test('send cookies with same-origin credentials', function() { + return fetch('/cookie?name=foo&value=bar', {credentials: 'same-origin'}).then(function() { + return fetch('/cookie?name=foo', {credentials: 'same-origin'}) + }).then(function(response) { + return response.text() + }).then(function(data) { + assert.equal(data, 'bar') + }) + }) + }) + + suite('include', function() { + test('send cookies with include credentials', function() { + return fetch('/cookie?name=foo&value=bar', {credentials: 'include'}).then(function() { + return fetch('/cookie?name=foo', {credentials: 'include'}) + }).then(function(response) { + return response.text() + }).then(function(data) { + assert.equal(data, 'bar') + }) + }) + }) +}) diff --git a/jspm_packages/npm/whatwg-fetch@0.7.0/test/worker.js b/jspm_packages/npm/whatwg-fetch@0.7.0/test/worker.js new file mode 100644 index 0000000..0102b0d --- /dev/null +++ b/jspm_packages/npm/whatwg-fetch@0.7.0/test/worker.js @@ -0,0 +1,41 @@ +/* */ +"format cjs"; +importScripts('../node_modules/chai/chai.js') +importScripts('../node_modules/mocha/mocha.js') + +mocha.setup('tdd') +self.assert = chai.assert + +importScripts('../bower_components/es6-promise/promise.js') +importScripts('../fetch.js') + +importScripts('test.js') + +function title(test) { + return test.fullTitle().replace(/#/g, ''); +} + +function reporter(runner) { + runner.on('pending', function(test){ + self.postMessage({name: 'pending', title: title(test)}); + }); + + runner.on('pass', function(test){ + self.postMessage({name: 'pass', title: title(test)}); + }); + + runner.on('fail', function(test, err){ + self.postMessage({ + name: 'fail', + title: title(test), + message: err.message, + stack: err.stack + }); + }); + + runner.on('end', function(){ + self.postMessage({name: 'end'}); + }); +} + +mocha.reporter(reporter).run() diff --git a/jspm_packages/system-csp-production.js b/jspm_packages/system-csp-production.js new file mode 100644 index 0000000..7611f40 --- /dev/null +++ b/jspm_packages/system-csp-production.js @@ -0,0 +1,6 @@ +/* + * SystemJS v0.19.24 + */ +!function(){function e(){!function(e){function t(e,t){if(!e.originalErr)for(var n=(e.stack||e.message||e).split("\n"),r=[],a=0;a2)throw new TypeError("Only one wildcard in a path is permitted");if(1==i.length){if(t==o)return e[o];if(t.substr(0,o.length-1)==o.substr(0,o.length-1)&&(t.lengtho.length?"/"+t.substr(o.length):"")}else{var s=i[0].length;s>=a&&t.substr(0,i[0].length)==i[0]&&t.substr(t.length-i[1].length)==i[1]&&(a=s,r=o,n=t.substr(i[0].length,t.length-i[1].length-i[0].length))}}var l=e[r];return"string"==typeof n&&(l=l.replace("*",n)),l}function s(){}function l(){o.call(this),B.call(this)}function u(){}function d(e,t){l.prototype[e]=t(l.prototype[e]||function(){})}function c(e){B=e(B||function(){})}function f(e){for(var t=[],n=[],r=0,a=e.length;a>r;r++){var o=J.call(t,e[r]);-1===o?(t.push(e[r]),n.push([r])):n[o].push(r)}return{names:t,indices:n}}function m(e){var t={};if("object"==typeof e||"function"==typeof e)if(H){var n;for(var r in e)(n=Object.getOwnPropertyDescriptor(e,r))&&C(t,r,n)}else{var a=e&&e.hasOwnProperty;for(var r in e)(!a||e.hasOwnProperty(r))&&(t[r]=e[r])}return t["default"]=e,C(t,"__useDefault",{value:!0}),t}function p(e,t,n){for(var r in t)n&&r in e||(e[r]=t[r]);return e}function h(e,t,n){for(var r in t){var a=t[r];r in e?a instanceof Array&&e[r]instanceof Array?e[r]=[].concat(n?a:e[r]).concat(n?e[r]:a):"object"==typeof a&&null!==a&&"object"==typeof e[r]?e[r]=p(p({},e[r]),a,n):n||(e[r]=a):e[r]=a}}function g(e){this.warnings&&"undefined"!=typeof console&&console.warn}function v(e,t){for(var n=e.split(".");n.length;)t=t[n.shift()];return t}function y(){if(Y[this.baseURL])return Y[this.baseURL];"/"!=this.baseURL[this.baseURL.length-1]&&(this.baseURL+="/");var e=new A(this.baseURL,U);return this.baseURL=e.href,Y[this.baseURL]=e}function b(e,t){var n,r=0;for(var a in e)if(t.substr(0,a.length)==a&&(t.length==a.length||"/"==t[a.length])){var o=a.split("/").length;if(r>=o)continue;n=a,r=o}return n}function w(e){this.set("@system-env",this.newModule({browser:T,node:!!this._nodeRequire,production:e,"default":!0}))}function x(e){return("."!=e[0]||!!e[1]&&"/"!=e[1]&&"."!=e[1])&&"/"!=e[0]&&!e.match(V)}function S(e,t){return t&&(t=t.replace(/#/g,"%05")),new A(e,t||Z).href.replace(/%05/g,"#")}function E(e,t){return new A(t,y.call(e)).href}function k(e,t){if(!x(e))return S(e,t);var n=b(this.map,e);if(n&&(e=this.map[n]+e.substr(n.length),!x(e)))return S(e);if(this.has(e))return e;if("@node/"==e.substr(0,6)&&-1!=K.indexOf(e.substr(6))){if(!this._nodeRequire)throw new TypeError("Error loading "+e+". Can only load node core modules in Node.");return this.set(e,this.newModule(m(this._nodeRequire(e.substr(6))))),e}var r=i(this.paths,e);return r&&!x(r)?S(r):E(this,r||e)}function j(e){var t=e.match(ee);return t&&"System.register"==e.substr(t[0].length,15)}function P(){return{name:null,deps:null,originalIndices:null,declare:null,execute:null,executingRequire:!1,declarative:!1,normalizedDeps:null,groupIndex:null,evaluated:!1,module:null,esModule:null,esmExports:!1}}function _(t){if("string"==typeof t)return v(t,e);if(!(t instanceof Array))throw new Error("Global exports must be a string or array.");for(var n={},r=!0,a=0;at;t++)if(this[t]===e)return t;return-1};!function(){try{Object.defineProperty({},"a",{})&&(C=Object.defineProperty)}catch(e){C=function(e,t,n){try{e[t]=n.value||n.get.call(e)}catch(r){}}}}();var U;if("undefined"!=typeof document&&document.getElementsByTagName){if(U=document.baseURI,!U){var q=document.getElementsByTagName("base");U=q[0]&&q[0].href||window.location.href}U=U.split("#")[0].split("?")[0],U=U.substr(0,U.lastIndexOf("/")+1)}else if("undefined"!=typeof process&&process.cwd)U="file://"+(D?"/":"")+process.cwd()+"/",D&&(U=U.replace(/\\/g,"/"));else{if("undefined"==typeof location)throw new TypeError("No environment baseURI");U=e.location.href}var A=e.URLPolyfill||e.URL;C(r.prototype,"toString",{value:function(){return"Module"}}),function(){function o(e){return{status:"loading",name:e,linkSets:[],dependencies:[],metadata:{}}}function i(e,t,n){return new Promise(c({step:n.address?"fetch":"locate",loader:e,moduleName:t,moduleMetadata:n&&n.metadata||{},moduleSource:n.source,moduleAddress:n.address}))}function s(e,t,n,r){return new Promise(function(a,o){a(e.loaderObj.normalize(t,n,r))}).then(function(t){var n;if(e.modules[t])return n=o(t),n.status="linked",n.module=e.modules[t],n;for(var r=0,a=e.loads.length;a>r;r++)if(n=e.loads[r],n.name==t)return n;return n=o(t),e.loads.push(n),l(e,n),n})}function l(e,t){u(e,t,Promise.resolve().then(function(){return e.loaderObj.locate({name:t.name,metadata:t.metadata})}))}function u(e,t,n){d(e,t,n.then(function(n){return"loading"==t.status?(t.address=n,e.loaderObj.fetch({name:t.name,metadata:t.metadata,address:n})):void 0}))}function d(t,r,a){a.then(function(a){return"loading"==r.status?Promise.resolve(t.loaderObj.translate({name:r.name,metadata:r.metadata,address:r.address,source:a})).then(function(e){return r.source=e,t.loaderObj.instantiate({name:r.name,metadata:r.metadata,address:r.address,source:e})}).then(function(a){if(void 0===a)return r.address=r.address||"",r.isDeclarative=!0,E.call(t.loaderObj,r).then(function(t){var a=e.System,o=a.register;a.register=function(e,t,n){"string"!=typeof e&&(n=t,t=e),r.declare=n,r.depsList=t},n(t,r.address,{}),a.register=o});if("object"!=typeof a)throw TypeError("Invalid instantiate return value");r.depsList=a.deps||[],r.execute=a.execute,r.isDeclarative=!1}).then(function(){r.dependencies=[];for(var e=r.depsList,n=[],a=0,o=e.length;o>a;a++)(function(e,a){n.push(s(t,e,r.name,r.address).then(function(t){if(r.dependencies[a]={key:e,value:t.name},"linked"!=t.status)for(var n=r.linkSets.concat([]),o=0,i=n.length;i>o;o++)m(n[o],t)}))})(e[a],a);return Promise.all(n)}).then(function(){r.status="loaded";for(var e=r.linkSets.concat([]),t=0,n=e.length;n>t;t++)h(e[t],r)}):void 0})["catch"](function(e){r.status="failed",r.exception=e;for(var t=r.linkSets.concat([]),n=0,a=t.length;a>n;n++)g(t[n],r,e)})}function c(e){return function(t,n){var r=e.loader,a=e.moduleName,i=e.step;if(r.modules[a])throw new TypeError('"'+a+'" already exists in the module table');for(var s,c=0,m=r.loads.length;m>c;c++)if(r.loads[c].name==a&&(s=r.loads[c],"translate"!=i||s.source||(s.address=e.moduleAddress,d(r,s,Promise.resolve(e.moduleSource))),s.linkSets.length&&s.linkSets[0].loads[0].name==s.name))return s.linkSets[0].done.then(function(){t(s)});var p=s||o(a);p.metadata=e.moduleMetadata;var h=f(r,p);r.loads.push(p),t(h.done),"locate"==i?l(r,p):"fetch"==i?u(r,p,Promise.resolve(e.moduleAddress)):(p.address=e.moduleAddress,d(r,p,Promise.resolve(e.moduleSource)))}}function f(e,t){var n={loader:e,loads:[],startingLoad:t,loadingCount:0};return n.done=new Promise(function(e,t){n.resolve=e,n.reject=t}),m(n,t),n}function m(e,t){if("failed"!=t.status){for(var n=0,r=e.loads.length;r>n;n++)if(e.loads[n]==t)return;e.loads.push(t),t.linkSets.push(e),"loaded"!=t.status&&e.loadingCount++;for(var a=e.loader,n=0,r=t.dependencies.length;r>n;n++)if(t.dependencies[n]){var o=t.dependencies[n].value;if(!a.modules[o])for(var i=0,s=a.loads.length;s>i;i++)if(a.loads[i].name==o){m(e,a.loads[i]);break}}}}function p(e){var t=!1;try{w(e,function(n,r){g(e,n,r),t=!0})}catch(n){g(e,null,n),t=!0}return t}function h(e,t){if(e.loadingCount--,!(e.loadingCount>0)){var n=e.startingLoad;if(e.loader.loaderObj.execute===!1){for(var r=[].concat(e.loads),a=0,o=r.length;o>a;a++){var t=r[a];t.module=t.isDeclarative?{name:t.name,module:j({}),evaluated:!0}:{module:j({})},t.status="linked",v(e.loader,t)}return e.resolve(n)}var i=p(e);i||e.resolve(n)}}function g(e,n,r){var a=e.loader;e:if(n)if(e.loads[0].name==n.name)r=t(r,"Error loading "+n.name);else{for(var o=0;oo;o++){var n=u[o];a.loaderObj.failed=a.loaderObj.failed||[],-1==J.call(a.loaderObj.failed,n)&&a.loaderObj.failed.push(n);var c=J.call(n.linkSets,e);if(n.linkSets.splice(c,1),0==n.linkSets.length){var f=J.call(e.loader.loads,n);-1!=f&&e.loader.loads.splice(f,1)}}e.reject(r)}function v(e,t){if(e.loaderObj.trace){e.loaderObj.loads||(e.loaderObj.loads={});var n={};t.dependencies.forEach(function(e){n[e.key]=e.value}),e.loaderObj.loads[t.name]={name:t.name,deps:t.dependencies.map(function(e){return e.key}),depMap:n,address:t.address,metadata:t.metadata,source:t.source,kind:t.isDeclarative?"declarative":"dynamic"}}t.name&&(e.modules[t.name]=t.module);var r=J.call(e.loads,t);-1!=r&&e.loads.splice(r,1);for(var a=0,o=t.linkSets.length;o>a;a++)r=J.call(t.linkSets[a].loads,t),-1!=r&&t.linkSets[a].loads.splice(r,1);t.linkSets.splice(0,t.linkSets.length)}function y(e,t,n){try{var a=t.execute()}catch(o){return void n(t,o)}return a&&a instanceof r?a:void n(t,new TypeError("Execution must define a Module instance"))}function b(e,t,n){var r=e._loader.importPromises;return r[t]=n.then(function(e){return r[t]=void 0,e},function(e){throw r[t]=void 0,e})}function w(e,t){var n=e.loader;if(e.loads.length)for(var r=e.loads.concat([]),a=0;aa&&(n=o,a=r));return n}function t(e,t,n,r,a){if(!r||"/"==r[r.length-1]||a||t.defaultExtension===!1)return r;if(r.match(te))return r;var o=!1;if(t.meta&&p(t.meta,r,function(e,t,n){return 0==n||e.lastIndexOf("*")!=e.length-1?o=!0:void 0}),!o&&e.meta&&p(e.meta,n+"/"+r,function(e,t,n){return 0==n||e.lastIndexOf("*")!=e.length-1?o=!0:void 0}),o)return r;var i="."+(t.defaultExtension||"js");return r.substr(r.length-i.length)!=i?r+i:r}function n(e,n,r,o,i){if(!o){if(!n.main)return r+(e.defaultJSExtensions?".js":"");o="./"==n.main.substr(0,2)?n.main.substr(2):n.main}if(n.map){var s="./"+o,l=b(n.map,s);if(l||(s="./"+t(e,n,r,o,i),s!="./"+o&&(l=b(n.map,s))),l)return a(e,n,r,l,s,i)}return r+"/"+t(e,n,r,o,i)}function r(e,t,n){if("."==e)throw new Error("Package "+n+' has a map entry for "." which is not permitted.');if(t.substr(0,e.length)==e&&"/"!=e[e.length-1]&&"/"==t[e.length])throw new Error("Package "+n+' has a recursive map for "'+e+'" which is not permitted.')}function a(e,n,a,o,i,s){var l=n.map[o];if(r(o,l,a),"string"!=typeof l&&(l=o=i),r(o,l,a),"."==l)l=a;else if("./"==l.substr(0,2))return a+"/"+t(e,n,a,l.substr(2)+i.substr(o.length),s);return e.normalizeSync(l+i.substr(o.length),a+"/")}function o(e,n,r,a,o){if(!a){if(!n.main)return Promise.resolve(r+(e.defaultJSExtensions?".js":""));a="./"==n.main.substr(0,2)?n.main.substr(2):n.main}var i,l;return n.map&&(i="./"+a,l=b(n.map,i),l||(i="./"+t(e,n,r,a,o),i!="./"+a&&(l=b(n.map,i)))),(l?s(e,n,r,l,i,o):Promise.resolve()).then(function(i){return i?Promise.resolve(i):Promise.resolve(r+"/"+t(e,n,r,a,o))})}function i(e,n,r,a,o,i,s){if("."==o)o=r;else if("./"==o.substr(0,2))return Promise.resolve(r+"/"+t(e,n,r,o.substr(2)+i.substr(a.length),s)).then(function(t){return M.call(e,t,r+"/")});return e.normalize(o+i.substr(a.length),r+"/")}function s(e,t,n,a,o,s){var l=t.map[a];return"string"==typeof l?(r(a,l,n),i(e,t,n,a,l,o,s)):e.builder?Promise.resolve(n+"/#:"+o):e["import"](t.map["@env"]||"@system-env",n).then(function(e){for(var t in l){var n="~"==t[0],r=v(n?t.substr(1):t,e);if(!n&&r||n&&!r)return l[t]}}).then(function(l){if(l){if("string"!=typeof l)throw new Error("Unable to map a package conditional to a package conditional.");return r(a,l,n),i(e,t,n,a,l,o,s)}})}function u(e){var t=e.lastIndexOf("*"),n=Math.max(t+1,e.lastIndexOf("/"));return{length:n,regEx:new RegExp("^("+e.substr(0,n).replace(/\*/g,"[^\\/]+")+")(\\/|$)"),wildcard:-1!=t}}function f(e,t){for(var n,r,a=!1,o=0;ol&&(l=n),h(s,t,n&&l>n)}),h(n.metadata,s)}}return t})}})}(),function(){function t(){if(o&&"interactive"===o.script.readyState)return o.load;for(var e=0;ea;a++){var i=e.normalizedDeps[a],s=n.defined[i];if(s&&!s.evaluated){var l=e.groupIndex+(s.declarative!=e.declarative);if(null===s.groupIndex||s.groupIndex=0;s--){for(var l=a[s],d=0;dr;r++){var i=a.importers[r];if(!i.locked){var l=J.call(i.dependencies,a);i.setters[l](s)}}return a.locked=!1,t},{id:t.name});if(a.setters=l.setters,a.execute=l.execute,!a.setters||!a.execute)throw new TypeError("Invalid System.register form for "+t.name);for(var u=0,d=t.normalizedDeps.length;d>u;u++){var c,f=t.normalizedDeps[u],m=n.defined[f],p=r[f];p?c=p.exports:m&&!m.declarative?c=m.esModule:m?(i(m,n),p=m.module,c=p.exports):c=n.get(f),p&&p.importers?(p.importers.push(a),a.dependencies.push(p)):a.dependencies.push(null); +for(var h=t.originalIndices[u],g=0,v=h.length;v>g;++g){var y=h[g];a.setters[y]&&a.setters[y](c)}}}}function s(e,t){var n,r=t.defined[e];if(r)r.declarative?p(e,[],t):r.evaluated||u(r,t),n=r.module.exports;else if(n=t.get(e),!n)throw new Error("Unable to load dependency "+e+".");return(!r||r.declarative)&&n&&n.__useDefault?n["default"]:n}function u(t,n){if(!t.module){var a={},o=t.module={exports:a,id:t.name};if(!t.executingRequire)for(var i=0,l=t.normalizedDeps.length;l>i;i++){var d=t.normalizedDeps[i],c=n.defined[d];c&&u(c,n)}t.evaluated=!0;var f=t.execute.call(e,function(e){for(var r=0,a=t.deps.length;a>r;r++)if(t.deps[r]==e)return s(t.normalizedDeps[r],n);var o=n.normalizeSync(e,t.name);if(-1!=J.call(t.normalizedDeps,o))return s(o,n);throw new Error("Module "+e+" not declared as a dependency of "+t.name)},a,o);f&&(o.exports=f),a=o.exports,a&&(a.__esModule||a instanceof r)?t.esModule=a:t.esmExports&&a!==e?t.esModule=m(a):t.esModule={"default":a}}}function p(t,n,r){var a=r.defined[t];if(a&&!a.evaluated&&a.declarative){n.push(t);for(var o=0,i=a.normalizedDeps.length;i>o;o++){var s=a.normalizedDeps[o];-1==J.call(n,s)&&(r.defined[s]?p(s,n,r):r.get(s))}a.evaluated||(a.evaluated=!0,a.module.execute.call(e))}}l.prototype.register=function(e,t,n){if("string"!=typeof e&&(n=t,t=e,e=null),"boolean"==typeof n)return this.registerDynamic.apply(this,arguments);var r=P();r.name=e&&(this.decanonicalize||this.normalize).call(this,e),r.declarative=!0,r.deps=t,r.declare=n,this.pushRegister_({amd:!1,entry:r})},l.prototype.registerDynamic=function(e,t,n,r){"string"!=typeof e&&(r=n,n=t,t=e,e=null);var a=P();a.name=e&&(this.decanonicalize||this.normalize).call(this,e),a.deps=t,a.execute=r,a.executingRequire=n,this.pushRegister_({amd:!1,entry:a})},d("reduceRegister_",function(){return function(e,t){if(t){var n=t.entry,r=e&&e.metadata;if(n.name&&(n.name in this.defined||(this.defined[n.name]=n),r&&(r.bundle=!0)),!n.name||e&&n.name==e.name){if(!r)throw new TypeError("Unexpected anonymous System.register call.");if(r.entry)throw"register"==r.format?new Error("Multiple anonymous System.register calls in module "+e.name+". If loading a bundle, ensure all the System.register calls are named."):new Error("Module "+e.name+" interpreted as "+r.format+" module format, but called System.register.");r.format||(r.format="register"),r.entry=n}}}}),c(function(e){return function(){e.call(this),this.defined={},this._loader.moduleRecords={}}}),C(a,"toString",{value:function(){return"Module"}}),d("delete",function(e){return function(t){return delete this._loader.moduleRecords[t],delete this.defined[t],e.call(this,t)}}),d("fetch",function(e){return function(t){return this.defined[t.name]?(t.metadata.format="defined",""):(t.metadata.deps=t.metadata.deps||[],e.call(this,t))}}),d("translate",function(e){return function(t){return t.metadata.deps=t.metadata.deps||[],Promise.resolve(e.call(this,t)).then(function(e){return("register"==t.metadata.format||!t.metadata.format&&j(t.source))&&(t.metadata.format="register"),e})}}),d("instantiate",function(e){return function(t){"detect"==t.metadata.format&&(t.metadata.format=void 0),e.call(this,t);var r,a=this;if(a.defined[t.name])r=a.defined[t.name],r.declarative||(r.deps=r.deps.concat(t.metadata.deps));else if(t.metadata.entry)r=t.metadata.entry,r.deps=r.deps.concat(t.metadata.deps);else if(!(a.builder&&t.metadata.bundle||"register"!=t.metadata.format&&"esm"!=t.metadata.format&&"es6"!=t.metadata.format)){if("undefined"!=typeof __exec&&__exec.call(a,t),!t.metadata.entry&&!t.metadata.bundle)throw new Error(t.name+" detected as "+t.metadata.format+" but didn't execute.");r=t.metadata.entry,r&&t.metadata.deps&&(r.deps=r.deps.concat(t.metadata.deps))}r||(r=P(),r.deps=t.metadata.deps,r.execute=function(){}),a.defined[t.name]=r;var o=f(r.deps);r.deps=o.names,r.originalIndices=o.indices,r.name=t.name,r.esmExports=t.metadata.esmExports!==!1;for(var i=[],s=0,l=r.deps.length;l>s;s++)i.push(Promise.resolve(a.normalize(r.deps[s],t.name)));return Promise.all(i).then(function(e){return r.normalizedDeps=e,{deps:r.deps,execute:function(){return n(t.name,a),p(t.name,[],a),a.defined[t.name]=void 0,a.newModule(r.declarative?r.module.exports:r.esModule)}}})}})}(),d("reduceRegister_",function(e){return function(t,n){if(n||!t.metadata.exports)return e.call(this,t,n);t.metadata.format="global";var r=t.metadata.entry=P();r.deps=t.metadata.deps;var a=_(t.metadata.exports);r.execute=function(){return a}}}),c(function(t){return function(){function n(t){if(Object.keys)Object.keys(e).forEach(t);else for(var n in e)i.call(e,n)&&t(n)}function r(t){n(function(n){if(-1==J.call(s,n)){try{var r=e[n]}catch(a){s.push(n)}t(n,r)}})}var a=this;t.call(a);var o,i=Object.prototype.hasOwnProperty,s=["_g","sessionStorage","localStorage","clipboardData","frames","frameElement","external","mozAnimationStartTime","webkitStorageInfo","webkitIndexedDB","mozInnerScreenY","mozInnerScreenX"];a.set("@@global-helpers",a.newModule({prepareGlobal:function(t,n,a){var i=e.define;e.define=void 0;var s;if(a){s={};for(var l in a)s[l]=e[l],e[l]=a[l]}return n||(o={},r(function(e,t){o[e]=t})),function(){var t;if(n)t=_(n);else{t={};var a,l;r(function(e,n){o[e]!==n&&"undefined"!=typeof n&&(t[e]=n,"undefined"!=typeof a?l||a===n||(l=!0):a=n)}),t=l?t:a}if(s)for(var u in s)e[u]=s[u];return e.define=i,t}}}))}}),c(function(e){return function(){function t(e){return"file:///"==e.substr(0,8)?e.substr(7+!!D):r&&e.substr(0,r.length)==r?e.substr(r.length):e}var n=this;if(e.call(n),"undefined"!=typeof window&&"undefined"!=typeof document&&window.location)var r=location.protocol+"//"+location.hostname+(location.port?":"+location.port:"");n.set("@@cjs-helpers",n.newModule({requireResolve:function(e,r){return t(n.normalizeSync(e,r))},getPathVars:function(e){var n,r=e.lastIndexOf("!");n=-1!=r?e.substr(0,r):e;var a=n.split("/");return a.pop(),a=a.join("/"),{filename:t(n),dirname:t(a)}}}))}}),d("fetch",function(t){return function(n){return n.metadata.scriptLoad&&T&&(e.define=this.amdDefine),t.call(this,n)}}),c(function(t){return function(){function n(e,t){e=e.replace(i,"");var n=e.match(u),r=(n[1].split(",")[t]||"require").replace(c,""),a=f[r]||(f[r]=new RegExp(s+r+l,"g"));a.lastIndex=0;for(var o,d=[];o=a.exec(e);)d.push(o[2]||o[3]);return d}function r(e,t,n,a){if("object"==typeof e&&!(e instanceof Array))return r.apply(null,Array.prototype.splice.call(arguments,1,arguments.length-1));if("string"==typeof e&&"function"==typeof t&&(e=[e]),!(e instanceof Array)){if("string"==typeof e){var i=o.defaultJSExtensions&&".js"!=e.substr(e.length-3,3),s=o.decanonicalize(e,a);i&&".js"==s.substr(s.length-3,3)&&(s=s.substr(0,s.length-3));var l=o.get(s);if(!l)throw new Error('Module not already loaded loading "'+e+'" as '+s+(a?' from "'+a+'".':"."));return l.__useDefault?l["default"]:l}throw new TypeError("Invalid require")}for(var u=[],d=0;d1;)r=a.shift(),e=e[r]=e[r]||{};r=a.shift(),r in e||(e[r]=n)}c(function(e){return function(){this.meta={},e.call(this)}}),d("locate",function(e){return function(t){var n,r=this.meta,a=t.name,o=0;for(var i in r)if(n=i.indexOf("*"),-1!==n&&i.substr(0,n)===a.substr(0,n)&&i.substr(n+1)===a.substr(a.length-i.length+n+1)){var s=i.split("/").length;s>o&&(o=s),h(t.metadata,r[i],o!=s)}return r[a]&&h(t.metadata,r[a]),e.call(this,t)}});var t=/^(\s*\/\*[^\*]*(\*(?!\/)[^\*]*)*\*\/|\s*\/\/[^\n]*|\s*"[^"]+"\s*;?|\s*'[^']+'\s*;?)+/,n=/\/\*[^\*]*(\*(?!\/)[^\*]*)*\*\/|\/\/[^\n]*|"[^"]+"\s*;?|'[^']+'\s*;?/g;d("translate",function(r){return function(a){var o=a.source.match(t);if(o)for(var i=o[0].match(n),s=0;s')}else e()}else if("undefined"!=typeof importScripts){var i="";try{throw new Error("_")}catch(n){n.stack.replace(/(?:at|@).*(http.+):[\d]+:[\d]+/,function(e,t){$__curScript={src:t},i=t.replace(/\/[^\/]*$/,"/")})}r&&importScripts(i+"system-polyfills.js"),e()}else $__curScript="undefined"!=typeof __filename?{src:__filename}:null,e()}(); +//# sourceMappingURL=system-csp-production.js.map diff --git a/jspm_packages/system-csp-production.js.map b/jspm_packages/system-csp-production.js.map new file mode 100644 index 0000000..ab4a214 --- /dev/null +++ b/jspm_packages/system-csp-production.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["system-csp-production.src.js"],"names":["bootstrap","__global","addToError","err","msg","originalErr","stack","message","split","newStack","i","length","$__curScript","indexOf","src","push","newMsg","join","isBrowser","replace","isWindows","newErr","Error","fileName","lineNumber","__eval","source","debugName","context","Function","call","e","Module","Loader","options","this","_loader","loaderObj","loads","modules","importPromises","moduleRecords","defineProperty","get","SystemLoader","paths","applyPaths","name","wildcard","pathMatch","maxWildcardPrefixLen","p","pathParts","TypeError","substr","wildcardPrefixLen","outPath","LoaderProto","SystemJSLoader","systemJSConstructor","SystemProto","hook","prototype","hookConstructor","group","deps","names","indices","l","index","getESModule","exports","esModule","getOwnPropertyDescriptor","d","Object","hasOwnProperty","value","extend","a","b","prepend","extendMeta","val","Array","concat","warn","warnings","console","readMemberExpression","pParts","shift","getBaseURLObj","baseURLCache","baseURL","URL","baseURI","href","getMapMatch","map","bestMatch","bestMatchLength","curMatchLength","setProduction","isProduction","set","newModule","browser","node","_nodeRequire","production","default","isPlain","match","absURLRegEx","urlResolve","parent","baseURIObj","baseURLResolve","loader","coreResolve","parentName","mapMatch","has","nodeCoreModules","pathed","detectRegisterFormat","leadingCommentAndMeta","leadingCommentAndMetaRegEx","createEntry","originalIndices","declare","execute","executingRequire","declarative","normalizedDeps","groupIndex","evaluated","module","esmExports","getGlobalValue","globalValue","first","pop","parseCondition","condition","conditionExport","conditionModule","negation","conditionExportIndex","lastIndexOf","prop","negate","serializeCondition","conditionObj","resolveCondition","bool","then","m","interpolateConditional","conditionalMatch","interpolationRegEx","Promise","resolve","builder","conditionValue","booleanConditional","booleanIndex","isWorker","window","self","importScripts","document","process","platform","assert","item","thisLen","obj","opt","getElementsByTagName","bases","location","cwd","URLPolyfill","createLoad","status","linkSets","dependencies","metadata","loadModule","asyncStartLoadPartwayThrough","step","address","moduleName","moduleMetadata","moduleSource","moduleAddress","requestLoad","request","refererName","refererAddress","reject","normalize","load","proceedToLocate","proceedToFetch","locate","proceedToTranslate","fetch","translate","instantiate","instantiateResult","undefined","anonCnt","isDeclarative","transpile","transpiled","curSystem","System","curRegister","register","depsList","loadPromises","depLoad","key","addLoadToLinkSet","all","updateLinkSetOnLoad","exc","exception","linkSetFailed","stepState","existingLoad","done","linkSet","createLinkSet","startingLoad","loadingCount","j","doLink","error","link","_newModule","finishLoad","abrupt","checkError","pLoad","dep","failed","linkIndex","splice","globalLoadsIndex","trace","depMap","forEach","kind","loadIndex","doDynamicExecute","linkError","createImportPromise","promise","evaluateLoadedModule","doEnsureEvaluated","constructor","define","delete","import","parentAddress","sourcePromise","pNames","getOwnPropertyNames","configurable","enumerable","freeze","referrerName","referrerAddress","fetchTextFromURL","XMLHttpRequest","url","authorization","fulfill","xhr","responseText","statusText","sameDomain","doTimeout","domainCheck","exec","host","protocol","XDomainRequest","onload","onerror","ontimeout","onprogress","timeout","onreadystatechange","readyState","addEventListener","open","setRequestHeader","withCredentials","setTimeout","send","require","fs","readFile","data","dataString","opts","headers","Accept","credentials","r","ok","text","packageProperties","defaultJSExtensions","pluginFirst","loaderErrorStack","skipExt","resolved","httpRequest","systemImport","__useDefault","systemTranslate","format","entry","JSON","parse","env","curCurScript","config","cfg","checkHasConfig","transpilerRuntime","loadedTranspilerRuntime","packages","meta","depCache","bundles","packageConfigPaths","objMaps","v","defaultJSExtension","decanonicalize","pkgMatch","pkg","main","path","packageLength","Math","max","normalized","bundle","normalizedBundleDep","q","c","getPackage","curPkg","pkgLen","curPkgLen","addDefaultExtension","pkgName","subPath","skipExtensions","defaultExtension","metaMatch","getMetaMatches","metaPattern","matchMeta","matchDepth","applyPackageConfigSync","mapPath","doMapSync","validateMapping","mapped","normalizeSync","applyPackageConfig","doMap","doStringMap","createPkgConfigPathObj","lastWildcard","regEx","RegExp","getPackageConfigMatch","configPath","exactMatch","packageConfigPath","packageName","loadPackageConfigPath","pkgConfigPath","configLoader","pluginLoader","systemjs","dNormalized","pkgMeta","matchFn","wildcardIndex","dotRel","exactMeta","decanonicalized","isPlugin","parentPackageName","parentPackage","parentMap","parentMapMatch","pkgConfigMatch","isConfigured","configured","bestDepth","getInteractiveScriptLoad","interactiveScript","script","interactiveLoadingScripts","webWorkerImport","integrity","workerLoad","head","ieEvents","s","createElement","isOpera","opera","toString","attachEvent","loadingCnt","registerQueue","pushRegister","reduceRegister_","scriptLoad","complete","evt","cleanup","detachEvent","removeEventListener","removeChild","async","crossOrigin","setAttribute","appendChild","buildGroups","groups","depName","depEntry","defined","depGroupIndex","startEntry","curGroupDeclarative","linkDeclarativeModule","linkDynamicModule","ModuleRecord","getOrCreateModuleRecord","importers","declaration","locked","importerModule","importerIndex","setters","id","depExports","depModule","len","getModule","ensureEvaluated","output","nameNormalized","__esModule","seen","registerDynamic","apply","arguments","pushRegister_","amd","curMeta","del","__exec","grouped","normalizePromises","reduceRegister","forEachGlobal","callback","keys","g","forEachGlobalValue","globalName","ignoredGlobalProps","globalSnapshot","prepareGlobal","globals","curDefine","oldGlobals","singleGlobal","multipleExports","stripOrigin","windowOrigin","hostname","port","requireResolve","parentId","getPathVars","moduleId","filename","pluginIndex","dirname","amdDefine","getCJSDeps","requireIndex","commentRegEx","params","fnBracketRegEx","requireAlias","wsRegEx","requireRegEx","requireRegExs","cjsRequirePre","cjsRequirePost","lastIndex","errback","referer","dynamicRequires","factory","req","contextualRequire","depValues","uri","moduleIndex","exportsIndex","toUrl","curRequire","amdRequire","getParentName","parentPluginIndex","parsePlugin","argumentName","pluginName","argument","plugin","combinePluginParts","checkDefaultExtension","arg","createNormalizeSync","parsed","pluginSyntaxIndex","loaderNormalized","loaderModule","result","sourceMap","originalName","file","sources","calledInstantiate","alias","aliasDeps","_export","setMetaProperty","target","curPart","depth","metaRegEx","metaPartRegEx","metaParts","firstChar","metaString","metaName","metaValue","loadedBundles","matched","curModule","parts","substring","SystemJS","version","Reflect","global","LoaderPolyfill","hasURL","doPolyfill","scripts","curPath","basePath","systemJSBootstrap","write","__filename"],"mappings":"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"} \ No newline at end of file diff --git a/jspm_packages/system-csp-production.src.js b/jspm_packages/system-csp-production.src.js new file mode 100644 index 0000000..fc87536 --- /dev/null +++ b/jspm_packages/system-csp-production.src.js @@ -0,0 +1,4367 @@ +/* + * SystemJS v0.19.24 + */ +(function() { +function bootstrap() {(function(__global) { + + var isWorker = typeof window == 'undefined' && typeof self != 'undefined' && typeof importScripts != 'undefined'; + var isBrowser = typeof window != 'undefined' && typeof document != 'undefined'; + var isWindows = typeof process != 'undefined' && typeof process.platform != 'undefined' && !!process.platform.match(/^win/); + + if (!__global.console) + __global.console = { assert: function() {} }; + + // IE8 support + var indexOf = Array.prototype.indexOf || function(item) { + for (var i = 0, thisLen = this.length; i < thisLen; i++) { + if (this[i] === item) { + return i; + } + } + return -1; + }; + + var defineProperty; + (function () { + try { + if (!!Object.defineProperty({}, 'a', {})) + defineProperty = Object.defineProperty; + } + catch (e) { + defineProperty = function(obj, prop, opt) { + try { + obj[prop] = opt.value || opt.get.call(obj); + } + catch(e) {} + } + } + })(); + + function addToError(err, msg) { + // parse the stack removing loader code lines for simplification + if (!err.originalErr) { + var stack = (err.stack || err.message || err).split('\n'); + var newStack = []; + for (var i = 0; i < stack.length; i++) { + if (typeof $__curScript == 'undefined' || stack[i].indexOf($__curScript.src) == -1) + newStack.push(stack[i]); + } + } + + var newMsg = (newStack ? newStack.join('\n\t') : err.message) + '\n\t' + msg; + + // Convert file:/// URLs to paths in Node + if (!isBrowser) + newMsg = newMsg.replace(isWindows ? /file:\/\/\//g : /file:\/\//g, ''); + + var newErr = new Error(newMsg, err.fileName, err.lineNumber); + + // Node needs stack adjustment for throw to show message + if (!isBrowser) + newErr.stack = newMsg; + // Clearing the stack stops unnecessary loader lines showing + else + newErr.stack = null; + + // track the original error + newErr.originalErr = err.originalErr || err; + + return newErr; + } + + function __eval(source, debugName, context) { + try { + new Function(source).call(context); + } + catch(e) { + throw addToError(e, 'Evaluating ' + debugName); + } + } + + var baseURI; + // environent baseURI detection + if (typeof document != 'undefined' && document.getElementsByTagName) { + baseURI = document.baseURI; + + if (!baseURI) { + var bases = document.getElementsByTagName('base'); + baseURI = bases[0] && bases[0].href || window.location.href; + } + + // sanitize out the hash and querystring + baseURI = baseURI.split('#')[0].split('?')[0]; + baseURI = baseURI.substr(0, baseURI.lastIndexOf('/') + 1); + } + else if (typeof process != 'undefined' && process.cwd) { + baseURI = 'file://' + (isWindows ? '/' : '') + process.cwd() + '/'; + if (isWindows) + baseURI = baseURI.replace(/\\/g, '/'); + } + else if (typeof location != 'undefined') { + baseURI = __global.location.href; + } + else { + throw new TypeError('No environment baseURI'); + } + + var URL = __global.URLPolyfill || __global.URL; +/* +********************************************************************************************* + + Dynamic Module Loader Polyfill + + - Implemented exactly to the former 2014-08-24 ES6 Specification Draft Rev 27, Section 15 + http://wiki.ecmascript.org/doku.php?id=harmony:specification_drafts#august_24_2014_draft_rev_27 + + - Functions are commented with their spec numbers, with spec differences commented. + + - Spec bugs are commented in this code with links. + + - Abstract functions have been combined where possible, and their associated functions + commented. + + - Realm implementation is entirely omitted. + +********************************************************************************************* +*/ + +function Module() {} +// http://www.ecma-international.org/ecma-262/6.0/#sec-@@tostringtag +defineProperty(Module.prototype, 'toString', { + value: function() { + return 'Module'; + } +}); +function Loader(options) { + this._loader = { + loaderObj: this, + loads: [], + modules: {}, + importPromises: {}, + moduleRecords: {} + }; + + // 26.3.3.6 + defineProperty(this, 'global', { + get: function() { + return __global; + } + }); + + // 26.3.3.13 realm not implemented +} + +(function() { + +// Some Helpers + +// logs a linkset snapshot for debugging +/* function snapshot(loader) { + console.log('---Snapshot---'); + for (var i = 0; i < loader.loads.length; i++) { + var load = loader.loads[i]; + var linkSetLog = ' ' + load.name + ' (' + load.status + '): '; + + for (var j = 0; j < load.linkSets.length; j++) { + linkSetLog += '{' + logloads(load.linkSets[j].loads) + '} '; + } + console.log(linkSetLog); + } + console.log(''); +} +function logloads(loads) { + var log = ''; + for (var k = 0; k < loads.length; k++) + log += loads[k].name + (k != loads.length - 1 ? ' ' : ''); + return log; +} */ + + +/* function checkInvariants() { + // see https://bugs.ecmascript.org/show_bug.cgi?id=2603#c1 + + var loads = System._loader.loads; + var linkSets = []; + + for (var i = 0; i < loads.length; i++) { + var load = loads[i]; + console.assert(load.status == 'loading' || load.status == 'loaded', 'Each load is loading or loaded'); + + for (var j = 0; j < load.linkSets.length; j++) { + var linkSet = load.linkSets[j]; + + for (var k = 0; k < linkSet.loads.length; k++) + console.assert(loads.indexOf(linkSet.loads[k]) != -1, 'linkSet loads are a subset of loader loads'); + + if (linkSets.indexOf(linkSet) == -1) + linkSets.push(linkSet); + } + } + + for (var i = 0; i < loads.length; i++) { + var load = loads[i]; + for (var j = 0; j < linkSets.length; j++) { + var linkSet = linkSets[j]; + + if (linkSet.loads.indexOf(load) != -1) + console.assert(load.linkSets.indexOf(linkSet) != -1, 'linkSet contains load -> load contains linkSet'); + + if (load.linkSets.indexOf(linkSet) != -1) + console.assert(linkSet.loads.indexOf(load) != -1, 'load contains linkSet -> linkSet contains load'); + } + } + + for (var i = 0; i < linkSets.length; i++) { + var linkSet = linkSets[i]; + for (var j = 0; j < linkSet.loads.length; j++) { + var load = linkSet.loads[j]; + + for (var k = 0; k < load.dependencies.length; k++) { + var depName = load.dependencies[k].value; + var depLoad; + for (var l = 0; l < loads.length; l++) { + if (loads[l].name != depName) + continue; + depLoad = loads[l]; + break; + } + + // loading records are allowed not to have their dependencies yet + // if (load.status != 'loading') + // console.assert(depLoad, 'depLoad found'); + + // console.assert(linkSet.loads.indexOf(depLoad) != -1, 'linkset contains all dependencies'); + } + } + } +} */ + + // 15.2.3 - Runtime Semantics: Loader State + + // 15.2.3.11 + function createLoaderLoad(object) { + return { + // modules is an object for ES5 implementation + modules: {}, + loads: [], + loaderObj: object + }; + } + + // 15.2.3.2 Load Records and LoadRequest Objects + + // 15.2.3.2.1 + function createLoad(name) { + return { + status: 'loading', + name: name, + linkSets: [], + dependencies: [], + metadata: {} + }; + } + + // 15.2.3.2.2 createLoadRequestObject, absorbed into calling functions + + // 15.2.4 + + // 15.2.4.1 + function loadModule(loader, name, options) { + return new Promise(asyncStartLoadPartwayThrough({ + step: options.address ? 'fetch' : 'locate', + loader: loader, + moduleName: name, + // allow metadata for import https://bugs.ecmascript.org/show_bug.cgi?id=3091 + moduleMetadata: options && options.metadata || {}, + moduleSource: options.source, + moduleAddress: options.address + })); + } + + // 15.2.4.2 + function requestLoad(loader, request, refererName, refererAddress) { + // 15.2.4.2.1 CallNormalize + return new Promise(function(resolve, reject) { + resolve(loader.loaderObj.normalize(request, refererName, refererAddress)); + }) + // 15.2.4.2.2 GetOrCreateLoad + .then(function(name) { + var load; + if (loader.modules[name]) { + load = createLoad(name); + load.status = 'linked'; + // https://bugs.ecmascript.org/show_bug.cgi?id=2795 + load.module = loader.modules[name]; + return load; + } + + for (var i = 0, l = loader.loads.length; i < l; i++) { + load = loader.loads[i]; + if (load.name != name) + continue; + console.assert(load.status == 'loading' || load.status == 'loaded', 'loading or loaded'); + return load; + } + + load = createLoad(name); + loader.loads.push(load); + + proceedToLocate(loader, load); + + return load; + }); + } + + // 15.2.4.3 + function proceedToLocate(loader, load) { + proceedToFetch(loader, load, + Promise.resolve() + // 15.2.4.3.1 CallLocate + .then(function() { + return loader.loaderObj.locate({ name: load.name, metadata: load.metadata }); + }) + ); + } + + // 15.2.4.4 + function proceedToFetch(loader, load, p) { + proceedToTranslate(loader, load, + p + // 15.2.4.4.1 CallFetch + .then(function(address) { + // adjusted, see https://bugs.ecmascript.org/show_bug.cgi?id=2602 + if (load.status != 'loading') + return; + load.address = address; + + return loader.loaderObj.fetch({ name: load.name, metadata: load.metadata, address: address }); + }) + ); + } + + var anonCnt = 0; + + // 15.2.4.5 + function proceedToTranslate(loader, load, p) { + p + // 15.2.4.5.1 CallTranslate + .then(function(source) { + if (load.status != 'loading') + return; + + return Promise.resolve(loader.loaderObj.translate({ name: load.name, metadata: load.metadata, address: load.address, source: source })) + + // 15.2.4.5.2 CallInstantiate + .then(function(source) { + load.source = source; + return loader.loaderObj.instantiate({ name: load.name, metadata: load.metadata, address: load.address, source: source }); + }) + + // 15.2.4.5.3 InstantiateSucceeded + .then(function(instantiateResult) { + if (instantiateResult === undefined) { + load.address = load.address || ''; + + // instead of load.kind, use load.isDeclarative + load.isDeclarative = true; + return transpile.call(loader.loaderObj, load) + .then(function(transpiled) { + // Hijack System.register to set declare function + var curSystem = __global.System; + var curRegister = curSystem.register; + curSystem.register = function(name, deps, declare) { + if (typeof name != 'string') { + declare = deps; + deps = name; + } + // store the registered declaration as load.declare + // store the deps as load.deps + load.declare = declare; + load.depsList = deps; + } + // empty {} context is closest to undefined 'this' we can get + __eval(transpiled, load.address, {}); + curSystem.register = curRegister; + }); + } + else if (typeof instantiateResult == 'object') { + load.depsList = instantiateResult.deps || []; + load.execute = instantiateResult.execute; + load.isDeclarative = false; + } + else + throw TypeError('Invalid instantiate return value'); + }) + // 15.2.4.6 ProcessLoadDependencies + .then(function() { + load.dependencies = []; + var depsList = load.depsList; + + var loadPromises = []; + for (var i = 0, l = depsList.length; i < l; i++) (function(request, index) { + loadPromises.push( + requestLoad(loader, request, load.name, load.address) + + // 15.2.4.6.1 AddDependencyLoad (load is parentLoad) + .then(function(depLoad) { + + // adjusted from spec to maintain dependency order + // this is due to the System.register internal implementation needs + load.dependencies[index] = { + key: request, + value: depLoad.name + }; + + if (depLoad.status != 'linked') { + var linkSets = load.linkSets.concat([]); + for (var i = 0, l = linkSets.length; i < l; i++) + addLoadToLinkSet(linkSets[i], depLoad); + } + + // console.log('AddDependencyLoad ' + depLoad.name + ' for ' + load.name); + // snapshot(loader); + }) + ); + })(depsList[i], i); + + return Promise.all(loadPromises); + }) + + // 15.2.4.6.2 LoadSucceeded + .then(function() { + // console.log('LoadSucceeded ' + load.name); + // snapshot(loader); + + console.assert(load.status == 'loading', 'is loading'); + + load.status = 'loaded'; + + var linkSets = load.linkSets.concat([]); + for (var i = 0, l = linkSets.length; i < l; i++) + updateLinkSetOnLoad(linkSets[i], load); + }); + }) + // 15.2.4.5.4 LoadFailed + ['catch'](function(exc) { + load.status = 'failed'; + load.exception = exc; + + var linkSets = load.linkSets.concat([]); + for (var i = 0, l = linkSets.length; i < l; i++) { + linkSetFailed(linkSets[i], load, exc); + } + + console.assert(load.linkSets.length == 0, 'linkSets not removed'); + }); + } + + // 15.2.4.7 PromiseOfStartLoadPartwayThrough absorbed into calling functions + + // 15.2.4.7.1 + function asyncStartLoadPartwayThrough(stepState) { + return function(resolve, reject) { + var loader = stepState.loader; + var name = stepState.moduleName; + var step = stepState.step; + + if (loader.modules[name]) + throw new TypeError('"' + name + '" already exists in the module table'); + + // adjusted to pick up existing loads + var existingLoad; + for (var i = 0, l = loader.loads.length; i < l; i++) { + if (loader.loads[i].name == name) { + existingLoad = loader.loads[i]; + + if (step == 'translate' && !existingLoad.source) { + existingLoad.address = stepState.moduleAddress; + proceedToTranslate(loader, existingLoad, Promise.resolve(stepState.moduleSource)); + } + + // a primary load -> use that existing linkset if it is for the direct load here + // otherwise create a new linkset unit + if (existingLoad.linkSets.length && existingLoad.linkSets[0].loads[0].name == existingLoad.name) + return existingLoad.linkSets[0].done.then(function() { + resolve(existingLoad); + }); + } + } + + var load = existingLoad || createLoad(name); + + load.metadata = stepState.moduleMetadata; + + var linkSet = createLinkSet(loader, load); + + loader.loads.push(load); + + resolve(linkSet.done); + + if (step == 'locate') + proceedToLocate(loader, load); + + else if (step == 'fetch') + proceedToFetch(loader, load, Promise.resolve(stepState.moduleAddress)); + + else { + console.assert(step == 'translate', 'translate step'); + load.address = stepState.moduleAddress; + proceedToTranslate(loader, load, Promise.resolve(stepState.moduleSource)); + } + } + } + + // Declarative linking functions run through alternative implementation: + // 15.2.5.1.1 CreateModuleLinkageRecord not implemented + // 15.2.5.1.2 LookupExport not implemented + // 15.2.5.1.3 LookupModuleDependency not implemented + + // 15.2.5.2.1 + function createLinkSet(loader, startingLoad) { + var linkSet = { + loader: loader, + loads: [], + startingLoad: startingLoad, // added see spec bug https://bugs.ecmascript.org/show_bug.cgi?id=2995 + loadingCount: 0 + }; + linkSet.done = new Promise(function(resolve, reject) { + linkSet.resolve = resolve; + linkSet.reject = reject; + }); + addLoadToLinkSet(linkSet, startingLoad); + return linkSet; + } + // 15.2.5.2.2 + function addLoadToLinkSet(linkSet, load) { + if (load.status == 'failed') + return; + + console.assert(load.status == 'loading' || load.status == 'loaded', 'loading or loaded on link set'); + + for (var i = 0, l = linkSet.loads.length; i < l; i++) + if (linkSet.loads[i] == load) + return; + + linkSet.loads.push(load); + load.linkSets.push(linkSet); + + // adjustment, see https://bugs.ecmascript.org/show_bug.cgi?id=2603 + if (load.status != 'loaded') { + linkSet.loadingCount++; + } + + var loader = linkSet.loader; + + for (var i = 0, l = load.dependencies.length; i < l; i++) { + if (!load.dependencies[i]) + continue; + + var name = load.dependencies[i].value; + + if (loader.modules[name]) + continue; + + for (var j = 0, d = loader.loads.length; j < d; j++) { + if (loader.loads[j].name != name) + continue; + + addLoadToLinkSet(linkSet, loader.loads[j]); + break; + } + } + // console.log('add to linkset ' + load.name); + // snapshot(linkSet.loader); + } + + // linking errors can be generic or load-specific + // this is necessary for debugging info + function doLink(linkSet) { + var error = false; + try { + link(linkSet, function(load, exc) { + linkSetFailed(linkSet, load, exc); + error = true; + }); + } + catch(e) { + linkSetFailed(linkSet, null, e); + error = true; + } + return error; + } + + // 15.2.5.2.3 + function updateLinkSetOnLoad(linkSet, load) { + // console.log('update linkset on load ' + load.name); + // snapshot(linkSet.loader); + + console.assert(load.status == 'loaded' || load.status == 'linked', 'loaded or linked'); + + linkSet.loadingCount--; + + if (linkSet.loadingCount > 0) + return; + + // adjusted for spec bug https://bugs.ecmascript.org/show_bug.cgi?id=2995 + var startingLoad = linkSet.startingLoad; + + // non-executing link variation for loader tracing + // on the server. Not in spec. + /***/ + if (linkSet.loader.loaderObj.execute === false) { + var loads = [].concat(linkSet.loads); + for (var i = 0, l = loads.length; i < l; i++) { + var load = loads[i]; + load.module = !load.isDeclarative ? { + module: _newModule({}) + } : { + name: load.name, + module: _newModule({}), + evaluated: true + }; + load.status = 'linked'; + finishLoad(linkSet.loader, load); + } + return linkSet.resolve(startingLoad); + } + /***/ + + var abrupt = doLink(linkSet); + + if (abrupt) + return; + + console.assert(linkSet.loads.length == 0, 'loads cleared'); + + linkSet.resolve(startingLoad); + } + + // 15.2.5.2.4 + function linkSetFailed(linkSet, load, exc) { + var loader = linkSet.loader; + var requests; + + checkError: + if (load) { + if (linkSet.loads[0].name == load.name) { + exc = addToError(exc, 'Error loading ' + load.name); + } + else { + for (var i = 0; i < linkSet.loads.length; i++) { + var pLoad = linkSet.loads[i]; + for (var j = 0; j < pLoad.dependencies.length; j++) { + var dep = pLoad.dependencies[j]; + if (dep.value == load.name) { + exc = addToError(exc, 'Error loading ' + load.name + ' as "' + dep.key + '" from ' + pLoad.name); + break checkError; + } + } + } + exc = addToError(exc, 'Error loading ' + load.name + ' from ' + linkSet.loads[0].name); + } + } + else { + exc = addToError(exc, 'Error linking ' + linkSet.loads[0].name); + } + + + var loads = linkSet.loads.concat([]); + for (var i = 0, l = loads.length; i < l; i++) { + var load = loads[i]; + + // store all failed load records + loader.loaderObj.failed = loader.loaderObj.failed || []; + if (indexOf.call(loader.loaderObj.failed, load) == -1) + loader.loaderObj.failed.push(load); + + var linkIndex = indexOf.call(load.linkSets, linkSet); + console.assert(linkIndex != -1, 'link not present'); + load.linkSets.splice(linkIndex, 1); + if (load.linkSets.length == 0) { + var globalLoadsIndex = indexOf.call(linkSet.loader.loads, load); + if (globalLoadsIndex != -1) + linkSet.loader.loads.splice(globalLoadsIndex, 1); + } + } + linkSet.reject(exc); + } + + // 15.2.5.2.5 + function finishLoad(loader, load) { + // add to global trace if tracing + if (loader.loaderObj.trace) { + if (!loader.loaderObj.loads) + loader.loaderObj.loads = {}; + var depMap = {}; + load.dependencies.forEach(function(dep) { + depMap[dep.key] = dep.value; + }); + loader.loaderObj.loads[load.name] = { + name: load.name, + deps: load.dependencies.map(function(dep){ return dep.key }), + depMap: depMap, + address: load.address, + metadata: load.metadata, + source: load.source, + kind: load.isDeclarative ? 'declarative' : 'dynamic' + }; + } + // if not anonymous, add to the module table + if (load.name) { + console.assert(!loader.modules[load.name], 'load not in module table'); + loader.modules[load.name] = load.module; + } + var loadIndex = indexOf.call(loader.loads, load); + if (loadIndex != -1) + loader.loads.splice(loadIndex, 1); + for (var i = 0, l = load.linkSets.length; i < l; i++) { + loadIndex = indexOf.call(load.linkSets[i].loads, load); + if (loadIndex != -1) + load.linkSets[i].loads.splice(loadIndex, 1); + } + load.linkSets.splice(0, load.linkSets.length); + } + + function doDynamicExecute(linkSet, load, linkError) { + try { + var module = load.execute(); + } + catch(e) { + linkError(load, e); + return; + } + if (!module || !(module instanceof Module)) + linkError(load, new TypeError('Execution must define a Module instance')); + else + return module; + } + + // 26.3 Loader + + // 26.3.1.1 + // defined at top + + // importPromises adds ability to import a module twice without error - https://bugs.ecmascript.org/show_bug.cgi?id=2601 + function createImportPromise(loader, name, promise) { + var importPromises = loader._loader.importPromises; + return importPromises[name] = promise.then(function(m) { + importPromises[name] = undefined; + return m; + }, function(e) { + importPromises[name] = undefined; + throw e; + }); + } + + Loader.prototype = { + // 26.3.3.1 + constructor: Loader, + // 26.3.3.2 + define: function(name, source, options) { + // check if already defined + if (this._loader.importPromises[name]) + throw new TypeError('Module is already loading.'); + return createImportPromise(this, name, new Promise(asyncStartLoadPartwayThrough({ + step: 'translate', + loader: this._loader, + moduleName: name, + moduleMetadata: options && options.metadata || {}, + moduleSource: source, + moduleAddress: options && options.address + }))); + }, + // 26.3.3.3 + 'delete': function(name) { + var loader = this._loader; + delete loader.importPromises[name]; + delete loader.moduleRecords[name]; + return loader.modules[name] ? delete loader.modules[name] : false; + }, + // 26.3.3.4 entries not implemented + // 26.3.3.5 + get: function(key) { + if (!this._loader.modules[key]) + return; + doEnsureEvaluated(this._loader.modules[key], [], this); + return this._loader.modules[key].module; + }, + // 26.3.3.7 + has: function(name) { + return !!this._loader.modules[name]; + }, + // 26.3.3.8 + 'import': function(name, parentName, parentAddress) { + if (typeof parentName == 'object') + parentName = parentName.name; + + // run normalize first + var loaderObj = this; + + // added, see https://bugs.ecmascript.org/show_bug.cgi?id=2659 + return Promise.resolve(loaderObj.normalize(name, parentName)) + .then(function(name) { + var loader = loaderObj._loader; + + if (loader.modules[name]) { + doEnsureEvaluated(loader.modules[name], [], loader._loader); + return loader.modules[name].module; + } + + return loader.importPromises[name] || createImportPromise(loaderObj, name, + loadModule(loader, name, {}) + .then(function(load) { + delete loader.importPromises[name]; + return evaluateLoadedModule(loader, load); + })); + }); + }, + // 26.3.3.9 keys not implemented + // 26.3.3.10 + load: function(name) { + var loader = this._loader; + if (loader.modules[name]) + return Promise.resolve(); + return loader.importPromises[name] || createImportPromise(this, name, new Promise(asyncStartLoadPartwayThrough({ + step: 'locate', + loader: loader, + moduleName: name, + moduleMetadata: {}, + moduleSource: undefined, + moduleAddress: undefined + })) + .then(function() { + delete loader.importPromises[name]; + })); + }, + // 26.3.3.11 + module: function(source, options) { + var load = createLoad(); + load.address = options && options.address; + var linkSet = createLinkSet(this._loader, load); + var sourcePromise = Promise.resolve(source); + var loader = this._loader; + var p = linkSet.done.then(function() { + return evaluateLoadedModule(loader, load); + }); + proceedToTranslate(loader, load, sourcePromise); + return p; + }, + // 26.3.3.12 + newModule: function (obj) { + if (typeof obj != 'object') + throw new TypeError('Expected object'); + + var m = new Module(); + + var pNames = []; + if (Object.getOwnPropertyNames && obj != null) + pNames = Object.getOwnPropertyNames(obj); + else + for (var key in obj) + pNames.push(key); + + for (var i = 0; i < pNames.length; i++) (function(key) { + defineProperty(m, key, { + configurable: false, + enumerable: true, + get: function () { + return obj[key]; + }, + set: function() { + throw new Error('Module exports cannot be changed externally.'); + } + }); + })(pNames[i]); + + if (Object.freeze) + Object.freeze(m); + + return m; + }, + // 26.3.3.14 + set: function(name, module) { + if (!(module instanceof Module)) + throw new TypeError('Loader.set(' + name + ', module) must be a module'); + this._loader.modules[name] = { + module: module + }; + }, + // 26.3.3.15 values not implemented + // 26.3.3.16 @@iterator not implemented + // 26.3.3.17 @@toStringTag not implemented + + // 26.3.3.18.1 + normalize: function(name, referrerName, referrerAddress) { + return name; + }, + // 26.3.3.18.2 + locate: function(load) { + return load.name; + }, + // 26.3.3.18.3 + fetch: function(load) { + }, + // 26.3.3.18.4 + translate: function(load) { + return load.source; + }, + // 26.3.3.18.5 + instantiate: function(load) { + } + }; + + var _newModule = Loader.prototype.newModule; +/* + * ES6 Module Declarative Linking Code - Dev Build Only + */ + function link(linkSet, linkError) { + + var loader = linkSet.loader; + + if (!linkSet.loads.length) + return; + + var loads = linkSet.loads.concat([]); + + for (var i = 0; i < loads.length; i++) { + var load = loads[i]; + + var module = doDynamicExecute(linkSet, load, linkError); + if (!module) + return; + load.module = { + name: load.name, + module: module + }; + load.status = 'linked'; + + finishLoad(loader, load); + } + } + + function evaluateLoadedModule(loader, load) { + console.assert(load.status == 'linked', 'is linked ' + load.name); + return load.module.module; + } + + function doEnsureEvaluated() {} + + function transpile() { + throw new TypeError('ES6 transpilation is only provided in the dev module loader build.'); + } +})();/* +********************************************************************************************* + + System Loader Implementation + + - Implemented to https://github.com/jorendorff/js-loaders/blob/master/browser-loader.js + + - ')}else e()}else if("undefined"!=typeof importScripts){var i="";try{throw new Error("_")}catch(n){n.stack.replace(/(?:at|@).*(http.+):[\d]+:[\d]+/,function(e,t){$__curScript={src:t},i=t.replace(/\/[^\/]*$/,"/")})}r&&importScripts(i+"system-polyfills.js"),e()}else $__curScript="undefined"!=typeof __filename?{src:__filename}:null,e()}(); +//# sourceMappingURL=system.js.map diff --git a/jspm_packages/system.js.map b/jspm_packages/system.js.map new file mode 100644 index 0000000..d7cdeb0 --- /dev/null +++ b/jspm_packages/system.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["system.src.js"],"names":["bootstrap","__global","addToError","err","msg","originalErr","stack","message","split","newStack","i","length","$__curScript","indexOf","src","push","newMsg","join","isBrowser","replace","isWindows","newErr","Error","fileName","lineNumber","__eval","source","debugName","context","Function","call","e","Module","Loader","options","this","_loader","loaderObj","loads","modules","importPromises","moduleRecords","defineProperty","get","SystemLoader","paths","applyPaths","name","wildcard","pathMatch","maxWildcardPrefixLen","p","pathParts","TypeError","substr","wildcardPrefixLen","outPath","LoaderProto","SystemJSLoader","systemJSConstructor","SystemProto","hook","prototype","hookConstructor","group","deps","names","indices","l","index","getESModule","exports","esModule","getOwnPropertyDescriptor","d","Object","hasOwnProperty","value","extend","a","b","prepend","extendMeta","val","Array","concat","warn","warnings","console","readMemberExpression","pParts","shift","getBaseURLObj","baseURLCache","baseURL","URL","baseURI","href","getMapMatch","map","bestMatch","bestMatchLength","curMatchLength","setProduction","isProduction","set","newModule","browser","node","_nodeRequire","production","default","isPlain","match","absURLRegEx","urlResolve","parent","baseURIObj","baseURLResolve","loader","coreResolve","parentName","mapMatch","has","nodeCoreModules","pathed","detectRegisterFormat","leadingCommentAndMeta","leadingCommentAndMetaRegEx","createEntry","originalIndices","declare","execute","executingRequire","declarative","normalizedDeps","groupIndex","evaluated","module","esmExports","getGlobalValue","globalValue","first","pop","parseCondition","condition","conditionExport","conditionModule","negation","conditionExportIndex","lastIndexOf","prop","negate","serializeCondition","conditionObj","resolveCondition","bool","then","m","interpolateConditional","conditionalMatch","interpolationRegEx","Promise","resolve","builder","conditionValue","booleanConditional","booleanIndex","isWorker","window","self","importScripts","document","process","platform","assert","item","thisLen","obj","opt","getElementsByTagName","bases","location","cwd","URLPolyfill","createLoad","status","linkSets","dependencies","metadata","loadModule","asyncStartLoadPartwayThrough","step","address","moduleName","moduleMetadata","moduleSource","moduleAddress","requestLoad","request","refererName","refererAddress","reject","normalize","load","proceedToLocate","proceedToFetch","locate","proceedToTranslate","fetch","translate","instantiate","instantiateResult","undefined","anonCnt","isDeclarative","transpile","transpiled","curSystem","System","curRegister","register","depsList","loadPromises","depLoad","key","addLoadToLinkSet","all","updateLinkSetOnLoad","exc","exception","linkSetFailed","stepState","existingLoad","done","linkSet","createLinkSet","startingLoad","loadingCount","j","doLink","error","link","_newModule","finishLoad","abrupt","checkError","pLoad","dep","failed","linkIndex","splice","globalLoadsIndex","trace","depMap","forEach","kind","loadIndex","doDynamicExecute","linkError","createImportPromise","promise","evaluateLoadedModule","doEnsureEvaluated","constructor","define","delete","import","parentAddress","sourcePromise","pNames","getOwnPropertyNames","configurable","enumerable","freeze","referrerName","referrerAddress","fetchTextFromURL","XMLHttpRequest","url","authorization","fulfill","xhr","responseText","statusText","sameDomain","doTimeout","domainCheck","exec","host","protocol","XDomainRequest","onload","onerror","ontimeout","onprogress","timeout","onreadystatechange","readyState","addEventListener","open","setRequestHeader","withCredentials","setTimeout","send","require","fs","readFile","data","dataString","opts","headers","Accept","credentials","r","ok","text","transpiler","pluginLoader","__useDefault","transpileFunction","Compiler","traceurTranspile","createLanguageService","typescriptTranspile","babelTranspile","traceur","traceurOptions","script","sourceMaps","filename","inputSourceMap","sourceMap","compiler","doTraceurCompile","compile","babel","babelOptions","code","ast","transform","ts","typescriptOptions","target","ScriptTarget","ES5","inlineSourceMap","ModuleKind","__exec","packageProperties","getSource","lastLineIndex","wrap","format","bundle","mappings","JSON","stringify","hashBangRegEx","hasBtoa","btoa","unescape","encodeURIComponent","preExec","curLoad","callCounter","SystemJS","postExec","scriptExec","head","body","documentElement","createElement","_e","integrity","setAttribute","nonce","appendChild","removeChild","reduceRegister_","supportsScriptExec","eval","scripts","chrome","extension","navigator","userAgent","defaultJSExtensions","pluginFirst","loaderErrorStack","skipExt","resolved","httpRequest","systemImport","systemTranslate","entry","parse","env","curCurScript","config","cfg","checkHasConfig","transpilerRuntime","loadedTranspilerRuntime","packages","meta","depCache","bundles","packageConfigPaths","objMaps","v","defaultJSExtension","decanonicalize","pkgMatch","pkg","main","path","packageLength","Math","max","normalized","normalizedBundleDep","q","c","getPackage","curPkg","pkgLen","curPkgLen","addDefaultExtension","pkgName","subPath","skipExtensions","defaultExtension","metaMatch","getMetaMatches","metaPattern","matchMeta","matchDepth","applyPackageConfigSync","mapPath","doMapSync","validateMapping","mapped","normalizeSync","applyPackageConfig","doMap","doStringMap","createPkgConfigPathObj","lastWildcard","regEx","RegExp","getPackageConfigMatch","configPath","exactMatch","packageConfigPath","packageName","loadPackageConfigPath","pkgConfigPath","configLoader","systemjs","dNormalized","pkgMeta","matchFn","wildcardIndex","dotRel","exactMeta","decanonicalized","isPlugin","parentPackageName","parentPackage","parentMap","parentMapMatch","pkgConfigMatch","isConfigured","configured","bestDepth","getInteractiveScriptLoad","interactiveScript","interactiveLoadingScripts","webWorkerImport","workerLoad","ieEvents","s","isOpera","opera","toString","attachEvent","loadingCnt","registerQueue","pushRegister","scriptLoad","complete","evt","cleanup","detachEvent","removeEventListener","async","crossOrigin","buildGroups","groups","depName","depEntry","defined","depGroupIndex","startEntry","curGroupDeclarative","linkDeclarativeModule","linkDynamicModule","ModuleRecord","getOrCreateModuleRecord","importers","declaration","locked","importerModule","importerIndex","setters","id","depExports","depModule","len","getModule","ensureEvaluated","output","nameNormalized","__esModule","seen","registerDynamic","apply","arguments","pushRegister_","amd","curMeta","del","grouped","normalizePromises","esmRegEx","traceurRuntimeRegEx","babelHelpersRegEx","loadedTranspiler","transpilerPromise","loaderModule","originalName","file","sources","originalSource","$traceurRuntime","babelHelpers","__globalName","registered","g","globals","gl","exportName","retrieveGlobal","prepareGlobal","reduceRegister","forEachGlobal","callback","keys","forEachGlobalValue","globalName","ignoredGlobalProps","globalSnapshot","curDefine","oldGlobals","singleGlobal","multipleExports","getCJSDeps","inLocation","locations","cjsRequireRegEx","lastIndex","commentRegEx","stringRegEx","stringLocations","commentLocations","cjsExportsRegEx","metaDeps","cjsRequireDetection","_require","requireResolve","cjsDeferDepsExecute","pathVars","getPathVars","__cjsWrapper","args","dirname","cjsWrapper","stripOrigin","windowOrigin","hostname","port","parentId","moduleId","pluginIndex","amdDefine","requireIndex","params","fnBracketRegEx","requireAlias","wsRegEx","requireRegEx","requireRegExs","cjsRequirePre","cjsRequirePost","errback","referer","dynamicRequires","factory","req","contextualRequire","depValues","uri","moduleIndex","exportsIndex","toUrl","curRequire","amdRequire","amdRegEx","builderExecute","getParentName","parentPluginIndex","parsePlugin","argumentName","pluginName","argument","plugin","combinePluginParts","checkDefaultExtension","arg","createNormalizeSync","parsed","pluginSyntaxIndex","loaderNormalized","result","calledInstantiate","alias","aliasDeps","_export","setMetaProperty","curPart","depth","metaRegEx","metaPartRegEx","metaParts","firstChar","metaString","metaName","metaValue","loadedBundles","matched","curModule","parts","substring","version","Reflect","global","LoaderPolyfill","hasURL","doPolyfill","curPath","basePath","systemJSBootstrap","write","__filename"],"mappings":"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"} \ No newline at end of file diff --git a/jspm_packages/system.src.js b/jspm_packages/system.src.js new file mode 100644 index 0000000..a741bc4 --- /dev/null +++ b/jspm_packages/system.src.js @@ -0,0 +1,4939 @@ +/* + * SystemJS v0.19.24 + */ +(function() { +function bootstrap() {(function(__global) { + + var isWorker = typeof window == 'undefined' && typeof self != 'undefined' && typeof importScripts != 'undefined'; + var isBrowser = typeof window != 'undefined' && typeof document != 'undefined'; + var isWindows = typeof process != 'undefined' && typeof process.platform != 'undefined' && !!process.platform.match(/^win/); + + if (!__global.console) + __global.console = { assert: function() {} }; + + // IE8 support + var indexOf = Array.prototype.indexOf || function(item) { + for (var i = 0, thisLen = this.length; i < thisLen; i++) { + if (this[i] === item) { + return i; + } + } + return -1; + }; + + var defineProperty; + (function () { + try { + if (!!Object.defineProperty({}, 'a', {})) + defineProperty = Object.defineProperty; + } + catch (e) { + defineProperty = function(obj, prop, opt) { + try { + obj[prop] = opt.value || opt.get.call(obj); + } + catch(e) {} + } + } + })(); + + function addToError(err, msg) { + // parse the stack removing loader code lines for simplification + if (!err.originalErr) { + var stack = (err.stack || err.message || err).split('\n'); + var newStack = []; + for (var i = 0; i < stack.length; i++) { + if (typeof $__curScript == 'undefined' || stack[i].indexOf($__curScript.src) == -1) + newStack.push(stack[i]); + } + } + + var newMsg = (newStack ? newStack.join('\n\t') : err.message) + '\n\t' + msg; + + // Convert file:/// URLs to paths in Node + if (!isBrowser) + newMsg = newMsg.replace(isWindows ? /file:\/\/\//g : /file:\/\//g, ''); + + var newErr = new Error(newMsg, err.fileName, err.lineNumber); + + // Node needs stack adjustment for throw to show message + if (!isBrowser) + newErr.stack = newMsg; + // Clearing the stack stops unnecessary loader lines showing + else + newErr.stack = null; + + // track the original error + newErr.originalErr = err.originalErr || err; + + return newErr; + } + + function __eval(source, debugName, context) { + try { + new Function(source).call(context); + } + catch(e) { + throw addToError(e, 'Evaluating ' + debugName); + } + } + + var baseURI; + // environent baseURI detection + if (typeof document != 'undefined' && document.getElementsByTagName) { + baseURI = document.baseURI; + + if (!baseURI) { + var bases = document.getElementsByTagName('base'); + baseURI = bases[0] && bases[0].href || window.location.href; + } + + // sanitize out the hash and querystring + baseURI = baseURI.split('#')[0].split('?')[0]; + baseURI = baseURI.substr(0, baseURI.lastIndexOf('/') + 1); + } + else if (typeof process != 'undefined' && process.cwd) { + baseURI = 'file://' + (isWindows ? '/' : '') + process.cwd() + '/'; + if (isWindows) + baseURI = baseURI.replace(/\\/g, '/'); + } + else if (typeof location != 'undefined') { + baseURI = __global.location.href; + } + else { + throw new TypeError('No environment baseURI'); + } + + var URL = __global.URLPolyfill || __global.URL; +/* +********************************************************************************************* + + Dynamic Module Loader Polyfill + + - Implemented exactly to the former 2014-08-24 ES6 Specification Draft Rev 27, Section 15 + http://wiki.ecmascript.org/doku.php?id=harmony:specification_drafts#august_24_2014_draft_rev_27 + + - Functions are commented with their spec numbers, with spec differences commented. + + - Spec bugs are commented in this code with links. + + - Abstract functions have been combined where possible, and their associated functions + commented. + + - Realm implementation is entirely omitted. + +********************************************************************************************* +*/ + +function Module() {} +// http://www.ecma-international.org/ecma-262/6.0/#sec-@@tostringtag +defineProperty(Module.prototype, 'toString', { + value: function() { + return 'Module'; + } +}); +function Loader(options) { + this._loader = { + loaderObj: this, + loads: [], + modules: {}, + importPromises: {}, + moduleRecords: {} + }; + + // 26.3.3.6 + defineProperty(this, 'global', { + get: function() { + return __global; + } + }); + + // 26.3.3.13 realm not implemented +} + +(function() { + +// Some Helpers + +// logs a linkset snapshot for debugging +/* function snapshot(loader) { + console.log('---Snapshot---'); + for (var i = 0; i < loader.loads.length; i++) { + var load = loader.loads[i]; + var linkSetLog = ' ' + load.name + ' (' + load.status + '): '; + + for (var j = 0; j < load.linkSets.length; j++) { + linkSetLog += '{' + logloads(load.linkSets[j].loads) + '} '; + } + console.log(linkSetLog); + } + console.log(''); +} +function logloads(loads) { + var log = ''; + for (var k = 0; k < loads.length; k++) + log += loads[k].name + (k != loads.length - 1 ? ' ' : ''); + return log; +} */ + + +/* function checkInvariants() { + // see https://bugs.ecmascript.org/show_bug.cgi?id=2603#c1 + + var loads = System._loader.loads; + var linkSets = []; + + for (var i = 0; i < loads.length; i++) { + var load = loads[i]; + console.assert(load.status == 'loading' || load.status == 'loaded', 'Each load is loading or loaded'); + + for (var j = 0; j < load.linkSets.length; j++) { + var linkSet = load.linkSets[j]; + + for (var k = 0; k < linkSet.loads.length; k++) + console.assert(loads.indexOf(linkSet.loads[k]) != -1, 'linkSet loads are a subset of loader loads'); + + if (linkSets.indexOf(linkSet) == -1) + linkSets.push(linkSet); + } + } + + for (var i = 0; i < loads.length; i++) { + var load = loads[i]; + for (var j = 0; j < linkSets.length; j++) { + var linkSet = linkSets[j]; + + if (linkSet.loads.indexOf(load) != -1) + console.assert(load.linkSets.indexOf(linkSet) != -1, 'linkSet contains load -> load contains linkSet'); + + if (load.linkSets.indexOf(linkSet) != -1) + console.assert(linkSet.loads.indexOf(load) != -1, 'load contains linkSet -> linkSet contains load'); + } + } + + for (var i = 0; i < linkSets.length; i++) { + var linkSet = linkSets[i]; + for (var j = 0; j < linkSet.loads.length; j++) { + var load = linkSet.loads[j]; + + for (var k = 0; k < load.dependencies.length; k++) { + var depName = load.dependencies[k].value; + var depLoad; + for (var l = 0; l < loads.length; l++) { + if (loads[l].name != depName) + continue; + depLoad = loads[l]; + break; + } + + // loading records are allowed not to have their dependencies yet + // if (load.status != 'loading') + // console.assert(depLoad, 'depLoad found'); + + // console.assert(linkSet.loads.indexOf(depLoad) != -1, 'linkset contains all dependencies'); + } + } + } +} */ + + // 15.2.3 - Runtime Semantics: Loader State + + // 15.2.3.11 + function createLoaderLoad(object) { + return { + // modules is an object for ES5 implementation + modules: {}, + loads: [], + loaderObj: object + }; + } + + // 15.2.3.2 Load Records and LoadRequest Objects + + // 15.2.3.2.1 + function createLoad(name) { + return { + status: 'loading', + name: name, + linkSets: [], + dependencies: [], + metadata: {} + }; + } + + // 15.2.3.2.2 createLoadRequestObject, absorbed into calling functions + + // 15.2.4 + + // 15.2.4.1 + function loadModule(loader, name, options) { + return new Promise(asyncStartLoadPartwayThrough({ + step: options.address ? 'fetch' : 'locate', + loader: loader, + moduleName: name, + // allow metadata for import https://bugs.ecmascript.org/show_bug.cgi?id=3091 + moduleMetadata: options && options.metadata || {}, + moduleSource: options.source, + moduleAddress: options.address + })); + } + + // 15.2.4.2 + function requestLoad(loader, request, refererName, refererAddress) { + // 15.2.4.2.1 CallNormalize + return new Promise(function(resolve, reject) { + resolve(loader.loaderObj.normalize(request, refererName, refererAddress)); + }) + // 15.2.4.2.2 GetOrCreateLoad + .then(function(name) { + var load; + if (loader.modules[name]) { + load = createLoad(name); + load.status = 'linked'; + // https://bugs.ecmascript.org/show_bug.cgi?id=2795 + load.module = loader.modules[name]; + return load; + } + + for (var i = 0, l = loader.loads.length; i < l; i++) { + load = loader.loads[i]; + if (load.name != name) + continue; + console.assert(load.status == 'loading' || load.status == 'loaded', 'loading or loaded'); + return load; + } + + load = createLoad(name); + loader.loads.push(load); + + proceedToLocate(loader, load); + + return load; + }); + } + + // 15.2.4.3 + function proceedToLocate(loader, load) { + proceedToFetch(loader, load, + Promise.resolve() + // 15.2.4.3.1 CallLocate + .then(function() { + return loader.loaderObj.locate({ name: load.name, metadata: load.metadata }); + }) + ); + } + + // 15.2.4.4 + function proceedToFetch(loader, load, p) { + proceedToTranslate(loader, load, + p + // 15.2.4.4.1 CallFetch + .then(function(address) { + // adjusted, see https://bugs.ecmascript.org/show_bug.cgi?id=2602 + if (load.status != 'loading') + return; + load.address = address; + + return loader.loaderObj.fetch({ name: load.name, metadata: load.metadata, address: address }); + }) + ); + } + + var anonCnt = 0; + + // 15.2.4.5 + function proceedToTranslate(loader, load, p) { + p + // 15.2.4.5.1 CallTranslate + .then(function(source) { + if (load.status != 'loading') + return; + + return Promise.resolve(loader.loaderObj.translate({ name: load.name, metadata: load.metadata, address: load.address, source: source })) + + // 15.2.4.5.2 CallInstantiate + .then(function(source) { + load.source = source; + return loader.loaderObj.instantiate({ name: load.name, metadata: load.metadata, address: load.address, source: source }); + }) + + // 15.2.4.5.3 InstantiateSucceeded + .then(function(instantiateResult) { + if (instantiateResult === undefined) { + load.address = load.address || ''; + + // instead of load.kind, use load.isDeclarative + load.isDeclarative = true; + return transpile.call(loader.loaderObj, load) + .then(function(transpiled) { + // Hijack System.register to set declare function + var curSystem = __global.System; + var curRegister = curSystem.register; + curSystem.register = function(name, deps, declare) { + if (typeof name != 'string') { + declare = deps; + deps = name; + } + // store the registered declaration as load.declare + // store the deps as load.deps + load.declare = declare; + load.depsList = deps; + } + // empty {} context is closest to undefined 'this' we can get + __eval(transpiled, load.address, {}); + curSystem.register = curRegister; + }); + } + else if (typeof instantiateResult == 'object') { + load.depsList = instantiateResult.deps || []; + load.execute = instantiateResult.execute; + load.isDeclarative = false; + } + else + throw TypeError('Invalid instantiate return value'); + }) + // 15.2.4.6 ProcessLoadDependencies + .then(function() { + load.dependencies = []; + var depsList = load.depsList; + + var loadPromises = []; + for (var i = 0, l = depsList.length; i < l; i++) (function(request, index) { + loadPromises.push( + requestLoad(loader, request, load.name, load.address) + + // 15.2.4.6.1 AddDependencyLoad (load is parentLoad) + .then(function(depLoad) { + + // adjusted from spec to maintain dependency order + // this is due to the System.register internal implementation needs + load.dependencies[index] = { + key: request, + value: depLoad.name + }; + + if (depLoad.status != 'linked') { + var linkSets = load.linkSets.concat([]); + for (var i = 0, l = linkSets.length; i < l; i++) + addLoadToLinkSet(linkSets[i], depLoad); + } + + // console.log('AddDependencyLoad ' + depLoad.name + ' for ' + load.name); + // snapshot(loader); + }) + ); + })(depsList[i], i); + + return Promise.all(loadPromises); + }) + + // 15.2.4.6.2 LoadSucceeded + .then(function() { + // console.log('LoadSucceeded ' + load.name); + // snapshot(loader); + + console.assert(load.status == 'loading', 'is loading'); + + load.status = 'loaded'; + + var linkSets = load.linkSets.concat([]); + for (var i = 0, l = linkSets.length; i < l; i++) + updateLinkSetOnLoad(linkSets[i], load); + }); + }) + // 15.2.4.5.4 LoadFailed + ['catch'](function(exc) { + load.status = 'failed'; + load.exception = exc; + + var linkSets = load.linkSets.concat([]); + for (var i = 0, l = linkSets.length; i < l; i++) { + linkSetFailed(linkSets[i], load, exc); + } + + console.assert(load.linkSets.length == 0, 'linkSets not removed'); + }); + } + + // 15.2.4.7 PromiseOfStartLoadPartwayThrough absorbed into calling functions + + // 15.2.4.7.1 + function asyncStartLoadPartwayThrough(stepState) { + return function(resolve, reject) { + var loader = stepState.loader; + var name = stepState.moduleName; + var step = stepState.step; + + if (loader.modules[name]) + throw new TypeError('"' + name + '" already exists in the module table'); + + // adjusted to pick up existing loads + var existingLoad; + for (var i = 0, l = loader.loads.length; i < l; i++) { + if (loader.loads[i].name == name) { + existingLoad = loader.loads[i]; + + if (step == 'translate' && !existingLoad.source) { + existingLoad.address = stepState.moduleAddress; + proceedToTranslate(loader, existingLoad, Promise.resolve(stepState.moduleSource)); + } + + // a primary load -> use that existing linkset if it is for the direct load here + // otherwise create a new linkset unit + if (existingLoad.linkSets.length && existingLoad.linkSets[0].loads[0].name == existingLoad.name) + return existingLoad.linkSets[0].done.then(function() { + resolve(existingLoad); + }); + } + } + + var load = existingLoad || createLoad(name); + + load.metadata = stepState.moduleMetadata; + + var linkSet = createLinkSet(loader, load); + + loader.loads.push(load); + + resolve(linkSet.done); + + if (step == 'locate') + proceedToLocate(loader, load); + + else if (step == 'fetch') + proceedToFetch(loader, load, Promise.resolve(stepState.moduleAddress)); + + else { + console.assert(step == 'translate', 'translate step'); + load.address = stepState.moduleAddress; + proceedToTranslate(loader, load, Promise.resolve(stepState.moduleSource)); + } + } + } + + // Declarative linking functions run through alternative implementation: + // 15.2.5.1.1 CreateModuleLinkageRecord not implemented + // 15.2.5.1.2 LookupExport not implemented + // 15.2.5.1.3 LookupModuleDependency not implemented + + // 15.2.5.2.1 + function createLinkSet(loader, startingLoad) { + var linkSet = { + loader: loader, + loads: [], + startingLoad: startingLoad, // added see spec bug https://bugs.ecmascript.org/show_bug.cgi?id=2995 + loadingCount: 0 + }; + linkSet.done = new Promise(function(resolve, reject) { + linkSet.resolve = resolve; + linkSet.reject = reject; + }); + addLoadToLinkSet(linkSet, startingLoad); + return linkSet; + } + // 15.2.5.2.2 + function addLoadToLinkSet(linkSet, load) { + if (load.status == 'failed') + return; + + console.assert(load.status == 'loading' || load.status == 'loaded', 'loading or loaded on link set'); + + for (var i = 0, l = linkSet.loads.length; i < l; i++) + if (linkSet.loads[i] == load) + return; + + linkSet.loads.push(load); + load.linkSets.push(linkSet); + + // adjustment, see https://bugs.ecmascript.org/show_bug.cgi?id=2603 + if (load.status != 'loaded') { + linkSet.loadingCount++; + } + + var loader = linkSet.loader; + + for (var i = 0, l = load.dependencies.length; i < l; i++) { + if (!load.dependencies[i]) + continue; + + var name = load.dependencies[i].value; + + if (loader.modules[name]) + continue; + + for (var j = 0, d = loader.loads.length; j < d; j++) { + if (loader.loads[j].name != name) + continue; + + addLoadToLinkSet(linkSet, loader.loads[j]); + break; + } + } + // console.log('add to linkset ' + load.name); + // snapshot(linkSet.loader); + } + + // linking errors can be generic or load-specific + // this is necessary for debugging info + function doLink(linkSet) { + var error = false; + try { + link(linkSet, function(load, exc) { + linkSetFailed(linkSet, load, exc); + error = true; + }); + } + catch(e) { + linkSetFailed(linkSet, null, e); + error = true; + } + return error; + } + + // 15.2.5.2.3 + function updateLinkSetOnLoad(linkSet, load) { + // console.log('update linkset on load ' + load.name); + // snapshot(linkSet.loader); + + console.assert(load.status == 'loaded' || load.status == 'linked', 'loaded or linked'); + + linkSet.loadingCount--; + + if (linkSet.loadingCount > 0) + return; + + // adjusted for spec bug https://bugs.ecmascript.org/show_bug.cgi?id=2995 + var startingLoad = linkSet.startingLoad; + + // non-executing link variation for loader tracing + // on the server. Not in spec. + /***/ + if (linkSet.loader.loaderObj.execute === false) { + var loads = [].concat(linkSet.loads); + for (var i = 0, l = loads.length; i < l; i++) { + var load = loads[i]; + load.module = !load.isDeclarative ? { + module: _newModule({}) + } : { + name: load.name, + module: _newModule({}), + evaluated: true + }; + load.status = 'linked'; + finishLoad(linkSet.loader, load); + } + return linkSet.resolve(startingLoad); + } + /***/ + + var abrupt = doLink(linkSet); + + if (abrupt) + return; + + console.assert(linkSet.loads.length == 0, 'loads cleared'); + + linkSet.resolve(startingLoad); + } + + // 15.2.5.2.4 + function linkSetFailed(linkSet, load, exc) { + var loader = linkSet.loader; + var requests; + + checkError: + if (load) { + if (linkSet.loads[0].name == load.name) { + exc = addToError(exc, 'Error loading ' + load.name); + } + else { + for (var i = 0; i < linkSet.loads.length; i++) { + var pLoad = linkSet.loads[i]; + for (var j = 0; j < pLoad.dependencies.length; j++) { + var dep = pLoad.dependencies[j]; + if (dep.value == load.name) { + exc = addToError(exc, 'Error loading ' + load.name + ' as "' + dep.key + '" from ' + pLoad.name); + break checkError; + } + } + } + exc = addToError(exc, 'Error loading ' + load.name + ' from ' + linkSet.loads[0].name); + } + } + else { + exc = addToError(exc, 'Error linking ' + linkSet.loads[0].name); + } + + + var loads = linkSet.loads.concat([]); + for (var i = 0, l = loads.length; i < l; i++) { + var load = loads[i]; + + // store all failed load records + loader.loaderObj.failed = loader.loaderObj.failed || []; + if (indexOf.call(loader.loaderObj.failed, load) == -1) + loader.loaderObj.failed.push(load); + + var linkIndex = indexOf.call(load.linkSets, linkSet); + console.assert(linkIndex != -1, 'link not present'); + load.linkSets.splice(linkIndex, 1); + if (load.linkSets.length == 0) { + var globalLoadsIndex = indexOf.call(linkSet.loader.loads, load); + if (globalLoadsIndex != -1) + linkSet.loader.loads.splice(globalLoadsIndex, 1); + } + } + linkSet.reject(exc); + } + + // 15.2.5.2.5 + function finishLoad(loader, load) { + // add to global trace if tracing + if (loader.loaderObj.trace) { + if (!loader.loaderObj.loads) + loader.loaderObj.loads = {}; + var depMap = {}; + load.dependencies.forEach(function(dep) { + depMap[dep.key] = dep.value; + }); + loader.loaderObj.loads[load.name] = { + name: load.name, + deps: load.dependencies.map(function(dep){ return dep.key }), + depMap: depMap, + address: load.address, + metadata: load.metadata, + source: load.source, + kind: load.isDeclarative ? 'declarative' : 'dynamic' + }; + } + // if not anonymous, add to the module table + if (load.name) { + console.assert(!loader.modules[load.name], 'load not in module table'); + loader.modules[load.name] = load.module; + } + var loadIndex = indexOf.call(loader.loads, load); + if (loadIndex != -1) + loader.loads.splice(loadIndex, 1); + for (var i = 0, l = load.linkSets.length; i < l; i++) { + loadIndex = indexOf.call(load.linkSets[i].loads, load); + if (loadIndex != -1) + load.linkSets[i].loads.splice(loadIndex, 1); + } + load.linkSets.splice(0, load.linkSets.length); + } + + function doDynamicExecute(linkSet, load, linkError) { + try { + var module = load.execute(); + } + catch(e) { + linkError(load, e); + return; + } + if (!module || !(module instanceof Module)) + linkError(load, new TypeError('Execution must define a Module instance')); + else + return module; + } + + // 26.3 Loader + + // 26.3.1.1 + // defined at top + + // importPromises adds ability to import a module twice without error - https://bugs.ecmascript.org/show_bug.cgi?id=2601 + function createImportPromise(loader, name, promise) { + var importPromises = loader._loader.importPromises; + return importPromises[name] = promise.then(function(m) { + importPromises[name] = undefined; + return m; + }, function(e) { + importPromises[name] = undefined; + throw e; + }); + } + + Loader.prototype = { + // 26.3.3.1 + constructor: Loader, + // 26.3.3.2 + define: function(name, source, options) { + // check if already defined + if (this._loader.importPromises[name]) + throw new TypeError('Module is already loading.'); + return createImportPromise(this, name, new Promise(asyncStartLoadPartwayThrough({ + step: 'translate', + loader: this._loader, + moduleName: name, + moduleMetadata: options && options.metadata || {}, + moduleSource: source, + moduleAddress: options && options.address + }))); + }, + // 26.3.3.3 + 'delete': function(name) { + var loader = this._loader; + delete loader.importPromises[name]; + delete loader.moduleRecords[name]; + return loader.modules[name] ? delete loader.modules[name] : false; + }, + // 26.3.3.4 entries not implemented + // 26.3.3.5 + get: function(key) { + if (!this._loader.modules[key]) + return; + doEnsureEvaluated(this._loader.modules[key], [], this); + return this._loader.modules[key].module; + }, + // 26.3.3.7 + has: function(name) { + return !!this._loader.modules[name]; + }, + // 26.3.3.8 + 'import': function(name, parentName, parentAddress) { + if (typeof parentName == 'object') + parentName = parentName.name; + + // run normalize first + var loaderObj = this; + + // added, see https://bugs.ecmascript.org/show_bug.cgi?id=2659 + return Promise.resolve(loaderObj.normalize(name, parentName)) + .then(function(name) { + var loader = loaderObj._loader; + + if (loader.modules[name]) { + doEnsureEvaluated(loader.modules[name], [], loader._loader); + return loader.modules[name].module; + } + + return loader.importPromises[name] || createImportPromise(loaderObj, name, + loadModule(loader, name, {}) + .then(function(load) { + delete loader.importPromises[name]; + return evaluateLoadedModule(loader, load); + })); + }); + }, + // 26.3.3.9 keys not implemented + // 26.3.3.10 + load: function(name) { + var loader = this._loader; + if (loader.modules[name]) + return Promise.resolve(); + return loader.importPromises[name] || createImportPromise(this, name, new Promise(asyncStartLoadPartwayThrough({ + step: 'locate', + loader: loader, + moduleName: name, + moduleMetadata: {}, + moduleSource: undefined, + moduleAddress: undefined + })) + .then(function() { + delete loader.importPromises[name]; + })); + }, + // 26.3.3.11 + module: function(source, options) { + var load = createLoad(); + load.address = options && options.address; + var linkSet = createLinkSet(this._loader, load); + var sourcePromise = Promise.resolve(source); + var loader = this._loader; + var p = linkSet.done.then(function() { + return evaluateLoadedModule(loader, load); + }); + proceedToTranslate(loader, load, sourcePromise); + return p; + }, + // 26.3.3.12 + newModule: function (obj) { + if (typeof obj != 'object') + throw new TypeError('Expected object'); + + var m = new Module(); + + var pNames = []; + if (Object.getOwnPropertyNames && obj != null) + pNames = Object.getOwnPropertyNames(obj); + else + for (var key in obj) + pNames.push(key); + + for (var i = 0; i < pNames.length; i++) (function(key) { + defineProperty(m, key, { + configurable: false, + enumerable: true, + get: function () { + return obj[key]; + }, + set: function() { + throw new Error('Module exports cannot be changed externally.'); + } + }); + })(pNames[i]); + + if (Object.freeze) + Object.freeze(m); + + return m; + }, + // 26.3.3.14 + set: function(name, module) { + if (!(module instanceof Module)) + throw new TypeError('Loader.set(' + name + ', module) must be a module'); + this._loader.modules[name] = { + module: module + }; + }, + // 26.3.3.15 values not implemented + // 26.3.3.16 @@iterator not implemented + // 26.3.3.17 @@toStringTag not implemented + + // 26.3.3.18.1 + normalize: function(name, referrerName, referrerAddress) { + return name; + }, + // 26.3.3.18.2 + locate: function(load) { + return load.name; + }, + // 26.3.3.18.3 + fetch: function(load) { + }, + // 26.3.3.18.4 + translate: function(load) { + return load.source; + }, + // 26.3.3.18.5 + instantiate: function(load) { + } + }; + + var _newModule = Loader.prototype.newModule; +/* + * ES6 Module Declarative Linking Code - Dev Build Only + */ + function link(linkSet, linkError) { + + var loader = linkSet.loader; + + if (!linkSet.loads.length) + return; + + var loads = linkSet.loads.concat([]); + + for (var i = 0; i < loads.length; i++) { + var load = loads[i]; + + var module = doDynamicExecute(linkSet, load, linkError); + if (!module) + return; + load.module = { + name: load.name, + module: module + }; + load.status = 'linked'; + + finishLoad(loader, load); + } + } + + function evaluateLoadedModule(loader, load) { + console.assert(load.status == 'linked', 'is linked ' + load.name); + return load.module.module; + } + + function doEnsureEvaluated() {} + + function transpile() { + throw new TypeError('ES6 transpilation is only provided in the dev module loader build.'); + } +})();/* +********************************************************************************************* + + System Loader Implementation + + - Implemented to https://github.com/jorendorff/js-loaders/blob/master/browser-loader.js + + - - - - - - - diff --git a/package.json b/package.json deleted file mode 100644 index bffd086..0000000 --- a/package.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "name": "pixi-examples", - "version": "1.0.0", - "description": "Examples for using pixi.js v3+", - "repository": { - "type": "git", - "url": "https://github.com/pixijs/examples.git" - }, - "scripts": { - "start": "hs ." - }, - "keywords": [ - "pixi", - "2d", - "canvas", - "webgl", - "renderer", - "examples" - ], - "license": "MIT", - "bugs": { - "url": "https://github.com/pixijs/examples/issues" - }, - "homepage": "https://github.com/pixijs/examples", - "devDependencies": { - "gulp": "^3.8.11", - "gulp-jshint": "^1.9.2", - "http-server": "^0.7.5", - "jshint-summary": "^0.4.0" - } -} diff --git a/_assets/BGrotate.jpg b/required/assets/BGrotate.jpg old mode 100644 new mode 100755 similarity index 100% rename from _assets/BGrotate.jpg rename to required/assets/BGrotate.jpg diff --git a/_assets/LightRotate1.png b/required/assets/LightRotate1.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/LightRotate1.png rename to required/assets/LightRotate1.png diff --git a/_assets/LightRotate2.png b/required/assets/LightRotate2.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/LightRotate2.png rename to required/assets/LightRotate2.png diff --git a/_assets/SceneRotate.jpg b/required/assets/SceneRotate.jpg old mode 100644 new mode 100755 similarity index 100% rename from _assets/SceneRotate.jpg rename to required/assets/SceneRotate.jpg diff --git a/_assets/basics/bunny.png b/required/assets/basics/bunny.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/basics/bunny.png rename to required/assets/basics/bunny.png diff --git a/_assets/basics/fighter.json b/required/assets/basics/fighter.json old mode 100644 new mode 100755 similarity index 100% rename from _assets/basics/fighter.json rename to required/assets/basics/fighter.json diff --git a/_assets/basics/fighter.png b/required/assets/basics/fighter.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/basics/fighter.png rename to required/assets/basics/fighter.png diff --git a/_assets/basics/shader.frag b/required/assets/basics/shader.frag old mode 100644 new mode 100755 similarity index 100% rename from _assets/basics/shader.frag rename to required/assets/basics/shader.frag diff --git a/_assets/basics/strip.png b/required/assets/basics/strip.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/basics/strip.png rename to required/assets/basics/strip.png diff --git a/_assets/basics/tilingsky.jpg b/required/assets/basics/tilingsky.jpg old mode 100644 new mode 100755 similarity index 100% rename from _assets/basics/tilingsky.jpg rename to required/assets/basics/tilingsky.jpg diff --git a/_assets/bkg-grass.jpg b/required/assets/bkg-grass.jpg old mode 100644 new mode 100755 similarity index 100% rename from _assets/bkg-grass.jpg rename to required/assets/bkg-grass.jpg diff --git a/_assets/bkg.jpg b/required/assets/bkg.jpg old mode 100644 new mode 100755 similarity index 100% rename from _assets/bkg.jpg rename to required/assets/bkg.jpg diff --git a/_assets/bricks.png b/required/assets/bricks.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/bricks.png rename to required/assets/bricks.png diff --git a/_assets/bubble_32x32.png b/required/assets/bubble_32x32.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/bubble_32x32.png rename to required/assets/bubble_32x32.png diff --git a/_assets/bubble_64x64.png b/required/assets/bubble_64x64.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/bubble_64x64.png rename to required/assets/bubble_64x64.png diff --git a/required/assets/bunnies/square_blue.png b/required/assets/bunnies/square_blue.png new file mode 100755 index 0000000..3188b50 Binary files /dev/null and b/required/assets/bunnies/square_blue.png differ diff --git a/required/assets/bunnies/square_green.png b/required/assets/bunnies/square_green.png new file mode 100755 index 0000000..031917d Binary files /dev/null and b/required/assets/bunnies/square_green.png differ diff --git a/_assets/bunny.png b/required/assets/bunny.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/bunny.png rename to required/assets/bunny.png diff --git a/_assets/button.png b/required/assets/button.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/button.png rename to required/assets/button.png diff --git a/_assets/buttonDown.png b/required/assets/buttonDown.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/buttonDown.png rename to required/assets/buttonDown.png diff --git a/_assets/buttonOver.png b/required/assets/buttonOver.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/buttonOver.png rename to required/assets/buttonOver.png diff --git a/_assets/button_test_BG.jpg b/required/assets/button_test_BG.jpg old mode 100644 new mode 100755 similarity index 100% rename from _assets/button_test_BG.jpg rename to required/assets/button_test_BG.jpg diff --git a/_assets/cells.png b/required/assets/cells.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/cells.png rename to required/assets/cells.png diff --git a/_assets/click.png b/required/assets/click.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/click.png rename to required/assets/click.png diff --git a/_assets/compressed/Official-Chimera-Logo.png b/required/assets/compressed/Official-Chimera-Logo.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/compressed/Official-Chimera-Logo.png rename to required/assets/compressed/Official-Chimera-Logo.png diff --git a/_assets/compressed/building1.dds b/required/assets/compressed/building1.dds old mode 100644 new mode 100755 similarity index 100% rename from _assets/compressed/building1.dds rename to required/assets/compressed/building1.dds diff --git a/_assets/compressed/building1.json b/required/assets/compressed/building1.json old mode 100644 new mode 100755 similarity index 100% rename from _assets/compressed/building1.json rename to required/assets/compressed/building1.json diff --git a/_assets/compressed/building1.png b/required/assets/compressed/building1.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/compressed/building1.png rename to required/assets/compressed/building1.png diff --git a/_assets/compressed/building1@2x.dds b/required/assets/compressed/building1@2x.dds old mode 100644 new mode 100755 similarity index 100% rename from _assets/compressed/building1@2x.dds rename to required/assets/compressed/building1@2x.dds diff --git a/_assets/compressed/building1@2x.json b/required/assets/compressed/building1@2x.json old mode 100644 new mode 100755 similarity index 100% rename from _assets/compressed/building1@2x.json rename to required/assets/compressed/building1@2x.json diff --git a/_assets/compressed/building1@2x.png b/required/assets/compressed/building1@2x.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/compressed/building1@2x.png rename to required/assets/compressed/building1@2x.png diff --git a/_assets/compressed/building2.dds b/required/assets/compressed/building2.dds old mode 100644 new mode 100755 similarity index 100% rename from _assets/compressed/building2.dds rename to required/assets/compressed/building2.dds diff --git a/_assets/compressed/building2.json b/required/assets/compressed/building2.json old mode 100644 new mode 100755 similarity index 100% rename from _assets/compressed/building2.json rename to required/assets/compressed/building2.json diff --git a/_assets/compressed/building2.png b/required/assets/compressed/building2.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/compressed/building2.png rename to required/assets/compressed/building2.png diff --git a/_assets/compressed/building2@2x.dds b/required/assets/compressed/building2@2x.dds old mode 100644 new mode 100755 similarity index 100% rename from _assets/compressed/building2@2x.dds rename to required/assets/compressed/building2@2x.dds diff --git a/_assets/compressed/building2@2x.json b/required/assets/compressed/building2@2x.json old mode 100644 new mode 100755 similarity index 100% rename from _assets/compressed/building2@2x.json rename to required/assets/compressed/building2@2x.json diff --git a/_assets/compressed/building2@2x.png b/required/assets/compressed/building2@2x.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/compressed/building2@2x.png rename to required/assets/compressed/building2@2x.png diff --git a/_assets/compressed/buildings.dds b/required/assets/compressed/buildings.dds old mode 100644 new mode 100755 similarity index 100% rename from _assets/compressed/buildings.dds rename to required/assets/compressed/buildings.dds diff --git a/_assets/compressed/buildings.json b/required/assets/compressed/buildings.json old mode 100644 new mode 100755 similarity index 100% rename from _assets/compressed/buildings.json rename to required/assets/compressed/buildings.json diff --git a/_assets/compressed/buildings.png b/required/assets/compressed/buildings.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/compressed/buildings.png rename to required/assets/compressed/buildings.png diff --git a/_assets/compressed/buildings@2x.dds b/required/assets/compressed/buildings@2x.dds old mode 100644 new mode 100755 similarity index 100% rename from _assets/compressed/buildings@2x.dds rename to required/assets/compressed/buildings@2x.dds diff --git a/_assets/compressed/buildings@2x.json b/required/assets/compressed/buildings@2x.json old mode 100644 new mode 100755 similarity index 100% rename from _assets/compressed/buildings@2x.json rename to required/assets/compressed/buildings@2x.json diff --git a/_assets/compressed/buildings@2x.png b/required/assets/compressed/buildings@2x.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/compressed/buildings@2x.png rename to required/assets/compressed/buildings@2x.png diff --git a/_assets/depth_blur_BG.jpg b/required/assets/depth_blur_BG.jpg old mode 100644 new mode 100755 similarity index 100% rename from _assets/depth_blur_BG.jpg rename to required/assets/depth_blur_BG.jpg diff --git a/_assets/depth_blur_dudes.jpg b/required/assets/depth_blur_dudes.jpg old mode 100644 new mode 100755 similarity index 100% rename from _assets/depth_blur_dudes.jpg rename to required/assets/depth_blur_dudes.jpg diff --git a/_assets/depth_blur_moby.jpg b/required/assets/depth_blur_moby.jpg old mode 100644 new mode 100755 similarity index 100% rename from _assets/depth_blur_moby.jpg rename to required/assets/depth_blur_moby.jpg diff --git a/_assets/desyrel.png b/required/assets/desyrel.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/desyrel.png rename to required/assets/desyrel.png diff --git a/_assets/desyrel.xml b/required/assets/desyrel.xml old mode 100644 new mode 100755 similarity index 100% rename from _assets/desyrel.xml rename to required/assets/desyrel.xml diff --git a/_assets/displace.png b/required/assets/displace.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/displace.png rename to required/assets/displace.png diff --git a/_assets/displacementMAP.jpg b/required/assets/displacementMAP.jpg old mode 100644 new mode 100755 similarity index 100% rename from _assets/displacementMAP.jpg rename to required/assets/displacementMAP.jpg diff --git a/_assets/displacement_BG.jpg b/required/assets/displacement_BG.jpg old mode 100644 new mode 100755 similarity index 100% rename from _assets/displacement_BG.jpg rename to required/assets/displacement_BG.jpg diff --git a/_assets/displacement_fish1.png b/required/assets/displacement_fish1.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/displacement_fish1.png rename to required/assets/displacement_fish1.png diff --git a/_assets/displacement_fish2.png b/required/assets/displacement_fish2.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/displacement_fish2.png rename to required/assets/displacement_fish2.png diff --git a/_assets/displacement_fish3.png b/required/assets/displacement_fish3.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/displacement_fish3.png rename to required/assets/displacement_fish3.png diff --git a/_assets/displacement_fish4.png b/required/assets/displacement_fish4.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/displacement_fish4.png rename to required/assets/displacement_fish4.png diff --git a/_assets/displacement_map.jpg b/required/assets/displacement_map.jpg old mode 100644 new mode 100755 similarity index 100% rename from _assets/displacement_map.jpg rename to required/assets/displacement_map.jpg diff --git a/_assets/displacement_overlay.png b/required/assets/displacement_overlay.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/displacement_overlay.png rename to required/assets/displacement_overlay.png diff --git a/_assets/eggHead.png b/required/assets/eggHead.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/eggHead.png rename to required/assets/eggHead.png diff --git a/_assets/flowerTop.png b/required/assets/flowerTop.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/flowerTop.png rename to required/assets/flowerTop.png diff --git a/_assets/grass.png b/required/assets/grass.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/grass.png rename to required/assets/grass.png diff --git a/_assets/helmlok.png b/required/assets/helmlok.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/helmlok.png rename to required/assets/helmlok.png diff --git a/_assets/maggot.png b/required/assets/maggot.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/maggot.png rename to required/assets/maggot.png diff --git a/_assets/mc.json b/required/assets/mc.json old mode 100644 new mode 100755 similarity index 100% rename from _assets/mc.json rename to required/assets/mc.json diff --git a/_assets/mc.png b/required/assets/mc.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/mc.png rename to required/assets/mc.png diff --git a/_assets/monsters.json b/required/assets/monsters.json old mode 100644 new mode 100755 similarity index 100% rename from _assets/monsters.json rename to required/assets/monsters.json diff --git a/_assets/monsters.png b/required/assets/monsters.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/monsters.png rename to required/assets/monsters.png diff --git a/_assets/p2.jpeg b/required/assets/p2.jpeg old mode 100644 new mode 100755 similarity index 100% rename from _assets/p2.jpeg rename to required/assets/p2.jpeg diff --git a/_assets/panda.png b/required/assets/panda.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/panda.png rename to required/assets/panda.png diff --git a/_assets/photonstorm.png b/required/assets/photonstorm.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/photonstorm.png rename to required/assets/photonstorm.png diff --git a/_assets/pixel.png b/required/assets/pixel.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/pixel.png rename to required/assets/pixel.png diff --git a/_assets/pixi.png b/required/assets/pixi.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/pixi.png rename to required/assets/pixi.png diff --git a/_assets/ring.png b/required/assets/ring.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/ring.png rename to required/assets/ring.png diff --git a/_assets/skully.png b/required/assets/skully.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/skully.png rename to required/assets/skully.png diff --git a/_assets/smoke.jpg b/required/assets/smoke.jpg old mode 100644 new mode 100755 similarity index 100% rename from _assets/smoke.jpg rename to required/assets/smoke.jpg diff --git a/_assets/snake.png b/required/assets/snake.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/snake.png rename to required/assets/snake.png diff --git a/_assets/spinObj_01.png b/required/assets/spinObj_01.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/spinObj_01.png rename to required/assets/spinObj_01.png diff --git a/_assets/spinObj_02.png b/required/assets/spinObj_02.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/spinObj_02.png rename to required/assets/spinObj_02.png diff --git a/_assets/spinObj_03.png b/required/assets/spinObj_03.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/spinObj_03.png rename to required/assets/spinObj_03.png diff --git a/_assets/spinObj_04.png b/required/assets/spinObj_04.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/spinObj_04.png rename to required/assets/spinObj_04.png diff --git a/_assets/spinObj_05.png b/required/assets/spinObj_05.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/spinObj_05.png rename to required/assets/spinObj_05.png diff --git a/_assets/spinObj_06.png b/required/assets/spinObj_06.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/spinObj_06.png rename to required/assets/spinObj_06.png diff --git a/_assets/spinObj_07.png b/required/assets/spinObj_07.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/spinObj_07.png rename to required/assets/spinObj_07.png diff --git a/_assets/spinObj_08.png b/required/assets/spinObj_08.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/spinObj_08.png rename to required/assets/spinObj_08.png diff --git a/_assets/spine/Pixie.atlas b/required/assets/spine/Pixie.atlas old mode 100644 new mode 100755 similarity index 100% rename from _assets/spine/Pixie.atlas rename to required/assets/spine/Pixie.atlas diff --git a/_assets/spine/Pixie.json b/required/assets/spine/Pixie.json old mode 100644 new mode 100755 similarity index 100% rename from _assets/spine/Pixie.json rename to required/assets/spine/Pixie.json diff --git a/_assets/spine/Pixie.png b/required/assets/spine/Pixie.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/spine/Pixie.png rename to required/assets/spine/Pixie.png diff --git a/_assets/spine/dragon.atlas b/required/assets/spine/dragon.atlas old mode 100644 new mode 100755 similarity index 100% rename from _assets/spine/dragon.atlas rename to required/assets/spine/dragon.atlas diff --git a/_assets/spine/dragon.json b/required/assets/spine/dragon.json old mode 100644 new mode 100755 similarity index 100% rename from _assets/spine/dragon.json rename to required/assets/spine/dragon.json diff --git a/_assets/spine/dragon.png b/required/assets/spine/dragon.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/spine/dragon.png rename to required/assets/spine/dragon.png diff --git a/_assets/spine/dragon2.png b/required/assets/spine/dragon2.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/spine/dragon2.png rename to required/assets/spine/dragon2.png diff --git a/_assets/spine/goblins.atlas b/required/assets/spine/goblins.atlas old mode 100644 new mode 100755 similarity index 100% rename from _assets/spine/goblins.atlas rename to required/assets/spine/goblins.atlas diff --git a/_assets/spine/goblins.json b/required/assets/spine/goblins.json old mode 100644 new mode 100755 similarity index 100% rename from _assets/spine/goblins.json rename to required/assets/spine/goblins.json diff --git a/_assets/spine/goblins.png b/required/assets/spine/goblins.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/spine/goblins.png rename to required/assets/spine/goblins.png diff --git a/_assets/spine/iP4_BGtile.jpg b/required/assets/spine/iP4_BGtile.jpg old mode 100644 new mode 100755 similarity index 100% rename from _assets/spine/iP4_BGtile.jpg rename to required/assets/spine/iP4_BGtile.jpg diff --git a/_assets/spine/iP4_ground.png b/required/assets/spine/iP4_ground.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/spine/iP4_ground.png rename to required/assets/spine/iP4_ground.png diff --git a/_assets/spine/spineboy.atlas b/required/assets/spine/spineboy.atlas old mode 100644 new mode 100755 similarity index 100% rename from _assets/spine/spineboy.atlas rename to required/assets/spine/spineboy.atlas diff --git a/_assets/spine/spineboy.json b/required/assets/spine/spineboy.json old mode 100644 new mode 100755 similarity index 100% rename from _assets/spine/spineboy.json rename to required/assets/spine/spineboy.json diff --git a/_assets/spine/spineboy.png b/required/assets/spine/spineboy.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/spine/spineboy.png rename to required/assets/spine/spineboy.png diff --git a/_assets/testVideo.mp4 b/required/assets/testVideo.mp4 old mode 100644 new mode 100755 similarity index 100% rename from _assets/testVideo.mp4 rename to required/assets/testVideo.mp4 diff --git a/_assets/textDemoBG.jpg b/required/assets/textDemoBG.jpg old mode 100644 new mode 100755 similarity index 100% rename from _assets/textDemoBG.jpg rename to required/assets/textDemoBG.jpg diff --git a/_assets/tinyMaggot.png b/required/assets/tinyMaggot.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/tinyMaggot.png rename to required/assets/tinyMaggot.png diff --git a/_assets/zeldaWaves.png b/required/assets/zeldaWaves.png old mode 100644 new mode 100755 similarity index 100% rename from _assets/zeldaWaves.png rename to required/assets/zeldaWaves.png diff --git a/_site/css/codemirror/codemirror.css b/required/codemirror/codemirror.css similarity index 78% rename from _site/css/codemirror/codemirror.css rename to required/codemirror/codemirror.css index e2d4ec2..18b0bf7 100644 --- a/_site/css/codemirror/codemirror.css +++ b/required/codemirror/codemirror.css @@ -4,10 +4,7 @@ /* Set height, width, borders, and global font properties here */ font-family: monospace; height: 300px; -} -.CodeMirror-scroll { - /* Set scrolling behaviour here */ - overflow: auto; + color: black; } /* PADDING */ @@ -36,8 +33,7 @@ min-width: 20px; text-align: right; color: #999; - -moz-box-sizing: content-box; - box-sizing: content-box; + white-space: nowrap; } .CodeMirror-guttermarker { color: black; } @@ -45,19 +41,21 @@ /* CURSOR */ -.CodeMirror div.CodeMirror-cursor { +.CodeMirror-cursor { border-left: 1px solid black; + border-right: none; + width: 0; } /* Shown when moving in bi-directional text */ .CodeMirror div.CodeMirror-secondarycursor { border-left: 1px solid silver; } -.CodeMirror.cm-fat-cursor div.CodeMirror-cursor { +.cm-fat-cursor .CodeMirror-cursor { width: auto; - border: 0; + border: 0 !important; background: #7e7; } -.CodeMirror.cm-fat-cursor div.CodeMirror-cursors { +.cm-fat-cursor div.CodeMirror-cursors { z-index: 1; } @@ -67,35 +65,51 @@ -webkit-animation: blink 1.06s steps(1) infinite; -moz-animation: blink 1.06s steps(1) infinite; animation: blink 1.06s steps(1) infinite; + background-color: #7e7; } @-moz-keyframes blink { - 0% { background: #7e7; } - 50% { background: none; } - 100% { background: #7e7; } + 0% {} + 50% { background-color: transparent; } + 100% {} } @-webkit-keyframes blink { - 0% { background: #7e7; } - 50% { background: none; } - 100% { background: #7e7; } + 0% {} + 50% { background-color: transparent; } + 100% {} } @keyframes blink { - 0% { background: #7e7; } - 50% { background: none; } - 100% { background: #7e7; } + 0% {} + 50% { background-color: transparent; } + 100% {} } /* Can style cursor different in overwrite (non-insert) mode */ -div.CodeMirror-overwrite div.CodeMirror-cursor {} +.CodeMirror-overwrite .CodeMirror-cursor {} .cm-tab { display: inline-block; text-decoration: inherit; } +.CodeMirror-rulers { + position: absolute; + left: 0; right: 0; top: -50px; bottom: -20px; + overflow: hidden; +} .CodeMirror-ruler { border-left: 1px solid #ccc; + top: 0; bottom: 0; position: absolute; } /* DEFAULT THEME */ +.cm-s-default .cm-header {color: blue;} +.cm-s-default .cm-quote {color: #090;} +.cm-negative {color: #d44;} +.cm-positive {color: #292;} +.cm-header, .cm-strong {font-weight: bold;} +.cm-em {font-style: italic;} +.cm-link {text-decoration: underline;} +.cm-strikethrough {text-decoration: line-through;} + .cm-s-default .cm-keyword {color: #708;} .cm-s-default .cm-atom {color: #219;} .cm-s-default .cm-number {color: #164;} @@ -115,21 +129,14 @@ div.CodeMirror-overwrite div.CodeMirror-cursor {} .cm-s-default .cm-bracket {color: #997;} .cm-s-default .cm-tag {color: #170;} .cm-s-default .cm-attribute {color: #00c;} -.cm-s-default .cm-header {color: blue;} -.cm-s-default .cm-quote {color: #090;} .cm-s-default .cm-hr {color: #999;} .cm-s-default .cm-link {color: #00c;} -.cm-negative {color: #d44;} -.cm-positive {color: #292;} -.cm-header, .cm-strong {font-weight: bold;} -.cm-em {font-style: italic;} -.cm-link {text-decoration: underline;} -.cm-strikethrough {text-decoration: line-through;} - .cm-s-default .cm-error {color: #f00;} .cm-invalidchar {color: #f00;} +.CodeMirror-composing { border-bottom: 2px solid; } + /* Default styles for common addons */ div.CodeMirror span.CodeMirror-matchingbracket {color: #0f0;} @@ -143,14 +150,13 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;} the editor. You probably shouldn't touch them. */ .CodeMirror { - line-height: 1; position: relative; overflow: hidden; background: white; - color: black; } .CodeMirror-scroll { + overflow: scroll !important; /* Things will break if this is overridden */ /* 30px is the magic margin used to hide the element's real scrollbars */ /* See overflow: hidden in .CodeMirror */ margin-bottom: -30px; margin-right: -30px; @@ -158,18 +164,14 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;} height: 100%; outline: none; /* Prevent dragging from highlighting the element */ position: relative; - -moz-box-sizing: content-box; - box-sizing: content-box; } .CodeMirror-sizer { position: relative; border-right: 30px solid transparent; - -moz-box-sizing: content-box; - box-sizing: content-box; } /* The fake, visible scrollbars. Used to force redraw during scrolling - before actuall scrolling happens, thus preventing shaking and + before actual scrolling happens, thus preventing shaking and flickering artifacts. */ .CodeMirror-vscrollbar, .CodeMirror-hscrollbar, .CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler { position: absolute; @@ -195,17 +197,15 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;} .CodeMirror-gutters { position: absolute; left: 0; top: 0; - padding-bottom: 30px; + min-height: 100%; z-index: 3; } .CodeMirror-gutter { white-space: normal; height: 100%; - -moz-box-sizing: content-box; - box-sizing: content-box; - padding-bottom: 30px; - margin-bottom: -32px; display: inline-block; + vertical-align: top; + margin-bottom: -30px; /* Hack to make IE7 behave */ *zoom:1; *display:inline; @@ -213,13 +213,24 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;} .CodeMirror-gutter-wrapper { position: absolute; z-index: 4; - height: 100%; + background: none !important; + border: none !important; +} +.CodeMirror-gutter-background { + position: absolute; + top: 0; bottom: 0; + z-index: 4; } .CodeMirror-gutter-elt { position: absolute; cursor: default; z-index: 4; } +.CodeMirror-gutter-wrapper { + -webkit-user-select: none; + -moz-user-select: none; + user-select: none; +} .CodeMirror-lines { cursor: text; @@ -240,6 +251,9 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;} z-index: 2; position: relative; overflow: visible; + -webkit-tap-highlight-color: transparent; + -webkit-font-variant-ligatures: none; + font-variant-ligatures: none; } .CodeMirror-wrap pre { word-wrap: break-word; @@ -261,8 +275,18 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;} .CodeMirror-widget {} -.CodeMirror-wrap .CodeMirror-scroll { - overflow-x: hidden; +.CodeMirror-code { + outline: none; +} + +/* Force content-box sizing for the elements where we expect it */ +.CodeMirror-scroll, +.CodeMirror-sizer, +.CodeMirror-gutter, +.CodeMirror-gutters, +.CodeMirror-linenumber { + -moz-box-sizing: content-box; + box-sizing: content-box; } .CodeMirror-measure { @@ -272,19 +296,22 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;} overflow: hidden; visibility: hidden; } -.CodeMirror-measure pre { position: static; } -.CodeMirror div.CodeMirror-cursor { +.CodeMirror-cursor { position: absolute; - border-right: none; - width: 0; + pointer-events: none; } +.CodeMirror-measure pre { position: static; } div.CodeMirror-cursors { visibility: hidden; position: relative; z-index: 3; } +div.CodeMirror-dragcursors { + visibility: visible; +} + .CodeMirror-focused div.CodeMirror-cursors { visibility: visible; } @@ -292,6 +319,8 @@ div.CodeMirror-cursors { .CodeMirror-selected { background: #d9d9d9; } .CodeMirror-focused .CodeMirror-selected { background: #d7d4f0; } .CodeMirror-crosshair { cursor: crosshair; } +.CodeMirror-line::selection, .CodeMirror-line > span::selection, .CodeMirror-line > span > span::selection { background: #d7d4f0; } +.CodeMirror-line::-moz-selection, .CodeMirror-line > span::-moz-selection, .CodeMirror-line > span > span::-moz-selection { background: #d7d4f0; } .cm-searching { background: #ffa; diff --git a/_site/js/vendor/codemirror/codemirror.js b/required/codemirror/codemirror.js similarity index 77% rename from _site/js/vendor/codemirror/codemirror.js rename to required/codemirror/codemirror.js index e6011f7..5009f83 100644 --- a/_site/js/vendor/codemirror/codemirror.js +++ b/required/codemirror/codemirror.js @@ -13,7 +13,7 @@ else if (typeof define == "function" && define.amd) // AMD return define([], mod); else // Plain browser env - this.CodeMirror = mod(); + (this || window).CodeMirror = mod(); })(function() { "use strict"; @@ -21,29 +21,30 @@ // Kludges for bugs and behavior differences that can't be feature // detected are enabled based on userAgent etc sniffing. + var userAgent = navigator.userAgent; + var platform = navigator.platform; - var gecko = /gecko\/\d/i.test(navigator.userAgent); - // ie_uptoN means Internet Explorer version N or lower - var ie_upto10 = /MSIE \d/.test(navigator.userAgent); - var ie_11up = /Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent); + var gecko = /gecko\/\d/i.test(userAgent); + var ie_upto10 = /MSIE \d/.test(userAgent); + var ie_11up = /Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(userAgent); var ie = ie_upto10 || ie_11up; var ie_version = ie && (ie_upto10 ? document.documentMode || 6 : ie_11up[1]); - var webkit = /WebKit\//.test(navigator.userAgent); - var qtwebkit = webkit && /Qt\/\d+\.\d+/.test(navigator.userAgent); - var chrome = /Chrome\//.test(navigator.userAgent); - var presto = /Opera\//.test(navigator.userAgent); + var webkit = /WebKit\//.test(userAgent); + var qtwebkit = webkit && /Qt\/\d+\.\d+/.test(userAgent); + var chrome = /Chrome\//.test(userAgent); + var presto = /Opera\//.test(userAgent); var safari = /Apple Computer/.test(navigator.vendor); - var khtml = /KHTML\//.test(navigator.userAgent); - var mac_geMountainLion = /Mac OS X 1\d\D([8-9]|\d\d)\D/.test(navigator.userAgent); - var phantom = /PhantomJS/.test(navigator.userAgent); + var mac_geMountainLion = /Mac OS X 1\d\D([8-9]|\d\d)\D/.test(userAgent); + var phantom = /PhantomJS/.test(userAgent); - var ios = /AppleWebKit/.test(navigator.userAgent) && /Mobile\/\w+/.test(navigator.userAgent); + var ios = /AppleWebKit/.test(userAgent) && /Mobile\/\w+/.test(userAgent); // This is woefully incomplete. Suggestions for alternative methods welcome. - var mobile = ios || /Android|webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(navigator.userAgent); - var mac = ios || /Mac/.test(navigator.platform); - var windows = /win/i.test(navigator.platform); + var mobile = ios || /Android|webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(userAgent); + var mac = ios || /Mac/.test(platform); + var chromeOS = /\bCrOS\b/.test(userAgent); + var windows = /win/i.test(platform); - var presto_version = presto && navigator.userAgent.match(/Version\/(\d*\.\d*)/); + var presto_version = presto && userAgent.match(/Version\/(\d*\.\d*)/); if (presto_version) presto_version = Number(presto_version[1]); if (presto_version && presto_version >= 15) { presto = false; webkit = true; } // Some browsers use the wrong event properties to signal cmd/ctrl on OS X @@ -67,32 +68,40 @@ setGuttersForLineNumbers(options); var doc = options.value; - if (typeof doc == "string") doc = new Doc(doc, options.mode); + if (typeof doc == "string") doc = new Doc(doc, options.mode, null, options.lineSeparator); this.doc = doc; - var display = this.display = new Display(place, doc); + var input = new CodeMirror.inputStyles[options.inputStyle](this); + var display = this.display = new Display(place, doc, input); display.wrapper.CodeMirror = this; updateGutters(this); themeChanged(this); if (options.lineWrapping) this.display.wrapper.className += " CodeMirror-wrap"; - if (options.autofocus && !mobile) focusInput(this); + if (options.autofocus && !mobile) display.input.focus(); + initScrollbars(this); this.state = { keyMaps: [], // stores maps added by addKeyMap overlays: [], // highlighting overlays, as added by addOverlay modeGen: 0, // bumped when mode/overlay changes, used to invalidate highlighting info - overwrite: false, focused: false, + overwrite: false, + delayingBlurEvent: false, + focused: false, suppressEdits: false, // used to disable editing during key handlers when in readOnly mode - pasteIncoming: false, cutIncoming: false, // help recognize paste/cut edits in readInput + pasteIncoming: false, cutIncoming: false, // help recognize paste/cut edits in input.poll + selectingText: false, draggingText: false, highlight: new Delayed(), // stores highlight worker timeout - keySeq: null // Unfinished key sequence + keySeq: null, // Unfinished key sequence + specialChars: null }; + var cm = this; + // Override magic textarea content restore that IE sometimes does // on our hidden textarea on reload - if (ie && ie_version < 11) setTimeout(bind(resetInput, this, true), 20); + if (ie && ie_version < 11) setTimeout(function() { cm.display.input.reset(true); }, 20); registerEventHandlers(this); ensureGlobalHandlers(); @@ -101,7 +110,7 @@ this.curOp.forceUpdate = true; attachDoc(this, doc); - if ((options.autofocus && !mobile) || activeElt() == display.input) + if ((options.autofocus && !mobile) || cm.hasFocus()) setTimeout(bind(onFocus, this), 20); else onBlur(this); @@ -109,8 +118,14 @@ for (var opt in optionHandlers) if (optionHandlers.hasOwnProperty(opt)) optionHandlers[opt](this, options[opt], Init); maybeUpdateLineNumberWidth(this); + if (options.finishInit) options.finishInit(this); for (var i = 0; i < initHooks.length; ++i) initHooks[i](this); endOperation(this); + // Suppress optimizelegibility in Webkit, since it breaks text + // measuring on line wrapping boundaries. + if (webkit && options.lineWrapping && + getComputedStyle(display.lineDiv).textRendering == "optimizelegibility") + display.lineDiv.style.textRendering = "auto"; } // DISPLAY CONSTRUCTOR @@ -119,32 +134,17 @@ // and content drawing. It holds references to DOM nodes and // display-related state. - function Display(place, doc) { + function Display(place, doc, input) { var d = this; + this.input = input; - // The semihidden textarea that is focused when the editor is - // focused, and receives input. - var input = d.input = elt("textarea", null, null, "position: absolute; padding: 0; width: 1px; height: 1em; outline: none"); - // The textarea is kept positioned near the cursor to prevent the - // fact that it'll be scrolled into view on input from scrolling - // our fake cursor out of view. On webkit, when wrap=off, paste is - // very slow. So make the area wide instead. - if (webkit) input.style.width = "1000px"; - else input.setAttribute("wrap", "off"); - // If border: 0; -- iOS fails to open keyboard (issue #1287) - if (ios) input.style.border = "1px solid black"; - input.setAttribute("autocorrect", "off"); input.setAttribute("autocapitalize", "off"); input.setAttribute("spellcheck", "false"); - - // Wraps and hides input textarea - d.inputDiv = elt("div", [input], null, "overflow: hidden; position: relative; width: 3px; height: 0px;"); - // The fake scrollbar elements. - d.scrollbarH = elt("div", [elt("div", null, null, "height: 100%; min-height: 1px")], "CodeMirror-hscrollbar"); - d.scrollbarV = elt("div", [elt("div", null, null, "min-width: 1px")], "CodeMirror-vscrollbar"); // Covers bottom-right square when both scrollbars are present. d.scrollbarFiller = elt("div", null, "CodeMirror-scrollbar-filler"); + d.scrollbarFiller.setAttribute("cm-not-content", "true"); // Covers bottom of gutter when coverGutterNextToScrollbar is on // and h scrollbar is present. d.gutterFiller = elt("div", null, "CodeMirror-gutter-filler"); + d.gutterFiller.setAttribute("cm-not-content", "true"); // Will contain the actual code, positioned to cover the viewport. d.lineDiv = elt("div", null, "CodeMirror-code"); // Elements are added to these to represent selection and cursors. @@ -161,10 +161,11 @@ d.mover = elt("div", [elt("div", [d.lineSpace], "CodeMirror-lines")], null, "position: relative"); // Set to the height of the document, allowing scrolling. d.sizer = elt("div", [d.mover], "CodeMirror-sizer"); + d.sizerWidth = null; // Behavior of elts with overflow: auto and padding is // inconsistent across browsers. This is used to ensure the // scrollable area is big enough. - d.heightForcer = elt("div", null, null, "position: absolute; height: " + scrollerCutOff + "px; width: 1px;"); + d.heightForcer = elt("div", null, null, "position: absolute; height: " + scrollerGap + "px; width: 1px;"); // Will contain the gutters, if any. d.gutters = elt("div", null, "CodeMirror-gutters"); d.lineGutter = null; @@ -172,18 +173,11 @@ d.scroller = elt("div", [d.sizer, d.heightForcer, d.gutters], "CodeMirror-scroll"); d.scroller.setAttribute("tabIndex", "-1"); // The element in which the editor lives. - d.wrapper = elt("div", [d.inputDiv, d.scrollbarH, d.scrollbarV, - d.scrollbarFiller, d.gutterFiller, d.scroller], "CodeMirror"); + d.wrapper = elt("div", [d.scrollbarFiller, d.gutterFiller, d.scroller], "CodeMirror"); // Work around IE7 z-index bug (not perfect, hence IE7 not really being supported) if (ie && ie_version < 8) { d.gutters.style.zIndex = -1; d.scroller.style.paddingRight = 0; } - // Needed to hide big blue blinking cursor on Mobile Safari - if (ios) input.style.width = "0px"; - if (!webkit) d.scroller.draggable = true; - // Needed to handle Tab key in KHTML - if (khtml) { d.inputDiv.style.height = "1px"; d.inputDiv.style.position = "absolute"; } - // Need to set a minimum width to see the scrollbar on IE7 (but must not set it on IE8). - if (ie && ie_version < 8) d.scrollbarH.style.minHeight = d.scrollbarV.style.minWidth = "18px"; + if (!webkit && !(gecko && mobile)) d.scroller.draggable = true; if (place) { if (place.appendChild) place.appendChild(d.wrapper); @@ -192,8 +186,10 @@ // Current rendered range (may be bigger than the view window). d.viewFrom = d.viewTo = doc.first; + d.reportedViewFrom = d.reportedViewTo = doc.first; // Information about the rendered lines. d.view = []; + d.renderedView = null; // Holds info about a single rendered line when it was rendered // for measurement, while not in view. d.externalMeasured = null; @@ -202,28 +198,19 @@ d.lastWrapHeight = d.lastWrapWidth = 0; d.updateLineNumbers = null; + d.nativeBarWidth = d.barHeight = d.barWidth = 0; + d.scrollbarsClipped = false; + // Used to only resize the line number gutter when necessary (when // the amount of lines crosses a boundary that makes its width change) d.lineNumWidth = d.lineNumInnerWidth = d.lineNumChars = null; - // See readInput and resetInput - d.prevInput = ""; // Set to true when a non-horizontal-scrolling line widget is // added. As an optimization, line widget aligning is skipped when // this is false. d.alignWidgets = false; - // Flag that indicates whether we expect input to appear real soon - // now (after some event like 'keypress' or 'input') and are - // polling intensively. - d.pollingFast = false; - // Self-resetting timeout for the poller - d.poll = new Delayed(); d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = null; - // Tracks when resetInput has punted to just putting a short - // string into the textarea instead of the full selection. - d.inaccurateSelection = false; - // Tracks the maximum line length so that the horizontal scrollbar // can be kept static when scrolling. d.maxLine = null; @@ -239,6 +226,10 @@ // Used to track whether anything happened since the context menu // was opened. d.selForContextMenu = null; + + d.activeTouch = null; + + input.init(d); } // STATE UPDATES @@ -265,6 +256,7 @@ if (cm.options.lineWrapping) { addClass(cm.display.wrapper, "CodeMirror-wrap"); cm.display.sizer.style.minWidth = ""; + cm.display.sizerWidth = null; } else { rmClass(cm.display.wrapper, "CodeMirror-wrap"); findMaxLine(cm); @@ -336,7 +328,6 @@ function updateGutterSpace(cm) { var width = cm.display.gutters.offsetWidth; cm.display.sizer.style.marginLeft = width + "px"; - cm.display.scrollbarH.style.left = cm.options.fixedGutter ? width + "px" : 0; } // Compute the character length of a line, taking into account @@ -389,78 +380,182 @@ // SCROLLBARS - function hScrollbarTakesSpace(cm) { - return cm.display.scroller.clientHeight - cm.display.wrapper.clientHeight < scrollerCutOff - 3; - } - // Prepare DOM reads needed to update the scrollbars. Done in one // shot to minimize update/measure roundtrips. function measureForScrollbars(cm) { - var scroll = cm.display.scroller; + var d = cm.display, gutterW = d.gutters.offsetWidth; + var docH = Math.round(cm.doc.height + paddingVert(cm.display)); return { - clientHeight: scroll.clientHeight, - barHeight: cm.display.scrollbarV.clientHeight, - scrollWidth: scroll.scrollWidth, clientWidth: scroll.clientWidth, - hScrollbarTakesSpace: hScrollbarTakesSpace(cm), - barWidth: cm.display.scrollbarH.clientWidth, - docHeight: Math.round(cm.doc.height + paddingVert(cm.display)) + clientHeight: d.scroller.clientHeight, + viewHeight: d.wrapper.clientHeight, + scrollWidth: d.scroller.scrollWidth, clientWidth: d.scroller.clientWidth, + viewWidth: d.wrapper.clientWidth, + barLeft: cm.options.fixedGutter ? gutterW : 0, + docHeight: docH, + scrollHeight: docH + scrollGap(cm) + d.barHeight, + nativeBarWidth: d.nativeBarWidth, + gutterWidth: gutterW }; } - // Re-synchronize the fake scrollbars with the actual size of the - // content. + function NativeScrollbars(place, scroll, cm) { + this.cm = cm; + var vert = this.vert = elt("div", [elt("div", null, null, "min-width: 1px")], "CodeMirror-vscrollbar"); + var horiz = this.horiz = elt("div", [elt("div", null, null, "height: 100%; min-height: 1px")], "CodeMirror-hscrollbar"); + place(vert); place(horiz); + + on(vert, "scroll", function() { + if (vert.clientHeight) scroll(vert.scrollTop, "vertical"); + }); + on(horiz, "scroll", function() { + if (horiz.clientWidth) scroll(horiz.scrollLeft, "horizontal"); + }); + + this.checkedZeroWidth = false; + // Need to set a minimum width to see the scrollbar on IE7 (but must not set it on IE8). + if (ie && ie_version < 8) this.horiz.style.minHeight = this.vert.style.minWidth = "18px"; + } + + NativeScrollbars.prototype = copyObj({ + update: function(measure) { + var needsH = measure.scrollWidth > measure.clientWidth + 1; + var needsV = measure.scrollHeight > measure.clientHeight + 1; + var sWidth = measure.nativeBarWidth; + + if (needsV) { + this.vert.style.display = "block"; + this.vert.style.bottom = needsH ? sWidth + "px" : "0"; + var totalHeight = measure.viewHeight - (needsH ? sWidth : 0); + // A bug in IE8 can cause this value to be negative, so guard it. + this.vert.firstChild.style.height = + Math.max(0, measure.scrollHeight - measure.clientHeight + totalHeight) + "px"; + } else { + this.vert.style.display = ""; + this.vert.firstChild.style.height = "0"; + } + + if (needsH) { + this.horiz.style.display = "block"; + this.horiz.style.right = needsV ? sWidth + "px" : "0"; + this.horiz.style.left = measure.barLeft + "px"; + var totalWidth = measure.viewWidth - measure.barLeft - (needsV ? sWidth : 0); + this.horiz.firstChild.style.width = + (measure.scrollWidth - measure.clientWidth + totalWidth) + "px"; + } else { + this.horiz.style.display = ""; + this.horiz.firstChild.style.width = "0"; + } + + if (!this.checkedZeroWidth && measure.clientHeight > 0) { + if (sWidth == 0) this.zeroWidthHack(); + this.checkedZeroWidth = true; + } + + return {right: needsV ? sWidth : 0, bottom: needsH ? sWidth : 0}; + }, + setScrollLeft: function(pos) { + if (this.horiz.scrollLeft != pos) this.horiz.scrollLeft = pos; + if (this.disableHoriz) this.enableZeroWidthBar(this.horiz, this.disableHoriz); + }, + setScrollTop: function(pos) { + if (this.vert.scrollTop != pos) this.vert.scrollTop = pos; + if (this.disableVert) this.enableZeroWidthBar(this.vert, this.disableVert); + }, + zeroWidthHack: function() { + var w = mac && !mac_geMountainLion ? "12px" : "18px"; + this.horiz.style.height = this.vert.style.width = w; + this.horiz.style.pointerEvents = this.vert.style.pointerEvents = "none"; + this.disableHoriz = new Delayed; + this.disableVert = new Delayed; + }, + enableZeroWidthBar: function(bar, delay) { + bar.style.pointerEvents = "auto"; + function maybeDisable() { + // To find out whether the scrollbar is still visible, we + // check whether the element under the pixel in the bottom + // left corner of the scrollbar box is the scrollbar box + // itself (when the bar is still visible) or its filler child + // (when the bar is hidden). If it is still visible, we keep + // it enabled, if it's hidden, we disable pointer events. + var box = bar.getBoundingClientRect(); + var elt = document.elementFromPoint(box.left + 1, box.bottom - 1); + if (elt != bar) bar.style.pointerEvents = "none"; + else delay.set(1000, maybeDisable); + } + delay.set(1000, maybeDisable); + }, + clear: function() { + var parent = this.horiz.parentNode; + parent.removeChild(this.horiz); + parent.removeChild(this.vert); + } + }, NativeScrollbars.prototype); + + function NullScrollbars() {} + + NullScrollbars.prototype = copyObj({ + update: function() { return {bottom: 0, right: 0}; }, + setScrollLeft: function() {}, + setScrollTop: function() {}, + clear: function() {} + }, NullScrollbars.prototype); + + CodeMirror.scrollbarModel = {"native": NativeScrollbars, "null": NullScrollbars}; + + function initScrollbars(cm) { + if (cm.display.scrollbars) { + cm.display.scrollbars.clear(); + if (cm.display.scrollbars.addClass) + rmClass(cm.display.wrapper, cm.display.scrollbars.addClass); + } + + cm.display.scrollbars = new CodeMirror.scrollbarModel[cm.options.scrollbarStyle](function(node) { + cm.display.wrapper.insertBefore(node, cm.display.scrollbarFiller); + // Prevent clicks in the scrollbars from killing focus + on(node, "mousedown", function() { + if (cm.state.focused) setTimeout(function() { cm.display.input.focus(); }, 0); + }); + node.setAttribute("cm-not-content", "true"); + }, function(pos, axis) { + if (axis == "horizontal") setScrollLeft(cm, pos); + else setScrollTop(cm, pos); + }, cm); + if (cm.display.scrollbars.addClass) + addClass(cm.display.wrapper, cm.display.scrollbars.addClass); + } + function updateScrollbars(cm, measure) { if (!measure) measure = measureForScrollbars(cm); - var d = cm.display, sWidth = scrollbarWidth(d.measure); - var scrollHeight = measure.docHeight + scrollerCutOff; - var needsH = measure.scrollWidth > measure.clientWidth; - if (needsH && measure.scrollWidth <= measure.clientWidth + 1 && - sWidth > 0 && !measure.hScrollbarTakesSpace) - needsH = false; // (Issue #2562) - var needsV = scrollHeight > measure.clientHeight; - - if (needsV) { - d.scrollbarV.style.display = "block"; - d.scrollbarV.style.bottom = needsH ? sWidth + "px" : "0"; - // A bug in IE8 can cause this value to be negative, so guard it. - d.scrollbarV.firstChild.style.height = - Math.max(0, scrollHeight - measure.clientHeight + (measure.barHeight || d.scrollbarV.clientHeight)) + "px"; - } else { - d.scrollbarV.style.display = ""; - d.scrollbarV.firstChild.style.height = "0"; - } - if (needsH) { - d.scrollbarH.style.display = "block"; - d.scrollbarH.style.right = needsV ? sWidth + "px" : "0"; - d.scrollbarH.firstChild.style.width = - (measure.scrollWidth - measure.clientWidth + (measure.barWidth || d.scrollbarH.clientWidth)) + "px"; - } else { - d.scrollbarH.style.display = ""; - d.scrollbarH.firstChild.style.width = "0"; + var startWidth = cm.display.barWidth, startHeight = cm.display.barHeight; + updateScrollbarsInner(cm, measure); + for (var i = 0; i < 4 && startWidth != cm.display.barWidth || startHeight != cm.display.barHeight; i++) { + if (startWidth != cm.display.barWidth && cm.options.lineWrapping) + updateHeightsInViewport(cm); + updateScrollbarsInner(cm, measureForScrollbars(cm)); + startWidth = cm.display.barWidth; startHeight = cm.display.barHeight; } - if (needsH && needsV) { + } + + // Re-synchronize the fake scrollbars with the actual size of the + // content. + function updateScrollbarsInner(cm, measure) { + var d = cm.display; + var sizes = d.scrollbars.update(measure); + + d.sizer.style.paddingRight = (d.barWidth = sizes.right) + "px"; + d.sizer.style.paddingBottom = (d.barHeight = sizes.bottom) + "px"; + d.heightForcer.style.borderBottom = sizes.bottom + "px solid transparent" + + if (sizes.right && sizes.bottom) { d.scrollbarFiller.style.display = "block"; - d.scrollbarFiller.style.height = d.scrollbarFiller.style.width = sWidth + "px"; + d.scrollbarFiller.style.height = sizes.bottom + "px"; + d.scrollbarFiller.style.width = sizes.right + "px"; } else d.scrollbarFiller.style.display = ""; - if (needsH && cm.options.coverGutterNextToScrollbar && cm.options.fixedGutter) { + if (sizes.bottom && cm.options.coverGutterNextToScrollbar && cm.options.fixedGutter) { d.gutterFiller.style.display = "block"; - d.gutterFiller.style.height = sWidth + "px"; - d.gutterFiller.style.width = d.gutters.offsetWidth + "px"; + d.gutterFiller.style.height = sizes.bottom + "px"; + d.gutterFiller.style.width = measure.gutterWidth + "px"; } else d.gutterFiller.style.display = ""; - - if (!cm.state.checkedOverlayScrollbar && measure.clientHeight > 0) { - if (sWidth === 0) { - var w = mac && !mac_geMountainLion ? "12px" : "18px"; - d.scrollbarV.style.minWidth = d.scrollbarH.style.minHeight = w; - var barMouseDown = function(e) { - if (e_target(e) != d.scrollbarV && e_target(e) != d.scrollbarH) - operation(cm, onMouseDown)(e); - }; - on(d.scrollbarV, "mousedown", barMouseDown); - on(d.scrollbarH, "mousedown", barMouseDown); - } - cm.state.checkedOverlayScrollbar = true; - } } // Compute the lines that are visible in a given viewport (defaults @@ -476,12 +571,13 @@ // forces those lines into the viewport (if possible). if (viewport && viewport.ensure) { var ensureFrom = viewport.ensure.from.line, ensureTo = viewport.ensure.to.line; - if (ensureFrom < from) - return {from: ensureFrom, - to: lineAtHeight(doc, heightAtLine(getLine(doc, ensureFrom)) + display.wrapper.clientHeight)}; - if (Math.min(ensureTo, doc.lastLine()) >= to) - return {from: lineAtHeight(doc, heightAtLine(getLine(doc, ensureTo)) - display.wrapper.clientHeight), - to: ensureTo}; + if (ensureFrom < from) { + from = ensureFrom; + to = lineAtHeight(doc, heightAtLine(getLine(doc, ensureFrom)) + display.wrapper.clientHeight); + } else if (Math.min(ensureTo, doc.lastLine()) >= to) { + from = lineAtHeight(doc, heightAtLine(getLine(doc, ensureTo)) - display.wrapper.clientHeight); + to = ensureTo; + } } return {from: from, to: Math.max(to, from + 1)}; } @@ -517,7 +613,7 @@ "CodeMirror-linenumber CodeMirror-gutter-elt")); var innerW = test.firstChild.offsetWidth, padding = test.offsetWidth - innerW; display.lineGutter.style.width = ""; - display.lineNumInnerWidth = Math.max(innerW, display.lineGutter.offsetWidth - padding); + display.lineNumInnerWidth = Math.max(innerW, display.lineGutter.offsetWidth - padding) + 1; display.lineNumWidth = display.lineNumInnerWidth + padding; display.lineNumChars = display.lineNumInnerWidth ? last.length : -1; display.lineGutter.style.width = display.lineNumWidth + "px"; @@ -549,10 +645,30 @@ this.editorIsHidden = !display.wrapper.offsetWidth; this.wrapperHeight = display.wrapper.clientHeight; this.wrapperWidth = display.wrapper.clientWidth; - this.oldViewFrom = display.viewFrom; this.oldViewTo = display.viewTo; - this.oldScrollerWidth = display.scroller.clientWidth; + this.oldDisplayWidth = displayWidth(cm); this.force = force; this.dims = getDimensions(cm); + this.events = []; + } + + DisplayUpdate.prototype.signal = function(emitter, type) { + if (hasHandler(emitter, type)) + this.events.push(arguments); + }; + DisplayUpdate.prototype.finish = function() { + for (var i = 0; i < this.events.length; i++) + signal.apply(null, this.events[i]); + }; + + function maybeClipScrollbars(cm) { + var display = cm.display; + if (!display.scrollbarsClipped && display.scroller.offsetWidth) { + display.nativeBarWidth = display.scroller.offsetWidth - display.scroller.clientWidth; + display.heightForcer.style.height = scrollGap(cm) + "px"; + display.sizer.style.marginBottom = -display.nativeBarWidth + "px"; + display.sizer.style.borderRightWidth = scrollGap(cm) + "px"; + display.scrollbarsClipped = true; + } } // Does the actual updating of the line display. Bails out @@ -560,6 +676,7 @@ // false. function updateDisplayIfNeeded(cm, update) { var display = cm.display, doc = cm.doc; + if (update.editorIsHidden) { resetView(cm); return false; @@ -569,7 +686,7 @@ if (!update.force && update.visible.from >= display.viewFrom && update.visible.to <= display.viewTo && (display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo) && - countDirtyView(cm) == 0) + display.renderedView == display.view && countDirtyView(cm) == 0) return false; if (maybeUpdateLineNumberWidth(cm)) { @@ -597,7 +714,7 @@ cm.display.mover.style.top = display.viewOffset + "px"; var toUpdate = countDirtyView(cm); - if (!different && toUpdate == 0 && !update.force && + if (!different && toUpdate == 0 && !update.force && display.renderedView == display.view && (display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo)) return false; @@ -607,14 +724,16 @@ if (toUpdate > 4) display.lineDiv.style.display = "none"; patchDisplay(cm, display.updateLineNumbers, update.dims); if (toUpdate > 4) display.lineDiv.style.display = ""; + display.renderedView = display.view; // There might have been a widget with a focused element that got // hidden or updated, if so re-focus it. if (focused && activeElt() != focused && focused.offsetHeight) focused.focus(); // Prevent selection and cursors from interfering with the scroll - // width. + // width and height. removeChildren(display.cursorDiv); removeChildren(display.selectionDiv); + display.gutters.style.height = display.sizer.style.minHeight = 0; if (different) { display.lastWrapHeight = update.wrapperHeight; @@ -628,16 +747,13 @@ } function postUpdateDisplay(cm, update) { - var force = update.force, viewport = update.viewport; + var viewport = update.viewport; + for (var first = true;; first = false) { - if (first && cm.options.lineWrapping && update.oldScrollerWidth != cm.display.scroller.clientWidth) { - force = true; - } else { - force = false; + if (!first || !cm.options.lineWrapping || update.oldDisplayWidth == displayWidth(cm)) { // Clip forced viewport to actual scrollable area. if (viewport && viewport.top != null) - viewport = {top: Math.min(cm.doc.height + paddingVert(cm.display) - scrollerCutOff - - cm.display.scroller.clientHeight, viewport.top)}; + viewport = {top: Math.min(cm.doc.height + paddingVert(cm.display) - displayHeight(cm), viewport.top)}; // Updated line heights might result in the drawn area not // actually covering the viewport. Keep looping until it does. update.visible = visibleLines(cm.display, cm.doc, viewport); @@ -648,13 +764,15 @@ updateHeightsInViewport(cm); var barMeasure = measureForScrollbars(cm); updateSelection(cm); - setDocumentHeight(cm, barMeasure); updateScrollbars(cm, barMeasure); + setDocumentHeight(cm, barMeasure); } - signalLater(cm, "update", cm); - if (cm.display.viewFrom != update.oldViewFrom || cm.display.viewTo != update.oldViewTo) - signalLater(cm, "viewportChange", cm, cm.display.viewFrom, cm.display.viewTo); + update.signal(cm, "update", cm); + if (cm.display.viewFrom != cm.display.reportedViewFrom || cm.display.viewTo != cm.display.reportedViewTo) { + update.signal(cm, "viewportChange", cm, cm.display.viewFrom, cm.display.viewTo); + cm.display.reportedViewFrom = cm.display.viewFrom; cm.display.reportedViewTo = cm.display.viewTo; + } } function updateDisplaySimple(cm, viewport) { @@ -664,23 +782,16 @@ postUpdateDisplay(cm, update); var barMeasure = measureForScrollbars(cm); updateSelection(cm); - setDocumentHeight(cm, barMeasure); updateScrollbars(cm, barMeasure); + setDocumentHeight(cm, barMeasure); + update.finish(); } } function setDocumentHeight(cm, measure) { - cm.display.sizer.style.minHeight = cm.display.heightForcer.style.top = measure.docHeight + "px"; - cm.display.gutters.style.height = Math.max(measure.docHeight, measure.clientHeight - scrollerCutOff) + "px"; - } - - function checkForWebkitWidthBug(cm, measure) { - // Work around Webkit bug where it sometimes reserves space for a - // non-existing phantom scrollbar in the scroller (Issue #2420) - if (cm.display.sizer.offsetWidth + cm.display.gutters.offsetWidth < cm.display.scroller.clientWidth - 1) { - cm.display.sizer.style.minHeight = cm.display.heightForcer.style.top = "0px"; - cm.display.gutters.style.height = measure.docHeight + "px"; - } + cm.display.sizer.style.minHeight = measure.docHeight + "px"; + cm.display.heightForcer.style.top = measure.docHeight + "px"; + cm.display.gutters.style.height = (measure.docHeight + cm.display.barHeight + scrollGap(cm)) + "px"; } // Read the actual heights of the rendered lines, and update their @@ -714,7 +825,7 @@ // given line. function updateWidgetHeight(line) { if (line.widgets) for (var i = 0; i < line.widgets.length; ++i) - line.widgets[i].height = line.widgets[i].node.offsetHeight; + line.widgets[i].height = line.widgets[i].node.parentNode.offsetHeight; } // Do a bulk-read of the DOM positions and sizes needed to draw the @@ -757,7 +868,7 @@ for (var i = 0; i < view.length; i++) { var lineView = view[i]; if (lineView.hidden) { - } else if (!lineView.node) { // Not drawn yet + } else if (!lineView.node || lineView.node.parentNode != container) { // Not drawn yet var node = buildLineElement(cm, lineView, lineN, dims); container.insertBefore(node, cur); } else { // Already drawn @@ -788,7 +899,7 @@ if (type == "text") updateLineText(cm, lineView); else if (type == "gutter") updateLineGutter(cm, lineView, lineN, dims); else if (type == "class") updateLineClasses(lineView); - else if (type == "widget") updateLineWidgets(lineView, dims); + else if (type == "widget") updateLineWidgets(cm, lineView, dims); } lineView.changes = null; } @@ -863,14 +974,24 @@ lineView.node.removeChild(lineView.gutter); lineView.gutter = null; } + if (lineView.gutterBackground) { + lineView.node.removeChild(lineView.gutterBackground); + lineView.gutterBackground = null; + } + if (lineView.line.gutterClass) { + var wrap = ensureLineWrapped(lineView); + lineView.gutterBackground = elt("div", null, "CodeMirror-gutter-background " + lineView.line.gutterClass, + "left: " + (cm.options.fixedGutter ? dims.fixedPos : -dims.gutterTotalWidth) + + "px; width: " + dims.gutterTotalWidth + "px"); + wrap.insertBefore(lineView.gutterBackground, lineView.text); + } var markers = lineView.line.gutterMarkers; if (cm.options.lineNumbers || markers) { var wrap = ensureLineWrapped(lineView); - var gutterWrap = lineView.gutter = - wrap.insertBefore(elt("div", null, "CodeMirror-gutter-wrapper", "left: " + - (cm.options.fixedGutter ? dims.fixedPos : -dims.gutterTotalWidth) + - "px; width: " + dims.gutterTotalWidth + "px"), - lineView.text); + var gutterWrap = lineView.gutter = elt("div", null, "CodeMirror-gutter-wrapper", "left: " + + (cm.options.fixedGutter ? dims.fixedPos : -dims.gutterTotalWidth) + "px"); + cm.display.input.setUneditable(gutterWrap); + wrap.insertBefore(gutterWrap, lineView.text); if (lineView.line.gutterClass) gutterWrap.className += " " + lineView.line.gutterClass; if (cm.options.lineNumbers && (!markers || !markers["CodeMirror-linenumbers"])) @@ -888,14 +1009,14 @@ } } - function updateLineWidgets(lineView, dims) { + function updateLineWidgets(cm, lineView, dims) { if (lineView.alignable) lineView.alignable = null; for (var node = lineView.node.firstChild, next; node; node = next) { var next = node.nextSibling; if (node.className == "CodeMirror-linewidget") lineView.node.removeChild(node); } - insertLineWidgets(lineView, dims); + insertLineWidgets(cm, lineView, dims); } // Build a line's DOM representation from scratch @@ -907,25 +1028,26 @@ updateLineClasses(lineView); updateLineGutter(cm, lineView, lineN, dims); - insertLineWidgets(lineView, dims); + insertLineWidgets(cm, lineView, dims); return lineView.node; } // A lineView may contain multiple logical lines (when merged by // collapsed spans). The widgets for all of them need to be drawn. - function insertLineWidgets(lineView, dims) { - insertLineWidgetsFor(lineView.line, lineView, dims, true); + function insertLineWidgets(cm, lineView, dims) { + insertLineWidgetsFor(cm, lineView.line, lineView, dims, true); if (lineView.rest) for (var i = 0; i < lineView.rest.length; i++) - insertLineWidgetsFor(lineView.rest[i], lineView, dims, false); + insertLineWidgetsFor(cm, lineView.rest[i], lineView, dims, false); } - function insertLineWidgetsFor(line, lineView, dims, allowAbove) { + function insertLineWidgetsFor(cm, line, lineView, dims, allowAbove) { if (!line.widgets) return; var wrap = ensureLineWrapped(lineView); for (var i = 0, ws = line.widgets; i < ws.length; ++i) { var widget = ws[i], node = elt("div", [widget.node], "CodeMirror-linewidget"); - if (!widget.handleMouseEvents) node.ignoreEvents = true; + if (!widget.handleMouseEvents) node.setAttribute("cm-ignore-events", "true"); positionLineWidget(widget, node, lineView, dims); + cm.display.input.setUneditable(node); if (allowAbove && widget.above) wrap.insertBefore(node, lineView.gutter || lineView.text); else @@ -952,21 +1074,939 @@ } } - // POSITION OBJECT - - // A Pos instance represents a position within the text. - var Pos = CodeMirror.Pos = function(line, ch) { - if (!(this instanceof Pos)) return new Pos(line, ch); - this.line = line; this.ch = ch; - }; - - // Compare two positions, return 0 if they are the same, a negative - // number when a is less, and a positive number otherwise. - var cmp = CodeMirror.cmpPos = function(a, b) { return a.line - b.line || a.ch - b.ch; }; - - function copyPos(x) {return Pos(x.line, x.ch);} - function maxPos(a, b) { return cmp(a, b) < 0 ? b : a; } - function minPos(a, b) { return cmp(a, b) < 0 ? a : b; } + // POSITION OBJECT + + // A Pos instance represents a position within the text. + var Pos = CodeMirror.Pos = function(line, ch) { + if (!(this instanceof Pos)) return new Pos(line, ch); + this.line = line; this.ch = ch; + }; + + // Compare two positions, return 0 if they are the same, a negative + // number when a is less, and a positive number otherwise. + var cmp = CodeMirror.cmpPos = function(a, b) { return a.line - b.line || a.ch - b.ch; }; + + function copyPos(x) {return Pos(x.line, x.ch);} + function maxPos(a, b) { return cmp(a, b) < 0 ? b : a; } + function minPos(a, b) { return cmp(a, b) < 0 ? a : b; } + + // INPUT HANDLING + + function ensureFocus(cm) { + if (!cm.state.focused) { cm.display.input.focus(); onFocus(cm); } + } + + // This will be set to a {lineWise: bool, text: [string]} object, so + // that, when pasting, we know what kind of selections the copied + // text was made out of. + var lastCopied = null; + + function applyTextInput(cm, inserted, deleted, sel, origin) { + var doc = cm.doc; + cm.display.shift = false; + if (!sel) sel = doc.sel; + + var paste = cm.state.pasteIncoming || origin == "paste"; + var textLines = doc.splitLines(inserted), multiPaste = null + // When pasing N lines into N selections, insert one line per selection + if (paste && sel.ranges.length > 1) { + if (lastCopied && lastCopied.text.join("\n") == inserted) { + if (sel.ranges.length % lastCopied.text.length == 0) { + multiPaste = []; + for (var i = 0; i < lastCopied.text.length; i++) + multiPaste.push(doc.splitLines(lastCopied.text[i])); + } + } else if (textLines.length == sel.ranges.length) { + multiPaste = map(textLines, function(l) { return [l]; }); + } + } + + // Normal behavior is to insert the new text into every selection + for (var i = sel.ranges.length - 1; i >= 0; i--) { + var range = sel.ranges[i]; + var from = range.from(), to = range.to(); + if (range.empty()) { + if (deleted && deleted > 0) // Handle deletion + from = Pos(from.line, from.ch - deleted); + else if (cm.state.overwrite && !paste) // Handle overwrite + to = Pos(to.line, Math.min(getLine(doc, to.line).text.length, to.ch + lst(textLines).length)); + else if (lastCopied && lastCopied.lineWise && lastCopied.text.join("\n") == inserted) + from = to = Pos(from.line, 0) + } + var updateInput = cm.curOp.updateInput; + var changeEvent = {from: from, to: to, text: multiPaste ? multiPaste[i % multiPaste.length] : textLines, + origin: origin || (paste ? "paste" : cm.state.cutIncoming ? "cut" : "+input")}; + makeChange(cm.doc, changeEvent); + signalLater(cm, "inputRead", cm, changeEvent); + } + if (inserted && !paste) + triggerElectric(cm, inserted); + + ensureCursorVisible(cm); + cm.curOp.updateInput = updateInput; + cm.curOp.typing = true; + cm.state.pasteIncoming = cm.state.cutIncoming = false; + } + + function handlePaste(e, cm) { + var pasted = e.clipboardData && e.clipboardData.getData("text/plain"); + if (pasted) { + e.preventDefault(); + if (!cm.isReadOnly() && !cm.options.disableInput) + runInOp(cm, function() { applyTextInput(cm, pasted, 0, null, "paste"); }); + return true; + } + } + + function triggerElectric(cm, inserted) { + // When an 'electric' character is inserted, immediately trigger a reindent + if (!cm.options.electricChars || !cm.options.smartIndent) return; + var sel = cm.doc.sel; + + for (var i = sel.ranges.length - 1; i >= 0; i--) { + var range = sel.ranges[i]; + if (range.head.ch > 100 || (i && sel.ranges[i - 1].head.line == range.head.line)) continue; + var mode = cm.getModeAt(range.head); + var indented = false; + if (mode.electricChars) { + for (var j = 0; j < mode.electricChars.length; j++) + if (inserted.indexOf(mode.electricChars.charAt(j)) > -1) { + indented = indentLine(cm, range.head.line, "smart"); + break; + } + } else if (mode.electricInput) { + if (mode.electricInput.test(getLine(cm.doc, range.head.line).text.slice(0, range.head.ch))) + indented = indentLine(cm, range.head.line, "smart"); + } + if (indented) signalLater(cm, "electricInput", cm, range.head.line); + } + } + + function copyableRanges(cm) { + var text = [], ranges = []; + for (var i = 0; i < cm.doc.sel.ranges.length; i++) { + var line = cm.doc.sel.ranges[i].head.line; + var lineRange = {anchor: Pos(line, 0), head: Pos(line + 1, 0)}; + ranges.push(lineRange); + text.push(cm.getRange(lineRange.anchor, lineRange.head)); + } + return {text: text, ranges: ranges}; + } + + function disableBrowserMagic(field) { + field.setAttribute("autocorrect", "off"); + field.setAttribute("autocapitalize", "off"); + field.setAttribute("spellcheck", "false"); + } + + // TEXTAREA INPUT STYLE + + function TextareaInput(cm) { + this.cm = cm; + // See input.poll and input.reset + this.prevInput = ""; + + // Flag that indicates whether we expect input to appear real soon + // now (after some event like 'keypress' or 'input') and are + // polling intensively. + this.pollingFast = false; + // Self-resetting timeout for the poller + this.polling = new Delayed(); + // Tracks when input.reset has punted to just putting a short + // string into the textarea instead of the full selection. + this.inaccurateSelection = false; + // Used to work around IE issue with selection being forgotten when focus moves away from textarea + this.hasSelection = false; + this.composing = null; + }; + + function hiddenTextarea() { + var te = elt("textarea", null, null, "position: absolute; bottom: -1em; padding: 0; width: 1px; height: 1em; outline: none"); + var div = elt("div", [te], null, "overflow: hidden; position: relative; width: 3px; height: 0px;"); + // The textarea is kept positioned near the cursor to prevent the + // fact that it'll be scrolled into view on input from scrolling + // our fake cursor out of view. On webkit, when wrap=off, paste is + // very slow. So make the area wide instead. + if (webkit) te.style.width = "1000px"; + else te.setAttribute("wrap", "off"); + // If border: 0; -- iOS fails to open keyboard (issue #1287) + if (ios) te.style.border = "1px solid black"; + disableBrowserMagic(te); + return div; + } + + TextareaInput.prototype = copyObj({ + init: function(display) { + var input = this, cm = this.cm; + + // Wraps and hides input textarea + var div = this.wrapper = hiddenTextarea(); + // The semihidden textarea that is focused when the editor is + // focused, and receives input. + var te = this.textarea = div.firstChild; + display.wrapper.insertBefore(div, display.wrapper.firstChild); + + // Needed to hide big blue blinking cursor on Mobile Safari (doesn't seem to work in iOS 8 anymore) + if (ios) te.style.width = "0px"; + + on(te, "input", function() { + if (ie && ie_version >= 9 && input.hasSelection) input.hasSelection = null; + input.poll(); + }); + + on(te, "paste", function(e) { + if (signalDOMEvent(cm, e) || handlePaste(e, cm)) return + + cm.state.pasteIncoming = true; + input.fastPoll(); + }); + + function prepareCopyCut(e) { + if (signalDOMEvent(cm, e)) return + if (cm.somethingSelected()) { + lastCopied = {lineWise: false, text: cm.getSelections()}; + if (input.inaccurateSelection) { + input.prevInput = ""; + input.inaccurateSelection = false; + te.value = lastCopied.text.join("\n"); + selectInput(te); + } + } else if (!cm.options.lineWiseCopyCut) { + return; + } else { + var ranges = copyableRanges(cm); + lastCopied = {lineWise: true, text: ranges.text}; + if (e.type == "cut") { + cm.setSelections(ranges.ranges, null, sel_dontScroll); + } else { + input.prevInput = ""; + te.value = ranges.text.join("\n"); + selectInput(te); + } + } + if (e.type == "cut") cm.state.cutIncoming = true; + } + on(te, "cut", prepareCopyCut); + on(te, "copy", prepareCopyCut); + + on(display.scroller, "paste", function(e) { + if (eventInWidget(display, e) || signalDOMEvent(cm, e)) return; + cm.state.pasteIncoming = true; + input.focus(); + }); + + // Prevent normal selection in the editor (we handle our own) + on(display.lineSpace, "selectstart", function(e) { + if (!eventInWidget(display, e)) e_preventDefault(e); + }); + + on(te, "compositionstart", function() { + var start = cm.getCursor("from"); + if (input.composing) input.composing.range.clear() + input.composing = { + start: start, + range: cm.markText(start, cm.getCursor("to"), {className: "CodeMirror-composing"}) + }; + }); + on(te, "compositionend", function() { + if (input.composing) { + input.poll(); + input.composing.range.clear(); + input.composing = null; + } + }); + }, + + prepareSelection: function() { + // Redraw the selection and/or cursor + var cm = this.cm, display = cm.display, doc = cm.doc; + var result = prepareSelection(cm); + + // Move the hidden textarea near the cursor to prevent scrolling artifacts + if (cm.options.moveInputWithCursor) { + var headPos = cursorCoords(cm, doc.sel.primary().head, "div"); + var wrapOff = display.wrapper.getBoundingClientRect(), lineOff = display.lineDiv.getBoundingClientRect(); + result.teTop = Math.max(0, Math.min(display.wrapper.clientHeight - 10, + headPos.top + lineOff.top - wrapOff.top)); + result.teLeft = Math.max(0, Math.min(display.wrapper.clientWidth - 10, + headPos.left + lineOff.left - wrapOff.left)); + } + + return result; + }, + + showSelection: function(drawn) { + var cm = this.cm, display = cm.display; + removeChildrenAndAdd(display.cursorDiv, drawn.cursors); + removeChildrenAndAdd(display.selectionDiv, drawn.selection); + if (drawn.teTop != null) { + this.wrapper.style.top = drawn.teTop + "px"; + this.wrapper.style.left = drawn.teLeft + "px"; + } + }, + + // Reset the input to correspond to the selection (or to be empty, + // when not typing and nothing is selected) + reset: function(typing) { + if (this.contextMenuPending) return; + var minimal, selected, cm = this.cm, doc = cm.doc; + if (cm.somethingSelected()) { + this.prevInput = ""; + var range = doc.sel.primary(); + minimal = hasCopyEvent && + (range.to().line - range.from().line > 100 || (selected = cm.getSelection()).length > 1000); + var content = minimal ? "-" : selected || cm.getSelection(); + this.textarea.value = content; + if (cm.state.focused) selectInput(this.textarea); + if (ie && ie_version >= 9) this.hasSelection = content; + } else if (!typing) { + this.prevInput = this.textarea.value = ""; + if (ie && ie_version >= 9) this.hasSelection = null; + } + this.inaccurateSelection = minimal; + }, + + getField: function() { return this.textarea; }, + + supportsTouch: function() { return false; }, + + focus: function() { + if (this.cm.options.readOnly != "nocursor" && (!mobile || activeElt() != this.textarea)) { + try { this.textarea.focus(); } + catch (e) {} // IE8 will throw if the textarea is display: none or not in DOM + } + }, + + blur: function() { this.textarea.blur(); }, + + resetPosition: function() { + this.wrapper.style.top = this.wrapper.style.left = 0; + }, + + receivedFocus: function() { this.slowPoll(); }, + + // Poll for input changes, using the normal rate of polling. This + // runs as long as the editor is focused. + slowPoll: function() { + var input = this; + if (input.pollingFast) return; + input.polling.set(this.cm.options.pollInterval, function() { + input.poll(); + if (input.cm.state.focused) input.slowPoll(); + }); + }, + + // When an event has just come in that is likely to add or change + // something in the input textarea, we poll faster, to ensure that + // the change appears on the screen quickly. + fastPoll: function() { + var missed = false, input = this; + input.pollingFast = true; + function p() { + var changed = input.poll(); + if (!changed && !missed) {missed = true; input.polling.set(60, p);} + else {input.pollingFast = false; input.slowPoll();} + } + input.polling.set(20, p); + }, + + // Read input from the textarea, and update the document to match. + // When something is selected, it is present in the textarea, and + // selected (unless it is huge, in which case a placeholder is + // used). When nothing is selected, the cursor sits after previously + // seen text (can be empty), which is stored in prevInput (we must + // not reset the textarea when typing, because that breaks IME). + poll: function() { + var cm = this.cm, input = this.textarea, prevInput = this.prevInput; + // Since this is called a *lot*, try to bail out as cheaply as + // possible when it is clear that nothing happened. hasSelection + // will be the case when there is a lot of text in the textarea, + // in which case reading its value would be expensive. + if (this.contextMenuPending || !cm.state.focused || + (hasSelection(input) && !prevInput && !this.composing) || + cm.isReadOnly() || cm.options.disableInput || cm.state.keySeq) + return false; + + var text = input.value; + // If nothing changed, bail. + if (text == prevInput && !cm.somethingSelected()) return false; + // Work around nonsensical selection resetting in IE9/10, and + // inexplicable appearance of private area unicode characters on + // some key combos in Mac (#2689). + if (ie && ie_version >= 9 && this.hasSelection === text || + mac && /[\uf700-\uf7ff]/.test(text)) { + cm.display.input.reset(); + return false; + } + + if (cm.doc.sel == cm.display.selForContextMenu) { + var first = text.charCodeAt(0); + if (first == 0x200b && !prevInput) prevInput = "\u200b"; + if (first == 0x21da) { this.reset(); return this.cm.execCommand("undo"); } + } + // Find the part of the input that is actually new + var same = 0, l = Math.min(prevInput.length, text.length); + while (same < l && prevInput.charCodeAt(same) == text.charCodeAt(same)) ++same; + + var self = this; + runInOp(cm, function() { + applyTextInput(cm, text.slice(same), prevInput.length - same, + null, self.composing ? "*compose" : null); + + // Don't leave long text in the textarea, since it makes further polling slow + if (text.length > 1000 || text.indexOf("\n") > -1) input.value = self.prevInput = ""; + else self.prevInput = text; + + if (self.composing) { + self.composing.range.clear(); + self.composing.range = cm.markText(self.composing.start, cm.getCursor("to"), + {className: "CodeMirror-composing"}); + } + }); + return true; + }, + + ensurePolled: function() { + if (this.pollingFast && this.poll()) this.pollingFast = false; + }, + + onKeyPress: function() { + if (ie && ie_version >= 9) this.hasSelection = null; + this.fastPoll(); + }, + + onContextMenu: function(e) { + var input = this, cm = input.cm, display = cm.display, te = input.textarea; + var pos = posFromMouse(cm, e), scrollPos = display.scroller.scrollTop; + if (!pos || presto) return; // Opera is difficult. + + // Reset the current text selection only if the click is done outside of the selection + // and 'resetSelectionOnContextMenu' option is true. + var reset = cm.options.resetSelectionOnContextMenu; + if (reset && cm.doc.sel.contains(pos) == -1) + operation(cm, setSelection)(cm.doc, simpleSelection(pos), sel_dontScroll); + + var oldCSS = te.style.cssText, oldWrapperCSS = input.wrapper.style.cssText; + input.wrapper.style.cssText = "position: absolute" + var wrapperBox = input.wrapper.getBoundingClientRect() + te.style.cssText = "position: absolute; width: 30px; height: 30px; top: " + (e.clientY - wrapperBox.top - 5) + + "px; left: " + (e.clientX - wrapperBox.left - 5) + "px; z-index: 1000; background: " + + (ie ? "rgba(255, 255, 255, .05)" : "transparent") + + "; outline: none; border-width: 0; outline: none; overflow: hidden; opacity: .05; filter: alpha(opacity=5);"; + if (webkit) var oldScrollY = window.scrollY; // Work around Chrome issue (#2712) + display.input.focus(); + if (webkit) window.scrollTo(null, oldScrollY); + display.input.reset(); + // Adds "Select all" to context menu in FF + if (!cm.somethingSelected()) te.value = input.prevInput = " "; + input.contextMenuPending = true; + display.selForContextMenu = cm.doc.sel; + clearTimeout(display.detectingSelectAll); + + // Select-all will be greyed out if there's nothing to select, so + // this adds a zero-width space so that we can later check whether + // it got selected. + function prepareSelectAllHack() { + if (te.selectionStart != null) { + var selected = cm.somethingSelected(); + var extval = "\u200b" + (selected ? te.value : ""); + te.value = "\u21da"; // Used to catch context-menu undo + te.value = extval; + input.prevInput = selected ? "" : "\u200b"; + te.selectionStart = 1; te.selectionEnd = extval.length; + // Re-set this, in case some other handler touched the + // selection in the meantime. + display.selForContextMenu = cm.doc.sel; + } + } + function rehide() { + input.contextMenuPending = false; + input.wrapper.style.cssText = oldWrapperCSS + te.style.cssText = oldCSS; + if (ie && ie_version < 9) display.scrollbars.setScrollTop(display.scroller.scrollTop = scrollPos); + + // Try to detect the user choosing select-all + if (te.selectionStart != null) { + if (!ie || (ie && ie_version < 9)) prepareSelectAllHack(); + var i = 0, poll = function() { + if (display.selForContextMenu == cm.doc.sel && te.selectionStart == 0 && + te.selectionEnd > 0 && input.prevInput == "\u200b") + operation(cm, commands.selectAll)(cm); + else if (i++ < 10) display.detectingSelectAll = setTimeout(poll, 500); + else display.input.reset(); + }; + display.detectingSelectAll = setTimeout(poll, 200); + } + } + + if (ie && ie_version >= 9) prepareSelectAllHack(); + if (captureRightClick) { + e_stop(e); + var mouseup = function() { + off(window, "mouseup", mouseup); + setTimeout(rehide, 20); + }; + on(window, "mouseup", mouseup); + } else { + setTimeout(rehide, 50); + } + }, + + readOnlyChanged: function(val) { + if (!val) this.reset(); + }, + + setUneditable: nothing, + + needsContentAttribute: false + }, TextareaInput.prototype); + + // CONTENTEDITABLE INPUT STYLE + + function ContentEditableInput(cm) { + this.cm = cm; + this.lastAnchorNode = this.lastAnchorOffset = this.lastFocusNode = this.lastFocusOffset = null; + this.polling = new Delayed(); + this.gracePeriod = false; + } + + ContentEditableInput.prototype = copyObj({ + init: function(display) { + var input = this, cm = input.cm; + var div = input.div = display.lineDiv; + disableBrowserMagic(div); + + on(div, "paste", function(e) { + if (!signalDOMEvent(cm, e)) handlePaste(e, cm); + }) + + on(div, "compositionstart", function(e) { + var data = e.data; + input.composing = {sel: cm.doc.sel, data: data, startData: data}; + if (!data) return; + var prim = cm.doc.sel.primary(); + var line = cm.getLine(prim.head.line); + var found = line.indexOf(data, Math.max(0, prim.head.ch - data.length)); + if (found > -1 && found <= prim.head.ch) + input.composing.sel = simpleSelection(Pos(prim.head.line, found), + Pos(prim.head.line, found + data.length)); + }); + on(div, "compositionupdate", function(e) { + input.composing.data = e.data; + }); + on(div, "compositionend", function(e) { + var ours = input.composing; + if (!ours) return; + if (e.data != ours.startData && !/\u200b/.test(e.data)) + ours.data = e.data; + // Need a small delay to prevent other code (input event, + // selection polling) from doing damage when fired right after + // compositionend. + setTimeout(function() { + if (!ours.handled) + input.applyComposition(ours); + if (input.composing == ours) + input.composing = null; + }, 50); + }); + + on(div, "touchstart", function() { + input.forceCompositionEnd(); + }); + + on(div, "input", function() { + if (input.composing) return; + if (cm.isReadOnly() || !input.pollContent()) + runInOp(input.cm, function() {regChange(cm);}); + }); + + function onCopyCut(e) { + if (signalDOMEvent(cm, e)) return + if (cm.somethingSelected()) { + lastCopied = {lineWise: false, text: cm.getSelections()}; + if (e.type == "cut") cm.replaceSelection("", null, "cut"); + } else if (!cm.options.lineWiseCopyCut) { + return; + } else { + var ranges = copyableRanges(cm); + lastCopied = {lineWise: true, text: ranges.text}; + if (e.type == "cut") { + cm.operation(function() { + cm.setSelections(ranges.ranges, 0, sel_dontScroll); + cm.replaceSelection("", null, "cut"); + }); + } + } + // iOS exposes the clipboard API, but seems to discard content inserted into it + if (e.clipboardData && !ios) { + e.preventDefault(); + e.clipboardData.clearData(); + e.clipboardData.setData("text/plain", lastCopied.text.join("\n")); + } else { + // Old-fashioned briefly-focus-a-textarea hack + var kludge = hiddenTextarea(), te = kludge.firstChild; + cm.display.lineSpace.insertBefore(kludge, cm.display.lineSpace.firstChild); + te.value = lastCopied.text.join("\n"); + var hadFocus = document.activeElement; + selectInput(te); + setTimeout(function() { + cm.display.lineSpace.removeChild(kludge); + hadFocus.focus(); + }, 50); + } + } + on(div, "copy", onCopyCut); + on(div, "cut", onCopyCut); + }, + + prepareSelection: function() { + var result = prepareSelection(this.cm, false); + result.focus = this.cm.state.focused; + return result; + }, + + showSelection: function(info, takeFocus) { + if (!info || !this.cm.display.view.length) return; + if (info.focus || takeFocus) this.showPrimarySelection(); + this.showMultipleSelections(info); + }, + + showPrimarySelection: function() { + var sel = window.getSelection(), prim = this.cm.doc.sel.primary(); + var curAnchor = domToPos(this.cm, sel.anchorNode, sel.anchorOffset); + var curFocus = domToPos(this.cm, sel.focusNode, sel.focusOffset); + if (curAnchor && !curAnchor.bad && curFocus && !curFocus.bad && + cmp(minPos(curAnchor, curFocus), prim.from()) == 0 && + cmp(maxPos(curAnchor, curFocus), prim.to()) == 0) + return; + + var start = posToDOM(this.cm, prim.from()); + var end = posToDOM(this.cm, prim.to()); + if (!start && !end) return; + + var view = this.cm.display.view; + var old = sel.rangeCount && sel.getRangeAt(0); + if (!start) { + start = {node: view[0].measure.map[2], offset: 0}; + } else if (!end) { // FIXME dangerously hacky + var measure = view[view.length - 1].measure; + var map = measure.maps ? measure.maps[measure.maps.length - 1] : measure.map; + end = {node: map[map.length - 1], offset: map[map.length - 2] - map[map.length - 3]}; + } + + try { var rng = range(start.node, start.offset, end.offset, end.node); } + catch(e) {} // Our model of the DOM might be outdated, in which case the range we try to set can be impossible + if (rng) { + if (!gecko && this.cm.state.focused) { + sel.collapse(start.node, start.offset); + if (!rng.collapsed) sel.addRange(rng); + } else { + sel.removeAllRanges(); + sel.addRange(rng); + } + if (old && sel.anchorNode == null) sel.addRange(old); + else if (gecko) this.startGracePeriod(); + } + this.rememberSelection(); + }, + + startGracePeriod: function() { + var input = this; + clearTimeout(this.gracePeriod); + this.gracePeriod = setTimeout(function() { + input.gracePeriod = false; + if (input.selectionChanged()) + input.cm.operation(function() { input.cm.curOp.selectionChanged = true; }); + }, 20); + }, + + showMultipleSelections: function(info) { + removeChildrenAndAdd(this.cm.display.cursorDiv, info.cursors); + removeChildrenAndAdd(this.cm.display.selectionDiv, info.selection); + }, + + rememberSelection: function() { + var sel = window.getSelection(); + this.lastAnchorNode = sel.anchorNode; this.lastAnchorOffset = sel.anchorOffset; + this.lastFocusNode = sel.focusNode; this.lastFocusOffset = sel.focusOffset; + }, + + selectionInEditor: function() { + var sel = window.getSelection(); + if (!sel.rangeCount) return false; + var node = sel.getRangeAt(0).commonAncestorContainer; + return contains(this.div, node); + }, + + focus: function() { + if (this.cm.options.readOnly != "nocursor") this.div.focus(); + }, + blur: function() { this.div.blur(); }, + getField: function() { return this.div; }, + + supportsTouch: function() { return true; }, + + receivedFocus: function() { + var input = this; + if (this.selectionInEditor()) + this.pollSelection(); + else + runInOp(this.cm, function() { input.cm.curOp.selectionChanged = true; }); + + function poll() { + if (input.cm.state.focused) { + input.pollSelection(); + input.polling.set(input.cm.options.pollInterval, poll); + } + } + this.polling.set(this.cm.options.pollInterval, poll); + }, + + selectionChanged: function() { + var sel = window.getSelection(); + return sel.anchorNode != this.lastAnchorNode || sel.anchorOffset != this.lastAnchorOffset || + sel.focusNode != this.lastFocusNode || sel.focusOffset != this.lastFocusOffset; + }, + + pollSelection: function() { + if (!this.composing && !this.gracePeriod && this.selectionChanged()) { + var sel = window.getSelection(), cm = this.cm; + this.rememberSelection(); + var anchor = domToPos(cm, sel.anchorNode, sel.anchorOffset); + var head = domToPos(cm, sel.focusNode, sel.focusOffset); + if (anchor && head) runInOp(cm, function() { + setSelection(cm.doc, simpleSelection(anchor, head), sel_dontScroll); + if (anchor.bad || head.bad) cm.curOp.selectionChanged = true; + }); + } + }, + + pollContent: function() { + var cm = this.cm, display = cm.display, sel = cm.doc.sel.primary(); + var from = sel.from(), to = sel.to(); + if (from.line < display.viewFrom || to.line > display.viewTo - 1) return false; + + var fromIndex; + if (from.line == display.viewFrom || (fromIndex = findViewIndex(cm, from.line)) == 0) { + var fromLine = lineNo(display.view[0].line); + var fromNode = display.view[0].node; + } else { + var fromLine = lineNo(display.view[fromIndex].line); + var fromNode = display.view[fromIndex - 1].node.nextSibling; + } + var toIndex = findViewIndex(cm, to.line); + if (toIndex == display.view.length - 1) { + var toLine = display.viewTo - 1; + var toNode = display.lineDiv.lastChild; + } else { + var toLine = lineNo(display.view[toIndex + 1].line) - 1; + var toNode = display.view[toIndex + 1].node.previousSibling; + } + + var newText = cm.doc.splitLines(domTextBetween(cm, fromNode, toNode, fromLine, toLine)); + var oldText = getBetween(cm.doc, Pos(fromLine, 0), Pos(toLine, getLine(cm.doc, toLine).text.length)); + while (newText.length > 1 && oldText.length > 1) { + if (lst(newText) == lst(oldText)) { newText.pop(); oldText.pop(); toLine--; } + else if (newText[0] == oldText[0]) { newText.shift(); oldText.shift(); fromLine++; } + else break; + } + + var cutFront = 0, cutEnd = 0; + var newTop = newText[0], oldTop = oldText[0], maxCutFront = Math.min(newTop.length, oldTop.length); + while (cutFront < maxCutFront && newTop.charCodeAt(cutFront) == oldTop.charCodeAt(cutFront)) + ++cutFront; + var newBot = lst(newText), oldBot = lst(oldText); + var maxCutEnd = Math.min(newBot.length - (newText.length == 1 ? cutFront : 0), + oldBot.length - (oldText.length == 1 ? cutFront : 0)); + while (cutEnd < maxCutEnd && + newBot.charCodeAt(newBot.length - cutEnd - 1) == oldBot.charCodeAt(oldBot.length - cutEnd - 1)) + ++cutEnd; + + newText[newText.length - 1] = newBot.slice(0, newBot.length - cutEnd); + newText[0] = newText[0].slice(cutFront); + + var chFrom = Pos(fromLine, cutFront); + var chTo = Pos(toLine, oldText.length ? lst(oldText).length - cutEnd : 0); + if (newText.length > 1 || newText[0] || cmp(chFrom, chTo)) { + replaceRange(cm.doc, newText, chFrom, chTo, "+input"); + return true; + } + }, + + ensurePolled: function() { + this.forceCompositionEnd(); + }, + reset: function() { + this.forceCompositionEnd(); + }, + forceCompositionEnd: function() { + if (!this.composing || this.composing.handled) return; + this.applyComposition(this.composing); + this.composing.handled = true; + this.div.blur(); + this.div.focus(); + }, + applyComposition: function(composing) { + if (this.cm.isReadOnly()) + operation(this.cm, regChange)(this.cm) + else if (composing.data && composing.data != composing.startData) + operation(this.cm, applyTextInput)(this.cm, composing.data, 0, composing.sel); + }, + + setUneditable: function(node) { + node.contentEditable = "false" + }, + + onKeyPress: function(e) { + e.preventDefault(); + if (!this.cm.isReadOnly()) + operation(this.cm, applyTextInput)(this.cm, String.fromCharCode(e.charCode == null ? e.keyCode : e.charCode), 0); + }, + + readOnlyChanged: function(val) { + this.div.contentEditable = String(val != "nocursor") + }, + + onContextMenu: nothing, + resetPosition: nothing, + + needsContentAttribute: true + }, ContentEditableInput.prototype); + + function posToDOM(cm, pos) { + var view = findViewForLine(cm, pos.line); + if (!view || view.hidden) return null; + var line = getLine(cm.doc, pos.line); + var info = mapFromLineView(view, line, pos.line); + + var order = getOrder(line), side = "left"; + if (order) { + var partPos = getBidiPartAt(order, pos.ch); + side = partPos % 2 ? "right" : "left"; + } + var result = nodeAndOffsetInLineMap(info.map, pos.ch, side); + result.offset = result.collapse == "right" ? result.end : result.start; + return result; + } + + function badPos(pos, bad) { if (bad) pos.bad = true; return pos; } + + function domToPos(cm, node, offset) { + var lineNode; + if (node == cm.display.lineDiv) { + lineNode = cm.display.lineDiv.childNodes[offset]; + if (!lineNode) return badPos(cm.clipPos(Pos(cm.display.viewTo - 1)), true); + node = null; offset = 0; + } else { + for (lineNode = node;; lineNode = lineNode.parentNode) { + if (!lineNode || lineNode == cm.display.lineDiv) return null; + if (lineNode.parentNode && lineNode.parentNode == cm.display.lineDiv) break; + } + } + for (var i = 0; i < cm.display.view.length; i++) { + var lineView = cm.display.view[i]; + if (lineView.node == lineNode) + return locateNodeInLineView(lineView, node, offset); + } + } + + function locateNodeInLineView(lineView, node, offset) { + var wrapper = lineView.text.firstChild, bad = false; + if (!node || !contains(wrapper, node)) return badPos(Pos(lineNo(lineView.line), 0), true); + if (node == wrapper) { + bad = true; + node = wrapper.childNodes[offset]; + offset = 0; + if (!node) { + var line = lineView.rest ? lst(lineView.rest) : lineView.line; + return badPos(Pos(lineNo(line), line.text.length), bad); + } + } + + var textNode = node.nodeType == 3 ? node : null, topNode = node; + if (!textNode && node.childNodes.length == 1 && node.firstChild.nodeType == 3) { + textNode = node.firstChild; + if (offset) offset = textNode.nodeValue.length; + } + while (topNode.parentNode != wrapper) topNode = topNode.parentNode; + var measure = lineView.measure, maps = measure.maps; + + function find(textNode, topNode, offset) { + for (var i = -1; i < (maps ? maps.length : 0); i++) { + var map = i < 0 ? measure.map : maps[i]; + for (var j = 0; j < map.length; j += 3) { + var curNode = map[j + 2]; + if (curNode == textNode || curNode == topNode) { + var line = lineNo(i < 0 ? lineView.line : lineView.rest[i]); + var ch = map[j] + offset; + if (offset < 0 || curNode != textNode) ch = map[j + (offset ? 1 : 0)]; + return Pos(line, ch); + } + } + } + } + var found = find(textNode, topNode, offset); + if (found) return badPos(found, bad); + + // FIXME this is all really shaky. might handle the few cases it needs to handle, but likely to cause problems + for (var after = topNode.nextSibling, dist = textNode ? textNode.nodeValue.length - offset : 0; after; after = after.nextSibling) { + found = find(after, after.firstChild, 0); + if (found) + return badPos(Pos(found.line, found.ch - dist), bad); + else + dist += after.textContent.length; + } + for (var before = topNode.previousSibling, dist = offset; before; before = before.previousSibling) { + found = find(before, before.firstChild, -1); + if (found) + return badPos(Pos(found.line, found.ch + dist), bad); + else + dist += after.textContent.length; + } + } + + function domTextBetween(cm, from, to, fromLine, toLine) { + var text = "", closing = false, lineSep = cm.doc.lineSeparator(); + function recognizeMarker(id) { return function(marker) { return marker.id == id; }; } + function walk(node) { + if (node.nodeType == 1) { + var cmText = node.getAttribute("cm-text"); + if (cmText != null) { + if (cmText == "") cmText = node.textContent.replace(/\u200b/g, ""); + text += cmText; + return; + } + var markerID = node.getAttribute("cm-marker"), range; + if (markerID) { + var found = cm.findMarks(Pos(fromLine, 0), Pos(toLine + 1, 0), recognizeMarker(+markerID)); + if (found.length && (range = found[0].find())) + text += getBetween(cm.doc, range.from, range.to).join(lineSep); + return; + } + if (node.getAttribute("contenteditable") == "false") return; + for (var i = 0; i < node.childNodes.length; i++) + walk(node.childNodes[i]); + if (/^(pre|div|p)$/i.test(node.nodeName)) + closing = true; + } else if (node.nodeType == 3) { + var val = node.nodeValue; + if (!val) return; + if (closing) { + text += lineSep; + closing = false; + } + text += val; + } + } + for (;;) { + walk(from); + if (from == to) break; + from = from.nextSibling; + } + return text; + } + + CodeMirror.inputStyles = {"textarea": TextareaInput, "contenteditable": ContentEditableInput}; // SELECTION / CURSOR @@ -1124,7 +2164,7 @@ // Give beforeSelectionChange handlers a change to influence a // selection update. - function filterSelectionChange(doc, sel) { + function filterSelectionChange(doc, sel, options) { var obj = { ranges: sel.ranges, update: function(ranges) { @@ -1132,7 +2172,8 @@ for (var i = 0; i < ranges.length; i++) this.ranges[i] = new Range(clipPos(doc, ranges[i].anchor), clipPos(doc, ranges[i].head)); - } + }, + origin: options && options.origin }; signal(doc, "beforeSelectionChange", doc, obj); if (doc.cm) signal(doc.cm, "beforeSelectionChange", doc.cm, obj); @@ -1158,7 +2199,7 @@ function setSelectionNoUndo(doc, sel, options) { if (hasHandler(doc, "beforeSelectionChange") || doc.cm && hasHandler(doc.cm, "beforeSelectionChange")) - sel = filterSelectionChange(doc, sel); + sel = filterSelectionChange(doc, sel, options); var bias = options && options.bias || (cmp(sel.primary().head, doc.sel.primary().head) < 0 ? -1 : 1); @@ -1192,8 +2233,9 @@ var out; for (var i = 0; i < sel.ranges.length; i++) { var range = sel.ranges[i]; - var newAnchor = skipAtomic(doc, range.anchor, bias, mayClear); - var newHead = skipAtomic(doc, range.head, bias, mayClear); + var old = sel.ranges.length == doc.sel.ranges.length && doc.sel.ranges[i]; + var newAnchor = skipAtomic(doc, range.anchor, old && old.anchor, bias, mayClear); + var newHead = skipAtomic(doc, range.head, old && old.head, bias, mayClear); if (out || newAnchor != range.anchor || newHead != range.head) { if (!out) out = sel.ranges.slice(0, i); out[i] = new Range(newAnchor, newHead); @@ -1202,103 +2244,91 @@ return out ? normalizeSelection(out, sel.primIndex) : sel; } - // Ensure a given position is not inside an atomic range. - function skipAtomic(doc, pos, bias, mayClear) { - var flipped = false, curPos = pos; - var dir = bias || 1; - doc.cantEdit = false; - search: for (;;) { - var line = getLine(doc, curPos.line); - if (line.markedSpans) { - for (var i = 0; i < line.markedSpans.length; ++i) { - var sp = line.markedSpans[i], m = sp.marker; - if ((sp.from == null || (m.inclusiveLeft ? sp.from <= curPos.ch : sp.from < curPos.ch)) && - (sp.to == null || (m.inclusiveRight ? sp.to >= curPos.ch : sp.to > curPos.ch))) { - if (mayClear) { - signal(m, "beforeCursorEnter"); - if (m.explicitlyCleared) { - if (!line.markedSpans) break; - else {--i; continue;} - } - } - if (!m.atomic) continue; - var newPos = m.find(dir < 0 ? -1 : 1); - if (cmp(newPos, curPos) == 0) { - newPos.ch += dir; - if (newPos.ch < 0) { - if (newPos.line > doc.first) newPos = clipPos(doc, Pos(newPos.line - 1)); - else newPos = null; - } else if (newPos.ch > line.text.length) { - if (newPos.line < doc.first + doc.size - 1) newPos = Pos(newPos.line + 1, 0); - else newPos = null; - } - if (!newPos) { - if (flipped) { - // Driven in a corner -- no valid cursor position found at all - // -- try again *with* clearing, if we didn't already - if (!mayClear) return skipAtomic(doc, pos, bias, true); - // Otherwise, turn off editing until further notice, and return the start of the doc - doc.cantEdit = true; - return Pos(doc.first, 0); - } - flipped = true; newPos = pos; dir = -dir; - } - } - curPos = newPos; - continue search; + function skipAtomicInner(doc, pos, oldPos, dir, mayClear) { + var line = getLine(doc, pos.line); + if (line.markedSpans) for (var i = 0; i < line.markedSpans.length; ++i) { + var sp = line.markedSpans[i], m = sp.marker; + if ((sp.from == null || (m.inclusiveLeft ? sp.from <= pos.ch : sp.from < pos.ch)) && + (sp.to == null || (m.inclusiveRight ? sp.to >= pos.ch : sp.to > pos.ch))) { + if (mayClear) { + signal(m, "beforeCursorEnter"); + if (m.explicitlyCleared) { + if (!line.markedSpans) break; + else {--i; continue;} } } + if (!m.atomic) continue; + + if (oldPos) { + var near = m.find(dir < 0 ? 1 : -1), diff; + if (dir < 0 ? m.inclusiveRight : m.inclusiveLeft) + near = movePos(doc, near, -dir, near && near.line == pos.line ? line : null); + if (near && near.line == pos.line && (diff = cmp(near, oldPos)) && (dir < 0 ? diff < 0 : diff > 0)) + return skipAtomicInner(doc, near, pos, dir, mayClear); + } + + var far = m.find(dir < 0 ? -1 : 1); + if (dir < 0 ? m.inclusiveLeft : m.inclusiveRight) + far = movePos(doc, far, dir, far.line == pos.line ? line : null); + return far ? skipAtomicInner(doc, far, pos, dir, mayClear) : null; } - return curPos; + } + return pos; + } + + // Ensure a given position is not inside an atomic range. + function skipAtomic(doc, pos, oldPos, bias, mayClear) { + var dir = bias || 1; + var found = skipAtomicInner(doc, pos, oldPos, dir, mayClear) || + (!mayClear && skipAtomicInner(doc, pos, oldPos, dir, true)) || + skipAtomicInner(doc, pos, oldPos, -dir, mayClear) || + (!mayClear && skipAtomicInner(doc, pos, oldPos, -dir, true)); + if (!found) { + doc.cantEdit = true; + return Pos(doc.first, 0); + } + return found; + } + + function movePos(doc, pos, dir, line) { + if (dir < 0 && pos.ch == 0) { + if (pos.line > doc.first) return clipPos(doc, Pos(pos.line - 1)); + else return null; + } else if (dir > 0 && pos.ch == (line || getLine(doc, pos.line)).text.length) { + if (pos.line < doc.first + doc.size - 1) return Pos(pos.line + 1, 0); + else return null; + } else { + return new Pos(pos.line, pos.ch + dir); } } // SELECTION DRAWING - // Redraw the selection and/or cursor - function drawSelection(cm) { - var display = cm.display, doc = cm.doc, result = {}; + function updateSelection(cm) { + cm.display.input.showSelection(cm.display.input.prepareSelection()); + } + + function prepareSelection(cm, primary) { + var doc = cm.doc, result = {}; var curFragment = result.cursors = document.createDocumentFragment(); var selFragment = result.selection = document.createDocumentFragment(); for (var i = 0; i < doc.sel.ranges.length; i++) { + if (primary === false && i == doc.sel.primIndex) continue; var range = doc.sel.ranges[i]; + if (range.from().line >= cm.display.viewTo || range.to().line < cm.display.viewFrom) continue; var collapsed = range.empty(); if (collapsed || cm.options.showCursorWhenSelecting) - drawSelectionCursor(cm, range, curFragment); + drawSelectionCursor(cm, range.head, curFragment); if (!collapsed) drawSelectionRange(cm, range, selFragment); } - - // Move the hidden textarea near the cursor to prevent scrolling artifacts - if (cm.options.moveInputWithCursor) { - var headPos = cursorCoords(cm, doc.sel.primary().head, "div"); - var wrapOff = display.wrapper.getBoundingClientRect(), lineOff = display.lineDiv.getBoundingClientRect(); - result.teTop = Math.max(0, Math.min(display.wrapper.clientHeight - 10, - headPos.top + lineOff.top - wrapOff.top)); - result.teLeft = Math.max(0, Math.min(display.wrapper.clientWidth - 10, - headPos.left + lineOff.left - wrapOff.left)); - } - return result; } - function showSelection(cm, drawn) { - removeChildrenAndAdd(cm.display.cursorDiv, drawn.cursors); - removeChildrenAndAdd(cm.display.selectionDiv, drawn.selection); - if (drawn.teTop != null) { - cm.display.inputDiv.style.top = drawn.teTop + "px"; - cm.display.inputDiv.style.left = drawn.teLeft + "px"; - } - } - - function updateSelection(cm) { - showSelection(cm, drawSelection(cm)); - } - // Draws a cursor for the given range - function drawSelectionCursor(cm, range, output) { - var pos = cursorCoords(cm, range.head, "div", null, null, !cm.options.singleCursorHeightPerLine); + function drawSelectionCursor(cm, head, output) { + var pos = cursorCoords(cm, head, "div", null, null, !cm.options.singleCursorHeightPerLine); var cursor = output.appendChild(elt("div", "\u00a0", "CodeMirror-cursor")); cursor.style.left = pos.left + "px"; @@ -1319,7 +2349,8 @@ function drawSelectionRange(cm, range, output) { var display = cm.display, doc = cm.doc; var fragment = document.createDocumentFragment(); - var padding = paddingH(cm.display), leftSide = padding.left, rightSide = display.lineSpace.offsetWidth - padding.right; + var padding = paddingH(cm.display), leftSide = padding.left; + var rightSide = Math.max(display.sizerWidth, displayWidth(cm) - display.sizer.offsetLeft) - padding.right; function add(left, top, width, bottom) { if (top < 0) top = 0; @@ -1421,8 +2452,8 @@ doc.iter(doc.frontier, Math.min(doc.first + doc.size, cm.display.viewTo + 500), function(line) { if (doc.frontier >= cm.display.viewFrom) { // Visible - var oldStyles = line.styles; - var highlighted = highlightLine(cm, line, state, true); + var oldStyles = line.styles, tooLong = line.text.length > cm.options.maxHighlightLength; + var highlighted = highlightLine(cm, line, tooLong ? copyState(doc.mode, state) : state, true); line.styles = highlighted.styles; var oldCls = line.styleClasses, newCls = highlighted.classes; if (newCls) line.styleClasses = newCls; @@ -1431,9 +2462,10 @@ oldCls != newCls && (!oldCls || !newCls || oldCls.bgClass != newCls.bgClass || oldCls.textClass != newCls.textClass); for (var i = 0; !ischange && i < oldStyles.length; ++i) ischange = oldStyles[i] != line.styles[i]; if (ischange) changedLines.push(doc.frontier); - line.stateAfter = copyState(doc.mode, state); + line.stateAfter = tooLong ? state : copyState(doc.mode, state); } else { - processLine(cm, line.text, state); + if (line.text.length <= cm.options.maxHighlightLength) + processLine(cm, line.text, state); line.stateAfter = doc.frontier % 5 == 0 ? copyState(doc.mode, state) : null; } ++doc.frontier; @@ -1498,13 +2530,21 @@ return data; } + function scrollGap(cm) { return scrollerGap - cm.display.nativeBarWidth; } + function displayWidth(cm) { + return cm.display.scroller.clientWidth - scrollGap(cm) - cm.display.barWidth; + } + function displayHeight(cm) { + return cm.display.scroller.clientHeight - scrollGap(cm) - cm.display.barHeight; + } + // Ensure the lineView.wrapping.heights array is populated. This is // an array of bottom offsets for the lines that make up a drawn // line. When lineWrapping is on, there might be more than one // height. function ensureLineHeights(cm, lineView, rect) { var wrapping = cm.options.lineWrapping; - var curWidth = wrapping && cm.display.scroller.clientWidth; + var curWidth = wrapping && displayWidth(cm); if (!lineView.measure.heights || wrapping && lineView.measure.width != curWidth) { var heights = lineView.measure.heights = []; if (wrapping) { @@ -1570,10 +2610,12 @@ function prepareMeasureForLine(cm, line) { var lineN = lineNo(line); var view = findViewForLine(cm, lineN); - if (view && !view.text) + if (view && !view.text) { view = null; - else if (view && view.changes) + } else if (view && view.changes) { updateLineForChanges(cm, view, lineN, getDimensions(cm)); + cm.curOp.forceUpdate = true; + } if (!view) view = updateExternalMeasurement(cm, line); @@ -1609,9 +2651,7 @@ var nullRect = {left: 0, right: 0, top: 0, bottom: 0}; - function measureCharInner(cm, prepared, ch, bias) { - var map = prepared.map; - + function nodeAndOffsetInLineMap(map, ch, bias) { var node, start, end, collapse; // First, search the line map for the text node corresponding to, // or closest to, the target character. @@ -1645,23 +2685,32 @@ break; } } + return {node: node, start: start, end: end, collapse: collapse, coverStart: mStart, coverEnd: mEnd}; + } + + function getUsefulRect(rects, bias) { + var rect = nullRect + if (bias == "left") for (var i = 0; i < rects.length; i++) { + if ((rect = rects[i]).left != rect.right) break + } else for (var i = rects.length - 1; i >= 0; i--) { + if ((rect = rects[i]).left != rect.right) break + } + return rect + } + + function measureCharInner(cm, prepared, ch, bias) { + var place = nodeAndOffsetInLineMap(prepared.map, ch, bias); + var node = place.node, start = place.start, end = place.end, collapse = place.collapse; var rect; if (node.nodeType == 3) { // If it is a text node, use a range to retrieve the coordinates. for (var i = 0; i < 4; i++) { // Retry a maximum of 4 times when nonsense rectangles are returned - while (start && isExtendingChar(prepared.line.text.charAt(mStart + start))) --start; - while (mStart + end < mEnd && isExtendingChar(prepared.line.text.charAt(mStart + end))) ++end; - if (ie && ie_version < 9 && start == 0 && end == mEnd - mStart) { + while (start && isExtendingChar(prepared.line.text.charAt(place.coverStart + start))) --start; + while (place.coverStart + end < place.coverEnd && isExtendingChar(prepared.line.text.charAt(place.coverStart + end))) ++end; + if (ie && ie_version < 9 && start == 0 && end == place.coverEnd - place.coverStart) rect = node.parentNode.getBoundingClientRect(); - } else if (ie && cm.options.lineWrapping) { - var rects = range(node, start, end).getClientRects(); - if (rects.length) - rect = rects[bias == "right" ? rects.length - 1 : 0]; - else - rect = nullRect; - } else { - rect = range(node, start, end).getBoundingClientRect() || nullRect; - } + else + rect = getUsefulRect(range(node, start, end).getClientRects(), bias) if (rect.left || rect.right || start == 0) break; end = start; start = start - 1; @@ -1739,7 +2788,8 @@ // Converts a {top, bottom, left, right} box from line-local // coordinates into another coordinate system. Context may be one of - // "line", "div" (display.lineDiv), "local"/null (editor), or "page". + // "line", "div" (display.lineDiv), "local"/null (editor), "window", + // or "page". function intoCoordSystem(cm, lineObj, rect, context) { if (lineObj.widgets) for (var i = 0; i < lineObj.widgets.length; ++i) if (lineObj.widgets[i].above) { var size = widgetHeight(lineObj.widgets[i]); @@ -1886,10 +2936,23 @@ for (;;) { if (bidi ? to == from || to == moveVisually(lineObj, from, 1) : to - from <= 1) { var ch = x < fromX || x - fromX <= toX - x ? from : to; + var outside = ch == from ? fromOutside : toOutside var xDiff = x - (ch == from ? fromX : toX); + // This is a kludge to handle the case where the coordinates + // are after a line-wrapped line. We should replace it with a + // more general handling of cursor positions around line + // breaks. (Issue #4078) + if (toOutside && !bidi && !/\s/.test(lineObj.text.charAt(ch)) && xDiff > 0 && + ch < lineObj.text.length && preparedMeasure.view.measure.heights.length > 1) { + var charSize = measureCharPrepared(cm, preparedMeasure, ch, "right"); + if (innerOff <= charSize.bottom && innerOff >= charSize.top && Math.abs(x - charSize.right) < xDiff) { + outside = false + ch++ + xDiff = x - charSize.right + } + } while (isExtendingChar(lineObj.text.charAt(ch))) ++ch; - var pos = PosWithInfo(lineNo, ch, ch == from ? fromOutside : toOutside, - xDiff < -1 ? -1 : xDiff > 1 ? 1 : 0); + var pos = PosWithInfo(lineNo, ch, outside, xDiff < -1 ? -1 : xDiff > 1 ? 1 : 0); return pos; } var step = Math.ceil(dist / 2), middle = from + step; @@ -1962,6 +3025,7 @@ updateMaxLine: false, // Set when the widest line needs to be determined anew scrollLeft: null, scrollTop: null, // Intermediate scroll position, not pushed to DOM yet scrollToPos: null, // Used to scroll to a specific position + focus: false, id: ++nextOpId // Unique ID }; if (operationGroup) { @@ -1980,12 +3044,12 @@ var callbacks = group.delayedCallbacks, i = 0; do { for (; i < callbacks.length; i++) - callbacks[i](); + callbacks[i].call(null); for (var j = 0; j < group.ops.length; j++) { var op = group.ops[j]; if (op.cursorActivityHandlers) while (op.cursorActivityCalled < op.cursorActivityHandlers.length) - op.cursorActivityHandlers[op.cursorActivityCalled++](op.cm); + op.cursorActivityHandlers[op.cursorActivityCalled++].call(null, op.cm); } } while (i < callbacks.length); } @@ -2022,6 +3086,7 @@ function endOperation_R1(op) { var cm = op.cm, display = cm.display; + maybeClipScrollbars(cm); if (op.updateMaxLine) findMaxLine(cm); op.mustUpdate = op.viewChanged || op.forceUpdate || op.scrollTop != null || @@ -2047,12 +3112,14 @@ // updateDisplay_W2 will use these properties to do the actual resizing if (display.maxLineChanged && !cm.options.lineWrapping) { op.adjustWidthTo = measureChar(cm, display.maxLine, display.maxLine.text.length).left + 3; - op.maxScrollLeft = Math.max(0, display.sizer.offsetLeft + op.adjustWidthTo + - scrollerCutOff - display.scroller.clientWidth); + cm.display.sizerWidth = op.adjustWidthTo; + op.barMeasure.scrollWidth = + Math.max(display.scroller.clientWidth, display.sizer.offsetLeft + op.adjustWidthTo + scrollGap(cm) + cm.display.barWidth); + op.maxScrollLeft = Math.max(0, display.sizer.offsetLeft + op.adjustWidthTo - displayWidth(cm)); } if (op.updatedDisplay || op.selectionChanged) - op.newSelectionNodes = drawSelection(cm); + op.preparedSelection = display.input.prepareSelection(op.focus); } function endOperation_W2(op) { @@ -2065,25 +3132,24 @@ cm.display.maxLineChanged = false; } - if (op.newSelectionNodes) - showSelection(cm, op.newSelectionNodes); - if (op.updatedDisplay) - setDocumentHeight(cm, op.barMeasure); + var takeFocus = op.focus && op.focus == activeElt() && (!document.hasFocus || document.hasFocus()) + if (op.preparedSelection) + cm.display.input.showSelection(op.preparedSelection, takeFocus); if (op.updatedDisplay || op.startHeight != cm.doc.height) updateScrollbars(cm, op.barMeasure); + if (op.updatedDisplay) + setDocumentHeight(cm, op.barMeasure); if (op.selectionChanged) restartBlink(cm); if (cm.state.focused && op.updateInput) - resetInput(cm, op.typing); + cm.display.input.reset(op.typing); + if (takeFocus) ensureFocus(op.cm); } function endOperation_finish(op) { var cm = op.cm, display = cm.display, doc = cm.doc; - if (op.adjustWidthTo != null && Math.abs(op.barMeasure.scrollWidth - cm.display.scroller.scrollWidth) > 1) - updateScrollbars(cm); - if (op.updatedDisplay) postUpdateDisplay(cm, op.update); // Abort mouse wheel delta measurement, when scrolling explicitly @@ -2092,12 +3158,14 @@ // Propagate the scroll position to the actual DOM scroller if (op.scrollTop != null && (display.scroller.scrollTop != op.scrollTop || op.forceScroll)) { - var top = Math.max(0, Math.min(display.scroller.scrollHeight - display.scroller.clientHeight, op.scrollTop)); - display.scroller.scrollTop = display.scrollbarV.scrollTop = doc.scrollTop = top; + doc.scrollTop = Math.max(0, Math.min(display.scroller.scrollHeight - display.scroller.clientHeight, op.scrollTop)); + display.scrollbars.setScrollTop(doc.scrollTop); + display.scroller.scrollTop = doc.scrollTop; } if (op.scrollLeft != null && (display.scroller.scrollLeft != op.scrollLeft || op.forceScroll)) { - var left = Math.max(0, Math.min(display.scroller.scrollWidth - display.scroller.clientWidth, op.scrollLeft)); - display.scroller.scrollLeft = display.scrollbarH.scrollLeft = doc.scrollLeft = left; + doc.scrollLeft = Math.max(0, Math.min(display.scroller.scrollWidth - display.scroller.clientWidth, op.scrollLeft)); + display.scrollbars.setScrollLeft(doc.scrollLeft); + display.scroller.scrollLeft = doc.scrollLeft; alignHorizontally(cm); } // If we need to scroll a specific position into view, do so. @@ -2118,19 +3186,11 @@ if (display.wrapper.offsetHeight) doc.scrollTop = cm.display.scroller.scrollTop; - // Apply workaround for two webkit bugs - if (op.updatedDisplay && webkit) { - if (cm.options.lineWrapping) - checkForWebkitWidthBug(cm, op.barMeasure); // (Issue #2420) - if (op.barMeasure.scrollWidth > op.barMeasure.clientWidth && - op.barMeasure.scrollWidth < op.barMeasure.clientWidth + 1 && - !hScrollbarTakesSpace(cm)) - updateScrollbars(cm); // (Issue #2562) - } - // Fire change events, and delayed event handlers if (op.changeObjs) signal(cm, "changes", cm, op.changeObjs); + if (op.update) + op.update.finish(); } // Run the given function in an operation @@ -2356,166 +3416,6 @@ return dirty; } - // INPUT HANDLING - - // Poll for input changes, using the normal rate of polling. This - // runs as long as the editor is focused. - function slowPoll(cm) { - if (cm.display.pollingFast) return; - cm.display.poll.set(cm.options.pollInterval, function() { - readInput(cm); - if (cm.state.focused) slowPoll(cm); - }); - } - - // When an event has just come in that is likely to add or change - // something in the input textarea, we poll faster, to ensure that - // the change appears on the screen quickly. - function fastPoll(cm) { - var missed = false; - cm.display.pollingFast = true; - function p() { - var changed = readInput(cm); - if (!changed && !missed) {missed = true; cm.display.poll.set(60, p);} - else {cm.display.pollingFast = false; slowPoll(cm);} - } - cm.display.poll.set(20, p); - } - - // This will be set to an array of strings when copying, so that, - // when pasting, we know what kind of selections the copied text - // was made out of. - var lastCopied = null; - - // Read input from the textarea, and update the document to match. - // When something is selected, it is present in the textarea, and - // selected (unless it is huge, in which case a placeholder is - // used). When nothing is selected, the cursor sits after previously - // seen text (can be empty), which is stored in prevInput (we must - // not reset the textarea when typing, because that breaks IME). - function readInput(cm) { - var input = cm.display.input, prevInput = cm.display.prevInput, doc = cm.doc; - // Since this is called a *lot*, try to bail out as cheaply as - // possible when it is clear that nothing happened. hasSelection - // will be the case when there is a lot of text in the textarea, - // in which case reading its value would be expensive. - if (!cm.state.focused || (hasSelection(input) && !prevInput) || isReadOnly(cm) || cm.options.disableInput || cm.state.keySeq) - return false; - // See paste handler for more on the fakedLastChar kludge - if (cm.state.pasteIncoming && cm.state.fakedLastChar) { - input.value = input.value.substring(0, input.value.length - 1); - cm.state.fakedLastChar = false; - } - var text = input.value; - // If nothing changed, bail. - if (text == prevInput && !cm.somethingSelected()) return false; - // Work around nonsensical selection resetting in IE9/10, and - // inexplicable appearance of private area unicode characters on - // some key combos in Mac (#2689). - if (ie && ie_version >= 9 && cm.display.inputHasSelection === text || - mac && /[\uf700-\uf7ff]/.test(text)) { - resetInput(cm); - return false; - } - - var withOp = !cm.curOp; - if (withOp) startOperation(cm); - cm.display.shift = false; - - if (text.charCodeAt(0) == 0x200b && doc.sel == cm.display.selForContextMenu && !prevInput) - prevInput = "\u200b"; - // Find the part of the input that is actually new - var same = 0, l = Math.min(prevInput.length, text.length); - while (same < l && prevInput.charCodeAt(same) == text.charCodeAt(same)) ++same; - var inserted = text.slice(same), textLines = splitLines(inserted); - - // When pasing N lines into N selections, insert one line per selection - var multiPaste = null; - if (cm.state.pasteIncoming && doc.sel.ranges.length > 1) { - if (lastCopied && lastCopied.join("\n") == inserted) - multiPaste = doc.sel.ranges.length % lastCopied.length == 0 && map(lastCopied, splitLines); - else if (textLines.length == doc.sel.ranges.length) - multiPaste = map(textLines, function(l) { return [l]; }); - } - - // Normal behavior is to insert the new text into every selection - for (var i = doc.sel.ranges.length - 1; i >= 0; i--) { - var range = doc.sel.ranges[i]; - var from = range.from(), to = range.to(); - // Handle deletion - if (same < prevInput.length) - from = Pos(from.line, from.ch - (prevInput.length - same)); - // Handle overwrite - else if (cm.state.overwrite && range.empty() && !cm.state.pasteIncoming) - to = Pos(to.line, Math.min(getLine(doc, to.line).text.length, to.ch + lst(textLines).length)); - var updateInput = cm.curOp.updateInput; - var changeEvent = {from: from, to: to, text: multiPaste ? multiPaste[i % multiPaste.length] : textLines, - origin: cm.state.pasteIncoming ? "paste" : cm.state.cutIncoming ? "cut" : "+input"}; - makeChange(cm.doc, changeEvent); - signalLater(cm, "inputRead", cm, changeEvent); - // When an 'electric' character is inserted, immediately trigger a reindent - if (inserted && !cm.state.pasteIncoming && cm.options.electricChars && - cm.options.smartIndent && range.head.ch < 100 && - (!i || doc.sel.ranges[i - 1].head.line != range.head.line)) { - var mode = cm.getModeAt(range.head); - var end = changeEnd(changeEvent); - if (mode.electricChars) { - for (var j = 0; j < mode.electricChars.length; j++) - if (inserted.indexOf(mode.electricChars.charAt(j)) > -1) { - indentLine(cm, end.line, "smart"); - break; - } - } else if (mode.electricInput) { - if (mode.electricInput.test(getLine(doc, end.line).text.slice(0, end.ch))) - indentLine(cm, end.line, "smart"); - } - } - } - ensureCursorVisible(cm); - cm.curOp.updateInput = updateInput; - cm.curOp.typing = true; - - // Don't leave long text in the textarea, since it makes further polling slow - if (text.length > 1000 || text.indexOf("\n") > -1) input.value = cm.display.prevInput = ""; - else cm.display.prevInput = text; - if (withOp) endOperation(cm); - cm.state.pasteIncoming = cm.state.cutIncoming = false; - return true; - } - - // Reset the input to correspond to the selection (or to be empty, - // when not typing and nothing is selected) - function resetInput(cm, typing) { - var minimal, selected, doc = cm.doc; - if (cm.somethingSelected()) { - cm.display.prevInput = ""; - var range = doc.sel.primary(); - minimal = hasCopyEvent && - (range.to().line - range.from().line > 100 || (selected = cm.getSelection()).length > 1000); - var content = minimal ? "-" : selected || cm.getSelection(); - cm.display.input.value = content; - if (cm.state.focused) selectInput(cm.display.input); - if (ie && ie_version >= 9) cm.display.inputHasSelection = content; - } else if (!typing) { - cm.display.prevInput = cm.display.input.value = ""; - if (ie && ie_version >= 9) cm.display.inputHasSelection = null; - } - cm.display.inaccurateSelection = minimal; - } - - function focusInput(cm) { - if (cm.options.readOnly != "nocursor" && (!mobile || activeElt() != cm.display.input)) - cm.display.input.focus(); - } - - function ensureFocus(cm) { - if (!cm.state.focused) { focusInput(cm); onFocus(cm); } - } - - function isReadOnly(cm) { - return cm.options.readOnly || cm.doc.cantEdit; - } - // EVENT HANDLERS // Attach the necessary event handlers when initializing the editor @@ -2534,15 +3434,64 @@ })); else on(d.scroller, "dblclick", function(e) { signalDOMEvent(cm, e) || e_preventDefault(e); }); - // Prevent normal selection in the editor (we handle our own) - on(d.lineSpace, "selectstart", function(e) { - if (!eventInWidget(d, e)) e_preventDefault(e); - }); // Some browsers fire contextmenu *after* opening the menu, at // which point we can't mess with it anymore. Context menu is // handled in onMouseDown for these browsers. if (!captureRightClick) on(d.scroller, "contextmenu", function(e) {onContextMenu(cm, e);}); + // Used to suppress mouse event handling when a touch happens + var touchFinished, prevTouch = {end: 0}; + function finishTouch() { + if (d.activeTouch) { + touchFinished = setTimeout(function() {d.activeTouch = null;}, 1000); + prevTouch = d.activeTouch; + prevTouch.end = +new Date; + } + }; + function isMouseLikeTouchEvent(e) { + if (e.touches.length != 1) return false; + var touch = e.touches[0]; + return touch.radiusX <= 1 && touch.radiusY <= 1; + } + function farAway(touch, other) { + if (other.left == null) return true; + var dx = other.left - touch.left, dy = other.top - touch.top; + return dx * dx + dy * dy > 20 * 20; + } + on(d.scroller, "touchstart", function(e) { + if (!signalDOMEvent(cm, e) && !isMouseLikeTouchEvent(e)) { + clearTimeout(touchFinished); + var now = +new Date; + d.activeTouch = {start: now, moved: false, + prev: now - prevTouch.end <= 300 ? prevTouch : null}; + if (e.touches.length == 1) { + d.activeTouch.left = e.touches[0].pageX; + d.activeTouch.top = e.touches[0].pageY; + } + } + }); + on(d.scroller, "touchmove", function() { + if (d.activeTouch) d.activeTouch.moved = true; + }); + on(d.scroller, "touchend", function(e) { + var touch = d.activeTouch; + if (touch && !eventInWidget(d, e) && touch.left != null && + !touch.moved && new Date - touch.start < 300) { + var pos = cm.coordsChar(d.activeTouch, "page"), range; + if (!touch.prev || farAway(touch, touch.prev)) // Single tap + range = new Range(pos, pos); + else if (!touch.prev.prev || farAway(touch, touch.prev.prev)) // Double tap + range = cm.findWordAt(pos); + else // Triple tap + range = new Range(Pos(pos.line, 0), clipPos(cm.doc, Pos(pos.line + 1, 0))); + cm.setSelection(range.anchor, range.head); + cm.focus(); + e_preventDefault(e); + } + finishTouch(); + }); + on(d.scroller, "touchcancel", finishTouch); + // Sync scrolling between fake scrollbars and real scrollable // area, ensure viewport is updated when scrolling. on(d.scroller, "scroll", function() { @@ -2552,104 +3501,41 @@ signal(cm, "scroll", cm); } }); - on(d.scrollbarV, "scroll", function() { - if (d.scroller.clientHeight) setScrollTop(cm, d.scrollbarV.scrollTop); - }); - on(d.scrollbarH, "scroll", function() { - if (d.scroller.clientHeight) setScrollLeft(cm, d.scrollbarH.scrollLeft); - }); // Listen to wheel events in order to try and update the viewport on time. on(d.scroller, "mousewheel", function(e){onScrollWheel(cm, e);}); on(d.scroller, "DOMMouseScroll", function(e){onScrollWheel(cm, e);}); - // Prevent clicks in the scrollbars from killing focus - function reFocus() { if (cm.state.focused) setTimeout(bind(focusInput, cm), 0); } - on(d.scrollbarH, "mousedown", reFocus); - on(d.scrollbarV, "mousedown", reFocus); // Prevent wrapper from ever scrolling on(d.wrapper, "scroll", function() { d.wrapper.scrollTop = d.wrapper.scrollLeft = 0; }); - on(d.input, "keyup", function(e) { onKeyUp.call(cm, e); }); - on(d.input, "input", function() { - if (ie && ie_version >= 9 && cm.display.inputHasSelection) cm.display.inputHasSelection = null; - fastPoll(cm); - }); - on(d.input, "keydown", operation(cm, onKeyDown)); - on(d.input, "keypress", operation(cm, onKeyPress)); - on(d.input, "focus", bind(onFocus, cm)); - on(d.input, "blur", bind(onBlur, cm)); - - function drag_(e) { - if (!signalDOMEvent(cm, e)) e_stop(e); - } - if (cm.options.dragDrop) { - on(d.scroller, "dragstart", function(e){onDragStart(cm, e);}); - on(d.scroller, "dragenter", drag_); - on(d.scroller, "dragover", drag_); - on(d.scroller, "drop", operation(cm, onDrop)); - } - on(d.scroller, "paste", function(e) { - if (eventInWidget(d, e)) return; - cm.state.pasteIncoming = true; - focusInput(cm); - fastPoll(cm); - }); - on(d.input, "paste", function() { - // Workaround for webkit bug https://bugs.webkit.org/show_bug.cgi?id=90206 - // Add a char to the end of textarea before paste occur so that - // selection doesn't span to the end of textarea. - if (webkit && !cm.state.fakedLastChar && !(new Date - cm.state.lastMiddleDown < 200)) { - var start = d.input.selectionStart, end = d.input.selectionEnd; - d.input.value += "$"; - // The selection end needs to be set before the start, otherwise there - // can be an intermediate non-empty selection between the two, which - // can override the middle-click paste buffer on linux and cause the - // wrong thing to get pasted. - d.input.selectionEnd = end; - d.input.selectionStart = start; - cm.state.fakedLastChar = true; - } - cm.state.pasteIncoming = true; - fastPoll(cm); - }); + d.dragFunctions = { + enter: function(e) {if (!signalDOMEvent(cm, e)) e_stop(e);}, + over: function(e) {if (!signalDOMEvent(cm, e)) { onDragOver(cm, e); e_stop(e); }}, + start: function(e){onDragStart(cm, e);}, + drop: operation(cm, onDrop), + leave: function(e) {if (!signalDOMEvent(cm, e)) { clearDragCursor(cm); }} + }; - function prepareCopyCut(e) { - if (cm.somethingSelected()) { - lastCopied = cm.getSelections(); - if (d.inaccurateSelection) { - d.prevInput = ""; - d.inaccurateSelection = false; - d.input.value = lastCopied.join("\n"); - selectInput(d.input); - } - } else { - var text = [], ranges = []; - for (var i = 0; i < cm.doc.sel.ranges.length; i++) { - var line = cm.doc.sel.ranges[i].head.line; - var lineRange = {anchor: Pos(line, 0), head: Pos(line + 1, 0)}; - ranges.push(lineRange); - text.push(cm.getRange(lineRange.anchor, lineRange.head)); - } - if (e.type == "cut") { - cm.setSelections(ranges, null, sel_dontScroll); - } else { - d.prevInput = ""; - d.input.value = text.join("\n"); - selectInput(d.input); - } - lastCopied = text; - } - if (e.type == "cut") cm.state.cutIncoming = true; - } - on(d.input, "cut", prepareCopyCut); - on(d.input, "copy", prepareCopyCut); + var inp = d.input.getField(); + on(inp, "keyup", function(e) { onKeyUp.call(cm, e); }); + on(inp, "keydown", operation(cm, onKeyDown)); + on(inp, "keypress", operation(cm, onKeyPress)); + on(inp, "focus", bind(onFocus, cm)); + on(inp, "blur", bind(onBlur, cm)); + } - // Needed to handle Tab key in KHTML - if (khtml) on(d.sizer, "mouseup", function() { - if (activeElt() == d.input) d.input.blur(); - focusInput(cm); - }); + function dragDropChanged(cm, value, old) { + var wasOn = old && old != CodeMirror.Init; + if (!value != !wasOn) { + var funcs = cm.display.dragFunctions; + var toggle = value ? on : off; + toggle(cm.display.scroller, "dragstart", funcs.start); + toggle(cm.display.scroller, "dragenter", funcs.enter); + toggle(cm.display.scroller, "dragover", funcs.over); + toggle(cm.display.scroller, "dragleave", funcs.leave); + toggle(cm.display.scroller, "drop", funcs.drop); + } } // Called when the window resizes @@ -2659,6 +3545,7 @@ return; // Might be a text scaling operation, clear size caches. d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = null; + d.scrollbarsClipped = false; cm.setSize(); } @@ -2667,7 +3554,9 @@ // Return true when the given mouse event happened in a widget function eventInWidget(display, e) { for (var n = e_target(e); n != display.wrapper; n = n.parentNode) { - if (!n || n.ignoreEvents || n.parentNode == display.sizer && n != display.mover) return true; + if (!n || (n.nodeType == 1 && n.getAttribute("cm-ignore-events") == "true") || + (n.parentNode == display.sizer && n != display.mover)) + return true; } } @@ -2678,11 +3567,8 @@ // coordinates beyond the right of the text. function posFromMouse(cm, e, liberal, forRect) { var display = cm.display; - if (!liberal) { - var target = e_target(e); - if (target == display.scrollbarH || target == display.scrollbarV || - target == display.scrollbarFiller || target == display.gutterFiller) return null; - } + if (!liberal && e_target(e).getAttribute("cm-not-content") == "true") return null; + var x, y, space = display.lineSpace.getBoundingClientRect(); // Fails unpredictably on IE[67] when mouse is dragged around quickly. try { x = e.clientX - space.left; y = e.clientY - space.top; } @@ -2701,8 +3587,8 @@ // middle-click-paste. Or it might be a click on something we should // not interfere with, such as a scrollbar or widget. function onMouseDown(e) { - if (signalDOMEvent(this, e)) return; var cm = this, display = cm.display; + if (signalDOMEvent(cm, e) || display.activeTouch && display.input.supportsTouch()) return; display.shift = e.shiftKey; if (eventInWidget(display, e)) { @@ -2720,7 +3606,10 @@ switch (e_button(e)) { case 1: - if (start) + // #3261: make sure, that we're not starting a second selection + if (cm.state.selectingText) + cm.state.selectingText(e); + else if (start) leftButtonDown(cm, e, start); else if (e_target(e) == display.scroller) e_preventDefault(e); @@ -2728,18 +3617,20 @@ case 2: if (webkit) cm.state.lastMiddleDown = +new Date; if (start) extendSelection(cm.doc, start); - setTimeout(bind(focusInput, cm), 20); + setTimeout(function() {display.input.focus();}, 20); e_preventDefault(e); break; case 3: if (captureRightClick) onContextMenu(cm, e); + else delayBlurEvent(cm); break; } } var lastClick, lastDoubleClick; function leftButtonDown(cm, e, start) { - setTimeout(bind(ensureFocus, cm), 0); + if (ie) setTimeout(bind(ensureFocus, cm), 0); + else cm.curOp.focus = activeElt(); var now = +new Date, type; if (lastDoubleClick && lastDoubleClick.time > now - 400 && cmp(lastDoubleClick.pos, start) == 0) { @@ -2752,9 +3643,11 @@ lastClick = {time: now, pos: start}; } - var sel = cm.doc.sel, modifier = mac ? e.metaKey : e.ctrlKey; - if (cm.options.dragDrop && dragAndDrop && !isReadOnly(cm) && - type == "single" && sel.contains(start) > -1 && sel.somethingSelected()) + var sel = cm.doc.sel, modifier = mac ? e.metaKey : e.ctrlKey, contained; + if (cm.options.dragDrop && dragAndDrop && !cm.isReadOnly() && + type == "single" && (contained = sel.contains(start)) > -1 && + (cmp((contained = sel.ranges[contained]).from(), start) < 0 || start.xRel > 0) && + (cmp(contained.to(), start) > 0 || start.xRel < 0)) leftButtonStartDrag(cm, e, start, modifier); else leftButtonSelect(cm, e, start, type, modifier); @@ -2763,7 +3656,7 @@ // Start a text drag. When it ends, see if any dragging actually // happen, and treat as a click if it didn't. function leftButtonStartDrag(cm, e, start, modifier) { - var display = cm.display; + var display = cm.display, startTime = +new Date; var dragEnd = operation(cm, function(e2) { if (webkit) display.scroller.draggable = false; cm.state.draggingText = false; @@ -2771,17 +3664,19 @@ off(display.scroller, "drop", dragEnd); if (Math.abs(e.clientX - e2.clientX) + Math.abs(e.clientY - e2.clientY) < 10) { e_preventDefault(e2); - if (!modifier) + if (!modifier && +new Date - 200 < startTime) extendSelection(cm.doc, start); - focusInput(cm); - // Work around unexplainable focus problem in IE9 (#2127) - if (ie && ie_version == 9) - setTimeout(function() {document.body.focus(); focusInput(cm);}, 20); + // Work around unexplainable focus problem in IE9 (#2127) and Chrome (#3081) + if (webkit || ie && ie_version == 9) + setTimeout(function() {document.body.focus(); display.input.focus();}, 20); + else + display.input.focus(); } }); // Let the drag handler handle this. if (webkit) display.scroller.draggable = true; cm.state.draggingText = dragEnd; + dragEnd.copy = mac ? e.altKey : e.ctrlKey // IE's approach to draggable if (display.scroller.dragDrop) display.scroller.dragDrop(); on(document, "mouseup", dragEnd); @@ -2793,18 +3688,19 @@ var display = cm.display, doc = cm.doc; e_preventDefault(e); - var ourRange, ourIndex, startSel = doc.sel; + var ourRange, ourIndex, startSel = doc.sel, ranges = startSel.ranges; if (addNew && !e.shiftKey) { ourIndex = doc.sel.contains(start); if (ourIndex > -1) - ourRange = doc.sel.ranges[ourIndex]; + ourRange = ranges[ourIndex]; else ourRange = new Range(start, start); } else { ourRange = doc.sel.primary(); + ourIndex = doc.sel.primIndex; } - if (e.altKey) { + if (chromeOS ? e.shiftKey && e.metaKey : e.altKey) { type = "rect"; if (!addNew) ourRange = new Range(start, start); start = posFromMouse(cm, e, true, true); @@ -2829,12 +3725,16 @@ ourIndex = 0; setSelection(doc, new Selection([ourRange], 0), sel_mouse); startSel = doc.sel; - } else if (ourIndex > -1) { - replaceOneSelection(doc, ourIndex, ourRange, sel_mouse); - } else { - ourIndex = doc.sel.ranges.length; - setSelection(doc, normalizeSelection(doc.sel.ranges.concat([ourRange]), ourIndex), + } else if (ourIndex == -1) { + ourIndex = ranges.length; + setSelection(doc, normalizeSelection(ranges.concat([ourRange]), ourIndex), {scroll: false, origin: "*mouse"}); + } else if (ranges.length > 1 && ranges[ourIndex].empty() && type == "single" && !e.shiftKey) { + setSelection(doc, normalizeSelection(ranges.slice(0, ourIndex).concat(ranges.slice(ourIndex + 1)), 0), + {scroll: false, origin: "*mouse"}); + startSel = doc.sel; + } else { + replaceOneSelection(doc, ourIndex, ourRange, sel_mouse); } var lastPos = start; @@ -2893,7 +3793,7 @@ var cur = posFromMouse(cm, e, true, type == "rect"); if (!cur) return; if (cmp(cur, lastPos) != 0) { - ensureFocus(cm); + cm.curOp.focus = activeElt(); extendTo(cur); var visible = visibleLines(display, doc); if (cur.line >= visible.to || cur.line < visible.from) @@ -2909,9 +3809,10 @@ } function done(e) { + cm.state.selectingText = false; counter = Infinity; e_preventDefault(e); - focusInput(cm); + display.input.focus(); off(document, "mousemove", move); off(document, "mouseup", up); doc.history.lastSelOrigin = null; @@ -2922,13 +3823,14 @@ else extend(e); }); var up = operation(cm, done); + cm.state.selectingText = up; on(document, "mousemove", move); on(document, "mouseup", up); } // Determines whether an event happened in the gutter, and fires the // handlers for the corresponding event. - function gutterEvent(cm, e, type, prevent, signalfn) { + function gutterEvent(cm, e, type, prevent) { try { var mX = e.clientX, mY = e.clientY; } catch(e) { return false; } if (mX >= Math.floor(cm.display.gutters.getBoundingClientRect().right)) return false; @@ -2945,14 +3847,14 @@ if (g && g.getBoundingClientRect().right >= mX) { var line = lineAtHeight(cm.doc, mY); var gutter = cm.options.gutters[i]; - signalfn(cm, type, cm, line, gutter, e); + signal(cm, type, cm, line, gutter, e); return e_defaultPrevented(e); } } } function clickInGutter(cm, e) { - return gutterEvent(cm, e, "gutterClick", true, signalLater); + return gutterEvent(cm, e, "gutterClick", true); } // Kludge to work around strange IE behavior where it'll sometimes @@ -2961,23 +3863,32 @@ function onDrop(e) { var cm = this; + clearDragCursor(cm); if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e)) return; e_preventDefault(e); if (ie) lastDrop = +new Date; var pos = posFromMouse(cm, e, true), files = e.dataTransfer.files; - if (!pos || isReadOnly(cm)) return; + if (!pos || cm.isReadOnly()) return; // Might be a file drop, in which case we simply extract the text // and insert it. if (files && files.length && window.FileReader && window.File) { var n = files.length, text = Array(n), read = 0; var loadFile = function(file, i) { + if (cm.options.allowDropFileTypes && + indexOf(cm.options.allowDropFileTypes, file.type) == -1) + return; + var reader = new FileReader; reader.onload = operation(cm, function() { - text[i] = reader.result; + var content = reader.result; + if (/[\x00-\x08\x0e-\x1f]{2}/.test(content)) content = ""; + text[i] = content; if (++read == n) { pos = clipPos(cm.doc, pos); - var change = {from: pos, to: pos, text: splitLines(text.join("\n")), origin: "paste"}; + var change = {from: pos, to: pos, + text: cm.doc.splitLines(text.join(cm.doc.lineSeparator())), + origin: "paste"}; makeChange(cm.doc, change); setSelectionReplaceHistory(cm.doc, simpleSelection(pos, changeEnd(change))); } @@ -2990,19 +3901,19 @@ if (cm.state.draggingText && cm.doc.sel.contains(pos) > -1) { cm.state.draggingText(e); // Ensure the editor is re-focused - setTimeout(bind(focusInput, cm), 20); + setTimeout(function() {cm.display.input.focus();}, 20); return; } try { var text = e.dataTransfer.getData("Text"); if (text) { - if (cm.state.draggingText && !(mac ? e.metaKey : e.ctrlKey)) + if (cm.state.draggingText && !cm.state.draggingText.copy) var selected = cm.listSelections(); setSelectionNoUndo(cm.doc, simpleSelection(pos, pos)); if (selected) for (var i = 0; i < selected.length; ++i) replaceRange(cm.doc, "", selected[i].anchor, selected[i].head, "drag"); cm.replaceSelection(text, "around", "paste"); - focusInput(cm); + cm.display.input.focus(); } } catch(e){} @@ -3014,6 +3925,7 @@ if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e)) return; e.dataTransfer.setData("Text", cm.getSelection()); + e.dataTransfer.effectAllowed = "copyMove" // Use dummy image instead of default browsers image. // Recent Safari (~6.0.2) have a tendency to segfault when this happens, so we don't do it there. @@ -3031,6 +3943,25 @@ } } + function onDragOver(cm, e) { + var pos = posFromMouse(cm, e); + if (!pos) return; + var frag = document.createDocumentFragment(); + drawSelectionCursor(cm, pos, frag); + if (!cm.display.dragCursor) { + cm.display.dragCursor = elt("div", null, "CodeMirror-cursors CodeMirror-dragcursors"); + cm.display.lineSpace.insertBefore(cm.display.dragCursor, cm.display.cursorDiv); + } + removeChildrenAndAdd(cm.display.dragCursor, frag); + } + + function clearDragCursor(cm) { + if (cm.display.dragCursor) { + cm.display.lineSpace.removeChild(cm.display.dragCursor); + cm.display.dragCursor = null; + } + } + // SCROLL EVENTS // Sync the scrollable area and scrollbars, ensure the viewport @@ -3040,7 +3971,7 @@ cm.doc.scrollTop = val; if (!gecko) updateDisplaySimple(cm, {top: val}); if (cm.display.scroller.scrollTop != val) cm.display.scroller.scrollTop = val; - if (cm.display.scrollbarV.scrollTop != val) cm.display.scrollbarV.scrollTop = val; + cm.display.scrollbars.setScrollTop(val); if (gecko) updateDisplaySimple(cm); startWorker(cm, 100); } @@ -3052,7 +3983,7 @@ cm.doc.scrollLeft = val; alignHorizontally(cm); if (cm.display.scroller.scrollLeft != val) cm.display.scroller.scrollLeft = val; - if (cm.display.scrollbarH.scrollLeft != val) cm.display.scrollbarH.scrollLeft = val; + cm.display.scrollbars.setScrollLeft(val); } // Since the delta values reported on mouse wheel events are @@ -3076,16 +4007,28 @@ else if (chrome) wheelPixelsPerUnit = -.7; else if (safari) wheelPixelsPerUnit = -1/3; - function onScrollWheel(cm, e) { + var wheelEventDelta = function(e) { var dx = e.wheelDeltaX, dy = e.wheelDeltaY; if (dx == null && e.detail && e.axis == e.HORIZONTAL_AXIS) dx = e.detail; if (dy == null && e.detail && e.axis == e.VERTICAL_AXIS) dy = e.detail; else if (dy == null) dy = e.wheelDelta; + return {x: dx, y: dy}; + }; + CodeMirror.wheelEventPixels = function(e) { + var delta = wheelEventDelta(e); + delta.x *= wheelPixelsPerUnit; + delta.y *= wheelPixelsPerUnit; + return delta; + }; + + function onScrollWheel(cm, e) { + var delta = wheelEventDelta(e), dx = delta.x, dy = delta.y; var display = cm.display, scroll = display.scroller; // Quit if there's nothing to scroll here - if (!(dx && scroll.scrollWidth > scroll.clientWidth || - dy && scroll.scrollHeight > scroll.clientHeight)) return; + var canScrollX = scroll.scrollWidth > scroll.clientWidth; + var canScrollY = scroll.scrollHeight > scroll.clientHeight; + if (!(dx && canScrollX || dy && canScrollY)) return; // Webkit browsers on OS X abort momentum scrolls when the target // of the scroll event is removed from the scrollable element. @@ -3109,10 +4052,15 @@ // scrolling entirely here. It'll be slightly off from native, but // better than glitching out. if (dx && !gecko && !presto && wheelPixelsPerUnit != null) { - if (dy) + if (dy && canScrollY) setScrollTop(cm, Math.max(0, Math.min(scroll.scrollTop + dy * wheelPixelsPerUnit, scroll.scrollHeight - scroll.clientHeight))); setScrollLeft(cm, Math.max(0, Math.min(scroll.scrollLeft + dx * wheelPixelsPerUnit, scroll.scrollWidth - scroll.clientWidth))); - e_preventDefault(e); + // Only prevent default scrolling if vertical scrolling is + // actually possible. Otherwise, it causes vertical scroll + // jitter on OSX trackpads when deltaX is small and deltaY + // is large (issue #3579) + if (!dy || (dy && canScrollY)) + e_preventDefault(e); display.wheelStartX = null; // Abort measurement, if in progress return; } @@ -3158,10 +4106,10 @@ } // Ensure previous input has been read, so that the handler sees a // consistent view of the document - if (cm.display.pollingFast && readInput(cm)) cm.display.pollingFast = false; + cm.display.input.ensurePolled(); var prevShift = cm.display.shift, done = false; try { - if (isReadOnly(cm)) cm.state.suppressEdits = true; + if (cm.isReadOnly()) cm.state.suppressEdits = true; if (dropShift) cm.display.shift = false; done = bound(cm) != Pass; } finally { @@ -3173,11 +4121,11 @@ function lookupKeyForEditor(cm, name, handle) { for (var i = 0; i < cm.state.keyMaps.length; i++) { - var result = lookupKey(name, cm.state.keyMaps[i], handle); + var result = lookupKey(name, cm.state.keyMaps[i], handle, cm); if (result) return result; } - return (cm.options.extraKeys && lookupKey(name, cm.options.extraKeys, handle)) - || lookupKey(name, cm.options.keyMap, handle); + return (cm.options.extraKeys && lookupKey(name, cm.options.extraKeys, handle, cm)) + || lookupKey(name, cm.options.keyMap, handle, cm); } var stopSeq = new Delayed; @@ -3188,7 +4136,7 @@ stopSeq.set(50, function() { if (cm.state.keySeq == seq) { cm.state.keySeq = null; - resetInput(cm); + cm.display.input.reset(); } }); name = seq + " " + name; @@ -3240,7 +4188,7 @@ var lastStoppedKey = null; function onKeyDown(e) { var cm = this; - ensureFocus(cm); + cm.curOp.focus = activeElt(); if (signalDOMEvent(cm, e)) return; // IE does strange things with escape. if (ie && ie_version < 11 && e.keyCode == 27) e.returnValue = false; @@ -3281,36 +4229,49 @@ function onKeyPress(e) { var cm = this; - if (signalDOMEvent(cm, e) || e.ctrlKey && !e.altKey || mac && e.metaKey) return; + if (eventInWidget(cm.display, e) || signalDOMEvent(cm, e) || e.ctrlKey && !e.altKey || mac && e.metaKey) return; var keyCode = e.keyCode, charCode = e.charCode; if (presto && keyCode == lastStoppedKey) {lastStoppedKey = null; e_preventDefault(e); return;} - if (((presto && (!e.which || e.which < 10)) || khtml) && handleKeyBinding(cm, e)) return; + if ((presto && (!e.which || e.which < 10)) && handleKeyBinding(cm, e)) return; var ch = String.fromCharCode(charCode == null ? keyCode : charCode); if (handleCharBinding(cm, e, ch)) return; - if (ie && ie_version >= 9) cm.display.inputHasSelection = null; - fastPoll(cm); + cm.display.input.onKeyPress(e); } // FOCUS/BLUR EVENTS + function delayBlurEvent(cm) { + cm.state.delayingBlurEvent = true; + setTimeout(function() { + if (cm.state.delayingBlurEvent) { + cm.state.delayingBlurEvent = false; + onBlur(cm); + } + }, 100); + } + function onFocus(cm) { + if (cm.state.delayingBlurEvent) cm.state.delayingBlurEvent = false; + if (cm.options.readOnly == "nocursor") return; if (!cm.state.focused) { signal(cm, "focus", cm); cm.state.focused = true; addClass(cm.display.wrapper, "CodeMirror-focused"); - // The prevInput test prevents this from firing when a context - // menu is closed (since the resetInput would kill the + // This test prevents this from firing when a context + // menu is closed (since the input reset would kill the // select-all detection hack) if (!cm.curOp && cm.display.selForContextMenu != cm.doc.sel) { - resetInput(cm); - if (webkit) setTimeout(bind(resetInput, cm, true), 0); // Issue #1730 + cm.display.input.reset(); + if (webkit) setTimeout(function() { cm.display.input.reset(true); }, 20); // Issue #1730 } + cm.display.input.receivedFocus(); } - slowPoll(cm); restartBlink(cm); } function onBlur(cm) { + if (cm.state.delayingBlurEvent) return; + if (cm.state.focused) { signal(cm, "blur", cm); cm.state.focused = false; @@ -3326,83 +4287,14 @@ // textarea (making it as unobtrusive as possible) to let the // right-click take effect on it. function onContextMenu(cm, e) { + if (eventInWidget(cm.display, e) || contextMenuInGutter(cm, e)) return; if (signalDOMEvent(cm, e, "contextmenu")) return; - var display = cm.display; - if (eventInWidget(display, e) || contextMenuInGutter(cm, e)) return; - - var pos = posFromMouse(cm, e), scrollPos = display.scroller.scrollTop; - if (!pos || presto) return; // Opera is difficult. - - // Reset the current text selection only if the click is done outside of the selection - // and 'resetSelectionOnContextMenu' option is true. - var reset = cm.options.resetSelectionOnContextMenu; - if (reset && cm.doc.sel.contains(pos) == -1) - operation(cm, setSelection)(cm.doc, simpleSelection(pos), sel_dontScroll); - - var oldCSS = display.input.style.cssText; - display.inputDiv.style.position = "absolute"; - display.input.style.cssText = "position: fixed; width: 30px; height: 30px; top: " + (e.clientY - 5) + - "px; left: " + (e.clientX - 5) + "px; z-index: 1000; background: " + - (ie ? "rgba(255, 255, 255, .05)" : "transparent") + - "; outline: none; border-width: 0; outline: none; overflow: hidden; opacity: .05; filter: alpha(opacity=5);"; - if (webkit) var oldScrollY = window.scrollY; // Work around Chrome issue (#2712) - focusInput(cm); - if (webkit) window.scrollTo(null, oldScrollY); - resetInput(cm); - // Adds "Select all" to context menu in FF - if (!cm.somethingSelected()) display.input.value = display.prevInput = " "; - display.selForContextMenu = cm.doc.sel; - clearTimeout(display.detectingSelectAll); - - // Select-all will be greyed out if there's nothing to select, so - // this adds a zero-width space so that we can later check whether - // it got selected. - function prepareSelectAllHack() { - if (display.input.selectionStart != null) { - var selected = cm.somethingSelected(); - var extval = display.input.value = "\u200b" + (selected ? display.input.value : ""); - display.prevInput = selected ? "" : "\u200b"; - display.input.selectionStart = 1; display.input.selectionEnd = extval.length; - // Re-set this, in case some other handler touched the - // selection in the meantime. - display.selForContextMenu = cm.doc.sel; - } - } - function rehide() { - display.inputDiv.style.position = "relative"; - display.input.style.cssText = oldCSS; - if (ie && ie_version < 9) display.scrollbarV.scrollTop = display.scroller.scrollTop = scrollPos; - slowPoll(cm); - - // Try to detect the user choosing select-all - if (display.input.selectionStart != null) { - if (!ie || (ie && ie_version < 9)) prepareSelectAllHack(); - var i = 0, poll = function() { - if (display.selForContextMenu == cm.doc.sel && display.input.selectionStart == 0) - operation(cm, commands.selectAll)(cm); - else if (i++ < 10) display.detectingSelectAll = setTimeout(poll, 500); - else resetInput(cm); - }; - display.detectingSelectAll = setTimeout(poll, 200); - } - } - - if (ie && ie_version >= 9) prepareSelectAllHack(); - if (captureRightClick) { - e_stop(e); - var mouseup = function() { - off(window, "mouseup", mouseup); - setTimeout(rehide, 20); - }; - on(window, "mouseup", mouseup); - } else { - setTimeout(rehide, 50); - } + cm.display.input.onContextMenu(e); } function contextMenuInGutter(cm, e) { if (!hasHandler(cm, "gutterContextMenu")) return false; - return gutterEvent(cm, e, "gutterContextMenu", false, signal); + return gutterEvent(cm, e, "gutterContextMenu", false); } // UPDATING @@ -3530,7 +4422,7 @@ // Revert a change stored in a document's history. function makeChangeFromHistory(doc, type, allowSelectionOnly) { - if (doc.cm && doc.cm.state.suppressEdits) return; + if (doc.cm && doc.cm.state.suppressEdits && !allowSelectionOnly) return; var hist = doc.history, event, selAfter = doc.sel; var source = type == "undo" ? hist.done : hist.undone, dest = type == "undo" ? hist.undone : hist.done; @@ -3682,7 +4574,9 @@ var lendiff = change.text.length - (to.line - from.line) - 1; // Remember that these lines changed, for updating the display - if (from.line == to.line && change.text.length == 1 && !isWholeLineUpdate(cm.doc, change)) + if (change.full) + regChange(cm); + else if (from.line == to.line && change.text.length == 1 && !isWholeLineUpdate(cm.doc, change)) regLineChange(cm, from.line, "text"); else regChange(cm, from.line, to.line + 1, lendiff); @@ -3704,7 +4598,7 @@ function replaceRange(doc, code, from, to, origin) { if (!to) to = from; if (cmp(to, from) < 0) { var tmp = to; to = from; from = tmp; } - if (typeof code == "string") code = splitLines(code); + if (typeof code == "string") code = doc.splitLines(code); makeChange(doc, {from: from, to: to, text: code, origin: origin}); } @@ -3721,7 +4615,7 @@ if (doScroll != null && !phantom) { var scrollNode = elt("div", "\u200b", null, "position: absolute; top: " + (coords.top - display.viewOffset - paddingTop(cm.display)) + "px; height: " + - (coords.bottom - coords.top + scrollerCutOff) + "px; left: " + + (coords.bottom - coords.top + scrollGap(cm) + display.barHeight) + "px; left: " + coords.left + "px; width: 2px;"); cm.display.lineSpace.appendChild(scrollNode); scrollNode.scrollIntoView(doScroll); @@ -3750,8 +4644,9 @@ setScrollLeft(cm, scrollPos.scrollLeft); if (Math.abs(cm.doc.scrollLeft - startLeft) > 1) changed = true; } - if (!changed) return coords; + if (!changed) break; } + return coords; } // Scroll a given set of coordinates into view (immediately). @@ -3769,7 +4664,7 @@ var display = cm.display, snapMargin = textHeight(cm.display); if (y1 < 0) y1 = 0; var screentop = cm.curOp && cm.curOp.scrollTop != null ? cm.curOp.scrollTop : display.scroller.scrollTop; - var screen = display.scroller.clientHeight - scrollerCutOff, result = {}; + var screen = displayHeight(cm), result = {}; if (y2 - y1 > screen) y2 = y1 + screen; var docBottom = cm.doc.height + paddingVert(display); var atTop = y1 < snapMargin, atBottom = y2 > docBottom - snapMargin; @@ -3781,7 +4676,7 @@ } var screenleft = cm.curOp && cm.curOp.scrollLeft != null ? cm.curOp.scrollLeft : display.scroller.scrollLeft; - var screenw = display.scroller.clientWidth - scrollerCutOff - display.gutters.offsetWidth; + var screenw = displayWidth(cm) - (cm.options.fixedGutter ? display.gutters.offsetWidth : 0); var tooWide = x2 - x1 > screenw; if (tooWide) x2 = x1 + screenw; if (x1 < 10) @@ -3790,7 +4685,6 @@ result.scrollLeft = Math.max(0, x1 - (tooWide ? 0 : 10)); else if (x2 > screenw + screenleft - 3) result.scrollLeft = x2 + (tooWide ? 0 : 10) - screenw; - return result; } @@ -3883,6 +4777,8 @@ if (indentString != curSpaceString) { replaceRange(doc, indentString, Pos(n, 0), Pos(n, curSpaceString.length), "+input"); + line.stateAfter = null; + return true; } else { // Ensure that, if the cursor was in the whitespace at the start // of the line, it is moved to the end of that space. @@ -3895,7 +4791,6 @@ } } } - line.stateAfter = null; } // Utility for applying a change to a line by handle or number, @@ -3947,10 +4842,9 @@ function findPosH(doc, pos, dir, unit, visually) { var line = pos.line, ch = pos.ch, origDir = dir; var lineObj = getLine(doc, line); - var possible = true; function findNextLine() { var l = line + dir; - if (l < doc.first || l >= doc.first + doc.size) return (possible = false); + if (l < doc.first || l >= doc.first + doc.size) return false line = l; return lineObj = getLine(doc, l); } @@ -3960,14 +4854,16 @@ if (!boundToLine && findNextLine()) { if (visually) ch = (dir < 0 ? lineRight : lineLeft)(lineObj); else ch = dir < 0 ? lineObj.text.length : 0; - } else return (possible = false); + } else return false } else ch = next; return true; } - if (unit == "char") moveOnce(); - else if (unit == "column") moveOnce(true); - else if (unit == "word" || unit == "group") { + if (unit == "char") { + moveOnce() + } else if (unit == "column") { + moveOnce(true) + } else if (unit == "word" || unit == "group") { var sawType = null, group = unit == "group"; var helper = doc.cm && doc.cm.getHelper(pos, "wordChars"); for (var first = true;; first = false) { @@ -3987,8 +4883,8 @@ if (dir > 0 && !moveOnce(!first)) break; } } - var result = skipAtomic(doc, Pos(line, ch), origDir, true); - if (!possible) result.hitSide = true; + var result = skipAtomic(doc, Pos(line, ch), pos, origDir, true); + if (!cmp(pos, result)) result.hitSide = true; return result; } @@ -4024,7 +4920,7 @@ CodeMirror.prototype = { constructor: CodeMirror, - focus: function(){window.focus(); focusInput(this); fastPoll(this);}, + focus: function(){window.focus(); this.display.input.focus();}, setOption: function(option, value) { var options = this.options, old = options[option]; @@ -4135,7 +5031,7 @@ getHelpers: function(pos, type) { var found = []; - if (!helpers.hasOwnProperty(type)) return helpers; + if (!helpers.hasOwnProperty(type)) return found; var help = helpers[type], mode = this.getModeAt(pos); if (typeof mode[type] == "string") { if (help[mode[type]]) found.push(help[mode[type]]); @@ -4185,10 +5081,15 @@ return lineAtHeight(this.doc, height + this.display.viewOffset); }, heightAtLine: function(line, mode) { - var end = false, last = this.doc.first + this.doc.size - 1; - if (line < this.doc.first) line = this.doc.first; - else if (line > last) { line = last; end = true; } - var lineObj = getLine(this.doc, line); + var end = false, lineObj; + if (typeof line == "number") { + var last = this.doc.first + this.doc.size - 1; + if (line < this.doc.first) line = this.doc.first; + else if (line > last) { line = last; end = true; } + lineObj = getLine(this.doc, line); + } else { + lineObj = line; + } return intoCoordSystem(this, lineObj, {top: 0, left: 0}, mode || "page").top + (end ? this.doc.height - heightAtLine(lineObj) : 0); }, @@ -4217,12 +5118,6 @@ }); }), - addLineWidget: methodOp(function(handle, node, options) { - return addLineWidget(this, handle, node, options); - }), - - removeLineWidget: function(widget) { widget.clear(); }, - lineInfo: function(line) { if (typeof line == "number") { if (!isLine(this.doc, line)) return null; @@ -4245,6 +5140,8 @@ pos = cursorCoords(this, clipPos(this.doc, pos)); var top = pos.bottom, left = pos.left; node.style.position = "absolute"; + node.setAttribute("cm-ignore-events", "true"); + this.display.input.setUneditable(node); display.sizer.appendChild(node); if (vert == "over") { top = pos.top; @@ -4279,9 +5176,11 @@ execCommand: function(cmd) { if (commands.hasOwnProperty(cmd)) - return commands[cmd](this); + return commands[cmd].call(null, this); }, + triggerElectric: methodOp(function(text) { triggerElectric(this, text); }), + findPosH: function(from, amount, unit, visually) { var dir = 1; if (amount < 0) { dir = -1; amount = -amount; } @@ -4371,7 +5270,8 @@ signal(this, "overwriteToggle", this, this.state.overwrite); }, - hasFocus: function() { return activeElt() == this.display.input; }, + hasFocus: function() { return this.display.input.getField() == activeElt(); }, + isReadOnly: function() { return !!(this.options.readOnly || this.doc.cantEdit); }, scrollTo: methodOp(function(x, y) { if (x != null || y != null) resolveScrollToPos(this); @@ -4379,10 +5279,11 @@ if (y != null) this.curOp.scrollTop = y; }), getScrollInfo: function() { - var scroller = this.display.scroller, co = scrollerCutOff; + var scroller = this.display.scroller; return {left: scroller.scrollLeft, top: scroller.scrollTop, - height: scroller.scrollHeight - co, width: scroller.scrollWidth - co, - clientHeight: scroller.clientHeight - co, clientWidth: scroller.clientWidth - co}; + height: scroller.scrollHeight - scrollGap(this) - this.display.barHeight, + width: scroller.scrollWidth - scrollGap(this) - this.display.barWidth, + clientHeight: displayHeight(this), clientWidth: displayWidth(this)}; }, scrollIntoView: methodOp(function(range, margin) { @@ -4446,14 +5347,14 @@ old.cm = null; attachDoc(this, doc); clearCaches(this); - resetInput(this); + this.display.input.reset(); this.scrollTo(doc.scrollLeft, doc.scrollTop); this.curOp.forceScroll = true; signalLater(this, "swapDoc", this, old); return old; }), - getInputField: function(){return this.display.input;}, + getInputField: function(){return this.display.input.getField();}, getWrapperElement: function(){return this.display.wrapper;}, getScrollerElement: function(){return this.display.scroller;}, getGutterElement: function(){return this.display.gutters;} @@ -4494,12 +5395,31 @@ clearCaches(cm); regChange(cm); }, true); - option("specialChars", /[\t\u0000-\u0019\u00ad\u200b-\u200f\u2028\u2029\ufeff]/g, function(cm, val) { - cm.options.specialChars = new RegExp(val.source + (val.test("\t") ? "" : "|\t"), "g"); - cm.refresh(); - }, true); + option("lineSeparator", null, function(cm, val) { + cm.doc.lineSep = val; + if (!val) return; + var newBreaks = [], lineNo = cm.doc.first; + cm.doc.iter(function(line) { + for (var pos = 0;;) { + var found = line.text.indexOf(val, pos); + if (found == -1) break; + pos = found + val.length; + newBreaks.push(Pos(lineNo, found)); + } + lineNo++; + }); + for (var i = newBreaks.length - 1; i >= 0; i--) + replaceRange(cm.doc, val, newBreaks[i], Pos(newBreaks[i].line, newBreaks[i].ch + val.length)) + }); + option("specialChars", /[\u0000-\u001f\u007f\u00ad\u200b-\u200f\u2028\u2029\ufeff]/g, function(cm, val, old) { + cm.state.specialChars = new RegExp(val.source + (val.test("\t") ? "" : "|\t"), "g"); + if (old != CodeMirror.Init) cm.refresh(); + }); option("specialCharPlaceholder", defaultSpecialCharPlaceholder, function(cm) {cm.refresh();}, true); option("electricChars", true); + option("inputStyle", mobile ? "contenteditable" : "textarea", function() { + throw new Error("inputStyle can not (yet) be changed in a running editor"); // FIXME + }, true); option("rtlMoveVisually", !windows); option("wholeLineUpdateBefore", true); @@ -4524,7 +5444,13 @@ cm.display.gutters.style.left = val ? compensateForHScroll(cm.display) + "px" : "0"; cm.refresh(); }, true); - option("coverGutterNextToScrollbar", false, updateScrollbars, true); + option("coverGutterNextToScrollbar", false, function(cm) {updateScrollbars(cm);}, true); + option("scrollbarStyle", "native", function(cm) { + initScrollbars(cm); + updateScrollbars(cm); + cm.display.scrollbars.setScrollTop(cm.doc.scrollTop); + cm.display.scrollbars.setScrollLeft(cm.doc.scrollLeft); + }, true); option("lineNumbers", false, function(cm) { setGuttersForLineNumbers(cm.options); guttersChanged(cm); @@ -4534,6 +5460,7 @@ option("showCursorWhenSelecting", false, updateSelection, true); option("resetSelectionOnContextMenu", true); + option("lineWiseCopyCut", true); option("readOnly", false, function(cm, val) { if (val == "nocursor") { @@ -4542,11 +5469,12 @@ cm.display.disabled = true; } else { cm.display.disabled = false; - if (!val) resetInput(cm); } + cm.display.input.readOnlyChanged(val) }); - option("disableInput", false, function(cm, val) {if (!val) resetInput(cm);}, true); - option("dragDrop", true); + option("disableInput", false, function(cm, val) {if (!val) cm.display.input.reset();}, true); + option("dragDrop", true, dragDropChanged); + option("allowDropFileTypes", null); option("cursorBlinkRate", 530); option("cursorScrollMargin", 0); @@ -4562,11 +5490,11 @@ option("viewportMargin", 10, function(cm){cm.refresh();}, true); option("maxHighlightLength", 10000, resetModeState, true); option("moveInputWithCursor", true, function(cm, val) { - if (!val) cm.display.inputDiv.style.top = cm.display.inputDiv.style.left = 0; + if (!val) cm.display.input.resetPosition(); }); option("tabindex", null, function(cm, val) { - cm.display.input.tabIndex = val || ""; + cm.display.input.getField().tabIndex = val || ""; }); option("autofocus", null); @@ -4812,7 +5740,7 @@ for (var i = 0; i < ranges.length; i++) { var pos = ranges[i].from(); var col = countColumn(cm.getLine(pos.line), pos.ch, tabSize); - spaces.push(new Array(tabSize - col % tabSize + 1).join(" ")); + spaces.push(spaceStr(tabSize - col % tabSize)); } cm.replaceSelections(spaces); }, @@ -4834,7 +5762,8 @@ } else if (cur.line > cm.doc.first) { var prev = getLine(cm.doc, cur.line - 1).text; if (prev) - cm.replaceRange(line.charAt(0) + "\n" + prev.charAt(prev.length - 1), + cm.replaceRange(line.charAt(0) + cm.doc.lineSeparator() + + prev.charAt(prev.length - 1), Pos(cur.line - 1, prev.length - 1), Pos(cur.line, 1), "+transpose"); } } @@ -4848,12 +5777,13 @@ var len = cm.listSelections().length; for (var i = 0; i < len; i++) { var range = cm.listSelections()[i]; - cm.replaceRange("\n", range.anchor, range.head, "+input"); + cm.replaceRange(cm.doc.lineSeparator(), range.anchor, range.head, "+input"); cm.indentLine(range.from().line + 1, null, true); - ensureCursorVisible(cm); } + ensureCursorVisible(cm); }); }, + openLine: function(cm) {cm.replaceSelection("\n", "start")}, toggleOverwrite: function(cm) {cm.toggleOverwrite();} }; @@ -4888,7 +5818,8 @@ "Ctrl-F": "goCharRight", "Ctrl-B": "goCharLeft", "Ctrl-P": "goLineUp", "Ctrl-N": "goLineDown", "Alt-F": "goWordRight", "Alt-B": "goWordLeft", "Ctrl-A": "goLineStart", "Ctrl-E": "goLineEnd", "Ctrl-V": "goPageDown", "Shift-Ctrl-V": "goPageUp", "Ctrl-D": "delCharAfter", "Ctrl-H": "delCharBefore", - "Alt-D": "delWordAfter", "Alt-Backspace": "delWordBefore", "Ctrl-K": "killLine", "Ctrl-T": "transposeChars" + "Alt-D": "delWordAfter", "Alt-Backspace": "delWordBefore", "Ctrl-K": "killLine", "Ctrl-T": "transposeChars", + "Ctrl-O": "openLine" }; keyMap.macDefault = { "Cmd-A": "selectAll", "Cmd-D": "deleteLine", "Cmd-Z": "undo", "Shift-Cmd-Z": "redo", "Cmd-Y": "redo", @@ -4938,7 +5869,7 @@ for (var i = 0; i < keys.length; i++) { var val, name; if (i == keys.length - 1) { - name = keyname; + name = keys.join(" "); val = value; } else { name = keys.slice(0, i + 1).join(" "); @@ -4954,18 +5885,18 @@ return keymap; }; - var lookupKey = CodeMirror.lookupKey = function(key, map, handle) { + var lookupKey = CodeMirror.lookupKey = function(key, map, handle, context) { map = getKeyMap(map); - var found = map.call ? map.call(key) : map[key]; + var found = map.call ? map.call(key, context) : map[key]; if (found === false) return "nothing"; if (found === "...") return "multi"; if (found != null && handle(found)) return "handled"; if (map.fallthrough) { if (Object.prototype.toString.call(map.fallthrough) != "[object Array]") - return lookupKey(key, map.fallthrough, handle); + return lookupKey(key, map.fallthrough, handle, context); for (var i = 0; i < map.fallthrough.length; i++) { - var result = lookupKey(key, map.fallthrough[i], handle); + var result = lookupKey(key, map.fallthrough[i], handle, context); if (result) return result; } } @@ -4997,10 +5928,10 @@ // FROMTEXTAREA CodeMirror.fromTextArea = function(textarea, options) { - if (!options) options = {}; + options = options ? copyObj(options) : {}; options.value = textarea.value; - if (!options.tabindex && textarea.tabindex) - options.tabindex = textarea.tabindex; + if (!options.tabindex && textarea.tabIndex) + options.tabindex = textarea.tabIndex; if (!options.placeholder && textarea.placeholder) options.placeholder = textarea.placeholder; // Set autofocus to true if this textarea is focused, or if it has @@ -5028,23 +5959,26 @@ } } + options.finishInit = function(cm) { + cm.save = save; + cm.getTextArea = function() { return textarea; }; + cm.toTextArea = function() { + cm.toTextArea = isNaN; // Prevent this from being ran twice + save(); + textarea.parentNode.removeChild(cm.getWrapperElement()); + textarea.style.display = ""; + if (textarea.form) { + off(textarea.form, "submit", save); + if (typeof textarea.form.submit == "function") + textarea.form.submit = realSubmit; + } + }; + }; + textarea.style.display = "none"; var cm = CodeMirror(function(node) { textarea.parentNode.insertBefore(node, textarea.nextSibling); }, options); - cm.save = save; - cm.getTextArea = function() { return textarea; }; - cm.toTextArea = function() { - cm.toTextArea = isNaN; // Prevent this from being ran twice - save(); - textarea.parentNode.removeChild(cm.getWrapperElement()); - textarea.style.display = ""; - if (textarea.form) { - off(textarea.form, "submit", save); - if (typeof textarea.form.submit == "function") - textarea.form.submit = realSubmit; - } - }; return cm; }; @@ -5137,10 +6071,13 @@ // marker continues beyond the start/end of the line. Markers have // links back to the lines they currently touch. + var nextMarkerId = 0; + var TextMarker = CodeMirror.TextMarker = function(doc, type) { this.lines = []; this.type = type; this.doc = doc; + this.id = ++nextMarkerId; }; eventMixin(TextMarker); @@ -5272,7 +6209,7 @@ // Showing up as a widget implies collapsed (widget replaces text) marker.collapsed = true; marker.widgetNode = elt("span", [marker.replacedWith], "CodeMirror-widget"); - if (!options.handleMouseEvents) marker.widgetNode.ignoreEvents = true; + if (!options.handleMouseEvents) marker.widgetNode.setAttribute("cm-ignore-events", "true"); if (options.insertLeft) marker.widgetNode.insertLeft = true; } if (marker.collapsed) { @@ -5316,7 +6253,7 @@ if (updateMaxLine) cm.curOp.updateMaxLine = true; if (marker.collapsed) regChange(cm, from.line, to.line + 1); - else if (marker.className || marker.title || marker.startStyle || marker.endStyle) + else if (marker.className || marker.title || marker.startStyle || marker.endStyle || marker.css) for (var i = from.line; i <= to.line; i++) regLineChange(cm, i, "text"); if (marker.atomic) reCheckSelection(cm.doc); signalLater(cm, "markerAdded", cm, marker); @@ -5456,6 +6393,7 @@ // spans partially within the change. Returns an array of span // arrays with one element for each line in (after) the change. function stretchSpansOverChange(doc, change) { + if (change.full) return null; var oldFirst = isLine(doc, change.from.line) && getLine(doc, change.from.line).markedSpans; var oldLast = isLine(doc, change.to.line) && getLine(doc, change.to.line).markedSpans; if (!oldFirst && !oldLast) return null; @@ -5643,8 +6581,8 @@ var fromCmp = cmp(found.from, from) || extraLeft(sp.marker) - extraLeft(marker); var toCmp = cmp(found.to, to) || extraRight(sp.marker) - extraRight(marker); if (fromCmp >= 0 && toCmp <= 0 || fromCmp <= 0 && toCmp >= 0) continue; - if (fromCmp <= 0 && (cmp(found.to, from) > 0 || (sp.marker.inclusiveRight && marker.inclusiveLeft)) || - fromCmp >= 0 && (cmp(found.from, to) < 0 || (sp.marker.inclusiveLeft && marker.inclusiveRight))) + if (fromCmp <= 0 && (sp.marker.inclusiveRight && marker.inclusiveLeft ? cmp(found.to, from) >= 0 : cmp(found.to, from) > 0) || + fromCmp >= 0 && (sp.marker.inclusiveRight && marker.inclusiveLeft ? cmp(found.from, to) <= 0 : cmp(found.from, to) < 0)) return true; } } @@ -5723,10 +6661,10 @@ // Line widgets are block elements displayed above or below a line. - var LineWidget = CodeMirror.LineWidget = function(cm, node, options) { + var LineWidget = CodeMirror.LineWidget = function(doc, node, options) { if (options) for (var opt in options) if (options.hasOwnProperty(opt)) this[opt] = options[opt]; - this.cm = cm; + this.doc = doc; this.node = node; }; eventMixin(LineWidget); @@ -5737,50 +6675,55 @@ } LineWidget.prototype.clear = function() { - var cm = this.cm, ws = this.line.widgets, line = this.line, no = lineNo(line); + var cm = this.doc.cm, ws = this.line.widgets, line = this.line, no = lineNo(line); if (no == null || !ws) return; for (var i = 0; i < ws.length; ++i) if (ws[i] == this) ws.splice(i--, 1); if (!ws.length) line.widgets = null; var height = widgetHeight(this); - runInOp(cm, function() { + updateLineHeight(line, Math.max(0, line.height - height)); + if (cm) runInOp(cm, function() { adjustScrollWhenAboveVisible(cm, line, -height); regLineChange(cm, no, "widget"); - updateLineHeight(line, Math.max(0, line.height - height)); }); }; LineWidget.prototype.changed = function() { - var oldH = this.height, cm = this.cm, line = this.line; + var oldH = this.height, cm = this.doc.cm, line = this.line; this.height = null; var diff = widgetHeight(this) - oldH; if (!diff) return; - runInOp(cm, function() { + updateLineHeight(line, line.height + diff); + if (cm) runInOp(cm, function() { cm.curOp.forceUpdate = true; adjustScrollWhenAboveVisible(cm, line, diff); - updateLineHeight(line, line.height + diff); }); }; function widgetHeight(widget) { if (widget.height != null) return widget.height; + var cm = widget.doc.cm; + if (!cm) return 0; if (!contains(document.body, widget.node)) { var parentStyle = "position: relative;"; if (widget.coverGutter) - parentStyle += "margin-left: -" + widget.cm.getGutterElement().offsetWidth + "px;"; - removeChildrenAndAdd(widget.cm.display.measure, elt("div", [widget.node], null, parentStyle)); + parentStyle += "margin-left: -" + cm.display.gutters.offsetWidth + "px;"; + if (widget.noHScroll) + parentStyle += "width: " + cm.display.wrapper.clientWidth + "px;"; + removeChildrenAndAdd(cm.display.measure, elt("div", [widget.node], null, parentStyle)); } - return widget.height = widget.node.offsetHeight; + return widget.height = widget.node.parentNode.offsetHeight; } - function addLineWidget(cm, handle, node, options) { - var widget = new LineWidget(cm, node, options); - if (widget.noHScroll) cm.display.alignWidgets = true; - changeLine(cm.doc, handle, "widget", function(line) { + function addLineWidget(doc, handle, node, options) { + var widget = new LineWidget(doc, node, options); + var cm = doc.cm; + if (cm && widget.noHScroll) cm.display.alignWidgets = true; + changeLine(doc, handle, "widget", function(line) { var widgets = line.widgets || (line.widgets = []); if (widget.insertAt == null) widgets.push(widget); else widgets.splice(Math.min(widgets.length - 1, Math.max(0, widget.insertAt)), 0, widget); widget.line = line; - if (!lineIsHidden(cm.doc, line)) { - var aboveVisible = heightAtLine(line) < cm.doc.scrollTop; + if (cm && !lineIsHidden(doc, line)) { + var aboveVisible = heightAtLine(line) < doc.scrollTop; updateLineHeight(line, line.height + widgetHeight(widget)); if (aboveVisible) addToScrollPos(cm, null, widget.height); cm.curOp.forceUpdate = true; @@ -5896,8 +6839,11 @@ if (mName) style = "m-" + (style ? mName + " " + style : mName); } if (!flattenSpans || curStyle != style) { - if (curStart < stream.start) f(stream.start, curStyle); - curStart = stream.start; curStyle = style; + while (curStart < stream.start) { + curStart = Math.min(stream.start, curStart + 50000); + f(curStart, curStyle); + } + curStyle = style; } stream.start = stream.pos; } @@ -5953,7 +6899,9 @@ function getLineStyles(cm, line, updateFrontier) { if (!line.styles || line.styles[0] != cm.state.modeGen) { - var result = highlightLine(cm, line, line.stateAfter = getStateBefore(cm, lineNo(line))); + var state = getStateBefore(cm, lineNo(line)); + var result = highlightLine(cm, line, line.text.length > cm.options.maxHighlightLength ? copyState(cm.doc.mode, state) : state); + line.stateAfter = state; line.styles = result.styles; if (result.classes) line.styleClasses = result.classes; else if (line.styleClasses) line.styleClasses = null; @@ -5970,7 +6918,7 @@ var stream = new StringStream(text, cm.options.tabSize); stream.start = stream.pos = startAt || 0; if (text == "") callBlankLine(mode, state); - while (!stream.eol() && stream.pos <= cm.options.maxHighlightLength) { + while (!stream.eol()) { readToken(mode, stream, state); stream.start = stream.pos; } @@ -5997,7 +6945,10 @@ // is needed on Webkit to be able to get line-level bounding // rectangles for it (in measureChar). var content = elt("span", null, null, webkit ? "padding-right: .1px" : null); - var builder = {pre: elt("pre", [content]), content: content, col: 0, pos: 0, cm: cm}; + var builder = {pre: elt("pre", [content], "CodeMirror-line"), content: content, + col: 0, pos: 0, cm: cm, + trailingSpace: false, + splitSpaces: (ie || webkit) && cm.getOption("lineWrapping")}; lineView.measure = {}; // Iterate over the logical lines that make up this visual line. @@ -6007,8 +6958,6 @@ builder.addToken = buildToken; // Optionally wire in some hacks into the token-rendering // algorithm, to deal with browser quirks. - if ((ie || webkit) && cm.getOption("lineWrapping")) - builder.addToken = buildTokenSplitSpaces(builder.addToken); if (hasBadBidiRects(cm.display.measure) && (order = getOrder(line))) builder.addToken = buildTokenBadBidi(builder.addToken, order); builder.map = []; @@ -6036,8 +6985,11 @@ } // See issue #2901 - if (webkit && /\bcm-tab\b/.test(builder.content.lastChild.className)) - builder.content.className = "cm-tab-wrap-hack"; + if (webkit) { + var last = builder.content.lastChild + if (/\bcm-tab\b/.test(last.className) || (last.querySelector && last.querySelector(".cm-tab"))) + builder.content.className = "cm-tab-wrap-hack"; + } signal(cm, "renderLine", cm, lineView.line, builder.pre); if (builder.pre.className) @@ -6049,17 +7001,19 @@ function defaultSpecialCharPlaceholder(ch) { var token = elt("span", "\u2022", "cm-invalidchar"); token.title = "\\u" + ch.charCodeAt(0).toString(16); + token.setAttribute("aria-label", token.title); return token; } // Build up the DOM representation for a single token, and add it to // the line map. Takes care to render special characters separately. - function buildToken(builder, text, style, startStyle, endStyle, title) { + function buildToken(builder, text, style, startStyle, endStyle, title, css) { if (!text) return; - var special = builder.cm.options.specialChars, mustWrap = false; + var displayText = builder.splitSpaces ? splitSpaces(text, builder.trailingSpace) : text + var special = builder.cm.state.specialChars, mustWrap = false; if (!special.test(text)) { builder.col += text.length; - var content = document.createTextNode(text); + var content = document.createTextNode(displayText); builder.map.push(builder.pos, builder.pos + text.length, content); if (ie && ie_version < 9) mustWrap = true; builder.pos += text.length; @@ -6070,7 +7024,7 @@ var m = special.exec(text); var skipped = m ? m.index - pos : text.length - pos; if (skipped) { - var txt = document.createTextNode(text.slice(pos, pos + skipped)); + var txt = document.createTextNode(displayText.slice(pos, pos + skipped)); if (ie && ie_version < 9) content.appendChild(elt("span", [txt])); else content.appendChild(txt); builder.map.push(builder.pos, builder.pos + skipped, txt); @@ -6082,9 +7036,16 @@ if (m[0] == "\t") { var tabSize = builder.cm.options.tabSize, tabWidth = tabSize - builder.col % tabSize; var txt = content.appendChild(elt("span", spaceStr(tabWidth), "cm-tab")); + txt.setAttribute("role", "presentation"); + txt.setAttribute("cm-text", "\t"); builder.col += tabWidth; + } else if (m[0] == "\r" || m[0] == "\n") { + var txt = content.appendChild(elt("span", m[0] == "\r" ? "\u240d" : "\u2424", "cm-invalidchar")); + txt.setAttribute("cm-text", m[0]); + builder.col += 1; } else { var txt = builder.cm.options.specialCharPlaceholder(m[0]); + txt.setAttribute("cm-text", m[0]); if (ie && ie_version < 9) content.appendChild(elt("span", [txt])); else content.appendChild(txt); builder.col += 1; @@ -6093,33 +7054,35 @@ builder.pos++; } } - if (style || startStyle || endStyle || mustWrap) { + builder.trailingSpace = displayText.charCodeAt(text.length - 1) == 32 + if (style || startStyle || endStyle || mustWrap || css) { var fullStyle = style || ""; if (startStyle) fullStyle += startStyle; if (endStyle) fullStyle += endStyle; - var token = elt("span", [content], fullStyle); + var token = elt("span", [content], fullStyle, css); if (title) token.title = title; return builder.content.appendChild(token); } builder.content.appendChild(content); } - function buildTokenSplitSpaces(inner) { - function split(old) { - var out = " "; - for (var i = 0; i < old.length - 2; ++i) out += i % 2 ? " " : "\u00a0"; - out += " "; - return out; + function splitSpaces(text, trailingBefore) { + if (text.length > 1 && !/ /.test(text)) return text + var spaceBefore = trailingBefore, result = "" + for (var i = 0; i < text.length; i++) { + var ch = text.charAt(i) + if (ch == " " && spaceBefore && (i == text.length - 1 || text.charCodeAt(i + 1) == 32)) + ch = "\u00a0" + result += ch + spaceBefore = ch == " " } - return function(builder, text, style, startStyle, endStyle, title) { - inner(builder, text.replace(/ {3,}/g, split), style, startStyle, endStyle, title); - }; + return result } // Work around nonsense dimensions being reported for stretches of // right-to-left text. function buildTokenBadBidi(inner, order) { - return function(builder, text, style, startStyle, endStyle, title) { + return function(builder, text, style, startStyle, endStyle, title, css) { style = style ? style + " cm-force-border" : "cm-force-border"; var start = builder.pos, end = start + text.length; for (;;) { @@ -6128,8 +7091,8 @@ var part = order[i]; if (part.to > start && part.from <= start) break; } - if (part.to >= end) return inner(builder, text, style, startStyle, endStyle, title); - inner(builder, text.slice(0, part.to - start), style, startStyle, null, title); + if (part.to >= end) return inner(builder, text, style, startStyle, endStyle, title, css); + inner(builder, text.slice(0, part.to - start), style, startStyle, null, title, css); startStyle = null; text = text.slice(part.to - start); start = part.to; @@ -6139,11 +7102,18 @@ function buildCollapsedSpan(builder, size, marker, ignoreWidget) { var widget = !ignoreWidget && marker.widgetNode; + if (widget) builder.map.push(builder.pos, builder.pos + size, widget); + if (!ignoreWidget && builder.cm.display.input.needsContentAttribute) { + if (!widget) + widget = builder.content.appendChild(document.createElement("span")); + widget.setAttribute("cm-marker", marker.id); + } if (widget) { - builder.map.push(builder.pos, builder.pos + size, widget); + builder.cm.display.input.setUneditable(widget); builder.content.appendChild(widget); } builder.pos += size; + builder.trailingSpace = false } // Outputs a number of spans to make up a line, taking highlighting @@ -6156,35 +7126,44 @@ return; } - var len = allText.length, pos = 0, i = 1, text = "", style; + var len = allText.length, pos = 0, i = 1, text = "", style, css; var nextChange = 0, spanStyle, spanEndStyle, spanStartStyle, title, collapsed; for (;;) { if (nextChange == pos) { // Update current marker set - spanStyle = spanEndStyle = spanStartStyle = title = ""; + spanStyle = spanEndStyle = spanStartStyle = title = css = ""; collapsed = null; nextChange = Infinity; - var foundBookmarks = []; + var foundBookmarks = [], endStyles for (var j = 0; j < spans.length; ++j) { var sp = spans[j], m = sp.marker; - if (sp.from <= pos && (sp.to == null || sp.to > pos)) { - if (sp.to != null && nextChange > sp.to) { nextChange = sp.to; spanEndStyle = ""; } + if (m.type == "bookmark" && sp.from == pos && m.widgetNode) { + foundBookmarks.push(m); + } else if (sp.from <= pos && (sp.to == null || sp.to > pos || m.collapsed && sp.to == pos && sp.from == pos)) { + if (sp.to != null && sp.to != pos && nextChange > sp.to) { + nextChange = sp.to; + spanEndStyle = ""; + } if (m.className) spanStyle += " " + m.className; + if (m.css) css = (css ? css + ";" : "") + m.css; if (m.startStyle && sp.from == pos) spanStartStyle += " " + m.startStyle; - if (m.endStyle && sp.to == nextChange) spanEndStyle += " " + m.endStyle; + if (m.endStyle && sp.to == nextChange) (endStyles || (endStyles = [])).push(m.endStyle, sp.to) if (m.title && !title) title = m.title; if (m.collapsed && (!collapsed || compareCollapsedMarkers(collapsed.marker, m) < 0)) collapsed = sp; } else if (sp.from > pos && nextChange > sp.from) { nextChange = sp.from; } - if (m.type == "bookmark" && sp.from == pos && m.widgetNode) foundBookmarks.push(m); } + if (endStyles) for (var j = 0; j < endStyles.length; j += 2) + if (endStyles[j + 1] == nextChange) spanEndStyle += " " + endStyles[j] + + if (!collapsed || collapsed.from == pos) for (var j = 0; j < foundBookmarks.length; ++j) + buildCollapsedSpan(builder, 0, foundBookmarks[j]); if (collapsed && (collapsed.from || 0) == pos) { buildCollapsedSpan(builder, (collapsed.to == null ? len + 1 : collapsed.to) - pos, collapsed.marker, collapsed.from == null); if (collapsed.to == null) return; + if (collapsed.to == pos) collapsed = false; } - if (!collapsed && foundBookmarks.length) for (var j = 0; j < foundBookmarks.length; ++j) - buildCollapsedSpan(builder, 0, foundBookmarks[j]); } if (pos >= len) break; @@ -6195,7 +7174,7 @@ if (!collapsed) { var tokenText = end > upto ? text.slice(0, upto - pos) : text; builder.addToken(builder, tokenText, style ? style + spanStyle : spanStyle, - spanStartStyle, pos + tokenText.length == nextChange ? spanEndStyle : "", title); + spanStartStyle, pos + tokenText.length == nextChange ? spanEndStyle : "", title, css); } if (end >= upto) {text = text.slice(upto - pos); pos = upto; break;} pos = end; @@ -6224,17 +7203,24 @@ updateLine(line, text, spans, estimateHeight); signalLater(line, "change", line, change); } + function linesFor(start, end) { + for (var i = start, result = []; i < end; ++i) + result.push(new Line(text[i], spansFor(i), estimateHeight)); + return result; + } var from = change.from, to = change.to, text = change.text; var firstLine = getLine(doc, from.line), lastLine = getLine(doc, to.line); var lastText = lst(text), lastSpans = spansFor(text.length - 1), nlines = to.line - from.line; // Adjust the line structure - if (isWholeLineUpdate(doc, change)) { + if (change.full) { + doc.insert(0, linesFor(0, text.length)); + doc.remove(text.length, doc.size - text.length); + } else if (isWholeLineUpdate(doc, change)) { // This is a whole-line replace. Treated specially to make // sure line objects move the way they are supposed to. - for (var i = 0, added = []; i < text.length - 1; ++i) - added.push(new Line(text[i], spansFor(i), estimateHeight)); + var added = linesFor(0, text.length - 1); update(lastLine, lastLine.text, lastSpans); if (nlines) doc.remove(from.line, nlines); if (added.length) doc.insert(from.line, added); @@ -6242,8 +7228,7 @@ if (text.length == 1) { update(firstLine, firstLine.text.slice(0, from.ch) + lastText + firstLine.text.slice(to.ch), lastSpans); } else { - for (var added = [], i = 1; i < text.length - 1; ++i) - added.push(new Line(text[i], spansFor(i), estimateHeight)); + var added = linesFor(1, text.length - 1); added.push(new Line(lastText + firstLine.text.slice(to.ch), lastSpans, estimateHeight)); update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0)); doc.insert(from.line + 1, added); @@ -6254,8 +7239,7 @@ } else { update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0)); update(lastLine, lastText + lastLine.text.slice(to.ch), lastSpans); - for (var i = 1, added = []; i < text.length - 1; ++i) - added.push(new Line(text[i], spansFor(i), estimateHeight)); + var added = linesFor(1, text.length - 1); if (nlines > 1) doc.remove(from.line + 1, nlines - 1); doc.insert(from.line + 1, added); } @@ -6365,13 +7349,16 @@ if (at <= sz) { child.insertInner(at, lines, height); if (child.lines && child.lines.length > 50) { - while (child.lines.length > 50) { - var spilled = child.lines.splice(child.lines.length - 25, 25); - var newleaf = new LeafChunk(spilled); - child.height -= newleaf.height; - this.children.splice(i + 1, 0, newleaf); - newleaf.parent = this; + // To avoid memory thrashing when child.lines is huge (e.g. first view of a large file), it's never spliced. + // Instead, small slices are taken. They're taken in order because sequential memory accesses are fastest. + var remaining = child.lines.length % 25 + 25 + for (var pos = remaining; pos < child.lines.length;) { + var leaf = new LeafChunk(child.lines.slice(pos, pos += 25)); + child.height -= leaf.height; + this.children.splice(++i, 0, leaf); + leaf.parent = this; } + child.lines = child.lines.slice(0, remaining); this.maybeSpill(); } break; @@ -6391,7 +7378,7 @@ copy.parent = me; me.children = [copy, sibling]; me = copy; - } else { + } else { me.size -= sibling.size; me.height -= sibling.height; var myIndex = indexOf(me.parent.children, me); @@ -6415,8 +7402,8 @@ }; var nextDocId = 0; - var Doc = CodeMirror.Doc = function(text, mode, firstLine) { - if (!(this instanceof Doc)) return new Doc(text, mode, firstLine); + var Doc = CodeMirror.Doc = function(text, mode, firstLine, lineSep) { + if (!(this instanceof Doc)) return new Doc(text, mode, firstLine, lineSep); if (firstLine == null) firstLine = 0; BranchChunk.call(this, [new LeafChunk([new Line("", null)])]); @@ -6430,8 +7417,10 @@ this.history = new History(null); this.id = ++nextDocId; this.modeOption = mode; + this.lineSep = lineSep; + this.extend = false; - if (typeof text == "string") text = splitLines(text); + if (typeof text == "string") text = this.splitLines(text); updateDoc(this, {from: start, to: start, text: text}); setSelection(this, simpleSelection(start), sel_dontScroll); }; @@ -6461,12 +7450,12 @@ getValue: function(lineSep) { var lines = getLines(this, this.first, this.first + this.size); if (lineSep === false) return lines; - return lines.join(lineSep || "\n"); + return lines.join(lineSep || this.lineSeparator()); }, setValue: docMethodOp(function(code) { var top = Pos(this.first, 0), last = this.first + this.size - 1; makeChange(this, {from: top, to: Pos(last, getLine(this, last).text.length), - text: splitLines(code), origin: "setValue"}, true); + text: this.splitLines(code), origin: "setValue", full: true}, true); setSelection(this, simpleSelection(top)); }), replaceRange: function(code, from, to, origin) { @@ -6477,7 +7466,7 @@ getRange: function(from, to, lineSep) { var lines = getBetween(this, clipPos(this, from), clipPos(this, to)); if (lineSep === false) return lines; - return lines.join(lineSep || "\n"); + return lines.join(lineSep || this.lineSeparator()); }, getLine: function(line) {var l = this.getLineHandle(line); return l && l.text;}, @@ -6517,10 +7506,11 @@ extendSelection(this, clipPos(this, head), other && clipPos(this, other), options); }), extendSelections: docMethodOp(function(heads, options) { - extendSelections(this, clipPosArray(this, heads, options)); + extendSelections(this, clipPosArray(this, heads), options); }), extendSelectionsBy: docMethodOp(function(f, options) { - extendSelections(this, map(this.sel.ranges, f), options); + var heads = map(this.sel.ranges, f); + extendSelections(this, clipPosArray(this, heads), options); }), setSelections: docMethodOp(function(ranges, primary, options) { if (!ranges.length) return; @@ -6543,13 +7533,13 @@ lines = lines ? lines.concat(sel) : sel; } if (lineSep === false) return lines; - else return lines.join(lineSep || "\n"); + else return lines.join(lineSep || this.lineSeparator()); }, getSelections: function(lineSep) { var parts = [], ranges = this.sel.ranges; for (var i = 0; i < ranges.length; i++) { var sel = getBetween(this, ranges[i].from(), ranges[i].to()); - if (lineSep !== false) sel = sel.join(lineSep || "\n"); + if (lineSep !== false) sel = sel.join(lineSep || this.lineSeparator()); parts[i] = sel; } return parts; @@ -6564,7 +7554,7 @@ var changes = [], sel = this.sel; for (var i = 0; i < sel.ranges.length; i++) { var range = sel.ranges[i]; - changes[i] = {from: range.from(), to: range.to(), text: splitLines(code[i]), origin: origin}; + changes[i] = {from: range.from(), to: range.to(), text: this.splitLines(code[i]), origin: origin}; } var newSel = collapse && collapse != "end" && computeReplacedSel(this, changes, collapse); for (var i = changes.length - 1; i >= 0; i--) @@ -6622,7 +7612,7 @@ }); }), removeLineClass: docMethodOp(function(handle, where, cls) { - return changeLine(this, handle, "class", function(line) { + return changeLine(this, handle, where == "gutter" ? "gutter" : "class", function(line) { var prop = where == "text" ? "textClass" : where == "background" ? "bgClass" : where == "gutter" ? "gutterClass" : "wrapClass"; @@ -6639,13 +7629,19 @@ }); }), + addLineWidget: docMethodOp(function(handle, node, options) { + return addLineWidget(this, handle, node, options); + }), + removeLineWidget: function(widget) { widget.clear(); }, + markText: function(from, to, options) { - return markText(this, clipPos(this, from), clipPos(this, to), options, "range"); + return markText(this, clipPos(this, from), clipPos(this, to), options, options && options.type || "range"); }, setBookmark: function(pos, options) { var realOpts = {replacedWith: options && (options.nodeType == null ? options.widget : options), insertLeft: options && options.insertLeft, - clearWhenEmpty: false, shared: options && options.shared}; + clearWhenEmpty: false, shared: options && options.shared, + handleMouseEvents: options && options.handleMouseEvents}; pos = clipPos(this, pos); return markText(this, pos, pos, realOpts, "bookmark"); }, @@ -6667,9 +7663,9 @@ var spans = line.markedSpans; if (spans) for (var i = 0; i < spans.length; i++) { var span = spans[i]; - if (!(lineNo == from.line && from.ch > span.to || - span.from == null && lineNo != from.line|| - lineNo == to.line && span.from > to.ch) && + if (!(span.to != null && lineNo == from.line && from.ch >= span.to || + span.from == null && lineNo != from.line || + span.from != null && lineNo == to.line && span.from >= to.ch) && (!filter || filter(span.marker))) found.push(span.marker.parent || span.marker); } @@ -6688,9 +7684,9 @@ }, posFromIndex: function(off) { - var ch, lineNo = this.first; + var ch, lineNo = this.first, sepSize = this.lineSeparator().length; this.iter(function(line) { - var sz = line.text.length + 1; + var sz = line.text.length + sepSize; if (sz > off) { ch = off; return true; } off -= sz; ++lineNo; @@ -6701,14 +7697,16 @@ coords = clipPos(this, coords); var index = coords.ch; if (coords.line < this.first || coords.ch < 0) return 0; + var sepSize = this.lineSeparator().length; this.iter(this.first, coords.line, function (line) { - index += line.text.length + 1; + index += line.text.length + sepSize; }); return index; }, copy: function(copyHistory) { - var doc = new Doc(getLines(this, this.first, this.first + this.size), this.modeOption, this.first); + var doc = new Doc(getLines(this, this.first, this.first + this.size), + this.modeOption, this.first, this.lineSep); doc.scrollTop = this.scrollTop; doc.scrollLeft = this.scrollLeft; doc.sel = this.sel; doc.extend = false; @@ -6724,7 +7722,7 @@ var from = this.first, to = this.first + this.size; if (options.from != null && options.from > from) from = options.from; if (options.to != null && options.to < to) to = options.to; - var copy = new Doc(getLines(this, from, to), options.mode || this.modeOption, from); + var copy = new Doc(getLines(this, from, to), options.mode || this.modeOption, from, this.lineSep); if (options.sharedHist) copy.history = this.history; (this.linked || (this.linked = [])).push({doc: copy, sharedHist: options.sharedHist}); copy.linked = [{doc: this, isParent: true, sharedHist: options.sharedHist}]; @@ -6753,14 +7751,20 @@ iterLinkedDocs: function(f) {linkedDocs(this, f);}, getMode: function() {return this.mode;}, - getEditor: function() {return this.cm;} + getEditor: function() {return this.cm;}, + + splitLines: function(str) { + if (this.lineSep) return str.split(this.lineSep); + return splitLinesAuto(str); + }, + lineSeparator: function() { return this.lineSep || "\n"; } }); // Public alias. Doc.prototype.eachLine = Doc.prototype.iter; // Set up methods on CodeMirror's prototype to redirect to the editor's document. - var dontDelegate = "iter insert remove copy getEditor".split(" "); + var dontDelegate = "iter insert remove copy getEditor constructor".split(" "); for (var prop in Doc.prototype) if (Doc.prototype.hasOwnProperty(prop) && indexOf(dontDelegate, prop) < 0) CodeMirror.prototype[prop] = (function(method) { return function() {return method.apply(this.doc, arguments);}; @@ -7193,24 +8197,30 @@ } }; + var noHandlers = [] + function getHandlers(emitter, type, copy) { + var arr = emitter._handlers && emitter._handlers[type] + if (copy) return arr && arr.length > 0 ? arr.slice() : noHandlers + else return arr || noHandlers + } + var off = CodeMirror.off = function(emitter, type, f) { if (emitter.removeEventListener) emitter.removeEventListener(type, f, false); else if (emitter.detachEvent) emitter.detachEvent("on" + type, f); else { - var arr = emitter._handlers && emitter._handlers[type]; - if (!arr) return; - for (var i = 0; i < arr.length; ++i) - if (arr[i] == f) { arr.splice(i, 1); break; } + var handlers = getHandlers(emitter, type, false) + for (var i = 0; i < handlers.length; ++i) + if (handlers[i] == f) { handlers.splice(i, 1); break; } } }; var signal = CodeMirror.signal = function(emitter, type /*, values...*/) { - var arr = emitter._handlers && emitter._handlers[type]; - if (!arr) return; + var handlers = getHandlers(emitter, type, true) + if (!handlers.length) return; var args = Array.prototype.slice.call(arguments, 2); - for (var i = 0; i < arr.length; ++i) arr[i].apply(null, args); + for (var i = 0; i < handlers.length; ++i) handlers[i].apply(null, args); }; var orphanDelayedCallbacks = null; @@ -7223,8 +8233,8 @@ // them to be executed when the last operation ends, or, if no // operation is active, when a timeout fires. function signalLater(emitter, type /*, values...*/) { - var arr = emitter._handlers && emitter._handlers[type]; - if (!arr) return; + var arr = getHandlers(emitter, type, false) + if (!arr.length) return; var args = Array.prototype.slice.call(arguments, 2), list; if (operationGroup) { list = operationGroup.delayedCallbacks; @@ -7264,8 +8274,7 @@ } function hasHandler(emitter, type) { - var arr = emitter._handlers && emitter._handlers[type]; - return arr && arr.length > 0; + return getHandlers(emitter, type).length > 0 } // Add on and off methods to a constructor's prototype, to make @@ -7278,7 +8287,7 @@ // MISC UTILITIES // Number of pixels added to scroller and sizer to hide scrollbar - var scrollerCutOff = 30; + var scrollerGap = 30; // Returned or thrown by various protocols to signal 'I'm not // handling this'. @@ -7312,7 +8321,7 @@ // The inverse of countColumn -- find the offset that corresponds to // a particular column. - function findColumn(string, goal, tabSize) { + var findColumn = CodeMirror.findColumn = function(string, goal, tabSize) { for (var pos = 0, col = 0;;) { var nextTab = string.indexOf("\t", pos); if (nextTab == -1) nextTab = string.length; @@ -7346,22 +8355,21 @@ if (array[i] == elt) return i; return -1; } - if ([].indexOf) indexOf = function(array, elt) { return array.indexOf(elt); }; function map(array, f) { var out = []; for (var i = 0; i < array.length; i++) out[i] = f(array[i], i); return out; } - if ([].map) map = function(array, f) { return array.map(f); }; + + function nothing() {} function createObj(base, props) { var inst; if (Object.create) { inst = Object.create(base); } else { - var ctor = function() {}; - ctor.prototype = base; - inst = new ctor(); + nothing.prototype = base; + inst = new nothing(); } if (props) copyObj(props, inst); return inst; @@ -7380,7 +8388,7 @@ return function(){return f.apply(null, args);}; } - var nonASCIISingleCaseWordChar = /[\u00df\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/; + var nonASCIISingleCaseWordChar = /[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/; var isWordCharBasic = CodeMirror.isWordChar = function(ch) { return /\w/.test(ch) || ch > "\x80" && (ch.toUpperCase() != ch.toLowerCase() || nonASCIISingleCaseWordChar.test(ch)); @@ -7416,9 +8424,9 @@ } var range; - if (document.createRange) range = function(node, start, end) { + if (document.createRange) range = function(node, start, end, endNode) { var r = document.createRange(); - r.setEnd(node, end); + r.setEnd(endNode || node, end); r.setStart(node, start); return r; }; @@ -7442,14 +8450,23 @@ return removeChildren(parent).appendChild(e); } - function contains(parent, child) { + var contains = CodeMirror.contains = function(parent, child) { + if (child.nodeType == 3) // Android browser always returns false when child is a textnode + child = child.parentNode; if (parent.contains) return parent.contains(child); - while (child = child.parentNode) + do { + if (child.nodeType == 11) child = child.host; if (child == parent) return true; - } + } while (child = child.parentNode); + }; - function activeElt() { return document.activeElement; } + function activeElt() { + var activeElement = document.activeElement; + while (activeElement && activeElement.root && activeElement.root.activeElement) + activeElement = activeElement.root.activeElement; + return activeElement; + } // Older versions of IE throws unspecified error when touching // document.activeElement in some cases (during loading, in iframe) if (ie && ie_version < 11) activeElt = function() { @@ -7504,7 +8521,6 @@ on(window, "resize", function() { if (resizeTimer == null) resizeTimer = setTimeout(function() { resizeTimer = null; - knownScrollbarWidth = null; forEachCodeMirror(onResize); }, 100); }); @@ -7525,16 +8541,6 @@ return "draggable" in div || "dragDrop" in div; }(); - var knownScrollbarWidth; - function scrollbarWidth(measure) { - if (knownScrollbarWidth != null) return knownScrollbarWidth; - var test = elt("div", null, null, "width: 50px; height: 50px; overflow-x: scroll"); - removeChildrenAndAdd(measure, test); - if (test.offsetWidth) - knownScrollbarWidth = test.offsetHeight - test.clientHeight; - return knownScrollbarWidth || 0; - } - var zwspSupported; function zeroWidthElement(measure) { if (zwspSupported == null) { @@ -7543,8 +8549,10 @@ if (measure.firstChild.offsetHeight != 0) zwspSupported = test.offsetWidth <= 1 && test.offsetHeight > 2 && !(ie && ie_version < 8); } - if (zwspSupported) return elt("span", "\u200b"); - else return elt("span", "\u00a0", null, "display: inline-block; width: 1px; margin-right: -1px"); + var node = zwspSupported ? elt("span", "\u200b") : + elt("span", "\u00a0", null, "display: inline-block; width: 1px; margin-right: -1px"); + node.setAttribute("cm-text", ""); + return node; } // Feature-detect IE's crummy client rect reporting for bidi text @@ -7553,14 +8561,15 @@ if (badBidiRects != null) return badBidiRects; var txt = removeChildrenAndAdd(measure, document.createTextNode("A\u062eA")); var r0 = range(txt, 0, 1).getBoundingClientRect(); - if (!r0 || r0.left == r0.right) return false; // Safari returns null in some cases (#2780) var r1 = range(txt, 1, 2).getBoundingClientRect(); + removeChildren(measure); + if (!r0 || r0.left == r0.right) return false; // Safari returns null in some cases (#2780) return badBidiRects = (r1.right - r0.right < 3); } // See if "".split is the broken IE version, if so, provide an // alternative way to split lines. - var splitLines = CodeMirror.splitLines = "\n\nb".split(/\n/).length != 3 ? function(string) { + var splitLinesAuto = CodeMirror.splitLines = "\n\nb".split(/\n/).length != 3 ? function(string) { var pos = 0, result = [], l = string.length; while (pos <= l) { var nl = string.indexOf("\n", pos); @@ -7606,14 +8615,16 @@ // KEY NAMES - var keyNames = {3: "Enter", 8: "Backspace", 9: "Tab", 13: "Enter", 16: "Shift", 17: "Ctrl", 18: "Alt", - 19: "Pause", 20: "CapsLock", 27: "Esc", 32: "Space", 33: "PageUp", 34: "PageDown", 35: "End", - 36: "Home", 37: "Left", 38: "Up", 39: "Right", 40: "Down", 44: "PrintScrn", 45: "Insert", - 46: "Delete", 59: ";", 61: "=", 91: "Mod", 92: "Mod", 93: "Mod", 107: "=", 109: "-", 127: "Delete", - 173: "-", 186: ";", 187: "=", 188: ",", 189: "-", 190: ".", 191: "/", 192: "`", 219: "[", 220: "\\", - 221: "]", 222: "'", 63232: "Up", 63233: "Down", 63234: "Left", 63235: "Right", 63272: "Delete", - 63273: "Home", 63275: "End", 63276: "PageUp", 63277: "PageDown", 63302: "Insert"}; - CodeMirror.keyNames = keyNames; + var keyNames = CodeMirror.keyNames = { + 3: "Enter", 8: "Backspace", 9: "Tab", 13: "Enter", 16: "Shift", 17: "Ctrl", 18: "Alt", + 19: "Pause", 20: "CapsLock", 27: "Esc", 32: "Space", 33: "PageUp", 34: "PageDown", 35: "End", + 36: "Home", 37: "Left", 38: "Up", 39: "Right", 40: "Down", 44: "PrintScrn", 45: "Insert", + 46: "Delete", 59: ";", 61: "=", 91: "Mod", 92: "Mod", 93: "Mod", + 106: "*", 107: "=", 109: "-", 110: ".", 111: "/", 127: "Delete", + 173: "-", 186: ";", 187: "=", 188: ",", 189: "-", 190: ".", 191: "/", 192: "`", 219: "[", 220: "\\", + 221: "]", 222: "'", 63232: "Up", 63233: "Down", 63234: "Left", 63235: "Right", 63272: "Delete", + 63273: "Home", 63275: "End", 63276: "PageUp", 63277: "PageDown", 63302: "Insert" + }; (function() { // Number keys for (var i = 0; i < 10; i++) keyNames[i + 48] = keyNames[i + 96] = String(i); @@ -7907,6 +8918,8 @@ lst(order).to -= m[0].length; order.push(new BidiSpan(0, len - m[0].length, len)); } + if (order[0].level == 2) + order.unshift(new BidiSpan(1, order[0].to, order[0].to)); if (order[0].level != lst(order).level) order.push(new BidiSpan(order[0].level, len, len)); @@ -7916,7 +8929,7 @@ // THE END - CodeMirror.version = "4.8.0"; + CodeMirror.version = "5.17.0"; return CodeMirror; }); diff --git a/_site/js/vendor/codemirror/modes/javascript.js b/required/codemirror/javascript.js similarity index 84% rename from _site/js/vendor/codemirror/modes/javascript.js rename to required/codemirror/javascript.js index b0ba8d0..3909c85 100644 --- a/_site/js/vendor/codemirror/modes/javascript.js +++ b/required/codemirror/javascript.js @@ -13,6 +13,11 @@ })(function(CodeMirror) { "use strict"; +function expressionAllowed(stream, state, backUp) { + return /^(?:operator|sof|keyword c|case|new|[\[{}\(,;:]|=>)$/.test(state.lastType) || + (state.lastType == "quasi" && /\{\s*$/.test(stream.string.slice(0, stream.pos - (backUp || 0)))) +} + CodeMirror.defineMode("javascript", function(config, parserConfig) { var indentUnit = config.indentUnit; var statementIndent = parserConfig.statementIndent; @@ -30,14 +35,15 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) { var jsKeywords = { "if": kw("if"), "while": A, "with": A, "else": B, "do": B, "try": B, "finally": B, - "return": C, "break": C, "continue": C, "new": C, "delete": C, "throw": C, "debugger": C, + "return": C, "break": C, "continue": C, "new": kw("new"), "delete": C, "throw": C, "debugger": C, "var": kw("var"), "const": kw("var"), "let": kw("var"), "function": kw("function"), "catch": kw("catch"), "for": kw("for"), "switch": kw("switch"), "case": kw("case"), "default": kw("default"), "in": operator, "typeof": operator, "instanceof": operator, "true": atom, "false": atom, "null": atom, "undefined": atom, "NaN": atom, "Infinity": atom, - "this": kw("this"), "module": kw("module"), "class": kw("class"), "super": kw("atom"), - "yield": C, "export": kw("export"), "import": kw("import"), "extends": C + "this": kw("this"), "class": kw("class"), "super": kw("atom"), + "yield": C, "export": kw("export"), "import": kw("import"), "extends": C, + "await": C, "async": kw("async") }; // Extend the 'normal' keywords with the TypeScript language extensions @@ -45,18 +51,23 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) { var type = {type: "variable", style: "variable-3"}; var tsKeywords = { // object-like things - "interface": kw("interface"), - "extends": kw("extends"), - "constructor": kw("constructor"), + "interface": kw("class"), + "implements": C, + "namespace": C, + "module": kw("module"), + "enum": kw("module"), // scope modifiers - "public": kw("public"), - "private": kw("private"), - "protected": kw("protected"), - "static": kw("static"), + "public": kw("modifier"), + "private": kw("modifier"), + "protected": kw("modifier"), + "abstract": kw("modifier"), + + // operators + "as": operator, // types - "string": type, "number": type, "bool": type, "any": type + "string": type, "number": type, "boolean": type, "any": type }; for (var attr in tsKeywords) { @@ -105,6 +116,12 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) { } else if (ch == "0" && stream.eat(/x/i)) { stream.eatWhile(/[\da-f]/i); return ret("number", "number"); + } else if (ch == "0" && stream.eat(/o/i)) { + stream.eatWhile(/[0-7]/i); + return ret("number", "number"); + } else if (ch == "0" && stream.eat(/b/i)) { + stream.eatWhile(/[01]/i); + return ret("number", "number"); } else if (/\d/.test(ch)) { stream.match(/^\d*(?:\.\d*)?(?:[eE][+\-]?\d+)?/); return ret("number", "number"); @@ -115,10 +132,9 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) { } else if (stream.eat("/")) { stream.skipToEnd(); return ret("comment", "comment"); - } else if (state.lastType == "operator" || state.lastType == "keyword c" || - state.lastType == "sof" || /^[\[{}\(,;:]$/.test(state.lastType)) { + } else if (expressionAllowed(stream, state, 1)) { readRegexp(stream); - stream.eatWhile(/[gimy]/); // 'y' is "sticky" option in Mozilla + stream.match(/^\b(([gimyu])(?![gimyu]*\2))+\b/); return ret("regexp", "string-2"); } else { stream.eatWhile(isOperatorChar); @@ -205,6 +221,8 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) { ++depth; } else if (wordRE.test(ch)) { sawSomething = true; + } else if (/["'\/]/.test(ch)) { + return; } else if (sawSomething && !depth) { ++pos; break; @@ -273,8 +291,8 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) { return false; } var state = cx.state; + cx.marked = "def"; if (state.context) { - cx.marked = "def"; if (inList(state.localVars)) return; state.localVars = {name: varname, next: state.localVars}; } else { @@ -345,10 +363,11 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) { if (type == "default") return cont(expect(":")); if (type == "catch") return cont(pushlex("form"), pushcontext, expect("("), funarg, expect(")"), statement, poplex, popcontext); - if (type == "module") return cont(pushlex("form"), pushcontext, afterModule, popcontext, poplex); if (type == "class") return cont(pushlex("form"), className, poplex); - if (type == "export") return cont(pushlex("form"), afterExport, poplex); - if (type == "import") return cont(pushlex("form"), afterImport, poplex); + if (type == "export") return cont(pushlex("stat"), afterExport, poplex); + if (type == "import") return cont(pushlex("stat"), afterImport, poplex); + if (type == "module") return cont(pushlex("form"), pattern, pushlex("}"), expect("{"), block, poplex, poplex) + if (type == "async") return cont(statement) return pass(pushlex("stat"), expression, expect(";"), poplex); } function expression(type) { @@ -367,12 +386,13 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) { var maybeop = noComma ? maybeoperatorNoComma : maybeoperatorComma; if (atomicTypes.hasOwnProperty(type)) return cont(maybeop); if (type == "function") return cont(functiondef, maybeop); - if (type == "keyword c") return cont(noComma ? maybeexpressionNoComma : maybeexpression); - if (type == "(") return cont(pushlex(")"), maybeexpression, comprehension, expect(")"), poplex, maybeop); + if (type == "keyword c" || type == "async") return cont(noComma ? maybeexpressionNoComma : maybeexpression); + if (type == "(") return cont(pushlex(")"), maybeexpression, expect(")"), poplex, maybeop); if (type == "operator" || type == "spread") return cont(noComma ? expressionNoComma : expression); if (type == "[") return cont(pushlex("]"), arrayLiteral, poplex, maybeop); if (type == "{") return contCommasep(objprop, "}", null, maybeop); - if (type == "quasi") { return pass(quasi, maybeop); } + if (type == "quasi") return pass(quasi, maybeop); + if (type == "new") return cont(maybeTarget(noComma)); return cont(); } function maybeexpression(type) { @@ -423,6 +443,18 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) { findFatArrow(cx.stream, cx.state); return pass(type == "{" ? statement : expressionNoComma); } + function maybeTarget(noComma) { + return function(type) { + if (type == ".") return cont(noComma ? targetNoComma : target); + else return pass(noComma ? expressionNoComma : expression); + }; + } + function target(_, value) { + if (value == "target") { cx.marked = "keyword"; return cont(maybeoperatorComma); } + } + function targetNoComma(_, value) { + if (value == "target") { cx.marked = "keyword"; return cont(maybeoperatorNoComma); } + } function maybelabel(type) { if (type == ":") return cont(poplex, statement); return pass(maybeoperatorComma, expect(";"), poplex); @@ -431,6 +463,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) { if (type == "variable") {cx.marked = "property"; return cont();} } function objprop(type, value) { + if (type == "async") return cont(objprop); if (type == "variable" || cx.style == "keyword") { cx.marked = "property"; if (value == "get" || value == "set") return cont(getterSetter); @@ -440,8 +473,12 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) { return cont(afterprop); } else if (type == "jsonld-keyword") { return cont(afterprop); + } else if (type == "modifier") { + return cont(objprop) } else if (type == "[") { return cont(expression, expect("]"), afterprop); + } else if (type == "spread") { + return cont(expression); } } function getterSetter(type) { @@ -454,17 +491,20 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) { if (type == "(") return pass(functiondef); } function commasep(what, end) { - function proceed(type) { + function proceed(type, value) { if (type == ",") { var lex = cx.state.lexical; if (lex.info == "call") lex.pos = (lex.pos || 0) + 1; - return cont(what, proceed); + return cont(function(type, value) { + if (type == end || value == end) return pass() + return pass(what) + }, proceed); } - if (type == end) return cont(); + if (type == end || value == end) return cont(); return cont(expect(end)); } - return function(type) { - if (type == end) return cont(); + return function(type, value) { + if (type == end || value == end) return cont(); return pass(what, proceed); }; } @@ -478,16 +518,25 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) { return pass(statement, block); } function maybetype(type) { - if (isTS && type == ":") return cont(typedef); + if (isTS && type == ":") return cont(typeexpr); } - function typedef(type) { - if (type == "variable"){cx.marked = "variable-3"; return cont();} + function maybedefault(_, value) { + if (value == "=") return cont(expressionNoComma); + } + function typeexpr(type) { + if (type == "variable") {cx.marked = "variable-3"; return cont(afterType);} + } + function afterType(type, value) { + if (value == "<") return cont(commasep(typeexpr, ">"), afterType) + if (type == "[") return cont(expect("]"), afterType) } function vardef() { return pass(pattern, maybetype, maybeAssign, vardefCont); } function pattern(type, value) { + if (type == "modifier") return cont(pattern) if (type == "variable") { register(value); return cont(); } + if (type == "spread") return cont(pattern); if (type == "[") return contCommasep(pattern, "]"); if (type == "{") return contCommasep(proppattern, "}"); } @@ -497,6 +546,8 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) { return cont(maybeAssign); } if (type == "variable") cx.marked = "property"; + if (type == "spread") return cont(pattern); + if (type == "}") return pass(); return cont(expect(":"), pattern, maybeAssign); } function maybeAssign(_type, value) { @@ -532,11 +583,11 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) { function functiondef(type, value) { if (value == "*") {cx.marked = "keyword"; return cont(functiondef);} if (type == "variable") {register(value); return cont(functiondef);} - if (type == "(") return cont(pushcontext, pushlex(")"), commasep(funarg, ")"), poplex, statement, popcontext); + if (type == "(") return cont(pushcontext, pushlex(")"), commasep(funarg, ")"), poplex, maybetype, statement, popcontext); } function funarg(type) { if (type == "spread") return cont(funarg); - return pass(pattern, maybetype); + return pass(pattern, maybetype, maybedefault); } function className(type, value) { if (type == "variable") {register(value); return cont(classNameAfter);} @@ -547,6 +598,10 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) { } function classBody(type, value) { if (type == "variable" || cx.style == "keyword") { + if (value == "static") { + cx.marked = "keyword"; + return cont(classBody); + } cx.marked = "property"; if (value == "get" || value == "set") return cont(classGetterSetter, functiondef, classBody); return cont(functiondef, classBody); @@ -563,10 +618,6 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) { cx.marked = "property"; return cont(); } - function afterModule(type, value) { - if (type == "string") return cont(statement); - if (type == "variable") { register(value); return cont(maybeFrom); } - } function afterExport(_type, value) { if (value == "*") { cx.marked = "keyword"; return cont(maybeFrom, expect(";")); } if (value == "default") { cx.marked = "keyword"; return cont(expression, expect(";")); } @@ -579,23 +630,24 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) { function importSpec(type, value) { if (type == "{") return contCommasep(importSpec, "}"); if (type == "variable") register(value); - return cont(); + if (value == "*") cx.marked = "keyword"; + return cont(maybeAs); + } + function maybeAs(_type, value) { + if (value == "as") { cx.marked = "keyword"; return cont(importSpec); } } function maybeFrom(_type, value) { if (value == "from") { cx.marked = "keyword"; return cont(expression); } } function arrayLiteral(type) { if (type == "]") return cont(); - return pass(expressionNoComma, maybeArrayComprehension); - } - function maybeArrayComprehension(type) { - if (type == "for") return pass(comprehension, expect("]")); - if (type == ",") return cont(commasep(maybeexpressionNoComma, "]")); - return pass(commasep(expressionNoComma, "]")); + return pass(expressionNoComma, commasep(expressionNoComma, "]")); } - function comprehension(type) { - if (type == "for") return cont(forspec, comprehension); - if (type == "if") return cont(expression, comprehension); + + function isContinuedStatement(state, textAfter) { + return state.lastType == "operator" || state.lastType == "," || + isOperatorChar.test(textAfter.charAt(0)) || + /[,.]/.test(textAfter.charAt(0)); } // Interface @@ -609,7 +661,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) { lexical: new JSLexical((basecolumn || 0) - indentUnit, 0, "block", false), localVars: parserConfig.localVars, context: parserConfig.localVars && {vars: parserConfig.localVars}, - indented: 0 + indented: basecolumn || 0 }; if (parserConfig.globalVars && typeof parserConfig.globalVars == "object") state.globalVars = parserConfig.globalVars; @@ -649,7 +701,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) { else if (type == "form" && firstChar == "{") return lexical.indented; else if (type == "form") return lexical.indented + indentUnit; else if (type == "stat") - return lexical.indented + (state.lastType == "operator" || state.lastType == "," ? statementIndent || indentUnit : 0); + return lexical.indented + (isContinuedStatement(state, textAfter) ? statementIndent || indentUnit : 0); else if (lexical.info == "switch" && !closing && parserConfig.doubleIndentSwitch != false) return lexical.indented + (/^(?:case|default)\b/.test(textAfter) ? indentUnit : 2 * indentUnit); else if (lexical.align) return lexical.column + (closing ? 0 : 1); @@ -661,10 +713,17 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) { blockCommentEnd: jsonMode ? null : "*/", lineComment: jsonMode ? null : "//", fold: "brace", + closeBrackets: "()[]{}''\"\"``", helperType: jsonMode ? "json" : "javascript", jsonldMode: jsonldMode, - jsonMode: jsonMode + jsonMode: jsonMode, + + expressionAllowed: expressionAllowed, + skipExpression: function(state) { + var top = state.cc[state.cc.length - 1] + if (top == expression || top == expressionNoComma) state.cc.pop() + } }; }); diff --git a/examples/basics/_details.json b/required/examples/basics/_details.json old mode 100644 new mode 100755 similarity index 92% rename from examples/basics/_details.json rename to required/examples/basics/_details.json index 941a559..7a9d05d --- a/examples/basics/_details.json +++ b/required/examples/basics/_details.json @@ -6,6 +6,10 @@ { "title": "Container", "entry": "container.js" + }, + { + "title": "Container Pivot", + "entry": "container-pivot.js" }, { "title": "SpriteSheet Animation", diff --git a/examples/basics/basic.js b/required/examples/basics/basic.js old mode 100644 new mode 100755 similarity index 90% rename from examples/basics/basic.js rename to required/examples/basics/basic.js index f2e69b9..01b866c --- a/examples/basics/basic.js +++ b/required/examples/basics/basic.js @@ -5,7 +5,7 @@ document.body.appendChild(renderer.view); var stage = new PIXI.Container(); // create a texture from an image path -var texture = PIXI.Texture.fromImage('_assets/basics/bunny.png'); +var texture = PIXI.Texture.fromImage('required/assets/basics/bunny.png'); // create a new Sprite using the texture var bunny = new PIXI.Sprite(texture); diff --git a/examples/basics/click.js b/required/examples/basics/click.js old mode 100644 new mode 100755 similarity index 89% rename from examples/basics/click.js rename to required/examples/basics/click.js index 86b84b8..9b265a6 --- a/examples/basics/click.js +++ b/required/examples/basics/click.js @@ -4,7 +4,7 @@ document.body.appendChild(renderer.view); // create the root of the scene graph var stage = new PIXI.Container(); -var sprite = PIXI.Sprite.fromImage('_assets/basics/bunny.png'); +var sprite = PIXI.Sprite.fromImage('required/assets/basics/bunny.png'); sprite.position.set(230,264); sprite.interactive = true; diff --git a/required/examples/basics/container-pivot.js b/required/examples/basics/container-pivot.js new file mode 100755 index 0000000..e43f975 --- /dev/null +++ b/required/examples/basics/container-pivot.js @@ -0,0 +1,41 @@ +var renderer = PIXI.autoDetectRenderer(800, 600,{backgroundColor : 0x1099bb}); +document.body.appendChild(renderer.view); + +// create the root of the scene graph +var stage = new PIXI.Container(); + +var container = new PIXI.Container(); + +stage.addChild(container); + +for (var j = 0; j < 5; j++) { + + for (var i = 0; i < 5; i++) { + var bunny = PIXI.Sprite.fromImage('required/assets/basics/bunny.png'); + bunny.x = 40 * i; + bunny.y = 40 * j; + container.addChild(bunny); + }; +}; + +// move container to the (200, 150) +container.position.x = 200; +container.position.y = 150; +// (93, 98.5) is center of center bunny sprite in local container coordinates +// we want it to be in (200, 150) of global coords +container.pivot.x = 80 + 26 * 0.5; +container.pivot.y = 80 + 37 * 0.5; + +// start animating +animate(); + +function animate() { + + requestAnimationFrame(animate); + + //rotate the container! + container.rotation -= 0.01; + + // render the root container + renderer.render(stage); +} diff --git a/examples/basics/container.js b/required/examples/basics/container.js old mode 100644 new mode 100755 similarity index 92% rename from examples/basics/container.js rename to required/examples/basics/container.js index f37a1fe..efc5928 --- a/examples/basics/container.js +++ b/required/examples/basics/container.js @@ -11,7 +11,7 @@ stage.addChild(container); for (var j = 0; j < 5; j++) { for (var i = 0; i < 5; i++) { - var bunny = PIXI.Sprite.fromImage('_assets/basics/bunny.png'); + var bunny = PIXI.Sprite.fromImage('required/assets/basics/bunny.png'); bunny.x = 40 * i; bunny.y = 40 * j; container.addChild(bunny); diff --git a/examples/basics/custom-filter-v3.js b/required/examples/basics/custom-filter-v3.js old mode 100644 new mode 100755 similarity index 88% rename from examples/basics/custom-filter-v3.js rename to required/examples/basics/custom-filter-v3.js index 74b11bc..01220cd --- a/examples/basics/custom-filter-v3.js +++ b/required/examples/basics/custom-filter-v3.js @@ -24,11 +24,11 @@ CustomFilter.prototype = Object.create(PIXI.AbstractFilter.prototype); CustomFilter.prototype.constructor = CustomFilter; -var bg = PIXI.Sprite.fromImage("_assets/bkg-grass.jpg"); +var bg = PIXI.Sprite.fromImage("required/assets/bkg-grass.jpg"); bg.scale.set(1.3,1); stage.addChild(bg); -PIXI.loader.add('shader','_assets/basics/shader.frag'); +PIXI.loader.add('shader','required/assets/basics/shader.frag'); PIXI.loader.once('complete',onLoaded); diff --git a/examples/basics/custom-filter.js b/required/examples/basics/custom-filter.js old mode 100644 new mode 100755 similarity index 87% rename from examples/basics/custom-filter.js rename to required/examples/basics/custom-filter.js index 04435e6..7790d09 --- a/examples/basics/custom-filter.js +++ b/required/examples/basics/custom-filter.js @@ -20,11 +20,11 @@ CustomFilter.prototype = Object.create(PIXI.Filter.prototype); CustomFilter.prototype.constructor = CustomFilter; -var bg = PIXI.Sprite.fromImage("_assets/bkg-grass.jpg"); +var bg = PIXI.Sprite.fromImage("required/assets/bkg-grass.jpg"); bg.scale.set(1.3,1); stage.addChild(bg); -PIXI.loader.add('shader','_assets/basics/shader.frag'); +PIXI.loader.add('shader','required/assets/basics/shader.frag'); PIXI.loader.once('complete',onLoaded); diff --git a/examples/basics/graphics.js b/required/examples/basics/graphics.js old mode 100644 new mode 100755 similarity index 100% rename from examples/basics/graphics.js rename to required/examples/basics/graphics.js diff --git a/examples/basics/render-texture-v3.js b/required/examples/basics/render-texture-v3.js old mode 100644 new mode 100755 similarity index 93% rename from examples/basics/render-texture-v3.js rename to required/examples/basics/render-texture-v3.js index ef025e8..68a215f --- a/examples/basics/render-texture-v3.js +++ b/required/examples/basics/render-texture-v3.js @@ -11,7 +11,7 @@ stage.addChild(container); for (var j = 0; j < 5; j++) { for (var i = 0; i < 5; i++) { - var bunny = PIXI.Sprite.fromImage('_assets/basics/bunny.png'); + var bunny = PIXI.Sprite.fromImage('required/assets/basics/bunny.png'); bunny.x = 30 * i; bunny.y = 30 * j; bunny.rotation = Math.random() * (Math.PI * 2) diff --git a/examples/basics/render-texture.js b/required/examples/basics/render-texture.js old mode 100644 new mode 100755 similarity index 92% rename from examples/basics/render-texture.js rename to required/examples/basics/render-texture.js index f439ac1..f544baf --- a/examples/basics/render-texture.js +++ b/required/examples/basics/render-texture.js @@ -11,7 +11,7 @@ stage.addChild(container); for (var j = 0; j < 5; j++) { for (var i = 0; i < 5; i++) { - var bunny = PIXI.Sprite.fromImage('_assets/basics/bunny.png'); + var bunny = PIXI.Sprite.fromImage('required/assets/basics/bunny.png'); bunny.x = 30 * i; bunny.y = 30 * j; bunny.rotation = Math.random() * (Math.PI * 2) @@ -19,7 +19,7 @@ for (var j = 0; j < 5; j++) { }; }; -var brt = new PIXI.BaseRenderTexture(300, 200, PIXI.SCALE_MODES.LINEAR, 0.1); +var brt = new PIXI.BaseRenderTexture(300, 200, PIXI.SCALE_MODES.LINEAR, 1); var rt = new PIXI.RenderTexture(brt); var sprite = new PIXI.Sprite(rt); diff --git a/examples/basics/spritesheet.js b/required/examples/basics/spritesheet.js old mode 100644 new mode 100755 similarity index 95% rename from examples/basics/spritesheet.js rename to required/examples/basics/spritesheet.js index 0b42876..a35dd29 --- a/examples/basics/spritesheet.js +++ b/required/examples/basics/spritesheet.js @@ -5,7 +5,7 @@ document.body.appendChild(renderer.view); var stage = new PIXI.Container(); PIXI.loader - .add('_assets/basics/fighter.json') + .add('required/assets/basics/fighter.json') .load(onAssetsLoaded); var movie; diff --git a/examples/basics/text.js b/required/examples/basics/text.js old mode 100644 new mode 100755 similarity index 100% rename from examples/basics/text.js rename to required/examples/basics/text.js diff --git a/examples/basics/textured-mesh.js b/required/examples/basics/textured-mesh.js old mode 100644 new mode 100755 similarity index 93% rename from examples/basics/textured-mesh.js rename to required/examples/basics/textured-mesh.js index 8fe57fd..66952e4 --- a/examples/basics/textured-mesh.js +++ b/required/examples/basics/textured-mesh.js @@ -17,7 +17,7 @@ for (var i = 0; i < 25; i++) points.push(new PIXI.Point(i * ropeLength, 0)); } -var strip = new PIXI.mesh.Rope(PIXI.Texture.fromImage('_assets/snake.png'), points); +var strip = new PIXI.mesh.Rope(PIXI.Texture.fromImage('required/assets/snake.png'), points); strip.position.x = -40; strip.position.y = 300; diff --git a/examples/basics/tiling-sprite.js b/required/examples/basics/tiling-sprite.js old mode 100644 new mode 100755 similarity index 92% rename from examples/basics/tiling-sprite.js rename to required/examples/basics/tiling-sprite.js index ef13df8..809b040 --- a/examples/basics/tiling-sprite.js +++ b/required/examples/basics/tiling-sprite.js @@ -5,7 +5,7 @@ document.body.appendChild(renderer.view); var stage = new PIXI.Container(); // create a texture from an image path -var texture = PIXI.Texture.fromImage('_assets/p2.jpeg'); +var texture = PIXI.Texture.fromImage('required/assets/p2.jpeg'); /* create a tiling sprite ... * requires a texture, a width and a height diff --git a/examples/basics/video.js b/required/examples/basics/video.js old mode 100644 new mode 100755 similarity index 88% rename from examples/basics/video.js rename to required/examples/basics/video.js index 5efa885..81c1e06 --- a/examples/basics/video.js +++ b/required/examples/basics/video.js @@ -5,7 +5,7 @@ document.body.appendChild(renderer.view); var stage = new PIXI.Container(); // create a video texture from a path -var texture = PIXI.Texture.fromVideo('_assets/testVideo.mp4'); +var texture = PIXI.Texture.fromVideo('required/assets/testVideo.mp4'); // create a new Sprite using the video texture (yes it's that easy) var videoSprite = new PIXI.Sprite(texture); diff --git a/examples/demos/_details.json b/required/examples/demos/_details.json old mode 100644 new mode 100755 similarity index 100% rename from examples/demos/_details.json rename to required/examples/demos/_details.json diff --git a/examples/demos/alpha-mask.js b/required/examples/demos/alpha-mask.js old mode 100644 new mode 100755 similarity index 81% rename from examples/demos/alpha-mask.js rename to required/examples/demos/alpha-mask.js index 821e355..f975351 --- a/examples/demos/alpha-mask.js +++ b/required/examples/demos/alpha-mask.js @@ -6,15 +6,15 @@ var stage = new PIXI.Container(); stage.interactive = true; -var bg = PIXI.Sprite.fromImage('_assets/bkg.jpg'); +var bg = PIXI.Sprite.fromImage('required/assets/bkg.jpg'); stage.addChild(bg); -var cells = PIXI.Sprite.fromImage('_assets/cells.png'); +var cells = PIXI.Sprite.fromImage('required/assets/cells.png'); cells.scale.set(1.5,1.5); -var mask = PIXI.Sprite.fromImage('_assets/flowerTop.png'); +var mask = PIXI.Sprite.fromImage('required/assets/flowerTop.png'); mask.anchor.set(0.5); mask.position.x = 310; mask.position.y = 190; diff --git a/examples/demos/batch-v3.js b/required/examples/demos/batch-v3.js old mode 100644 new mode 100755 similarity index 97% rename from examples/demos/batch-v3.js rename to required/examples/demos/batch-v3.js index c002f6f..7ab6779 --- a/examples/demos/batch-v3.js +++ b/required/examples/demos/batch-v3.js @@ -21,7 +21,7 @@ var totalSprites = renderer instanceof PIXI.WebGLRenderer ? 10000 : 100; for (var i = 0; i < totalSprites; i++) { // create a new Sprite - var dude = PIXI.Sprite.fromImage('_assets/tinyMaggot.png'); + var dude = PIXI.Sprite.fromImage('required/assets/tinyMaggot.png'); dude.tint = Math.random() * 0xE8D4CD; diff --git a/examples/demos/batch.js b/required/examples/demos/batch.js old mode 100644 new mode 100755 similarity index 97% rename from examples/demos/batch.js rename to required/examples/demos/batch.js index 4e47e52..4d23135 --- a/examples/demos/batch.js +++ b/required/examples/demos/batch.js @@ -21,7 +21,7 @@ var totalSprites = renderer instanceof PIXI.WebGLRenderer ? 10000 : 100; for (var i = 0; i < totalSprites; i++) { // create a new Sprite - var dude = PIXI.Sprite.fromImage('_assets/tinyMaggot.png'); + var dude = PIXI.Sprite.fromImage('required/assets/tinyMaggot.png'); dude.tint = Math.random() * 0xE8D4CD; diff --git a/examples/demos/blendmodes.js b/required/examples/demos/blendmodes.js old mode 100644 new mode 100755 similarity index 95% rename from examples/demos/blendmodes.js rename to required/examples/demos/blendmodes.js index c8baa20..18fa0f3 --- a/examples/demos/blendmodes.js +++ b/required/examples/demos/blendmodes.js @@ -5,7 +5,7 @@ document.body.appendChild(renderer.view); var stage = new PIXI.Container(); // create a new background sprite -var background = new PIXI.Sprite.fromImage('_assets/BGrotate.jpg'); +var background = new PIXI.Sprite.fromImage('required/assets/BGrotate.jpg'); stage.addChild(background); // create an array to store a reference to the dudes @@ -16,7 +16,7 @@ var totaldudes = 20; for (var i = 0; i < totaldudes; i++) { // create a new Sprite that uses the image name that we just generated as its source - var dude = PIXI.Sprite.fromImage('_assets/flowerTop.png'); + var dude = PIXI.Sprite.fromImage('required/assets/flowerTop.png'); dude.anchor.set(0.5); diff --git a/examples/demos/cacheAsBitmap.js b/required/examples/demos/cacheAsBitmap.js old mode 100644 new mode 100755 similarity index 97% rename from examples/demos/cacheAsBitmap.js rename to required/examples/demos/cacheAsBitmap.js index 2a6846a..58fc3bf --- a/examples/demos/cacheAsBitmap.js +++ b/required/examples/demos/cacheAsBitmap.js @@ -6,7 +6,7 @@ var stage = new PIXI.Container(); // load resources PIXI.loader - .add('spritesheet','_assets/monsters.json') + .add('spritesheet','required/assets/monsters.json') .load(onAssetsLoaded); // holder to store aliens diff --git a/examples/demos/dragging.js b/required/examples/demos/dragging.js old mode 100644 new mode 100755 similarity index 97% rename from examples/demos/dragging.js rename to required/examples/demos/dragging.js index 564328c..94a60b7 --- a/examples/demos/dragging.js +++ b/required/examples/demos/dragging.js @@ -5,7 +5,7 @@ document.body.appendChild(renderer.view); var stage = new PIXI.Container(); // create a texture from an image path -var texture = PIXI.Texture.fromImage('_assets/bunny.png'); +var texture = PIXI.Texture.fromImage('required/assets/bunny.png'); for (var i = 0; i < 10; i++) { diff --git a/examples/demos/graphics-demo.js b/required/examples/demos/graphics-demo.js old mode 100644 new mode 100755 similarity index 100% rename from examples/demos/graphics-demo.js rename to required/examples/demos/graphics-demo.js diff --git a/examples/demos/interactivity.js b/required/examples/demos/interactivity.js old mode 100644 new mode 100755 similarity index 88% rename from examples/demos/interactivity.js rename to required/examples/demos/interactivity.js index d61300c..924ff27 --- a/examples/demos/interactivity.js +++ b/required/examples/demos/interactivity.js @@ -5,7 +5,7 @@ document.body.appendChild(renderer.view); var stage = new PIXI.Container(); // create a background... -var background = PIXI.Sprite.fromImage('_assets/button_test_BG.jpg'); +var background = PIXI.Sprite.fromImage('required/assets/button_test_BG.jpg'); background.width = renderer.width; background.height = renderer.height; @@ -13,9 +13,9 @@ background.height = renderer.height; stage.addChild(background); // create some textures from an image path -var textureButton = PIXI.Texture.fromImage('_assets/button.png'); -var textureButtonDown = PIXI.Texture.fromImage('_assets/buttonDown.png'); -var textureButtonOver = PIXI.Texture.fromImage('_assets/buttonOver.png'); +var textureButton = PIXI.Texture.fromImage('required/assets/button.png'); +var textureButtonDown = PIXI.Texture.fromImage('required/assets/buttonDown.png'); +var textureButtonOver = PIXI.Texture.fromImage('required/assets/buttonOver.png'); var buttons = []; diff --git a/examples/demos/masking.js b/required/examples/demos/masking.js old mode 100644 new mode 100755 similarity index 87% rename from examples/demos/masking.js rename to required/examples/demos/masking.js index 103f5ea..7869157 --- a/examples/demos/masking.js +++ b/required/examples/demos/masking.js @@ -6,7 +6,7 @@ var stage = new PIXI.Container(); stage.interactive = true; -var bg = PIXI.Sprite.fromImage('_assets/BGrotate.jpg'); +var bg = PIXI.Sprite.fromImage('required/assets/BGrotate.jpg'); bg.anchor.x = 0.5; bg.anchor.y = 0.5; @@ -22,23 +22,23 @@ container.position.y = renderer.height / 2; // add a bunch of sprites -var bgFront = PIXI.Sprite.fromImage('_assets/SceneRotate.jpg'); +var bgFront = PIXI.Sprite.fromImage('required/assets/SceneRotate.jpg'); bgFront.anchor.x = 0.5; bgFront.anchor.y = 0.5; container.addChild(bgFront); -var light2 = PIXI.Sprite.fromImage('_assets/LightRotate2.png'); +var light2 = PIXI.Sprite.fromImage('required/assets/LightRotate2.png'); light2.anchor.x = 0.5; light2.anchor.y = 0.5; container.addChild(light2); -var light1 = PIXI.Sprite.fromImage('_assets/LightRotate1.png'); +var light1 = PIXI.Sprite.fromImage('required/assets/LightRotate1.png'); light1.anchor.x = 0.5; light1.anchor.y = 0.5; container.addChild(light1); -var panda = PIXI.Sprite.fromImage('_assets/panda.png'); +var panda = PIXI.Sprite.fromImage('required/assets/panda.png'); panda.anchor.x = 0.5; panda.anchor.y = 0.5; diff --git a/examples/demos/movieclip-demo.js b/required/examples/demos/movieclip-demo.js old mode 100644 new mode 100755 similarity index 95% rename from examples/demos/movieclip-demo.js rename to required/examples/demos/movieclip-demo.js index d6dcb72..11f71c1 --- a/examples/demos/movieclip-demo.js +++ b/required/examples/demos/movieclip-demo.js @@ -5,7 +5,7 @@ document.body.appendChild(renderer.view); var stage = new PIXI.Container(); PIXI.loader - .add('spritesheet', '_assets/mc.json') + .add('spritesheet', 'required/assets/mc.json') .load(onAssetsLoaded); function onAssetsLoaded() diff --git a/examples/demos/render-texture-demo.js b/required/examples/demos/render-texture-demo.js old mode 100644 new mode 100755 similarity index 87% rename from examples/demos/render-texture-demo.js rename to required/examples/demos/render-texture-demo.js index d5a7b6e..82cba18 --- a/examples/demos/render-texture-demo.js +++ b/required/examples/demos/render-texture-demo.js @@ -29,14 +29,14 @@ stage.addChild(stuffContainer); // create an array of image ids.. var fruits = [ - '_assets/spinObj_01.png', - '_assets/spinObj_02.png', - '_assets/spinObj_03.png', - '_assets/spinObj_04.png', - '_assets/spinObj_05.png', - '_assets/spinObj_06.png', - '_assets/spinObj_07.png', - '_assets/spinObj_08.png' + 'required/assets/spinObj_01.png', + 'required/assets/spinObj_02.png', + 'required/assets/spinObj_03.png', + 'required/assets/spinObj_04.png', + 'required/assets/spinObj_05.png', + 'required/assets/spinObj_06.png', + 'required/assets/spinObj_07.png', + 'required/assets/spinObj_08.png' ]; // create an array of items diff --git a/examples/demos/strip-demo.js b/required/examples/demos/strip-demo.js old mode 100644 new mode 100755 similarity index 91% rename from examples/demos/strip-demo.js rename to required/examples/demos/strip-demo.js index f2a5aa0..789fc50 --- a/examples/demos/strip-demo.js +++ b/required/examples/demos/strip-demo.js @@ -16,7 +16,7 @@ for (var i = 0; i < 20; i++) points.push(new PIXI.Point(i * ropeLength, 0)); } -var strip = new PIXI.mesh.Rope(PIXI.Texture.fromImage('_assets/snake.png'), points); +var strip = new PIXI.mesh.Rope(PIXI.Texture.fromImage('required/assets/snake.png'), points); strip.x = -459; diff --git a/examples/demos/text-demo.js b/required/examples/demos/text-demo.js old mode 100644 new mode 100755 similarity index 95% rename from examples/demos/text-demo.js rename to required/examples/demos/text-demo.js index 1eca7c2..e043fc8 --- a/examples/demos/text-demo.js +++ b/required/examples/demos/text-demo.js @@ -32,7 +32,7 @@ window.WebFontConfig = { function init() { PIXI.loader - .add('desyrel', '_assets/desyrel.xml') + .add('desyrel', 'required/assets/desyrel.xml') .load(onAssetsLoaded); function onAssetsLoaded() @@ -46,7 +46,7 @@ function init() } // add a shiny background... - var background = PIXI.Sprite.fromImage('_assets/textDemoBG.jpg'); + var background = PIXI.Sprite.fromImage('required/assets/textDemoBG.jpg'); stage.addChild(background); // create some white text using the Snippet webfont diff --git a/examples/demos/texture-rotate.js b/required/examples/demos/texture-rotate.js old mode 100644 new mode 100755 similarity index 97% rename from examples/demos/texture-rotate.js rename to required/examples/demos/texture-rotate.js index 27a9e86..47bddcf --- a/examples/demos/texture-rotate.js +++ b/required/examples/demos/texture-rotate.js @@ -8,7 +8,7 @@ var bol = false; // create a texture from an image path -PIXI.loader.add('flowerTop', '_assets/flowerTop.png'); +PIXI.loader.add('flowerTop', 'required/assets/flowerTop.png'); PIXI.loader.load(function(loader, resources) { texture = resources.flowerTop.texture; init(); diff --git a/examples/demos/texture-swap.js b/required/examples/demos/texture-swap.js old mode 100644 new mode 100755 similarity index 86% rename from examples/demos/texture-swap.js rename to required/examples/demos/texture-swap.js index a6f838f..291e623 --- a/examples/demos/texture-swap.js +++ b/required/examples/demos/texture-swap.js @@ -7,10 +7,10 @@ var stage = new PIXI.Container(); var bol = false; // create a texture from an image path -var texture = PIXI.Texture.fromImage('_assets/flowerTop.png'); +var texture = PIXI.Texture.fromImage('required/assets/flowerTop.png'); // create a second texture -var secondTexture = PIXI.Texture.fromImage('_assets/eggHead.png'); +var secondTexture = PIXI.Texture.fromImage('required/assets/eggHead.png'); // create a new Sprite using the texture var dude = new PIXI.Sprite(texture); diff --git a/examples/demos/tinting.js b/required/examples/demos/tinting.js old mode 100644 new mode 100755 similarity index 97% rename from examples/demos/tinting.js rename to required/examples/demos/tinting.js index 59987de..4f0d307 --- a/examples/demos/tinting.js +++ b/required/examples/demos/tinting.js @@ -12,7 +12,7 @@ var totalDudes = 20; for (var i = 0; i < totalDudes; i++) { // create a new Sprite that uses the image name that we just generated as its source - var dude = PIXI.Sprite.fromImage('_assets/eggHead.png'); + var dude = PIXI.Sprite.fromImage('required/assets/eggHead.png'); // set the anchor point so the texture is centerd on the sprite dude.anchor.set(0.5); diff --git a/examples/demos/transparent-background.js b/required/examples/demos/transparent-background.js old mode 100644 new mode 100755 similarity index 90% rename from examples/demos/transparent-background.js rename to required/examples/demos/transparent-background.js index 907bbde..3195bd4 --- a/examples/demos/transparent-background.js +++ b/required/examples/demos/transparent-background.js @@ -5,7 +5,7 @@ document.body.appendChild(renderer.view); var stage = new PIXI.Container(); // create a new Sprite from an image path. -var bunny = PIXI.Sprite.fromImage('_assets/bunny.png'); +var bunny = PIXI.Sprite.fromImage('required/assets/bunny.png'); // center the sprite's anchor point bunny.anchor.set(0.5); diff --git a/examples/demos/video.js b/required/examples/demos/video.js old mode 100644 new mode 100755 similarity index 100% rename from examples/demos/video.js rename to required/examples/demos/video.js diff --git a/required/examples/display/_details.json b/required/examples/display/_details.json new file mode 100755 index 0000000..1440c73 --- /dev/null +++ b/required/examples/display/_details.json @@ -0,0 +1,7 @@ +[ + { + "title": "Z-order", + "entry": "zorder.js", + "plugins": ["pixi-display"] + } +] diff --git a/required/examples/display/zorder.js b/required/examples/display/zorder.js new file mode 100755 index 0000000..e8fa56a --- /dev/null +++ b/required/examples/display/zorder.js @@ -0,0 +1,143 @@ +// This is demo of pixi-display.js, https://github.com/gameofbombs/pixi-display +// Drag the rabbits to understand what's going on + +var renderer = new PIXI.WebGLRenderer(800, 600, {backgroundColor: 0x1099bb}); +document.body.appendChild(renderer.view); + +// create the root of the scene graph +var root = new PIXI.Container(); +//specify display list component +root.displayList = new PIXI.DisplayList(); + +// z-index = 0, sorting = true; +var greenLayer = new PIXI.DisplayGroup(0, true); +greenLayer.on('add', function (sprite) { + //green bunnies go down + sprite.zOrder = -sprite.position.y; +}); + +// z-index = 1, sorting = true, we can provide zOrder function directly in constructor +var blueLayer = new PIXI.DisplayGroup(1, function (sprite) { + //blue bunnies go up + sprite.zOrder = +sprite.position.y; +}); + +// Drag is the best layer, dragged element is above everything else +var dragLayer = new PIXI.DisplayGroup(2, false); + +// Shadows are the lowest +var shadowLayer = new PIXI.DisplayGroup(-1, false); + + +var blurFilter = new PIXI.filters.BlurFilter(); +blurFilter.blur = 0.5; + +// create a texture from an image path +var texture_green = PIXI.Texture.fromImage('required/assets/bunnies/square_green.png'); +var texture_blue = PIXI.Texture.fromImage('required/assets/bunnies/square_blue.png'); + +var bunniesOdd = new PIXI.Container(); +var bunniesEven = new PIXI.Container(); +var bunniesBlue = new PIXI.Container(); +root.addChild(bunniesOdd); +root.addChild(bunniesBlue); +root.addChild(bunniesEven); + +var ind = []; +for (var i = 0; i < 15; i++) { + var bunny = new PIXI.Sprite(texture_green); + bunny.width = 50; + bunny.height = 50; + bunny.position.set(100 + 20 * i, 100 + 20 * i); + bunny.anchor.set(0.5); + // that thing is required + bunny.displayGroup = greenLayer; + if (i % 2 == 0) { + bunniesEven.addChild(bunny); + } else { + bunniesOdd.addChild(bunny); + } + subscribe(bunny); + addShadow(bunny); +} + +for (var i = 9; i >= 0; i--) { + var bunny = new PIXI.Sprite(texture_blue); + bunny.width = 50; + bunny.height = 50; + bunny.position.set(400 + 20 * i, 400 - 20 * i); + bunny.anchor.set(0.5); + // that thing is required + bunny.displayGroup = blueLayer; + bunniesBlue.addChild(bunny); + subscribe(bunny); + addShadow(bunny); +} + +function subscribe(obj) { + obj.interactive = true; + obj.on('mousedown', onDragStart) + .on('touchstart', onDragStart) + .on('mouseup', onDragEnd) + .on('mouseupoutside', onDragEnd) + .on('touchend', onDragEnd) + .on('touchendoutside', onDragEnd) + .on('mousemove', onDragMove) + .on('touchmove', onDragMove); +} + +function addShadow(obj) { + var gr = new PIXI.Graphics(); + gr.beginFill(0x0, 1); + //yes , I know bunny size, I'm sorry for this hack + var scale = 1.1; + gr.drawRect(-25/2 * scale, -36/2 * scale, 25 * scale, 36 * scale); + gr.endFill(); + gr.filters = [blurFilter]; + + gr.displayGroup = shadowLayer; + obj.addChild(gr); +} + +function onDragStart(event) { + if (!this.dragging) { + this.data = event.data; + this.oldGroup = this.displayGroup; + this.displayGroup = dragLayer; + this.dragging = true; + + this.scale.x *= 1.1; + this.scale.y *= 1.1; + this.dragPoint = event.data.getLocalPosition(this.parent); + this.dragPoint.x -= this.position.x; + this.dragPoint.y -= this.position.y; + } +} + +function onDragEnd() { + if (this.dragging) { + this.dragging = false; + this.displayGroup = this.oldGroup; + this.scale.x /= 1.1; + this.scale.y /= 1.1; + // set the interaction data to null + this.data = null; + } +} + +function onDragMove() { + if (this.dragging) { + var newPosition = this.data.getLocalPosition(this.parent); + this.position.x = newPosition.x - this.dragPoint.x; + this.position.y = newPosition.y - this.dragPoint.y; + } +} + +// start animating +var ticker = new PIXI.ticker.Ticker(); + +ticker.add(function (deltaTime) { + renderer.render(root); +}); + +ticker.start(); diff --git a/examples/filters/_details.json b/required/examples/filters/_details.json old mode 100644 new mode 100755 similarity index 100% rename from examples/filters/_details.json rename to required/examples/filters/_details.json diff --git a/examples/filters/blur-filter.js b/required/examples/filters/blur-filter.js old mode 100644 new mode 100755 similarity index 80% rename from examples/filters/blur-filter.js rename to required/examples/filters/blur-filter.js index 4047a85..bd6cf9e --- a/examples/filters/blur-filter.js +++ b/required/examples/filters/blur-filter.js @@ -4,17 +4,17 @@ document.body.appendChild(renderer.view); // create the root of the scene graph var stage = new PIXI.Container(); -var bg = PIXI.Sprite.fromImage('_assets/depth_blur_BG.jpg'); +var bg = PIXI.Sprite.fromImage('required/assets/depth_blur_BG.jpg'); bg.width = renderer.width; bg.height = renderer.height; stage.addChild(bg); -var littleDudes = PIXI.Sprite.fromImage('_assets/depth_blur_dudes.jpg'); +var littleDudes = PIXI.Sprite.fromImage('required/assets/depth_blur_dudes.jpg'); littleDudes.position.x = (renderer.width / 2) - 315; littleDudes.position.y = 200; stage.addChild(littleDudes); -var littleRobot = PIXI.Sprite.fromImage('_assets/depth_blur_moby.jpg'); +var littleRobot = PIXI.Sprite.fromImage('required/assets/depth_blur_moby.jpg'); littleRobot.position.x = (renderer.width / 2) - 200; littleRobot.position.y = 100; stage.addChild(littleRobot); diff --git a/examples/filters/displacement-map.js b/required/examples/filters/displacement-map.js old mode 100644 new mode 100755 similarity index 88% rename from examples/filters/displacement-map.js rename to required/examples/filters/displacement-map.js index eab2773..bb489ee --- a/examples/filters/displacement-map.js +++ b/required/examples/filters/displacement-map.js @@ -15,7 +15,7 @@ var maggots = []; for (var i = 0; i < 20; i++) { - var maggot = PIXI.Sprite.fromImage('_assets/maggot.png'); + var maggot = PIXI.Sprite.fromImage('required/assets/maggot.png'); maggot.anchor.set(0.5); container.addChild(maggot); @@ -27,12 +27,13 @@ for (var i = 0; i < 20; i++) maggot.position.y = Math.random() * bounds.height; maggot.scale.set(1 + Math.random() * 0.3); - maggot.original = maggot.scale.clone(); + maggot.original = new PIXI.Point(); + maggot.original.copy(maggot.scale); maggots.push(maggot); } -var displacementSprite = PIXI.Sprite.fromImage('_assets/displace.png'); +var displacementSprite = PIXI.Sprite.fromImage('required/assets/displace.png'); var displacementFilter = new PIXI.filters.DisplacementFilter(displacementSprite); stage.addChild(displacementSprite); @@ -42,7 +43,7 @@ container.filters = [displacementFilter]; displacementFilter.scale.x = 110; displacementFilter.scale.y = 110; -var ring = PIXI.Sprite.fromImage('_assets/ring.png'); +var ring = PIXI.Sprite.fromImage('required/assets/ring.png'); ring.anchor.set(0.5); @@ -50,7 +51,7 @@ ring.visible = false; stage.addChild(ring); -var bg = PIXI.Sprite.fromImage('_assets/bkg-grass.jpg'); +var bg = PIXI.Sprite.fromImage('required/assets/bkg-grass.jpg'); bg.width = renderer.width; bg.height = renderer.height; diff --git a/examples/filters/filter.js b/required/examples/filters/filter.js old mode 100644 new mode 100755 similarity index 83% rename from examples/filters/filter.js rename to required/examples/filters/filter.js index 708c76b..00f803a --- a/examples/filters/filter.js +++ b/required/examples/filters/filter.js @@ -6,7 +6,7 @@ var stage = new PIXI.Container(); stage.interactive = true; -var bg = PIXI.Sprite.fromImage('_assets/BGrotate.jpg'); +var bg = PIXI.Sprite.fromImage('required/assets/BGrotate.jpg'); bg.anchor.set(0.5); bg.position.x = renderer.width / 2; @@ -18,20 +18,20 @@ var container = new PIXI.Container(); container.position.x = renderer.width / 2; container.position.y = renderer.height / 2; -var bgFront = PIXI.Sprite.fromImage('_assets/SceneRotate.jpg'); +var bgFront = PIXI.Sprite.fromImage('required/assets/SceneRotate.jpg'); bgFront.anchor.set(0.5); container.addChild(bgFront); -var light2 = PIXI.Sprite.fromImage('_assets/LightRotate2.png'); +var light2 = PIXI.Sprite.fromImage('required/assets/LightRotate2.png'); light2.anchor.set(0.5); container.addChild(light2); -var light1 = PIXI.Sprite.fromImage('_assets/LightRotate1.png'); +var light1 = PIXI.Sprite.fromImage('required/assets/LightRotate1.png'); light1.anchor.set(0.5); container.addChild(light1); -var panda = PIXI.Sprite.fromImage('_assets/panda.png'); +var panda = PIXI.Sprite.fromImage('required/assets/panda.png'); panda.anchor.set(0.5); container.addChild(panda); diff --git a/required/examples/picture/_details.json b/required/examples/picture/_details.json new file mode 100755 index 0000000..4161988 --- /dev/null +++ b/required/examples/picture/_details.json @@ -0,0 +1,12 @@ +[ + { + "title": "Border artifacts", + "entry": "border-artifacts.js", + "plugins": ["pixi-picture"] + }, + { + "title": "Overlay blendMode", + "entry": "overlay.js", + "plugins": ["pixi-picture"] + } +] diff --git a/required/examples/picture/border-artifacts.js b/required/examples/picture/border-artifacts.js new file mode 100755 index 0000000..c731700 --- /dev/null +++ b/required/examples/picture/border-artifacts.js @@ -0,0 +1,24 @@ +// pixi-picture.js is REQUIRED for this demo +// plain, basic version of pixi-picture you can see at https://github.com/pixijs/pixi-plugin-example/ + +// ivan: border artifact example is not ready yet :) + +var renderer = new PIXI.CanvasRenderer(800, 600,{backgroundColor : 0x1099bb}); +document.body.appendChild(renderer.view); + +var stage = new PIXI.Container(); + +PIXI.loader.add('bunny', 'required/assets/bunny.png'); +PIXI.loader.load(function(loader, resources) { + var pic = new PIXI.extras.PictureSprite(resources.bunny.texture); + pic.position.set(200,200); + stage.addChild(pic); + + animate(); +}); + +function animate() { + requestAnimationFrame(animate); + // render the container + renderer.render(stage); +} diff --git a/required/examples/picture/overlay.js b/required/examples/picture/overlay.js new file mode 100755 index 0000000..93ffcb8 --- /dev/null +++ b/required/examples/picture/overlay.js @@ -0,0 +1,104 @@ +var renderer = PIXI.autoDetectRenderer(800, 600); +//var renderer = new PIXI.CanvasRenderer(800, 600); +document.body.appendChild(renderer.view); + +// create the root of the scene graph +var stage = new PIXI.Container(); + +// create a new background sprite +var background = new PIXI.Sprite.fromImage('required/assets/BGrotate.jpg'); +stage.addChild(background); +//speed up the process, because OVERLAY and HARD_LIGHT will use copyTex instead of readPixels +stage.filters = [new PIXI.filters.VoidFilter()]; +stage.filterArea = new PIXI.Rectangle(0, 0, 800, 600); + +// create an array to store a reference to the dudes +var dudeArray = []; + +var totaldudes = 20; + +for (var i = 0; i < totaldudes; i++) +{ + // create a new Sprite that uses the image name that we just generated as its source + var dude = new PIXI.extras.PictureSprite(PIXI.Texture.fromImage('required/assets/flowerTop.png')); + + dude.anchor.set(0.5); + + // set a random scale for the dude + dude.scale.set(0.8 + Math.random() * 0.3); + + // finally let's set the dude to be at a random position... + dude.position.x = Math.floor(Math.random() * renderer.width); + dude.position.y = Math.floor(Math.random() * renderer.height); + + // The important bit of this example, this is how you change the default blend mode of the sprite + dude.blendMode = Math.random()>0.5? PIXI.BLEND_MODES.OVERLAY:PIXI.BLEND_MODES.HARD_LIGHT; + + // create some extra properties that will control movement + dude.direction = Math.random() * Math.PI * 2; + + // this number will be used to modify the direction of the dude over time + dude.turningSpeed = Math.random() - 0.8; + + // create a random speed for the dude between 0 - 2 + dude.speed = 2 + Math.random() * 2; + + // finally we push the dude into the dudeArray so it it can be easily accessed later + dudeArray.push(dude); + + stage.addChild(dude); +} + +// create a bounding box box for the little dudes +var dudeBoundsPadding = 100; + +var dudeBounds = new PIXI.Rectangle(-dudeBoundsPadding, + -dudeBoundsPadding, + renderer.width + dudeBoundsPadding * 2, + renderer.height + dudeBoundsPadding * 2); + +var tick = 0; + +requestAnimationFrame(animate); + + +function animate() +{ + // iterate through the dudes and update the positions + for (var i = 0; i < dudeArray.length; i++) + { + var dude = dudeArray[i]; + dude.direction += dude.turningSpeed * 0.01; + dude.position.x += Math.sin(dude.direction) * dude.speed; + dude.position.y += Math.cos(dude.direction) * dude.speed; + dude.rotation = -dude.direction - Math.PI / 2; + + // wrap the dudes by testing their bounds... + if (dude.position.x < dudeBounds.x) + { + dude.position.x += dudeBounds.width; + } + else if (dude.position.x > dudeBounds.x + dudeBounds.width) + { + dude.position.x -= dudeBounds.width; + } + + if (dude.position.y < dudeBounds.y) + { + dude.position.y += dudeBounds.height; + } + else if (dude.position.y > dudeBounds.y + dudeBounds.height) + { + dude.position.y -= dudeBounds.height; + } + } + + // increment the ticker + tick += 0.1; + + // time to render the stage ! + renderer.render(stage); + + // request another animation frame... + requestAnimationFrame(animate); +} diff --git a/examples/spine/_details.json b/required/examples/spine/_details.json old mode 100644 new mode 100755 similarity index 100% rename from examples/spine/_details.json rename to required/examples/spine/_details.json diff --git a/examples/spine/dragon.js b/required/examples/spine/dragon.js old mode 100644 new mode 100755 similarity index 96% rename from examples/spine/dragon.js rename to required/examples/spine/dragon.js index d11cd85..dce46ef --- a/examples/spine/dragon.js +++ b/required/examples/spine/dragon.js @@ -6,7 +6,7 @@ var stage = new PIXI.Container(); // load spine data PIXI.loader - .add('dragon', '_assets/spine/dragon.json') + .add('dragon', 'required/assets/spine/dragon.json') .load(onAssetsLoaded); var dragon = null; diff --git a/examples/spine/goblins.js b/required/examples/spine/goblins.js old mode 100644 new mode 100755 similarity index 95% rename from examples/spine/goblins.js rename to required/examples/spine/goblins.js index 23d0bf0..69c2843 --- a/examples/spine/goblins.js +++ b/required/examples/spine/goblins.js @@ -6,7 +6,7 @@ var stage = new PIXI.Container(); // load spine data PIXI.loader - .add('goblins', '_assets/spine/goblins.json') + .add('goblins', 'required/assets/spine/goblins.json') .load(onAssetsLoaded); stage.interactive = true; diff --git a/examples/spine/pixie.js b/required/examples/spine/pixie.js old mode 100644 new mode 100755 similarity index 85% rename from examples/spine/pixie.js rename to required/examples/spine/pixie.js index fa9789e..dbfb8bd --- a/examples/spine/pixie.js +++ b/required/examples/spine/pixie.js @@ -6,7 +6,7 @@ var stage = new PIXI.Container(); // load spine data PIXI.loader - .add('pixie', '_assets/spine/Pixie.json') + .add('pixie', 'required/assets/spine/Pixie.json') .load(onAssetsLoaded); var postition = 0, @@ -19,13 +19,13 @@ stage.interactive = true; function onAssetsLoaded(loader,res) { - background = PIXI.Sprite.fromImage('_assets/spine/iP4_BGtile.jpg'); - background2 = PIXI.Sprite.fromImage('_assets/spine/iP4_BGtile.jpg'); + background = PIXI.Sprite.fromImage('required/assets/spine/iP4_BGtile.jpg'); + background2 = PIXI.Sprite.fromImage('required/assets/spine/iP4_BGtile.jpg'); stage.addChild(background); stage.addChild(background2); - foreground = PIXI.Sprite.fromImage('_assets/spine/iP4_ground.png'); - foreground2 = PIXI.Sprite.fromImage('_assets/spine/iP4_ground.png'); + foreground = PIXI.Sprite.fromImage('required/assets/spine/iP4_ground.png'); + foreground2 = PIXI.Sprite.fromImage('required/assets/spine/iP4_ground.png'); stage.addChild(foreground); stage.addChild(foreground2); foreground.position.y = foreground2.position.y = 640 - foreground2.height; diff --git a/examples/spine/spineboy.js b/required/examples/spine/spineboy.js old mode 100644 new mode 100755 similarity index 94% rename from examples/spine/spineboy.js rename to required/examples/spine/spineboy.js index 3317cce..6adb79b --- a/examples/spine/spineboy.js +++ b/required/examples/spine/spineboy.js @@ -6,7 +6,7 @@ var stage = new PIXI.Container(); // load spine data PIXI.loader - .add('spineboy', '_assets/spine/spineboy.json') + .add('spineboy', 'required/assets/spine/spineboy.json') .load(onAssetsLoaded); stage.interactive = true; diff --git a/examples/textures/_details.json b/required/examples/textures/_details.json old mode 100644 new mode 100755 similarity index 100% rename from examples/textures/_details.json rename to required/examples/textures/_details.json diff --git a/examples/textures/dds.js b/required/examples/textures/dds.js old mode 100644 new mode 100755 similarity index 89% rename from examples/textures/dds.js rename to required/examples/textures/dds.js index 2284ebd..8488e95 --- a/examples/textures/dds.js +++ b/required/examples/textures/dds.js @@ -17,9 +17,9 @@ var atlasOptions = { metadata: { choice: ["@2x.json"], imageMetadata: { choice: var stage = new PIXI.Container(); -loader.add('building1', '_assets/compressed/building1.png', textureOptions1) - .add('building2', '_assets/compressed/building2.png', textureOptions2) - .add('atlas1', '_assets/compressed/buildings.json', atlasOptions ) +loader.add('building1', 'required/assets/compressed/building1.png', textureOptions1) + .add('building2', 'required/assets/compressed/building2.png', textureOptions2) + .add('atlas1', 'required/assets/compressed/buildings.json', atlasOptions ) .load(function(loader, resources) { // You have to preload all compressed textures into videomemory, pixi renderer cant do that for you. // You also can specify different renderer or set in that function diff --git a/_site/js/plugins/pixi-compressed-textures.js b/required/plugins/pixi-compressed-textures.js old mode 100644 new mode 100755 similarity index 100% rename from _site/js/plugins/pixi-compressed-textures.js rename to required/plugins/pixi-compressed-textures.js diff --git a/required/plugins/pixi-display.js b/required/plugins/pixi-display.js new file mode 100755 index 0000000..683dde7 --- /dev/null +++ b/required/plugins/pixi-display.js @@ -0,0 +1,734 @@ +(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 b.zOrder) { + return -1; + } + return a.updateOrder - b.updateOrder; +}; + +/** + * clears temporary variables + */ +DisplayGroup.prototype.clear = function () { + var list = this.computedChildren; + for (var i = 0; i < list.length; i++) { + var children = list[i].displayChildren; + if (children && children.length > 0) { + for (var j = 0; j < children.length; j++) { + children[j].displayParent = null; + } + children.length = 0; + } + list[i].displayParent = null; + } + list.length = 0; + this.currentDisplayList = null; + this.currentIndex = 0; +}; + +/** + * used only by displayList before sorting takes place + * @param container {PIXI.DisplayObject} + */ +DisplayGroup.prototype.add = function (displayObject) { + displayObject.displayOrder = this.computedChildren.length; + this.emit('add', displayObject); + this.computedChildren.push(displayObject); +}; + +/** + * Called after all childrens are computed + */ +DisplayGroup.prototype.update = function () { + this.emit('update'); + if (this.enableSort && this.computedChildren.length > 1) { + this.computedChildren.sort(DisplayGroup.compareZOrder); + } +}; + +},{}],5:[function(require,module,exports){ +var EventEmitter = PIXI.utils.EventEmitter, + Const = require('./Const'), + DisplayGroup = require('./DisplayGroup'); +/** + * A component for container, sorts all children inside according to their displayGroups + * + * @class + * @extends EventEmitter + * @memberof PIXI + */ +function DisplayList() { + EventEmitter.call(this); + /** + * Children that were rendered in last run + * @type {Array} + */ + this.displayGroups = []; + + this.container = null; + + /** + * how many elements were rendered by display list last time + * also it is used to generate updateOrder for them + * @type {number} + */ + this.totalElements = 0; + + this.defaultDisplayGroup = new DisplayGroup(0, false); +} + +DisplayList.prototype = Object.create(EventEmitter.prototype); +DisplayList.prototype.constructor = DisplayList; +module.exports = DisplayList; + +/** + * clears all display lists that were used in last rendering session + * please clear it when you stop using this displayList, otherwise you may have problems with GC in some cases + */ +DisplayList.prototype.clear = function () { + var list = this.displayGroups; + for (var i = 0; i < list.length; i++) { + list[i].clear(); + } + list.length = 0; + this.totalElements = 0; + this.container = null; +}; + +/** + * alias for clear() + * please call it if you stop using this displayList + */ +DisplayList.prototype.destroy = function () { + this.clear(); +}; + +DisplayList.compareZIndex = function (a, b) { + if (a.zIndex !== b.zIndex) { + return a.zIndex - b.zIndex; + } + return a.currentIndex - b.currentIndex; +}; + +/** + * + * @param displayObject {PIXI.DisplayObject} container that we are adding to displaylist + * @param parent {PIXI.Container} it is not direct parent, but some of ancestors + * @private + */ +DisplayList.prototype._addRecursive = function (container, parent) { + if (!container.visible || !container.renderable) { + return; + } + var groups = this.displayGroups; + var group = parent.displayGroup; + + container.updateOrder = this.totalElements++; + if (container.displayGroup) { + group = container.displayGroup; + if (!group.currentDisplayList) { + group.currentDisplayList = this; + group.currentIndex = groups.length; + groups.push(group); + } + group.add(container); + + container.displayParent = container; + } else { + container.displayParent = parent; + if (!parent.displayChildren) { + parent.displayChildren = []; + } + parent.displayChildren.push(container); + } + + if (container.displayFlag !== Const.DISPLAY_FLAG.MANUAL_CONTAINER) { + var children = container.children; + if (children && children.length > 0) { + if (container._mask || container._filters && container._filters.length || container.displayList) { + container.displayFlag = Const.DISPLAY_FLAG.AUTO_CONTAINER; + } else { + container.displayFlag = Const.DISPLAY_FLAG.AUTO_CHILDREN; + for (var i = 0; i < children.length; i++) { + this._addRecursive(children[i], container.displayParent); + } + } + } else { + container.displayFlag = Const.DISPLAY_FLAG.AUTO_OBJECT; + } + } +}; + +/** + * Called from container that owns this display list + * @param parentContainer + */ +DisplayList.prototype.update = function (parentContainer) { + this.clear(); + var tempGroup = parentContainer.displayGroup; + this.displayGroups.push(this.defaultDisplayGroup); + this.defaultDisplayGroup.add(parentContainer); + + this.container = parentContainer; + var children = parentContainer.children; + var i; + for (i = 0; i < children.length; i++) { + this._addRecursive(children[i], parentContainer); + } + var groups = this.displayGroups; + groups.sort(DisplayList.compareZIndex); + for (i = 0; i < groups.length; i++) { + groups[i].currentIndex = i; + groups[i].update(); + } + this.emit('afterUpdate'); +}; + +/** + * renders container with webgl context + * @param parentContainer + * @param renderer + */ +DisplayList.prototype.renderWebGL = function (parentContainer, renderer) { + var groups = this.displayGroups; + for (var i = 0; i < groups.length; i++) { + var group = groups[i]; + var list = group.computedChildren; + for (var j = 0; j < list.length; j++) { + var container = list[j]; + if (container.displayFlag) { + container.renderWebGL(renderer); + } else { + container.displayOrder = renderer.incDisplayOrder(); + container._renderWebGL(renderer); + var children = container.displayChildren; + if (children && children.length) { + for (var k = 0; k < children.length; k++) { + var child = children[k]; + child.displayOrder = renderer.incDisplayOrder(); + if (child.displayFlag) { + child.renderWebGL(renderer); + } else { + child._renderWebGL(renderer); + } + } + } + } + } + } +}; + +/** + * renders container with canvas2d context + * @param parentContainer + * @param renderer + */ +DisplayList.prototype.renderCanvas = function (parentContainer, renderer) { + var groups = this.displayGroups; + for (var i = 0; i < groups.length; i++) { + var group = groups[i]; + var list = group.computedChildren; + for (var j = 0; j < list.length; j++) { + var container = list[j]; + if (container.displayFlag) { + container.renderCanvas(renderer); + } else { + container.displayOrder = renderer.incDisplayOrder(); + container._renderCanvas(renderer); + var children = container.displayChildren; + if (children && children.length) { + for (var k = 0; k < children.length; k++) { + var child = children[k]; + child.displayOrder = renderer.incDisplayOrder(); + if (child.displayFlag) { + child.renderCanvas(renderer); + } else { + child._renderCanvas(renderer); + } + } + } + } + } + } +}; + +},{"./Const":2,"./DisplayGroup":4}],6:[function(require,module,exports){ +var Const = require('./Const'); + +/** + * @mixin + */ +var DisplayObjectMixin = { + /** + * please specify it to handle zOrder and zIndex + * @type {PIXI.DisplayGroup} + */ + displayGroup: null, + + /** + * calculated inside displayList. Can be set to manual mode + * @type {number} + */ + displayFlag: Const.DISPLAY_FLAG.AUTO_CHILDREN, + + /** + * calculated inside displayList. Cleared on displayList.clear() + * Equal to 'this' if displayGroup is specified + * @type {PIXI.Container} + */ + displayParent: null, + + /** + * zOrder is distance between screen and object. Objects with largest zOrder will appear first in their DisplayGroup + * @type {number} + */ + zOrder: 0, + + /** + * updateOrder is calculated by DisplayList, it is required for sorting inside DisplayGroup + * @type {number} + */ + updateOrder: 0 +}; + +module.exports = DisplayObjectMixin; + +},{"./Const":2}],7:[function(require,module,exports){ +//TODO: add maxDisplayOrder for displayObjects and use it to speed up the interaction here + +var gameofbombs = !!PIXI.Camera2d; + +/** + * @mixin + */ +var InteractionManagerMixin = { + /** + * This is private recursive copy of processInteractive + */ + _processInteractive: function (point, displayObject, hitTestOrder, interactive) { + if (!displayObject || !displayObject.visible) { + return false; + } + + // Took a little while to rework this function correctly! But now it is done and nice and optimised. ^_^ + // + // This function will now loop through all objects and then only hit test the objects it HAS to, not all of them. MUCH faster.. + // An object will be hit test if the following is true: + // + // 1: It is interactive. + // 2: It belongs to a parent that is interactive AND one of the parents children have not already been hit. + // + // As another little optimisation once an interactive object has been hit we can carry on through the scenegraph, but we know that there will be no more hits! So we can avoid extra hit tests + // A final optimisation is that an object is not hit test directly if a child has already been hit. + + var hit = 0, + interactiveParent = interactive = displayObject.interactive || interactive; + + + // if the displayobject has a hitArea, then it does not need to hitTest children. + if (displayObject.hitArea) { + interactiveParent = false; + } + + // it has a mask! Then lets hit test that before continuing.. + if (hitTestOrder < Infinity && displayObject._mask) { + if (!displayObject._mask.containsPoint(point)) { + hitTestOrder = Infinity; + } + } + + // it has a filterArea! Same as mask but easier, its a rectangle + if (hitTestOrder < Infinity && displayObject.filterArea) { + if (!displayObject.filterArea.contains(point.x, point.y)) { + hitTestOrder = Infinity; + } + } + + // ** FREE TIP **! If an object is not interactive or has no buttons in it (such as a game scene!) set interactiveChildren to false for that displayObject. + // This will allow pixi to completly ignore and bypass checking the displayObjects children. + if (displayObject.interactiveChildren) { + var children = displayObject.children; + + for (var i = children.length - 1; i >= 0; i--) { + + var child = children[i]; + + var hitChild = this._processInteractive(point, child, hitTestOrder, interactiveParent); + // time to get recursive.. if this function will return if something is hit.. + if (hitChild) { + hit = hitChild; + hitTestOrder = hitChild; + } + } + } + + + // no point running this if the item is not interactive or does not have an interactive parent. + if (interactive) { + // if we are hit testing (as in we have no hit any objects yet) + // We also don't need to worry about hit testing if once of the displayObjects children has already been hit! + if (hitTestOrder < displayObject.displayOrder) { + if (gameofbombs) { + //gameofbombs version + if (displayObject.hitArea && displayObject.isRaycastPossible) { + if (displayObject.containsPoint(point)) { + hit = displayObject.displayOrder; + } + } + } else { + //pixi v4 + if (displayObject.hitArea) { + displayObject.worldTransform.applyInverse(point, this._tempPoint); + if (displayObject.hitArea.contains(this._tempPoint.x, this._tempPoint.y)) { + hit = displayObject.displayOrder; + } + } + else if (displayObject.containsPoint) { + if (displayObject.containsPoint(point)) { + hit = displayObject.displayOrder; + } + } + } + } + + if (displayObject.interactive) { + this._queueAdd(displayObject, hit); + } + } + + return hit; + + }, + + /** + * This function is provides a neat way of crawling through the scene graph and running a specified function on all interactive objects it finds. + * It will also take care of hit testing the interactive objects and passes the hit across in the function. + * + * @param {PIXI.Point} point the point that is tested for collision + * @param {PIXI.Container|PIXI.Sprite|PIXI.extras.TilingSprite} displayObject the displayObject that will be hit test (recursively crawls its children) + * @param {boolean} hitTest this indicates if the objects inside should be hit test against the point + * @param {Function} func the function that will be called on each interactive object. The displayObject and hit will be passed to the function + * @private + * @return {boolean} returns true if the displayObject hit the point + */ + processInteractive: function (point, displayObject, func, hitTest) { + this._startInteractionProcess(); + this._processInteractive(point, displayObject, hitTest ? 0 : Infinity, false); + this._finishInteractionProcess(func); + }, + + _startInteractionProcess: function () { + //move it to constructor + this._eventDisplayOrder = 1; + if (!this._queue) { + //move it to constructor + this._queue = [[], []]; + } + this._queue[0].length = 0; + this._queue[1].length = 0; + }, + + _queueAdd: function (displayObject, order) { + var queue = this._queue; + if (order < this._eventDisplayOrder) { + queue[0].push(displayObject); + } else { + if (order > this._eventDisplayOrder) { + this._eventDisplayOrder = order; + var q = queue[1]; + for (var i = 0; i < q.length; i++) { + queue[0].push(q[i]); + } + queue[1].length = 0; + } + queue[1].push(displayObject); + } + }, + + /** + * + * @param {Function} func the function that will be called on each interactive object. The displayObject and hit will be passed to the function + */ + _finishInteractionProcess: function (func) { + var queue = this._queue; + var q = queue[0]; + var i; + for (i = 0; i < q.length; i++) { + func(q[i], false); + } + q = queue[1]; + for (i = 0; i < q.length; i++) { + func(q[i], true); + } + } +}; + +module.exports = InteractionManagerMixin; + +},{}],8:[function(require,module,exports){ +/** + * @mixin + */ +var SystemRendererMixin = { + /** + * @private + * @type {number} + */ + _lastDisplayOrder: 0, + + /** + * gets new display order for container/displayobject + */ + incDisplayOrder: function() { + return ++this._lastDisplayOrder; + } +}; + +module.exports = SystemRendererMixin; + +},{}],9:[function(require,module,exports){ +/** + * @mixin + */ +var WebGLRendererMixin = { + _oldRender: PIXI.WebGLRenderer.prototype.render, + render: function (displayObject, renderTexture, clear, transform, skipUpdateTransform) { + if (!renderTexture) { + this._lastDisplayOrder = 0; + } + this._oldRender(displayObject, renderTexture, clear, transform, skipUpdateTransform); + } +}; + +module.exports = WebGLRendererMixin; + +},{}],10:[function(require,module,exports){ +var plugin = { + DisplayGroup: require('./DisplayGroup'), + DisplayList: require('./DisplayList'), + Const: require('./Const'), + DisplayObjectMixin: require('./DisplayObjectMixin'), + ContainerMixin: require('./ContainerMixin'), + SystemRendererMixin: require('./SystemRendererMixin'), + WebGLRendererMixin: require('./WebGLRendererMixin'), + CanvasRendererMixin: require('./CanvasRendererMixin'), + InteractionManagerMixin: require('./InteractionManagerMixin') +}; + +var pluginMixin = { + DisplayGroup: plugin.DisplayGroup, + DisplayList: plugin.DisplayList +}; + +Object.assign(pluginMixin, plugin.Const); + +Object.assign(PIXI.DisplayObject.prototype, plugin.DisplayObjectMixin); + +Object.assign(PIXI.Container.prototype, plugin.ContainerMixin); + +Object.assign(PIXI.WebGLRenderer.prototype, plugin.SystemRendererMixin, plugin.WebGLRendererMixin); + +Object.assign(PIXI.CanvasRenderer.prototype, plugin.SystemRendererMixin, plugin.CanvasRendererMixin); + +Object.assign(PIXI.interaction.InteractionManager.prototype, plugin.InteractionManagerMixin); + +Object.assign(PIXI, pluginMixin); + +module.exports = plugin; + +},{"./CanvasRendererMixin":1,"./Const":2,"./ContainerMixin":3,"./DisplayGroup":4,"./DisplayList":5,"./DisplayObjectMixin":6,"./InteractionManagerMixin":7,"./SystemRendererMixin":8,"./WebGLRendererMixin":9}]},{},[10]) + + +//# sourceMappingURL=pixi-display.js.map diff --git a/required/plugins/pixi-picture.js b/required/plugins/pixi-picture.js new file mode 100755 index 0000000..d1379a7 --- /dev/null +++ b/required/plugins/pixi-picture.js @@ -0,0 +1,383 @@ +(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 0.0) {\n\n Cs = target.rgb / target.a;\n\n }\n\n vec3 multiply = Cb * Cs * 2.0;\n\n vec3 Cs2 = Cs * 2.0 - 1.0;\n\n vec3 screen = Cb + Cs2 - Cb * Cs2;\n\n vec3 B;\n\n if (Cb.r <= 0.5) {\n\n B.r = multiply.r;\n\n } else {\n\n B.r = screen.r;\n\n }\n\n if (Cb.g <= 0.5) {\n\n B.g = multiply.g;\n\n } else {\n\n B.g = screen.g;\n\n }\n\n if (Cb.b <= 0.5) {\n\n B.b = multiply.b;\n\n } else {\n\n B.b = screen.b;\n\n }\n\n vec4 res;\n\n res.xyz = (1.0 - source.a) * Cs + source.a * B;\n\n res.a = source.a + target.a * (1.0-source.a);\n\n gl_FragColor = vec4(res.xyz * res.a, res.a);\n\n}\n\n" + ); + this.bind(); + this.uniforms.uSampler = [0, 1]; +} + +OverlayShader.prototype = Object.create(PIXI.Shader.prototype); +OverlayShader.prototype.constructor = OverlayShader; +module.exports = OverlayShader; + +},{}],2:[function(require,module,exports){ + + +/** + * @class + * @extends PIXI.Shader + * @memberof PIXI.tilemap + * @param gl {PIXI.Shader} The WebGL shader manager this shader works for. + */ +function OverlayShader(gl) +{ + PIXI.Shader.call(this, + gl, + "#define GLSLIFY 1\nattribute vec2 aVertexPosition;\n\nattribute vec2 aTextureCoord;\n\nattribute vec4 aColor;\n\nuniform mat3 projectionMatrix;\n\nuniform mat3 mapMatrix;\n\nvarying vec2 vTextureCoord;\n\nvarying vec2 vMapCoord;\n\nvoid main(void)\n\n{\n\n gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\n\n vMapCoord = (mapMatrix * vec3(aVertexPosition, 1.0)).xy;\n\n vTextureCoord = aTextureCoord;\n\n}\n\n", + "#define GLSLIFY 1\nvarying vec2 vTextureCoord;\n\nvarying vec2 vMapCoord;\n\nvarying vec4 vColor;\n\nuniform sampler2D uSampler[2];\n\nuniform vec4 uTextureClamp;\n\nuniform vec4 uColor;\n\nvoid main(void)\n\n{\n\n vec2 textureCoord = clamp(vTextureCoord, uTextureClamp.xy, uTextureClamp.zw);\n\n vec4 source = texture2D(uSampler[0], textureCoord);\n\n vec4 target = texture2D(uSampler[1], vMapCoord);\n\n //reverse hardlight\r\n if (source.a == 0.0) {\n\n gl_FragColor = vec4(0, 0, 0, 0);\n\n return;\n\n }\n\n //yeah, premultiplied\r\n vec3 Cb = source.rgb/source.a, Cs;\n\n if (target.a > 0.0) {\n\n Cs = target.rgb / target.a;\n\n }\n\n vec3 multiply = Cb * Cs * 2.0;\n\n vec3 Cb2 = Cb * 2.0 - 1.0;\n\n vec3 screen = Cb2 + Cs - Cb2 * Cs;\n\n vec3 B;\n\n if (Cs.r <= 0.5) {\n\n B.r = multiply.r;\n\n } else {\n\n B.r = screen.r;\n\n }\n\n if (Cs.g <= 0.5) {\n\n B.g = multiply.g;\n\n } else {\n\n B.g = screen.g;\n\n }\n\n if (Cs.b <= 0.5) {\n\n B.b = multiply.b;\n\n } else {\n\n B.b = screen.b;\n\n }\n\n vec4 res;\n\n res.xyz = (1.0 - source.a) * Cs + source.a * B;\n\n res.a = source.a + target.a * (1.0-source.a);\n\n gl_FragColor = vec4(res.xyz * res.a, res.a);\n\n}\n\n" + ); + this.bind(); + this.uniforms.uSampler = [0, 1]; +} + +OverlayShader.prototype = Object.create(PIXI.Shader.prototype); +OverlayShader.prototype.constructor = OverlayShader; +module.exports = OverlayShader; + +},{}],3:[function(require,module,exports){ +var PictureShader = require('./PictureShader'), + mapFilterBlendModesToPixi = require('./mapFilterBlendModesToPixi'), + glCore = PIXI.glCore; + +/** + * Renderer that clamps the texture so neighbour frames wont bleed on it + * immitates context2d drawImage behaviour + * + * @class + * @memberof PIXI.extras + * @extends PIXI.ObjectRenderer + * @param renderer {PIXI.WebGLRenderer} The renderer this plugin works for + */ +function PictureRenderer(renderer) { + PIXI.ObjectRenderer.call(this, renderer); +} + +PictureRenderer.prototype = Object.create(PIXI.ObjectRenderer.prototype); +PictureRenderer.prototype.constructor = PictureRenderer; + +PictureRenderer.prototype.onContextChange = function () { + var gl = this.renderer.gl; + this.quad = new PIXI.Quad(gl); + this.normalShader = new PictureShader(gl); + this.drawModes = mapFilterBlendModesToPixi(gl); + this.quad.initVao(this.normalShader); + this._tempClamp = new Float32Array(4); + this._tempColor = new Float32Array(4); + this._tempRect = new PIXI.Rectangle(); + this._tempRect2 = new PIXI.Rectangle(); + this._tempRect3 = new PIXI.Rectangle(); + this._tempMatrix = new PIXI.Matrix(); + this._bigBuf = new Uint8Array(1 << 20); + this._renderTexture = new PIXI.BaseRenderTexture(1024, 1024); +}; + +PictureRenderer.prototype.start = function () { + //noop +}; + +PictureRenderer.prototype.flush = function () { + //noop +}; + +function nextPow2(v) { + v += v === 0; + --v; + v |= v >>> 1; + v |= v >>> 2; + v |= v >>> 4; + v |= v >>> 8; + v |= v >>> 16; + return v + 1; +} + +PictureRenderer.prototype._getRenderTexture = function (minWidth, minHeight) { + if (this._renderTexture.width < minWidth || + this._renderTexture.height < minHeight) { + minHeight = nextPow2(minWidth * resolution); + minHeight = nextPow2(minHeight * resolution); + this._renderTexture.resize(minWidth, minHeight); + } + return this._renderTexture; +}; + +PictureRenderer.prototype._getBuf = function (size) { + var buf = this._bigBuf; + if (buf.length < size) { + size = nextPow2(size); + buf = new Uint8Array(size); + this._bigBuf = buf; + } + return buf; +}; + +/** + * Renders the picture object. + * + * @param sprite {PIXI.tilemap.PictureSprite} the picture to render + */ +PictureRenderer.prototype.render = function (sprite) { + if (!sprite.texture.valid) { + return; + } + var blendShader = this.drawModes[sprite.blendMode]; + if (blendShader) { + this._renderBlend(sprite, blendShader); + } else { + this._renderNormal(sprite, this.normalShader); + } +}; + +PictureRenderer.prototype._renderNormal = function (sprite, shader) { + var renderer = this.renderer; + renderer.bindShader(shader); + renderer.state.setBlendMode(sprite.blendMode); + this._renderInner(sprite, shader); +}; + +PictureRenderer.prototype._renderBlend = function (sprite, shader) { + //nothing there yet + var renderer = this.renderer; + var spriteBounds = sprite.getBounds(); + var renderTarget = renderer._activeRenderTarget; + var matrix = renderTarget.projectionMatrix; + var flipY = matrix.d < 0; + var resolution = renderTarget.resolution; + var screen = this._tempRect; + var fr = renderTarget.sourceFrame || renderTarget.destinationFrame; + screen.x = 0; + screen.y = 0; + screen.width = fr.width; + screen.height = fr.height; + + var bounds = this._tempRect2; + var fbw = fr.width * resolution, fbh = fr.height * resolution; + bounds.x = (spriteBounds.x + matrix.tx / matrix.a) * resolution + fbw / 2; + bounds.y = (spriteBounds.y + matrix.ty / matrix.d) * resolution + fbh / 2; + bounds.width = spriteBounds.width * resolution; + bounds.height = spriteBounds.height * resolution; + if (flipY) { + bounds.y = fbh - bounds.height - bounds.y; + } + + var screenBounds = this._tempRect3; + var x_1 = Math.floor(Math.max(screen.x, bounds.x)); + var x_2 = Math.ceil(Math.min(screen.x + screen.width, bounds.x + bounds.width)); + var y_1 = Math.floor(Math.max(screen.y, bounds.y)); + var y_2 = Math.ceil(Math.min(screen.y + screen.height, bounds.y + bounds.height)); + var pixelsWidth = x_2 - x_1; + var pixelsHeight = y_2 - y_1; + if (pixelsWidth <= 0 || pixelsHeight <= 0) { + //culling + return; + } + //TODO: padding + var rt = this._getRenderTexture(pixelsWidth, pixelsHeight); + renderer.bindTexture(rt, 1); + var gl = renderer.gl; + if (renderer.renderingToScreen && renderTarget.root) { + var buf = this._getBuf(pixelsWidth * pixelsHeight * 4); + gl.readPixels(x_1, y_1, pixelsWidth, pixelsHeight, gl.RGBA, gl.UNSIGNED_BYTE, this._bigBuf); + //REVERT Y? + gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, pixelsWidth, pixelsHeight, gl.RGBA, gl.UNSIGNED_BYTE, this._bigBuf); + } else { + gl.copyTexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, x_1, y_1, pixelsWidth, pixelsHeight); + } + + renderer.bindShader(shader); + renderer.state.setBlendMode(PIXI.BLEND_MODES.NORMAL); + if (shader.uniforms.mapMatrix) { + var mapMatrix = this._tempMatrix; + mapMatrix.a = bounds.width / rt.width / spriteBounds.width; + mapMatrix.tx = (bounds.x - x_1) / rt.width - spriteBounds.x * mapMatrix.a; + mapMatrix.d = bounds.height / rt.height / spriteBounds.height; + if (flipY) { + mapMatrix.d = -mapMatrix.d; + mapMatrix.ty = (bounds.y - y_1) / rt.height - (spriteBounds.y + spriteBounds.height) * mapMatrix.d; + } else { + mapMatrix.ty = (bounds.y - y_1) / rt.height - spriteBounds.y * mapMatrix.d; + } + + shader.uniforms.mapMatrix = mapMatrix.toArray(true, shader.uniforms.mapMatrix); + } + + this._renderInner(sprite, shader); +}; + + +PictureRenderer.prototype._renderInner = function (sprite, shader) { + var renderer = this.renderer; + var quad = this.quad; + var uvs = sprite.texture._uvs; + + //sprite already has calculated the vertices. lets transfer them to quad + var vertices = quad.vertices; + for (var i = 0; i < 8; i++) { + quad.vertices[i] = sprite.vertexData[i]; + } + + //SpriteRenderer works differently, with uint32 UVS + //but for our demo float uvs are just fine + quad.uvs[0] = uvs.x0; + quad.uvs[1] = uvs.y0; + quad.uvs[2] = uvs.x1; + quad.uvs[3] = uvs.y1; + quad.uvs[4] = uvs.x2; + quad.uvs[5] = uvs.y2; + quad.uvs[6] = uvs.x3; + quad.uvs[7] = uvs.y3; + + //TODO: add baricentric coords here + quad.upload(); + + var frame = sprite.texture.frame; + var base = sprite.texture.baseTexture; + var clamp = this._tempClamp; + //clamping 0.5 pixel from each side to reduce border artifact + //this is our plugin main purpose + clamp[0] = frame.x / base.width + 0.5 / base.realWidth; + clamp[1] = frame.y / base.height + 0.5 / base.realWidth; + clamp[2] = (frame.x + frame.width) / base.width - 0.5 / base.realWidth; + clamp[3] = (frame.y + frame.height) / base.height - 0.5 / base.realWidth; + //take a notice that size in pixels is realWidth,realHeight + //width and height are divided by resolution + shader.uniforms.uTextureClamp = clamp; + + var color = this._tempColor; + PIXI.utils.hex2rgb(sprite.tint, color); + var alpha = sprite.worldAlpha; + //premultiplied alpha tint + //of course we could do that in shader too + color[0] *= alpha; + color[1] *= alpha; + color[2] *= alpha; + color[3] = alpha; + shader.uniforms.uColor = color; + + //bind texture to unit 0, our default sampler unit + renderer.bindTexture(base, 0); + quad.draw(); +}; + +PIXI.WebGLRenderer.registerPlugin('picture', PictureRenderer); + +module.exports = PictureRenderer; + +},{"./PictureShader":4,"./mapFilterBlendModesToPixi":7}],4:[function(require,module,exports){ + + +/** + * @class + * @extends PIXI.Shader + * @memberof PIXI.extras + * @param gl {PIXI.Shader} The WebGL shader manager this shader works for. + */ +function PictureShader(gl) +{ + PIXI.Shader.call(this, + gl, + "#define GLSLIFY 1\nattribute vec2 aVertexPosition;\n\nattribute vec2 aTextureCoord;\n\nattribute vec4 aColor;\n\nuniform mat3 projectionMatrix;\n\nvarying vec2 vTextureCoord;\n\nvoid main(void)\n\n{\n\n gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\n\n vTextureCoord = aTextureCoord;\n\n}\n\n", + "#define GLSLIFY 1\nvarying vec2 vTextureCoord;\n\nvarying vec4 vColor;\n\nuniform sampler2D uSampler;\n\nuniform vec4 uTextureClamp;\n\nuniform vec4 uColor;\n\nvoid main(void)\n\n{\n\n vec2 textureCoord = clamp(vTextureCoord, uTextureClamp.xy, uTextureClamp.zw);\n\n vec4 sample = texture2D(uSampler, textureCoord);\n\n gl_FragColor = sample * uColor;\n\n}\n\n" + ); + //do some stuff, like default values for shader + //dont forget to bind it if you really are changing the uniforms + this.bind(); + //default tint + //Its an example, actually PictureRenderer takes care of this stuff + this.uniforms.uColor = new Float32Array(1,1,1,1); +} + +PictureShader.prototype = Object.create(PIXI.Shader.prototype); +PictureShader.prototype.constructor = PictureShader; +module.exports = PictureShader; + +},{}],5:[function(require,module,exports){ +/** + * A Sprite with reduced border artifacts + * + * @class + * @extends PIXI.Sprite + * @memberof PIXI.tilemap + * @param texture {PIXI.Texture} the texture for this sprite + */ +function PictureSprite(texture) +{ + PIXI.Sprite.call(this, texture); +} + +PictureSprite.prototype = Object.create(PIXI.Sprite.prototype); +PictureSprite.prototype.constructor = PictureSprite; +module.exports = PictureSprite; + +/** + * Renders the object using the WebGL renderer + * + * @param renderer {PIXI.WebGLRenderer} + * @private + */ +PictureSprite.prototype._renderWebGL = function (renderer) +{ + //copy of PIXI.Sprite v4 behaviour + if(this.transform.updated || this.textureDirty) + { + this.textureDirty = false; + // set the vertex data + this.calculateVertices(); + } + + //use different plugin for rendering + renderer.setObjectRenderer(renderer.plugins.picture); + renderer.plugins.picture.render(this); +}; + +},{}],6:[function(require,module,exports){ +var myPlugin = { + PictureSprite: require('./PictureSprite'), + PictureRenderer: require('./PictureRenderer') +}; + +//dump everything into extras + +Object.assign(PIXI.extras, myPlugin); + +module.exports = myPlugin; + +},{"./PictureRenderer":3,"./PictureSprite":5}],7:[function(require,module,exports){ +var CONST = PIXI, + OverlayShader = require('./OverlayShader'), + HardLightShader = require('./HardLightShader'); + +/** + * Maps gl blend combinations to WebGL + * @class + * @memberof PIXI + */ +function mapFilterBlendModesToPixi(gl, array) +{ + array = array || []; + + //TODO - premultiply alpha would be different. + //add a boolean for that! + array[CONST.BLEND_MODES.OVERLAY] = new OverlayShader(gl); + array[CONST.BLEND_MODES.HARD_LIGHT] = new HardLightShader(gl); + + return array; +} + +module.exports = mapFilterBlendModesToPixi; + +},{"./HardLightShader":1,"./OverlayShader":2}]},{},[6]) + + +//# sourceMappingURL=pixi-picture.js.map diff --git a/_site/js/plugins/pixi-spine.js b/required/plugins/pixi-spine.js old mode 100644 new mode 100755 similarity index 62% rename from _site/js/plugins/pixi-spine.js rename to required/plugins/pixi-spine.js index fef9cbb..928d6cc --- a/_site/js/plugins/pixi-spine.js +++ b/required/plugins/pixi-spine.js @@ -1,14 +1,14 @@ -(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 time) this.apply(skeleton, lastTime, Number.MAX_VALUE, null, 0); - return; - } else if (lastTime > time) // - lastTime = -1; - var frameIndex = (time >= frames[frames.length - 2] ? frames.length : spine.Animation.binarySearch(frames, time, 2)) - 2; - if (frames[frameIndex] < lastTime) return; - skeleton.bones[this.boneIndex].flipX = frames[frameIndex + 1] != 0; - } -}; -module.exports = spine.FlipXTimeline; - - -},{"../SpineUtil":42,"./Animation":2,"./Curves":16}],23:[function(require,module,exports){ -var spine = require('../SpineUtil'); -spine.Animation = require('./Animation'); -spine.Curves = require('./Curves'); -spine.FlipYTimeline = function (frameCount) -{ - this.curves = new spine.Curves(frameCount); - this.frames = []; // time, flip, ... - this.frames.length = frameCount * 2; -}; -spine.FlipYTimeline.prototype = { - boneIndex: 0, - getFrameCount: function () - { - return this.frames.length / 2; - }, - setFrame: function (frameIndex, time, flip) - { - frameIndex *= 2; - this.frames[frameIndex] = time; - this.frames[frameIndex + 1] = flip ? 1 : 0; - }, - apply: function (skeleton, lastTime, time, firedEvents, alpha) - { - var frames = this.frames; - if (time < frames[0]) - { - if (lastTime > time) this.apply(skeleton, lastTime, Number.MAX_VALUE, null, 0); - return; - } else if (lastTime > time) // - lastTime = -1; - var frameIndex = (time >= frames[frames.length - 2] ? frames.length : spine.Animation.binarySearch(frames, time, 2)) - 2; - if (frames[frameIndex] < lastTime) return; - skeleton.bones[this.boneIndex].flipY = frames[frameIndex + 1] != 0; - } -}; -module.exports = spine.FlipYTimeline; - - -},{"../SpineUtil":42,"./Animation":2,"./Curves":16}],24:[function(require,module,exports){ +},{"../SpineUtil":44,"./Animation":2,"./Curves":16}],22:[function(require,module,exports){ var spine = require('../SpineUtil'); spine.IkConstraint = function (data, skeleton) { @@ -1341,6 +1525,9 @@ spine.IkConstraint = function (data, skeleton) this.target = skeleton.findBone(data.target.name); }; spine.IkConstraint.prototype = { + update: function() { + this.apply(); + }, apply: function () { var target = this.target; @@ -1360,84 +1547,199 @@ spine.IkConstraint.prototype = { * coordinate system. */ spine.IkConstraint.apply1 = function (bone, targetX, targetY, alpha) { - var parentRotation = (!bone.data.inheritRotation || !bone.parent) ? 0 : bone.parent.worldRotation; + var parentRotation = bone.parent ? bone.parent.getWorldRotationX(): 0; var rotation = bone.rotation; - // worldY and targetY sign depends on global constant spine.Bone.yDown - var rotationIK = (spine.Bone.yDown?-spine.radDeg:spine.radDeg)* Math.atan2(targetY - bone.worldY, targetX - bone.worldX) - parentRotation; + var rotationIK = Math.atan2(targetY - bone.worldY, targetX - bone.worldX) * spine.radDeg - parentRotation; + if ((bone.worldSignX != bone.worldSignY) != (bone.skeleton.flipX != (bone.skeleton.flipY != spine.Bone.yDown))) rotationIK = 360 - rotationIK; +<<<<<<< HEAD:required/plugins/pixi-spine.js +======= + + //OLD ONE: + + // float parentRotation = bone.parent == null ? 0 : bone.parent.getWorldRotationX(); + // float rotation = bone.rotation; + // float rotationIK = atan2(targetY - bone.worldY, targetX - bone.worldX) * radDeg - parentRotation; + // if ((bone.worldSignX != bone.worldSignY) != (bone.skeleton.flipX != bone.skeleton.flipY)) rotationIK = 360 - rotationIK; + + //NEW ONE + + // var pp = bone.parent; + // float id = 1 / (pp.a * pp.d - pp.b * pp.c); + // float x = targetX - pp.worldX, y = targetY - pp.worldY; + // float tx = (x * pp.d - y * pp.b) * id - bone.x, ty = (y * pp.a - x * pp.c) * id - bone.y; + // float rotationIK = atan2(ty, tx) * radDeg - bone.shearX; + // if (bone.scaleX < 0) rotationIK += 180; + + +>>>>>>> origin/master:_site/js/plugins/pixi-spine.js + if (rotationIK > 180) + rotationIK -= 360; + else if (rotationIK < -180) rotationIK += 360; bone.rotationIK = rotation + (rotationIK - rotation) * alpha; + bone.updateWorldTransform(); }; /** Adjusts the parent and child bone rotations so the tip of the child is as close to the target position as possible. The * target is specified in the world coordinate system. * @param child Any descendant bone of the parent. */ -spine.IkConstraint.apply2 = function (parent, child, targetX, targetY, bendDirection, alpha) +spine.IkConstraint.apply2 = function (parent, child, targetX, targetY, bendDir, alpha) { - var childRotation = child.rotation, parentRotation = parent.rotation; - if (!alpha) - { - child.rotationIK = childRotation; - parent.rotationIK = parentRotation; - return; - } - var positionX, positionY, tempPosition = spine.temp; - var parentParent = parent.parent; - if (parentParent) - { - tempPosition[0] = targetX; - tempPosition[1] = targetY; - parentParent.worldToLocal(tempPosition); - targetX = (tempPosition[0] - parent.x) * parentParent.worldScaleX; - targetY = (tempPosition[1] - parent.y) * parentParent.worldScaleY; + if (alpha == 0) return; + var px = parent.x, py = parent.y, psx = parent.scaleX, psy = parent.scaleY, csx = child.scaleX, cy = child.y; + var offset1, offset2, sign2; + if (psx < 0) { + psx = -psx; + offset1 = 180; + sign2 = -1; } else { - targetX -= parent.x; - targetY -= parent.y; + offset1 = 0; + sign2 = 1; } - if (child.parent == parent) - { - positionX = child.x; - positionY = child.y; - } else { - tempPosition[0] = child.x; - tempPosition[1] = child.y; - child.parent.localToWorld(tempPosition); - parent.worldToLocal(tempPosition); - positionX = tempPosition[0]; - positionY = tempPosition[1]; + if (psy < 0) { + psy = -psy; + sign2 = -sign2; } - var childX = positionX * parent.worldScaleX, childY = positionY * parent.worldScaleY; - var offset = Math.atan2(childY, childX); - var len1 = Math.sqrt(childX * childX + childY * childY), len2 = child.data.length * child.worldScaleX; - // Based on code by Ryan Juckett with permission: Copyright (c) 2008-2009 Ryan Juckett, http://www.ryanjuckett.com/ - var cosDenom = 2 * len1 * len2; - if (cosDenom < 0.0001) - { - child.rotationIK = childRotation + (Math.atan2(targetY, targetX) * spine.radDeg - parentRotation - childRotation) * alpha; - return; + if (csx < 0) { + csx = -csx; + offset2 = 180; + } else + offset2 = 0; + var pp = parent.parent; + var ppm = pp.matrix; + var tx, ty, dx, dy; + if (pp == null) { + tx = targetX - px; + ty = targetY - py; + dx = child.worldX - px; + dy = child.worldY - py; + } else { + var a = ppm.a, b = ppm.c, c = ppm.b, d = ppm.d, invDet = 1 / (a * d - b * c); + var wx = ppm.tx, wy = ppm.ty, x = targetX - wx, y = targetY - wy; + tx = (x * d - y * b) * invDet - px; + ty = (y * a - x * c) * invDet - py; + x = child.worldX - wx; + y = child.worldY - wy; + dx = (x * d - y * b) * invDet - px; + dy = (y * a - x * c) * invDet - py; } - var cos = (targetX * targetX + targetY * targetY - len1 * len1 - len2 * len2) / cosDenom; - if (cos < -1) - cos = -1; - else if (cos > 1) - cos = 1; - var childAngle = Math.acos(cos) * bendDirection; - var adjacent = len1 + len2 * cos, opposite = len2 * Math.sin(childAngle); - var parentAngle = Math.atan2(targetY * adjacent - targetX * opposite, targetX * adjacent + targetY * opposite); - var rotation = (parentAngle - offset) * spine.radDeg - parentRotation; - if (rotation > 180) - rotation -= 360; - else if (rotation < -180) // - rotation += 360; - parent.rotationIK = parentRotation + rotation * alpha; - rotation = (childAngle + offset) * spine.radDeg - childRotation; - if (rotation > 180) - rotation -= 360; - else if (rotation < -180) // - rotation += 360; - child.rotationIK = childRotation + (rotation + parent.worldRotation - child.parent.worldRotation) * alpha; +<<<<<<< HEAD:required/plugins/pixi-spine.js +======= + + //OLD ONE + // float tx, ty, dx, dy; + // if (pp == null) { + // tx = targetX - px; + // ty = targetY - py; + // dx = child.worldX - px; + // dy = child.worldY - py; + // } else { + // float a = pp.a, b = pp.b, c = pp.c, d = pp.d, invDet = 1 / (a * d - b * c); + // float wx = pp.worldX, wy = pp.worldY, x = targetX - wx, y = targetY - wy; + // tx = (x * d - y * b) * invDet - px; + // ty = (y * a - x * c) * invDet - py; + // x = child.worldX - wx; + // y = child.worldY - wy; + // dx = (x * d - y * b) * invDet - px; + // dy = (y * a - x * c) * invDet - py; + // } + + //NEW ONE + // float ppa = pp.a, ppb = pp.b, ppc = pp.c, ppd = pp.d, id = 1 / (ppa * ppd - ppb * ppc); + // float x = targetX - pp.worldX, y = targetY - pp.worldY; + // float tx = (x * ppd - y * ppb) * id - px, ty = (y * ppa - x * ppc) * id - py; + // x = child.worldX - pp.worldX; + // y = child.worldY - pp.worldY; + // float dx = (x * ppd - y * ppb) * id - px, dy = (y * ppa - x * ppc) * id - py; + +>>>>>>> origin/master:_site/js/plugins/pixi-spine.js + var l1 = Math.sqrt(dx * dx + dy * dy), l2 = child.data.length * csx, a1, a2; + outer: + if (Math.abs(psx - psy) <= 0.0001) { + l2 *= psx; + var cos = (tx * tx + ty * ty - l1 * l1 - l2 * l2) / (2 * l1 * l2); + if (cos < -1) + cos = -1; + else if (cos > 1) cos = 1; + a2 = Math.acos(cos) * bendDir; + var a = l1 + l2 * cos, o = l2 * Math.sin(a2); + a1 = Math.atan2(ty * a - tx * o, tx * a + ty * o); + } else { + cy = 0; + var a = psx * l2, b = psy * l2, ta = Math.atan2(ty, tx); + var aa = a * a, bb = b * b, ll = l1 * l1, dd = tx * tx + ty * ty; + var c0 = bb * ll + aa * dd - aa * bb, c1 = -2 * bb * l1, c2 = bb - aa; + var d = c1 * c1 - 4 * c2 * c0; + if (d >= 0) { + var q = Math.sqrt(d); + if (c1 < 0) q = -q; + q = -(c1 + q) / 2; + var r0 = q / c2, r1 = c0 / q; + var r = Math.abs(r0) < Math.abs(r1) ? r0 : r1; + if (r * r <= dd) { + var y = Math.sqrt(dd - r * r) * bendDir; + a1 = ta - Math.atan2(y, r); + a2 = Math.atan2(y / psy, (r - l1) / psx); + break outer; + } + } + var minAngle = 0, minDist = Infinity, minX = 0, minY = 0; + var maxAngle = 0, maxDist = 0, maxX = 0, maxY = 0; + var x = l1 + a, dist = x * x; + if (dist > maxDist) { + maxAngle = 0; + maxDist = dist; + maxX = x; + } + x = l1 - a; + dist = x * x; + if (dist < minDist) { + minAngle = Math.PI; + minDist = dist; + minX = x; + } + var angle = Math.acos(-a * l1 / (aa - bb)); + x = a * Math.cos(angle) + l1; + var y = b * Math.sin(angle); + dist = x * x + y * y; + if (dist < minDist) { + minAngle = angle; + minDist = dist; + minX = x; + minY = y; + } + if (dist > maxDist) { + maxAngle = angle; + maxDist = dist; + maxX = x; + maxY = y; + } + if (dd <= (minDist + maxDist) / 2) { + a1 = ta - Math.atan2(minY * bendDir, minX); + a2 = minAngle * bendDir; + } else { + a1 = ta - Math.atan2(maxY * bendDir, maxX); + a2 = maxAngle * bendDir; + } + } + var offset = Math.atan2(cy, child.x) * sign2; + a1 = (a1 - offset) * spine.radDeg + offset1; + a2 = (a2 + offset) * spine.radDeg * sign2 + offset2; + if (a1 > 180) + a1 -= 360; + else if (a1 < -180) a1 += 360; + if (a2 > 180) + a2 -= 360; + else if (a2 < -180) a2 += 360; + var rotation = parent.rotation; + parent.rotationIK = rotation + (a1 - rotation) * alpha; + parent.updateWorldTransform(); + rotation = child.rotation; + child.rotationIK = rotation + (a2 - rotation) * alpha; + child.updateWorldTransform(); }; module.exports = spine.IkConstraint; -},{"../SpineUtil":42}],25:[function(require,module,exports){ +},{"../SpineUtil":44}],23:[function(require,module,exports){ var spine = require('../SpineUtil') || {}; spine.IkConstraintData = function (name) { @@ -1452,7 +1754,7 @@ spine.IkConstraintData.prototype = { module.exports = spine.IkConstraintData; -},{"../SpineUtil":42}],26:[function(require,module,exports){ +},{"../SpineUtil":44}],24:[function(require,module,exports){ var spine = require('../SpineUtil') || {}; spine.Animation = require('./Animation'); spine.Curves = require('./Curves'); @@ -1504,7 +1806,7 @@ spine.IkConstraintTimeline.prototype = { module.exports = spine.IkConstraintTimeline; -},{"../SpineUtil":42,"./Animation":2,"./Curves":16}],27:[function(require,module,exports){ +},{"../SpineUtil":44,"./Animation":2,"./Curves":16}],25:[function(require,module,exports){ var spine = require('../SpineUtil') || {}; spine.AttachmentType = require('./AttachmentType'); spine.MeshAttachment = function (name) @@ -1513,6 +1815,8 @@ spine.MeshAttachment = function (name) }; spine.MeshAttachment.prototype = { type: spine.AttachmentType.mesh, + parentMesh: null, + inheritFFD: false, vertices: null, uvs: null, regionUVs: null, @@ -1521,33 +1825,28 @@ spine.MeshAttachment.prototype = { r: 1, g: 1, b: 1, a: 1, path: null, rendererObject: null, - regionU: 0, regionV: 0, regionU2: 0, regionV2: 0, regionRotate: false, - regionOffsetX: 0, regionOffsetY: 0, - regionWidth: 0, regionHeight: 0, - regionOriginalWidth: 0, regionOriginalHeight: 0, edges: null, width: 0, height: 0, updateUVs: function () { - var width = this.regionU2 - this.regionU, height = this.regionV2 - this.regionV; var n = this.regionUVs.length; if (!this.uvs || this.uvs.length != n) { this.uvs = new spine.Float32Array(n); } - if (this.regionRotate) + var region = this.rendererObject; + if (!region) return; + var texture = region.texture; + var r = texture._uvs; + var w1 = region.width, h1 = region.height, w2 = region.originalWidth, h2 = region.originalHeight; + var x = region.offsetX, y = region.pixiOffsetY; + for (var i = 0; i < n; i += 2) { - for (var i = 0; i < n; i += 2) - { - this.uvs[i] = this.regionU + this.regionUVs[i + 1] * width; - this.uvs[i + 1] = this.regionV + height - this.regionUVs[i] * height; - } - } else { - for (var i = 0; i < n; i += 2) - { - this.uvs[i] = this.regionU + this.regionUVs[i] * width; - this.uvs[i + 1] = this.regionV + this.regionUVs[i + 1] * height; - } + var u = this.regionUVs[i], v = this.regionUVs[i+1]; + u = (u * w2 - x) / w1; + v = (v * h2 - y) / h1; + this.uvs[i] = (r.x0 * (1 - u) + r.x1 * u) * (1-v) + (r.x3 * (1 - u) + r.x2 * u) * v; + this.uvs[i+1] = (r.y0 * (1 - u) + r.y1 * u) * (1-v) + (r.y3 * (1 - u) + r.y2 * u) * v; } }, computeWorldVertices: function (x, y, slot, worldVertices) @@ -1555,7 +1854,7 @@ spine.MeshAttachment.prototype = { var bone = slot.bone; x += bone.worldX; y += bone.worldY; - var m00 = bone.m00, m01 = bone.m01, m10 = bone.m10, m11 = bone.m11; + var m00 = bone.matrix.a, m01 = bone.matrix.c, m10 = bone.matrix.b, m11 = bone.matrix.d; var vertices = this.vertices; var verticesCount = vertices.length; if (slot.attachmentVertices.length == verticesCount) vertices = slot.attachmentVertices; @@ -1566,12 +1865,35 @@ spine.MeshAttachment.prototype = { worldVertices[i] = vx * m00 + vy * m01 + x; worldVertices[i + 1] = vx * m10 + vy * m11 + y; } + }, + applyFFD: function(sourceAttachment) { + return this === sourceAttachment || (this.inheritFFD && parentMesh === sourceAttachment); + }, + setParentMesh: function(parentMesh) { + this.parentMesh = parentMesh; + if (parentMesh != null) { + this.vertices = parentMesh.vertices; + this.regionUVs = parentMesh.regionUVs; + this.triangles = parentMesh.triangles; + this.hullLength = parentMesh.hullLength; + } + }, + hackRegion: function(newRegion) { + if (!newRegion) { + if (!this.oldRegion) return; + newRegion = this.oldRegion; + } + if (!this.oldRegion) { + this.oldRegion = this.rendererObject; + } + this.rendererObject = newRegion; + this.updateUVs(); } }; module.exports = spine.MeshAttachment; -},{"../SpineUtil":42,"./AttachmentType":11}],28:[function(require,module,exports){ +},{"../SpineUtil":44,"./AttachmentType":11}],26:[function(require,module,exports){ var spine = require('../SpineUtil'); spine.AttachmentType = require('./AttachmentType'); spine.RegionAttachment = function (name) @@ -1651,7 +1973,7 @@ spine.RegionAttachment.prototype = { { x += bone.worldX; y += bone.worldY; - var m00 = bone.m00, m01 = bone.m01, m10 = bone.m10, m11 = bone.m11; + var m00 = bone.matrix.a, m01 = bone.matrix.c, m10 = bone.matrix.b, m11 = bone.matrix.d; var offset = this.offset; vertices[0/*X1*/] = offset[0/*X1*/] * m00 + offset[1/*Y1*/] * m01 + x; vertices[1/*Y1*/] = offset[0/*X1*/] * m10 + offset[1/*Y1*/] * m11 + y; @@ -1661,12 +1983,27 @@ spine.RegionAttachment.prototype = { vertices[5/*X3*/] = offset[4/*X3*/] * m10 + offset[5/*X3*/] * m11 + y; vertices[6/*X4*/] = offset[6/*X4*/] * m00 + offset[7/*Y4*/] * m01 + x; vertices[7/*Y4*/] = offset[6/*X4*/] * m10 + offset[7/*Y4*/] * m11 + y; + }, + hackRegion: function(newRegion) { + if (!newRegion) { + if (!this.oldRegion) return; + newRegion = this.oldRegion; + } + if (!this.oldRegion) { + this.oldRegion = this.rendererObject; + this.oldRegion.size = { width: this.width, height: this.height }; + } + this.rendererObject = newRegion; + if (newRegion.size) { + this.width = newRegion.size.width; + this.height = newRegion.size.height; + } } }; module.exports = spine.RegionAttachment; -},{"../SpineUtil":42,"./AttachmentType":11}],29:[function(require,module,exports){ +},{"../SpineUtil":44,"./AttachmentType":11}],27:[function(require,module,exports){ var spine = require('../SpineUtil') || {}; spine.Animation = require('./Animation'); spine.Curves = require('./Curves'); @@ -1729,7 +2066,7 @@ spine.RotateTimeline.prototype = { module.exports = spine.RotateTimeline; -},{"../SpineUtil":42,"./Animation":2,"./Curves":16}],30:[function(require,module,exports){ +},{"../SpineUtil":44,"./Animation":2,"./Curves":16}],28:[function(require,module,exports){ var spine = require('../SpineUtil'); spine.Animation = require('./Animation'); spine.Curves = require('./Curves'); @@ -1781,10 +2118,117 @@ spine.ScaleTimeline.prototype = { module.exports = spine.ScaleTimeline; -},{"../SpineUtil":42,"./Animation":2,"./Curves":16}],31:[function(require,module,exports){ +},{"../SpineUtil":44,"./Animation":2,"./Curves":16}],29:[function(require,module,exports){ +<<<<<<< HEAD:required/plugins/pixi-spine.js +======= var spine = require('../SpineUtil'); -spine.Bone = require('./Bone'); -spine.Slot = require('./Slot'); +spine.Animation = require('./Animation'); +spine.Curves = require('./Curves'); +spine.ShearTimeline = function (frameCount) +{ + this.curves = new spine.Curves(frameCount); + this.frames = []; // time, x, y, ... + this.frames.length = frameCount * 3; +}; +spine.ShearTimeline.prototype = { + boneIndex: 0, + getFrameCount: function () + { + return this.frames.length / 3; + }, + setFrame: function (frameIndex, time, x, y) + { + frameIndex *= 3; + this.frames[frameIndex] = time; + this.frames[frameIndex + 1] = x; + this.frames[frameIndex + 2] = y; + }, + apply: function (skeleton, lastTime, time, firedEvents, alpha) + { + var frames = this.frames; + if (time < frames[0]) return; // Time is before first frame. + + var bone = skeleton.bones[this.boneIndex]; + + if (time >= frames[frames.length - 3]) + { // Time is after last frame. + bone.shearX += (bone.data.shearX + frames[frames.length - 2] - bone.shearX) * alpha; + bone.shearY += (bone.data.shearY + frames[frames.length - 1] - bone.shearY) * alpha; + return; + } + + // Interpolate between the previous frame and the current frame. + var frameIndex = spine.Animation.binarySearch(frames, time, 3); + var prevFrameX = frames[frameIndex - 2]; + var prevFrameY = frames[frameIndex - 1]; + var frameTime = frames[frameIndex]; + var percent = 1 - (time - frameTime) / (frames[frameIndex + -3/*PREV_FRAME_TIME*/] - frameTime); + percent = this.curves.getCurvePercent(frameIndex / 3 - 1, percent); + + bone.shearX += (bone.data.shearX + (prevFrameX + (frames[frameIndex + 1/*FRAME_X*/] - prevFrameX) * percent) - bone.shearX) * alpha; + bone.shearY += (bone.data.shearY + (prevFrameY + (frames[frameIndex + 2/*FRAME_Y*/] - prevFrameY) * percent) - bone.shearY) * alpha; + } +}; +module.exports = spine.ShearTimeline; + + +},{"../SpineUtil":44,"./Animation":2,"./Curves":16}],30:[function(require,module,exports){ +>>>>>>> origin/master:_site/js/plugins/pixi-spine.js +var spine = require('../SpineUtil'); +spine.Animation = require('./Animation'); +spine.Curves = require('./Curves'); +spine.ShearTimeline = function (frameCount) +{ + this.curves = new spine.Curves(frameCount); + this.frames = []; // time, x, y, ... + this.frames.length = frameCount * 3; +}; +spine.ShearTimeline.prototype = { + boneIndex: 0, + getFrameCount: function () + { + return this.frames.length / 3; + }, + setFrame: function (frameIndex, time, x, y) + { + frameIndex *= 3; + this.frames[frameIndex] = time; + this.frames[frameIndex + 1] = x; + this.frames[frameIndex + 2] = y; + }, + apply: function (skeleton, lastTime, time, firedEvents, alpha) + { + var frames = this.frames; + if (time < frames[0]) return; // Time is before first frame. + + var bone = skeleton.bones[this.boneIndex]; + + if (time >= frames[frames.length - 3]) + { // Time is after last frame. + bone.shearX += (bone.data.shearX + frames[frames.length - 2] - bone.shearX) * alpha; + bone.shearY += (bone.data.shearY + frames[frames.length - 1] - bone.shearY) * alpha; + return; + } + + // Interpolate between the previous frame and the current frame. + var frameIndex = spine.Animation.binarySearch(frames, time, 3); + var prevFrameX = frames[frameIndex - 2]; + var prevFrameY = frames[frameIndex - 1]; + var frameTime = frames[frameIndex]; + var percent = 1 - (time - frameTime) / (frames[frameIndex + -3/*PREV_FRAME_TIME*/] - frameTime); + percent = this.curves.getCurvePercent(frameIndex / 3 - 1, percent); + + bone.shearX += (bone.data.shearX + (prevFrameX + (frames[frameIndex + 1/*FRAME_X*/] - prevFrameX) * percent) - bone.shearX) * alpha; + bone.shearY += (bone.data.shearY + (prevFrameY + (frames[frameIndex + 2/*FRAME_Y*/] - prevFrameY) * percent) - bone.shearY) * alpha; + } +}; +module.exports = spine.ShearTimeline; + + +},{"../SpineUtil":44,"./Animation":2,"./Curves":16}],30:[function(require,module,exports){ +var spine = require('../SpineUtil'); +spine.Bone = require('./Bone'); +spine.Slot = require('./Slot'); spine.IkConstraint = require('./IkConstraint'); spine.Skeleton = function (skeletonData) { @@ -1813,6 +2257,10 @@ spine.Skeleton = function (skeletonData) for (var i = 0, n = skeletonData.ikConstraints.length; i < n; i++) this.ikConstraints.push(new spine.IkConstraint(skeletonData.ikConstraints[i], this)); + this.transformConstraints = []; + for (var i = 0, n = skeletonData.transformConstraints.length; i < n; i++) + this.transformConstraints.push(new spine.TransformConstraint(skeletonData.transformConstraints[i], this)); + this.boneCache = []; this.updateCache(); }; @@ -1827,44 +2275,27 @@ spine.Skeleton.prototype = { { var ikConstraints = this.ikConstraints; var ikConstraintsCount = ikConstraints.length; + var transformConstraints = this.transformConstraints; + var transformConstraintsCount = transformConstraints.length; - var arrayCount = ikConstraintsCount + 1; var boneCache = this.boneCache; - if (boneCache.length > arrayCount) boneCache.length = arrayCount; - for (var i = 0, n = boneCache.length; i < n; i++) - boneCache[i].length = 0; - while (boneCache.length < arrayCount) - boneCache[boneCache.length] = []; - - var nonIkBones = boneCache[0]; + boneCache.length = 0; var bones = this.bones; - - outer: for (var i = 0, n = bones.length; i < n; i++) { var bone = bones[i]; - var current = bone; - do { - for (var ii = 0; ii < ikConstraintsCount; ii++) - { - var ikConstraint = ikConstraints[ii]; - var parent = ikConstraint.bones[0]; - var child= ikConstraint.bones[ikConstraint.bones.length - 1]; - while (true) - { - if (current == child) - { - boneCache[ii].push(bone); - boneCache[ii + 1].push(bone); - continue outer; - } - if (child == parent) break; - child = child.parent; - } + boneCache.push(bone); + for (var j=0; j < transformConstraintsCount; j++) { + if (transformConstraints[j].bone == bone) { + boneCache.push(transformConstraints[j]); } - current = current.parent; - } while (current); - nonIkBones[nonIkBones.length] = bone; + } + for (var j=0; j < ikConstraintsCount; j++) { + if (ikConstraints[j].bones[ikConstraints[j].bones.length-1] == bone) { + boneCache.push(ikConstraints[j]); + break; + } + } } }, /** Updates the world transform for each bone. */ @@ -1876,15 +2307,9 @@ spine.Skeleton.prototype = { var bone = bones[i]; bone.rotationIK = bone.rotation; } - var i = 0, last = this.boneCache.length - 1; - while (true) - { - var cacheBones = this.boneCache[i]; - for (var ii = 0, nn = cacheBones.length; ii < nn; ii++) - cacheBones[ii].updateWorldTransform(); - if (i == last) break; - this.ikConstraints[i].apply(); - i++; + var boneCache = this.boneCache; + for (var i = 0, n = boneCache.length; i < n; i++) { + boneCache[i].update(); } }, /** Sets the bones and slots to their setup pose values. */ @@ -1906,6 +2331,17 @@ spine.Skeleton.prototype = { ikConstraint.bendDirection = ikConstraint.data.bendDirection; ikConstraint.mix = ikConstraint.data.mix; } + + var transformConstraints = this.transformConstraints; + for (var i = 0, n = transformConstraints.length; i < n; i++) + { + var constraint = transformConstraints[i]; + var data = constraint.data; + constraint.rotateMix = data.rotateMix; + constraint.translateMix = data.translateMix; + constraint.scaleMix = data.scaleMix; + constraint.shearMix = data.shearMix; + } }, setSlotsToSetupPose: function () { @@ -2025,11 +2461,18 @@ spine.Skeleton.prototype = { throw "Slot not found: " + slotName; }, /** @return May be null. */ - findIkConstraint: function (ikConstraintName) + findIkConstraint: function (constraintName) { - var ikConstraints = this.ikConstraints; - for (var i = 0, n = ikConstraints.length; i < n; i++) - if (ikConstraints[i].data.name == ikConstraintName) return ikConstraints[i]; + var constraints = this.ikConstraints; + for (var i = 0, n = constraints.length; i < n; i++) + if (constraints[i].data.name == constraintName) return constraints[i]; + return null; + }, + findTransformConstraint: function (constraintName) + { + var constraints = this.transformConstraints; + for (var i = 0, n = constraints.length; i < n; i++) + if (constraints[i].data.name == constraintName) return constraints[i]; return null; }, update: function (delta) @@ -2046,7 +2489,7 @@ spine.Skeleton.prototype = { module.exports = spine.Skeleton; -},{"../SpineUtil":42,"./Bone":12,"./IkConstraint":24,"./Slot":37}],32:[function(require,module,exports){ +},{"../SpineUtil":44,"./Bone":12,"./IkConstraint":22,"./Slot":35}],31:[function(require,module,exports){ var spine = require('../SpineRuntime') || {}; spine.AttachmentType = require('./AttachmentType'); spine.SkeletonBounds = function () @@ -2220,7 +2663,7 @@ spine.SkeletonBounds.prototype = { module.exports = spine.SkeletonBounds; -},{"../SpineRuntime":41,"./AttachmentType":11}],33:[function(require,module,exports){ +},{"../SpineRuntime":43,"./AttachmentType":11}],32:[function(require,module,exports){ var spine = require('../SpineUtil'); spine.SkeletonData = function () { @@ -2230,6 +2673,7 @@ spine.SkeletonData = function () this.events = []; this.animations = []; this.ikConstraints = []; + this.transformConstraints = []; }; spine.SkeletonData.prototype = { name: null, @@ -2295,22 +2739,31 @@ spine.SkeletonData.prototype = { return null; }, /** @return May be null. */ - findIkConstraint: function (ikConstraintName) + findIkConstraint: function (constraintName) { - var ikConstraints = this.ikConstraints; - for (var i = 0, n = ikConstraints.length; i < n; i++) - if (ikConstraints[i].name == ikConstraintName) return ikConstraints[i]; + var constraints = this.ikConstraints; + for (var i = 0, n = constraints.length; i < n; i++) + if (constraints[i].name == constraintName) return constraints[i]; return null; - } + }, + /** @return May be null. */ + findTransformConstraint: function (constraintName) + { + var constraints = this.transformConstraints; + for (var i = 0, n = constraints.length; i < n; i++) + if (constraints[i].name == constraintName) return constraints[i]; + return null; + }, }; module.exports = spine.SkeletonData; -},{"../SpineUtil":42}],34:[function(require,module,exports){ +},{"../SpineUtil":44}],33:[function(require,module,exports){ var spine = require('../SpineUtil'); spine.SkeletonData = require('./SkeletonData'); spine.BoneData = require('./BoneData'); spine.IkConstraintData = require('./IkConstraintData'); +spine.TransformConstraintData = require('./TransformConstraintData'); spine.SlotData = require('./SlotData'); spine.Skin = require('./Skin'); spine.EventData = require('./EventData'); @@ -2320,17 +2773,35 @@ spine.AttachmentTimeline = require('./AttachmentTimeline'); spine.RotateTimeline = require('./RotateTimeline'); spine.ScaleTimeline = require('./ScaleTimeline'); spine.TranslateTimeline = require('./TranslateTimeline'); -spine.FlipXTimeline = require('./FlipXTimeline'); -spine.FlipYTimeline = require('./FlipYTimeline'); +spine.ShearTimeline = require('./ShearTimeline'); spine.IkConstraintTimeline = require('./IkConstraintTimeline'); +spine.TransformConstraintTimeline = require('./TransformConstraintTimeline'); spine.FfdTimeline = require('./FfdTimeline'); spine.DrawOrderTimeline = require('./DrawOrderTimeline'); spine.EventTimeline = require('./EventTimeline'); spine.Event = require('./Event'); spine.Animation = require('./Animation'); + +function LinkedMesh(mesh, skin, slotIndex, parent) { + this.mesh = mesh; + this.skin = skin; + this.slotIndex = slotIndex; + this.parent = parent; +} + spine.SkeletonJsonParser = function (attachmentLoader) { - this.attachmentLoader = attachmentLoader; + if (attachmentLoader.pages) { + //its an atlas, we have to wrap it + this.attachmentLoader = new spine.AtlasAttachmentLoader(attachmentLoader); + } else { + //got a loader, thats good + this.attachmentLoader = attachmentLoader; + } + if (!attachmentLoader.newRegionAttachment) { + console.warn("SkeletonJsonParser accepts AtlasAttachmentLoader or atlas as first parameter"); + } + this.linkedMeshes = []; }; spine.SkeletonJsonParser.prototype = { scale: 1, @@ -2339,6 +2810,7 @@ spine.SkeletonJsonParser.prototype = { var skeletonData = new spine.SkeletonData(); skeletonData.name = name; + var scale = this.scale; // Skeleton. var skeletonMap = root["skeleton"]; if (skeletonMap) @@ -2367,6 +2839,8 @@ spine.SkeletonJsonParser.prototype = { boneData.rotation = (boneMap["rotation"] || 0); boneData.scaleX = boneMap.hasOwnProperty("scaleX") ? boneMap["scaleX"] : 1; boneData.scaleY = boneMap.hasOwnProperty("scaleY") ? boneMap["scaleY"] : 1; + boneData.shearX = boneMap["shearX"] || 0; + boneData.shearY = boneMap["shearY"] || 0; boneData.inheritScale = boneMap.hasOwnProperty("inheritScale") ? boneMap["inheritScale"] : true; boneData.inheritRotation = boneMap.hasOwnProperty("inheritRotation") ? boneMap["inheritRotation"] : true; skeletonData.bones.push(boneData); @@ -2385,12 +2859,12 @@ spine.SkeletonJsonParser.prototype = { for (var ii = 0, nn = bones.length; ii < nn; ii++) { var bone = skeletonData.findBone(bones[ii]); - if (!bone) throw "IK bone not found: " + bones[ii]; + if (!bone) throw new Error( "IK bone not found: " + bones[ii] ); ikConstraintData.bones.push(bone); } ikConstraintData.target = skeletonData.findBone(ikMap["target"]); - if (!ikConstraintData.target) throw "Target bone not found: " + ikMap["target"]; + if (!ikConstraintData.target) throw new Error("Target bone not found: " + ikMap["target"]); ikConstraintData.bendDirection = (!ikMap.hasOwnProperty("bendPositive") || ikMap["bendPositive"]) ? 1 : -1; ikConstraintData.mix = ikMap.hasOwnProperty("mix") ? ikMap["mix"] : 1; @@ -2399,6 +2873,32 @@ spine.SkeletonJsonParser.prototype = { } } + var transform = root["transform"]; + if (transform) { + for (var i = 0, n = transform.length; i>>>>>> origin/master:_site/js/plugins/pixi-spine.js } throw "Unknown attachment type: " + type; }, @@ -2664,12 +3267,15 @@ spine.SkeletonJsonParser.prototype = { timelines.push(timeline); duration = Math.max(duration, timeline.frames[timeline.getFrameCount() * 2 - 2]); - } else if (timelineName == "translate" || timelineName == "scale") + } else if (timelineName == "translate" || timelineName == "scale" || timelineName == "shear") { var timeline; var timelineScale = 1; - if (timelineName == "scale") + if (timelineName == "scale") { timeline = new spine.ScaleTimeline(values.length); + } else if (timelineName == "shear") { + timeline = new spine.ShearTimeline(values.length); + } else { timeline = new spine.TranslateTimeline(values.length); @@ -2692,20 +3298,7 @@ spine.SkeletonJsonParser.prototype = { } else if (timelineName == "flipX" || timelineName == "flipY") { - var x = timelineName == "flipX"; - var timeline = x ? new spine.FlipXTimeline(values.length) : new spine.FlipYTimeline(values.length); - timeline.boneIndex = boneIndex; - - var field = x ? "x" : "y"; - var frameIndex = 0; - for (var i = 0, n = values.length; i < n; i++) - { - var valueMap = values[i]; - timeline.setFrame(frameIndex, valueMap["time"], valueMap[field] || false); - frameIndex++; - } - timelines.push(timeline); - duration = Math.max(duration, timeline.frames[timeline.getFrameCount() * 2 - 2]); + throw "flipX and flipY are not supported in spine v3: (" + boneName + ")"; } else throw "Invalid timeline type for a bone: " + timelineName + " (" + boneName + ")"; } @@ -2733,7 +3326,35 @@ spine.SkeletonJsonParser.prototype = { duration = Math.max(duration, timeline.frames[timeline.getFrameCount() * 3 - 3]); } + var transformMap = map["transform"]; + for (var transformConstraintName in transformMap) + { + if (!transformMap.hasOwnProperty(transformConstraintName)) continue; + var transformConstraint = skeletonData.findTransformConstraint(transformConstraintName); + var values = transformMap[transformConstraintName]; + var timeline = new spine.TransformConstraintTimeline(values.length); + timeline.transformConstraintIndex = skeletonData.transformConstraints.indexOf(transformConstraint); + var frameIndex = 0; + for (var i = 0, n = values.length; i < n; i++) + { + var valueMap = values[i]; + var rotateMix = valueMap.hasOwnProperty("rotateMix") ? valueMap["rotateMix"] : 1; + var translateMix = valueMap.hasOwnProperty("translateMix") ? valueMap["translateMix"] : 1; + var scaleMix = valueMap.hasOwnProperty("scaleMix") ? valueMap["scaleMix"] : 1; + var shearMix = valueMap.hasOwnProperty("shearMix") ? valueMap["shearMix"] : 1; + timeline.setFrame(frameIndex, valueMap["time"], translateMix, scaleMix, shearMix); + this.readCurve(timeline, frameIndex, valueMap); + frameIndex++; + } + timelines.push(timeline); + duration = Math.max(duration, timeline.frames[timeline.getFrameCount() * 5 - 5]); + } + +<<<<<<< HEAD:required/plugins/pixi-spine.js var ffd = map["ffd"]; +======= + var ffd = map["deform"] || map["ffd"]; +>>>>>>> origin/master:_site/js/plugins/pixi-spine.js for (var skinName in ffd) { var skin = skeletonData.findSkin(skinName); @@ -2913,7 +3534,7 @@ spine.SkeletonJsonParser.prototype = { module.exports = spine.SkeletonJsonParser; -},{"../SpineUtil":42,"./Animation":2,"./AttachmentTimeline":10,"./AttachmentType":11,"./BoneData":13,"./ColorTimeline":15,"./DrawOrderTimeline":17,"./Event":18,"./EventData":19,"./EventTimeline":20,"./FfdTimeline":21,"./FlipXTimeline":22,"./FlipYTimeline":23,"./IkConstraintData":25,"./IkConstraintTimeline":26,"./RotateTimeline":29,"./ScaleTimeline":30,"./SkeletonData":33,"./Skin":35,"./SlotData":38,"./TranslateTimeline":40}],35:[function(require,module,exports){ +},{"../SpineUtil":44,"./Animation":2,"./AttachmentTimeline":10,"./AttachmentType":11,"./BoneData":13,"./ColorTimeline":15,"./DrawOrderTimeline":17,"./Event":18,"./EventData":19,"./EventTimeline":20,"./FfdTimeline":21,"./IkConstraintData":23,"./IkConstraintTimeline":24,"./RotateTimeline":27,"./ScaleTimeline":28,"./ShearTimeline":29,"./SkeletonData":32,"./Skin":34,"./SlotData":36,"./TransformConstraintData":39,"./TransformConstraintTimeline":40,"./TranslateTimeline":41}],34:[function(require,module,exports){ var spine = require('../SpineUtil'); spine.Skin = function (name) { @@ -2948,106 +3569,7 @@ spine.Skin.prototype = { module.exports = spine.Skin; -},{"../SpineUtil":42}],36:[function(require,module,exports){ -var spine = require('../SpineUtil') || {}; -spine.AttachmentType = require('./AttachmentType'); -spine.SkinnedMeshAttachment = function (name) -{ - this.name = name; -}; -spine.SkinnedMeshAttachment.prototype = { - type: spine.AttachmentType.skinnedmesh, - bones: null, - weights: null, - uvs: null, - regionUVs: null, - triangles: null, - hullLength: 0, - r: 1, g: 1, b: 1, a: 1, - path: null, - rendererObject: null, - regionU: 0, regionV: 0, regionU2: 0, regionV2: 0, regionRotate: false, - regionOffsetX: 0, regionOffsetY: 0, - regionWidth: 0, regionHeight: 0, - regionOriginalWidth: 0, regionOriginalHeight: 0, - edges: null, - width: 0, height: 0, - updateUVs: function (u, v, u2, v2, rotate) - { - var width = this.regionU2 - this.regionU, height = this.regionV2 - this.regionV; - var n = this.regionUVs.length; - if (!this.uvs || this.uvs.length != n) - { - this.uvs = new spine.Float32Array(n); - } - if (this.regionRotate) - { - for (var i = 0; i < n; i += 2) - { - this.uvs[i] = this.regionU + this.regionUVs[i + 1] * width; - this.uvs[i + 1] = this.regionV + height - this.regionUVs[i] * height; - } - } else { - for (var i = 0; i < n; i += 2) - { - this.uvs[i] = this.regionU + this.regionUVs[i] * width; - this.uvs[i + 1] = this.regionV + this.regionUVs[i + 1] * height; - } - } - }, - computeWorldVertices: function (x, y, slot, worldVertices) - { - var skeletonBones = slot.bone.skeleton.bones; - var weights = this.weights; - var bones = this.bones; - - var w = 0, v = 0, b = 0, f = 0, n = bones.length, nn; - var wx, wy, bone, vx, vy, weight; - if (!slot.attachmentVertices.length) - { - for (; v < n; w += 2) - { - wx = 0; - wy = 0; - nn = bones[v++] + v; - for (; v < nn; v++, b += 3) - { - bone = skeletonBones[bones[v]]; - vx = weights[b]; - vy = weights[b + 1]; - weight = weights[b + 2]; - wx += (vx * bone.m00 + vy * bone.m01 + bone.worldX) * weight; - wy += (vx * bone.m10 + vy * bone.m11 + bone.worldY) * weight; - } - worldVertices[w] = wx + x; - worldVertices[w + 1] = wy + y; - } - } else { - var ffd = slot.attachmentVertices; - for (; v < n; w += 2) - { - wx = 0; - wy = 0; - nn = bones[v++] + v; - for (; v < nn; v++, b += 3, f += 2) - { - bone = skeletonBones[bones[v]]; - vx = weights[b] + ffd[f]; - vy = weights[b + 1] + ffd[f + 1]; - weight = weights[b + 2]; - wx += (vx * bone.m00 + vy * bone.m01 + bone.worldX) * weight; - wy += (vx * bone.m10 + vy * bone.m11 + bone.worldY) * weight; - } - worldVertices[w] = wx + x; - worldVertices[w + 1] = wy + y; - } - } - } -}; -module.exports = spine.SkinnedMeshAttachment; - - -},{"../SpineUtil":42,"./AttachmentType":11}],37:[function(require,module,exports){ +},{"../SpineUtil":44}],35:[function(require,module,exports){ var spine = require('../SpineUtil'); spine.Slot = function (slotData, bone) { @@ -3097,7 +3619,7 @@ spine.Slot.prototype = { module.exports = spine.Slot; -},{"../SpineUtil":42}],38:[function(require,module,exports){ +},{"../SpineUtil":44}],36:[function(require,module,exports){ var spine = require('../SpineUtil'); spine.SlotData = function (name, boneData) { @@ -3124,7 +3646,7 @@ spine.SlotData.prototype = { module.exports = spine.SlotData; -},{"../SpineUtil":42}],39:[function(require,module,exports){ +},{"../SpineUtil":44}],37:[function(require,module,exports){ var spine = require('../SpineUtil'); spine.TrackEntry = function () {}; @@ -3140,7 +3662,176 @@ spine.TrackEntry.prototype = { module.exports = spine.TrackEntry; -},{"../SpineUtil":42}],40:[function(require,module,exports){ +},{"../SpineUtil":44}],38:[function(require,module,exports){ +var spine = require('../SpineUtil'); +var tempVec = [0, 0]; +spine.TransformConstraint = function (data, skeleton) +{ + this.data = data; + this.translateMix = data.translateMix; + this.rotateMix = data.rotateMix; + this.scaleMix = data.scaleMix; + this.shearMix = data.shearMix; + this.offsetX = data.offsetX; + this.offsetY = data.offsetY; + this.offsetScaleX = data.offsetScaleX; + this.offsetScaleY = data.offsetScaleY; + this.offsetShearY = data.offsetShearY; + + this.bone = skeleton.findBone(data.bone.name); + this.target = skeleton.findBone(data.target.name); +}; + +spine.TransformConstraint.prototype = { + update: function() { + this.apply(); + }, + apply: function () + { + var bm = this.bone.matrix; + var tm = this.target.matrix; + + var rotateMix = this.rotateMix; + if (rotateMix > 0) { + var a = bm.a, b = bm.c, c = bm.b, d = bm.d; + var r = Math.atan2(tm.b, tm.a) - Math.atan2(c, a); + if (r > Math.PI) + r -= Math.PI*2; + else if (r < -Math.PI) r += Math.PI*2; + r *= rotateMix; + var cos = Math.cos(r), sin = Math.sin(r); + bm.a = cos * a - sin * c; + bm.c = cos * b - sin * d; + bm.b = sin * a + cos * c; + bm.d = sin * b + cos * d; + } + + var scaleMix = this.rotateMix; + if (scaleMix > 0) { + var bs = Math.sqrt(bm.a * bm.a + bm.b * bm.b); + var ts = Math.sqrt(tm.a * tm.a + tm.b * tm.b); + var s = bs > 0.00001 ? (bs + (ts - bs + this.offsetScaleX) * scaleMix) / bs : 0; + bm.a *= s; + bm.b *= s; + bs = Math.sqrt(bm.c * bm.c + bm.d * bm.d); + ts = Math.sqrt(bm.c * bm.c + bm.d * bm.d); + s = bs > 0.00001 ? (bs + (ts - bs + this.offsetScaleY) * scaleMix) / bs : 0; + bm.c *= s; + bm.d *= s; + } + + var shearMix = this.shearMix; + if (shearMix > 0) { + var b = bm.c, d = bm.d; + var by = Math.atan2(d, b); + var r = Math.atan2(tm.d, tm.c) - Math.atan2(tm.b, target.a) - (by - Math.atan2(bm.b, bm.a)); + if (r > Math.PI) + r -= Math.PI*2; + else if (r < -Math.PI) r += Math.PI*2; + r = by + (r + this.offsetShearY * spine.degRad) * shearMix; + var s = Math.sqrt(b * b + d * d); + bm.c = Math.cos(r) * s; + bm.d = Math.sin(r) * s; + } + + var translateMix = this.translateMix; + if (translateMix > 0) { + tempVec[0] = this.offsetX; + tempVec[1] = this.offsetY; + this.target.localToWorld(tempVec); + bm.tx += (tempVec[0] - bm.tx) * translateMix; + bm.ty += (tempVec[1] - bm.ty) * translateMix; + } + } +}; + +module.exports = spine.TransformConstraint; + +},{"../SpineUtil":44}],39:[function(require,module,exports){ +var spine = require('../SpineUtil') || {}; +spine.TransformConstraintData = function (name) +{ + this.name = name; + this.bone = null; +}; +spine.TransformConstraintData.prototype = { + target: null, + rotateMix: 1, + translateMix: 1, + scaleMix: 1, + shearMix: 1, + offsetRotation: 0, + offsetX: 0, + offsetY: 0, + offsetScaleX: 0, + offsetScaleY: 0, + offsetShearY: 0 +}; +module.exports = spine.TransformConstraintData; + + +},{"../SpineUtil":44}],40:[function(require,module,exports){ +var spine = require('../SpineUtil') || {}; +spine.Animation = require('./Animation'); +spine.Curves = require('./Curves'); +spine.TransformConstraintTimeline = function (frameCount) +{ + this.curves = new spine.Curves(frameCount); + this.frames = []; // time, mix, bendDirection, ... + this.frames.length = frameCount * 3; +}; +spine.TransformConstraintTimeline.prototype = { + transformConstraintIndex: 0, + getFrameCount: function () + { + return this.frames.length / 5; + }, + setFrame: function (frameIndex, time, rotateMix, translateMix, scaleMix, shareMix) + { + frameIndex *= 5; + this.frames[frameIndex] = time; + this.frames[frameIndex + 1] = rotateMix; + this.frames[frameIndex + 2] = translateMix; + this.frames[frameIndex + 3] = scaleMix; + this.frames[frameIndex + 4] = shareMix; + }, + apply: function (skeleton, lastTime, time, firedEvents, alpha) + { + var frames = this.frames; + if (time < frames[0]) return; // Time is before first frame. + + var constraint = skeleton.transformConstraints[this.transformConstraintIndex]; + + if (time >= frames[frames.length - 5]) + { // Time is after last frame. + constraint.rotateMix += (frames[i - 3] - constraint.rotateMix) * alpha; + constraint.translateMix += (frames[i - 2] - constraint.translateMix) * alpha; + constraint.scaleMix += (frames[i - 1] - constraint.scaleMix) * alpha; + constraint.shearMix += (frames[i] - constraint.shearMix) * alpha; + return; + } + + // Interpolate between the previous frame and the current frame. + var frame = spine.Animation.binarySearch(frames, time, 5); + var frameTime = frames[frame]; + var percent = 1 - (time - frameTime) / (frames[frame + -5/*PREV_FRAME_TIME*/] - frameTime); + percent = this.curves.getCurvePercent(frame / 5 - 1, percent); + + var rotate = frames[frame + -4/*PREV_ROTATE_MIX*/]; + var translate = frames[frame + -3/*PREV_TRANSLATE_MIX*/]; + var scale = frames[frame + -2/*PREV_SCALE_MIX*/]; + var shear = frames[frame + -1/*PREV_SHEAR_MIX*/]; + constraint.rotateMix += (rotate + (frames[frame + 1/*ROTATE_MIX*/] - rotate) * percent - constraint.rotateMix) * alpha; + constraint.translateMix += (translate + (frames[frame + 2/*TRANSLATE_MIX*/] - translate) * percent - constraint.translateMix) + * alpha; + constraint.scaleMix += (scale + (frames[frame + 3/*SCALE_MIX*/] - scale) * percent - constraint.scaleMix) * alpha; + constraint.shearMix += (shear + (frames[frame + 4/*SHEAR_MIX*/] - shear) * percent - constraint.shearMix) * alpha; + } +}; +module.exports = spine.TransformConstraintTimeline; + + +},{"../SpineUtil":44,"./Animation":2,"./Curves":16}],41:[function(require,module,exports){ var spine = require('../SpineUtil'); spine.Animation = require('./Animation'); spine.Curves = require('./Curves'); @@ -3192,7 +3883,118 @@ spine.TranslateTimeline.prototype = { module.exports = spine.TranslateTimeline; -},{"../SpineUtil":42,"./Animation":2,"./Curves":16}],41:[function(require,module,exports){ +},{"../SpineUtil":44,"./Animation":2,"./Curves":16}],42:[function(require,module,exports){ +var spine = require('../SpineUtil') || {}; +spine.AttachmentType = require('./AttachmentType'); +spine.WeightedMeshAttachment = function (name) +{ + this.name = name; +}; +spine.WeightedMeshAttachment.prototype = { + type: spine.AttachmentType.weightedmesh, + parentMesh: null, + inheritFFD: false, + bones: null, + weights: null, + uvs: null, + regionUVs: null, + triangles: null, + hullLength: 0, + r: 1, g: 1, b: 1, a: 1, + path: null, + rendererObject: null, + edges: null, + width: 0, height: 0, + updateUVs: function (u, v, u2, v2, rotate) + { + var width = this.regionU2 - this.regionU, height = this.regionV2 - this.regionV; + var n = this.regionUVs.length; + if (!this.uvs || this.uvs.length != n) + { + this.uvs = new spine.Float32Array(n); + } + var region = this.rendererObject; + if (!region) return; + var texture = region.texture; + var r = texture._uvs; + var w1 = region.width, h1 = region.height, w2 = region.originalWidth, h2 = region.originalHeight; + var x = region.offsetX, y = region.pixiOffsetY; + for (var i = 0; i < n; i += 2) + { + var u = this.regionUVs[i], v = this.regionUVs[i+1]; + u = (u * w2 - x) / w1; + v = (v * h2 - y) / h1; + this.uvs[i] = (r.x0 * (1 - u) + r.x1 * u) * (1-v) + (r.x3 * (1 - u) + r.x2 * u) * v; + this.uvs[i+1] = (r.y0 * (1 - u) + r.y1 * u) * (1-v) + (r.y3 * (1 - u) + r.y2 * u) * v; + } + }, + computeWorldVertices: function (x, y, slot, worldVertices) + { + var skeletonBones = slot.bone.skeleton.bones; + var weights = this.weights; + var bones = this.bones; + + var w = 0, v = 0, b = 0, f = 0, n = bones.length, nn; + var wx, wy, vx, vy, weight; + var m; + if (!slot.attachmentVertices.length) + { + for (; v < n; w += 2) + { + wx = 0; + wy = 0; + nn = bones[v++] + v; + for (; v < nn; v++, b += 3) + { + m = skeletonBones[bones[v]].matrix; + vx = weights[b]; + vy = weights[b + 1]; + weight = weights[b + 2]; + wx += (vx * m.a + vy * m.c + m.tx) * weight; + wy += (vx * m.b + vy * m.d + m.ty) * weight; + } + worldVertices[w] = wx + x; + worldVertices[w + 1] = wy + y; + } + } else { + var ffd = slot.attachmentVertices; + for (; v < n; w += 2) + { + wx = 0; + wy = 0; + nn = bones[v++] + v; + for (; v < nn; v++, b += 3, f += 2) + { + m = skeletonBones[bones[v]].matrix; + vx = weights[b] + ffd[f]; + vy = weights[b + 1] + ffd[f + 1]; + weight = weights[b + 2]; + wx += (vx * m.a + vy * m.c + m.tx) * weight; + wy += (vx * m.b + vy * m.d + m.ty) * weight; + } + worldVertices[w] = wx + x; + worldVertices[w + 1] = wy + y; + } + } + }, + applyFFD: function(sourceAttachment) { + return this === sourceAttachment || (this.inheritFFD && parentMesh === sourceAttachment); + }, + setParentMesh: function(parentMesh) { + this.parentMesh = parentMesh; + if (parentMesh != null) { + this.bones = parentMesh.bones; + this.weights = parentMesh.weights; + this.regionUVs = parentMesh.regionUVs; + this.triangles = parentMesh.triangles; + this.hullLength = parentMesh.hullLength; + } + } +}; +module.exports = spine.WeightedMeshAttachment; + + +},{"../SpineUtil":44,"./AttachmentType":11}],43:[function(require,module,exports){ /****************************************************************************** * Spine Runtimes Software License * Version 2.1 @@ -3243,40 +4045,48 @@ spine.EventData = require('./EventData'); spine.Event = require('./Event'); spine.EventTimeline = require('./EventTimeline'); spine.FfdTimeline = require('./FfdTimeline'); -spine.FlipXTimeline = require('./FlipXTimeline'); -spine.FlipYTimeline = require('./FlipYTimeline'); spine.IkConstraintData = require('./IkConstraintData'); spine.IkConstraint = require('./IkConstraint'); spine.IkConstraintTimeline = require('./IkConstraintTimeline'); +spine.TransformConstraintData = require('./TransformConstraintData'); +spine.TransformConstraint = require('./TransformConstraint'); +spine.TransformConstraintTimeline = require('./TransformConstraintTimeline'); spine.MeshAttachment = require('./MeshAttachment'); spine.RegionAttachment = require('./RegionAttachment'); spine.RotateTimeline = require('./RotateTimeline'); spine.ScaleTimeline = require('./ScaleTimeline'); +spine.ShearTimeline = require('./ShearTimeline'); spine.SkeletonBounds = require('./SkeletonBounds'); spine.SkeletonData = require('./SkeletonData'); spine.Skeleton = require('./Skeleton'); spine.SkeletonJsonParser = require('./SkeletonJsonParser'); spine.Skin = require('./Skin.js'); -spine.SkinnedMeshAttachment = require('./SkinnedMeshAttachment'); +spine.WeightedMeshAttachment = require('./WeightedMeshAttachment'); spine.SlotData = require('./SlotData'); spine.Slot = require('./Slot'); spine.TrackEntry = require('./TrackEntry'); spine.TranslateTimeline = require('./TranslateTimeline'); module.exports = spine; -},{"../SpineUtil":42,"./Animation":2,"./AnimationState":3,"./AnimationStateData":4,"./Atlas":5,"./AtlasAttachmentParser":6,"./AtlasPage":7,"./AtlasReader":8,"./AtlasRegion":9,"./AttachmentTimeline":10,"./AttachmentType":11,"./Bone":12,"./BoneData":13,"./BoundingBoxAttachment":14,"./ColorTimeline":15,"./Curves":16,"./DrawOrderTimeline":17,"./Event":18,"./EventData":19,"./EventTimeline":20,"./FfdTimeline":21,"./FlipXTimeline":22,"./FlipYTimeline":23,"./IkConstraint":24,"./IkConstraintData":25,"./IkConstraintTimeline":26,"./MeshAttachment":27,"./RegionAttachment":28,"./RotateTimeline":29,"./ScaleTimeline":30,"./Skeleton":31,"./SkeletonBounds":32,"./SkeletonData":33,"./SkeletonJsonParser":34,"./Skin.js":35,"./SkinnedMeshAttachment":36,"./Slot":37,"./SlotData":38,"./TrackEntry":39,"./TranslateTimeline":40}],42:[function(require,module,exports){ +},{"../SpineUtil":44,"./Animation":2,"./AnimationState":3,"./AnimationStateData":4,"./Atlas":5,"./AtlasAttachmentParser":6,"./AtlasPage":7,"./AtlasReader":8,"./AtlasRegion":9,"./AttachmentTimeline":10,"./AttachmentType":11,"./Bone":12,"./BoneData":13,"./BoundingBoxAttachment":14,"./ColorTimeline":15,"./Curves":16,"./DrawOrderTimeline":17,"./Event":18,"./EventData":19,"./EventTimeline":20,"./FfdTimeline":21,"./IkConstraint":22,"./IkConstraintData":23,"./IkConstraintTimeline":24,"./MeshAttachment":25,"./RegionAttachment":26,"./RotateTimeline":27,"./ScaleTimeline":28,"./ShearTimeline":29,"./Skeleton":30,"./SkeletonBounds":31,"./SkeletonData":32,"./SkeletonJsonParser":33,"./Skin.js":34,"./Slot":35,"./SlotData":36,"./TrackEntry":37,"./TransformConstraint":38,"./TransformConstraintData":39,"./TransformConstraintTimeline":40,"./TranslateTimeline":41,"./WeightedMeshAttachment":42}],44:[function(require,module,exports){ module.exports = { radDeg: 180 / Math.PI, degRad: Math.PI / 180, temp: [], Float32Array: (typeof(Float32Array) === 'undefined') ? Array : Float32Array, - Uint16Array: (typeof(Uint16Array) === 'undefined') ? Array : Uint16Array + Uint16Array: (typeof(Uint16Array) === 'undefined') ? Array : Uint16Array, + signum: function(x) { + if (x>0) return 1; + if (x<0) return -1; + return 0; + } }; -},{}],43:[function(require,module,exports){ +},{}],45:[function(require,module,exports){ var spine = require('../SpineRuntime'); var atlasParser = require('../loaders/atlasParser'); +var TransformBase = PIXI.TransformBase || PIXI.TransformManual; /* Esoteric Software SPINE wrapper for pixi.js */ spine.Bone.yDown = true; @@ -3381,6 +4191,14 @@ function Spine(spineData) * @member {boolean} */ this.autoUpdate = true; + + /** + * The tint applied to all spine slots. This is a [r,g,b] value. A value of [1,1,1] will remove any tint effect. + * + * @member {number} + * @memberof PIXI.spine.Spine# + */ + this.tintRgb = new Float32Array([1, 1, 1]); } Spine.fromAtlas = function(resourceName) { @@ -3409,7 +4227,7 @@ Object.defineProperties(Spine.prototype, { * autoupdate enabled but are harder to achieve. * * @member {boolean} - * @memberof Spine# + * @memberof PIXI.spine.Spine# * @default true */ autoUpdate: { @@ -3422,9 +4240,26 @@ Object.defineProperties(Spine.prototype, { { this.updateTransform = value ? Spine.prototype.autoUpdateTransform : PIXI.Container.prototype.updateTransform; } + }, + /** + * The tint applied to the spine object. This is a hex value. A value of 0xFFFFFF will remove any tint effect. + * + * @member {number} + * @memberof PIXI.spine.Spine# + * @default 0xFFFFFF + */ + tint: { + get: function() { + return PIXI.utils.rgb2hex(this.tintRgb); + }, + set: function(value) { + this.tintRgb = PIXI.utils.hex2rgb(value, this.tintRgb); + } } }); +var tempRgb = [0, 0, 0]; + /** * Update the spine skeleton and its animations by delta time (dt) * @@ -3444,6 +4279,10 @@ Spine.prototype.update = function (dt) this.children[i] = this.slotContainers[drawOrder[i]]; } + var r0 = this.tintRgb[0]; + var g0 = this.tintRgb[1]; + var b0 = this.tintRgb[2]; + for (i = 0, n = slots.length; i < n; i++) { var slot = slots[i]; @@ -3483,25 +4322,82 @@ Spine.prototype.update = function (dt) } } - var bone = slot.bone; - - slotContainer.position.x = bone.worldX + attachment.x * bone.m00 + attachment.y * bone.m01; - slotContainer.position.y = bone.worldY + attachment.x * bone.m10 + attachment.y * bone.m11; - slotContainer.scale.x = bone.worldScaleX; - slotContainer.scale.y = bone.worldScaleY; - slotContainer.rotation = -(slot.bone.worldRotation * spine.degRad); - if (bone.worldFlipX) { - slotContainer.scale.x = -slotContainer.scale.x; - slotContainer.rotation = -slotContainer.rotation; - } - if (bone.worldFlipY == spine.Bone.yDown) { - slotContainer.scale.y = -slotContainer.scale.y; - slotContainer.rotation = -slotContainer.rotation; + if (slotContainer.transform ) { + var transform = slotContainer.transform; + var lt; + if (slotContainer.transform.matrix2d) { + //gameofbombs pixi fork + lt = transform.matrix2d; + transform._dirtyVersion++; + transform.version = transform._dirtyVersion; + transform.isStatic = true; + transform.operMode = 0; +<<<<<<< HEAD:required/plugins/pixi-spine.js + } else + if (PIXI.TransformManual) { + //PIXI v4.0 + if (transform.position) { + transform = new PIXI.TransformManual(); + slotContainer.transform = transform; + } + lt = transform.localTransform; + } else { + //PIXI v4.0rc + if (!transform._dirtyLocal) { + transform = new PIXI.TransformStatic(); + slotContainer.transform = transform; + } + lt = transform.localTransform; + transform._dirtyParentVersion = -1; + transform._dirtyLocal = 1; + transform._versionLocal = 1; +======= + } else { + if (TransformBase) { + //PIXI v4.0 + if (transform.position) { + transform = new PIXI.TransformBase(); + slotContainer.transform = transform; + } + lt = transform.localTransform; + } else { + //PIXI v4.0rc + if (!transform._dirtyLocal) { + transform = new PIXI.TransformStatic(); + slotContainer.transform = transform; + } + lt = transform.localTransform; + transform._dirtyParentVersion = -1; + transform._dirtyLocal = 1; + transform._versionLocal = 1; + } +>>>>>>> origin/master:_site/js/plugins/pixi-spine.js + } + slot.bone.matrix.copy(lt); + lt.tx += slot.bone.skeleton.x; + lt.ty += slot.bone.skeleton.y; + } else { + //PIXI v3 + var lt = slotContainer.localTransform || new PIXI.Matrix(); + slot.bone.matrix.copy(lt); + lt.tx += slot.bone.skeleton.x; + lt.ty += slot.bone.skeleton.y; + slotContainer.localTransform = lt; + slotContainer.displayObjectUpdateTransform = SlotContainerUpdateTransformV3; } +<<<<<<< HEAD:required/plugins/pixi-spine.js + slot.currentSprite.blendMode = slot.blendMode; - slot.currentSprite.tint = PIXI.utils.rgb2hex([slot.r,slot.g,slot.b]); + slot.currentSprite.tint = PIXI.utils.rgb2hex([slot.r * attachment.r, slot.g * attachment.g, slot.b * attachment.b]); +======= + tempRgb[0] = r0 * slot.r * attachment.r; + tempRgb[1] = g0 * slot.g * attachment.g; + tempRgb[2] = b0 * slot.b * attachment.b; + slot.currentSprite.tint = PIXI.utils.rgb2hex(tempRgb); + slot.currentSprite.blendMode = slot.blendMode; +>>>>>>> origin/master:_site/js/plugins/pixi-spine.js } - else if (type === spine.AttachmentType.skinnedmesh || type === spine.AttachmentType.mesh) + else if (type === spine.AttachmentType.skinnedmesh || type === spine.AttachmentType.mesh || type === spine.AttachmentType.linkedmesh) { if (!slot.currentMeshName || slot.currentMeshName !== attachment.name) { @@ -3526,9 +4422,21 @@ Spine.prototype.update = function (dt) slot.currentMesh = slot.meshes[meshName]; slot.currentMeshName = meshName; } - attachment.computeWorldVertices(slot.bone.skeleton.x, slot.bone.skeleton.y, slot, slot.currentMesh.vertices); - + if (PIXI.VERSION[0] !== '3') { + // PIXI version 4 + slot.currentMesh.dirty = true; +<<<<<<< HEAD:required/plugins/pixi-spine.js + } +======= + //only for PIXI v4 + var tintRgb = slot.currentMesh.tintRgb; + tintRgb[0] = r0 * slot.r * attachment.r; + tintRgb[1] = g0 * slot.g * attachment.g; + tintRgb[2] = b0 * slot.b * attachment.b; + } + slot.currentMesh.blendMode = slot.blendMode; +>>>>>>> origin/master:_site/js/plugins/pixi-spine.js } else { @@ -3570,20 +4478,15 @@ Spine.prototype.autoUpdateTransform = function () Spine.prototype.createSprite = function (slot, attachment) { var descriptor = attachment.rendererObject; - var baseTexture = descriptor.page.rendererObject; - var spriteRect = new PIXI.Rectangle(descriptor.x, - descriptor.y, - descriptor.rotate ? descriptor.height : descriptor.width, - descriptor.rotate ? descriptor.width : descriptor.height); - var spriteTexture = new PIXI.Texture(baseTexture, spriteRect); - var sprite = new PIXI.Sprite(spriteTexture); - - var baseRotation = descriptor.rotate ? Math.PI * 0.5 : 0.0; - sprite.scale.x = attachment.width / descriptor.originalWidth * attachment.scaleX; - sprite.scale.y = attachment.height / descriptor.originalHeight * attachment.scaleY; - sprite.rotation = baseRotation - (attachment.rotation * spine.degRad); - sprite.anchor.x = (0.5 * descriptor.originalWidth - descriptor.offsetX) / descriptor.width; - sprite.anchor.y = 1.0 - ((0.5 * descriptor.originalHeight - descriptor.offsetY) / descriptor.height); + var texture = descriptor.texture; + var sprite = new PIXI.Sprite(texture); + sprite.scale.x = attachment.scaleX * attachment.width / descriptor.originalWidth; + sprite.scale.y = - attachment.scaleY * attachment.height / descriptor.originalHeight; + sprite.rotation = attachment.rotation * spine.degRad; + sprite.anchor.x = 0.5; + sprite.anchor.y = 0.5; + sprite.position.x = attachment.x; + sprite.position.y = attachment.y; sprite.alpha = attachment.a; slot.sprites = slot.sprites || {}; @@ -3620,7 +4523,91 @@ Spine.prototype.createMesh = function (slot, attachment) return strip; }; -},{"../SpineRuntime":41,"../loaders/atlasParser":45}],44:[function(require,module,exports){ +/** + * Changes texture in attachment in specific slot. + * + * PIXI runtime feature, it was made to satisfy our users. + * + * @param slotName {string} + * @param [texture = null] {PIXI.Texture} If null, take default (original) texture + * @param [size = null] {PIXI.Point} sometimes we need new size for region attachment, you can pass 'texture.orig' there + * @returns {boolean} Success flag + */ +Spine.prototype.hackTextureBySlotIndex = function(slotIndex, texture, size) { + var slot = this.skeleton.slots[slotIndex]; + if (!slot) { + return false; + } + var attachment = slot.attachment; + if (!attachment || !attachment.hackRegion) { + return false; + } + var region = null; + if (texture) { + region = new spine.AtlasRegion(); + region.texture = texture; + region.size = size; + } + + attachment.hackRegion(region); + var descriptor = attachment.rendererObject; + if (slot.currentSprite) { + var sprite = slot.currentSprite; + sprite.texture = descriptor.texture; + sprite.scale.x = attachment.width / descriptor.originalWidth; + sprite.scale.y = - attachment.height / descriptor.originalHeight; + } + if (slot.currentMesh) { + var mesh = slot.currentMesh; + mesh.texture = descriptor.texture; + for (var i = 0; i < attachment.uvs.length; i++) { + mesh.uvs[i] = attachment.uvs[i]; + } + if (PIXI.VERSION[0] !== '3') { + // PIXI version 4 + mesh.indexDirty = true; + } else { + // PIXI version 3 + mesh.dirty = true; + } + } + return true; +}; + +/** + * Changes texture in attachment in specific slot. + * + * PIXI runtime feature, it was made to satisfy our users. + * + * @param slotName {string} + * @param [texture = null] {PIXI.Texture} If null, take default (original) texture + * @param [size = null] {PIXI.Point} sometimes we need new size for region attachment, you can pass 'texture.orig' there + * @returns {boolean} Success flag + */ +Spine.prototype.hackTextureBySlotName = function(slotName, texture, size) { + var index = this.skeleton.findSlotIndex(slotName); + if (index == -1) { + return false; + } + return this.hackTextureBySlotIndex(index,texture, size); +}; + +function SlotContainerUpdateTransformV3() +{ + var pt = this.parent.worldTransform; + var wt = this.worldTransform; + var lt = this.localTransform; + wt.a = lt.a * pt.a + lt.b * pt.c; + wt.b = lt.a * pt.b + lt.b * pt.d; + wt.c = lt.c * pt.a + lt.d * pt.c; + wt.d = lt.c * pt.b + lt.d * pt.d; + wt.tx = lt.tx * pt.a + lt.ty * pt.c + pt.tx; + wt.ty = lt.tx * pt.b + lt.ty * pt.d + pt.ty; + this.worldAlpha = this.alpha * this.parent.worldAlpha; + this._currentBounds = null; +}; + +},{"../SpineRuntime":43,"../loaders/atlasParser":47}],46:[function(require,module,exports){ /** * @file Spine resource loader * @author Ivan Popelyshev @@ -3637,7 +4624,7 @@ var atlasParser = require('./atlasParser'); PIXI.loaders.Loader.addPixiMiddleware(atlasParser); PIXI.loader.use(atlasParser()); -},{"./atlasParser":45}],45:[function(require,module,exports){ +},{"./atlasParser":47}],47:[function(require,module,exports){ var Resource = PIXI.loaders.Resource, spine = require('../SpineRuntime'), imageLoaderAdapter = require('./imageLoaderAdapter'); @@ -3649,24 +4636,53 @@ var atlasParser = module.exports = function () { return next(); } + var metadataAtlas = resource.metadata ? resource.metadata.spineAtlas: null; + if (metadataAtlas === false) { + return next(); + } + if (metadataAtlas && metadataAtlas.pages) { + //its an atlas! + var spineJsonParser = new spine.SkeletonJsonParser(new spine.AtlasAttachmentParser(metadataAtlas)); + var skeletonData = spineJsonParser.readSkeletonData(resource.data); + + resource.spineData = skeletonData; + resource.spineAtlas = metadataAtlas; + if (atlasParser.enableCaching) { + atlasParser.AnimCache[resource.name] = resource.spineData; + } + + return next(); + } + + var metadataAtlasSuffix = '.atlas'; + if (resource.metadata && resource.metadata.spineAtlasSuffix) { + metadataAtlasSuffix = resource.metadata.spineAtlasSuffix; + } + /** * use a bit of hackery to load the atlas file, here we assume that the .json, .atlas and .png files * that correspond to the spine file are in the same base URL and that the .json and .atlas files * have the same name */ - var atlasPath = resource.url.substr(0, resource.url.lastIndexOf('.')) + '.atlas'; + var atlasPath = resource.url.substr(0, resource.url.lastIndexOf('.')) + metadataAtlasSuffix; + //remove the baseUrl + atlasPath = atlasPath.replace(this.baseUrl, ''); + var atlasOptions = { crossOrigin: resource.crossOrigin, xhrType: Resource.XHR_RESPONSE_TYPE.TEXT, - metadata: resource.spineMetadata + metadata: resource.metadata ? resource.metadata.spineMetadata : null }; var imageOptions = { crossOrigin: resource.crossOrigin, - metadata: resource.imageMetadata + metadata: resource.metadata ? resource.metadata.imageMetadata: null }; var baseUrl = resource.url.substr(0, resource.url.lastIndexOf('/') + 1); + //remove the baseUrl + baseUrl = baseUrl.replace(this.baseUrl, ''); var adapter = imageLoaderAdapter(this, resource.name + '_atlas_page_', baseUrl, imageOptions); + this.add(resource.name + '_atlas', atlasPath, atlasOptions, function (res) { new spine.Atlas(this.xhr.responseText, adapter, function(spineAtlas) { var spineJsonParser = new spine.SkeletonJsonParser(new spine.AtlasAttachmentParser(spineAtlas)); @@ -3674,8 +4690,9 @@ var atlasParser = module.exports = function () { resource.spineData = skeletonData; resource.spineAtlas = spineAtlas; - if (atlasParser.enableCaching) + if (atlasParser.enableCaching) { atlasParser.AnimCache[resource.name] = resource.spineData; + } next(); }); @@ -3684,9 +4701,9 @@ var atlasParser = module.exports = function () { }; atlasParser.AnimCache = {}; -atlasParser.enableCaching = true; +atlasParser.enableCaching = false; -},{"../SpineRuntime":41,"./imageLoaderAdapter":46}],46:[function(require,module,exports){ +},{"../SpineRuntime":43,"./imageLoaderAdapter":48}],48:[function(require,module,exports){ var spine = require('../SpineRuntime'); module.exports = function (loader, namePrefix, baseUrl, imageOptions) { @@ -3703,7 +4720,7 @@ module.exports = function (loader, namePrefix, baseUrl, imageOptions) { } }; -},{"../SpineRuntime":41}],47:[function(require,module,exports){ +},{"../SpineRuntime":43}],49:[function(require,module,exports){ module.exports = { atlasParser: require('./atlasParser'), Loader: require('./Loader'), @@ -3711,7 +4728,7 @@ module.exports = { imageLoaderAdapter: require('./imageLoaderAdapter') }; -},{"./Loader":44,"./atlasParser":45,"./imageLoaderAdapter":46,"./syncImageLoaderAdapter":48}],48:[function(require,module,exports){ +},{"./Loader":46,"./atlasParser":47,"./imageLoaderAdapter":48,"./syncImageLoaderAdapter":50}],50:[function(require,module,exports){ var spine = require('../SpineRuntime'); module.exports = function (baseUrl, crossOrigin) { @@ -3724,7 +4741,12 @@ module.exports = function (baseUrl, crossOrigin) { } }; -},{"../SpineRuntime":41}]},{},[1]) +<<<<<<< HEAD:required/plugins/pixi-spine.js +},{"../SpineRuntime":43}]},{},[1]) +======= +},{"../SpineRuntime":43}]},{},[1])(1) +}); +>>>>>>> origin/master:_site/js/plugins/pixi-spine.js //# sourceMappingURL=pixi-spine.js.map