Skip to content

Instantly share code, notes, and snippets.

@SethTisue
Created October 11, 2014 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SethTisue/d74739aea888b7c88563 to your computer and use it in GitHub Desktop.
Save SethTisue/d74739aea888b7c88563 to your computer and use it in GitHub Desktop.
<html>
<head>
<script>useGoogleGraph = false</script>
<!--
Uncomment if you'd like to use google graphs!
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script>useGoogleGraph = true</script>
-->
</head>
<body>
<label>speed<input id="speed-slider" type="range" min=0 max=1 step=.01 style="width: 400px"></input></label>
ticks: <span id="tick-counter"></span>
<br/>
<div class='view-container' style="position:relative"></div>
<div id="powered-by-wrapper" style="margin: 10px 0px -33px 440px;">
<a href="http://ccl.northwestern.edu/netlogo/">
<img style="vertical-align: middle;" alt="NetLogo" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAIGNIUk0AAHolAACAgwAA+f8AAIDpAAB1MAAA6mAAADqYAAAXb5JfxUYAAANcSURBVHjarJRdaFxFFMd/M/dj7252uxubKms+bGprVyIVbNMWWqkQqtLUSpQWfSiV+oVFTcE3DeiDgvoiUSiCYLH2oVoLtQ+iaaIWWtE2FKGkkSrkq5svN+sm7ma/7p3x4W42lEbjQw8MM8yc87/nzPnNFVprbqWJXyMyXuMqx1Ni6N3ny3cX8tOHNLoBUMvESoFI2Xbs4zeO1lzREpSrMSNS1zkBDv6uo1/noz1H7mpvS4SjprAl2AZYEqzKbEowBAgBAkjPKX2599JjT7R0bj412D0JYNplPSBD1G2SmR/e6u1ikEHG2vYiGxoJmxAyIGSCI8GpCItKimtvl2JtfGujDNkX6epuAhCjNeAZxM1ocPy2Qh4toGQ5DLU+ysiuA2S3P0KgJkjAgEAlQylAA64CG/jlUk6//ng4cNWmLK0yOPNMnG99Rs9LQINVKrD+wmke7upg55PrWP3eYcwrlykpKCkoelDy/HVegQhoABNAepbACwjOt72gZkJhypX70YDWEEklue+rbnYc2MiGp1upPfYReiJJUUG58gFXu4udch1wHcjFIgy0HyIjb2yvBpT2F6t+6+f+D15lW8c9JDo7iPSdgVIRLUqL2AyHDQAOf9hfbqxvMF98eT3RuTS1avHyl+Stcphe2chP9+4k/t3RbXVl3W+Ws17FY56/w3VcbO/koS/eZLoAqrQMxADZMTYOfwpwoWjL4+bCYcgssMqGOzPD6CIkZ/3SxTJ0ayFIN6/BnBrZb2XdE1JUgkJWkfrUNRJnPyc16zsbgPyXIUJBpvc+y89nk/S8/4nek3NPGeBWMwzGvhUPnP6RubRLwfODlqqx3LSCyee2MnlwMwA2RwgO5qouVcHmksUdJweYyi8hZkrUjgT5t/ejNq0jBsSqNWsKyT9uFtxw7Bs585d3g46KOeT2bWHmtd14KyP+5mzqpsYU3OyioACMhGiqPTMocsrHId9cy9BLDzKxq8X3ctMwlV6yKSHL4fr4dd0DeQBTBUgUkvpE1kVPbqkX117ZzuSaFf4zyfz5n9A4lk0yNU7vyb7jTy1kmFGipejKvh6h9n0W995ZPTu227hqmCz33xXgFV1v9NzI96NfjndWt7XWCB/7BSICFWL+j3lAofpCtfYFb6X9MwCJZ07mUsXRGwAAAABJRU5ErkJggg=="/>
<span style="font-size: 16px;">powered by NetLogo</span>
</a>
</div>
<div style="display: flex; flex-direction: row; display: -webkit-box;">
<div id='netlogo-code-wrapper' style="margin-top: 20px; flex: 1 1; -webkit-box-flex: 1; width: 50%; margin-right: 10px;">
<input id='toggle-code-button' type="button" onclick="toggleCodeVisibility();" value="Show NetLogo Code">
<pre id='netlogo-code' style="margin: 0; display: none; border: 2px solid gray; padding: 15px;
font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', monospace;">
<font color="#007f69">globals</font><font color="#000000"> [grass] </font><font color="#5a5a5a">;; keep track of how much grass there is</font>
<font color="#5a5a5a">;; Sheep and wolves are both breeds of turtle.</font>
<font color="#007f69">breed</font><font color="#000000"> [sheep a-sheep] </font><font color="#5a5a5a">;; sheep is its own plural, so we use &quot;a-sheep&quot; as the singular.</font>
<font color="#007f69">breed</font><font color="#000000"> [wolves wolf]</font>
<font color="#007f69">turtles-own</font><font color="#000000"> [energy] </font><font color="#5a5a5a">;; both wolves and sheep have energy</font>
<font color="#007f69">patches-own</font><font color="#000000"> [countdown]</font>
<font color="#007f69">to</font><font color="#000000"> setup</font>
<font color="#000000"> </font><font color="#0000aa">clear-all</font>
<font color="#000000"> </font><font color="#0000aa">ask</font><font color="#000000"> </font><font color="#660096">patches</font><font color="#000000"> [ </font><font color="#0000aa">set</font><font color="#000000"> </font><font color="#660096">pcolor</font><font color="#000000"> </font><font color="#963700">green</font><font color="#000000"> ]</font>
<font color="#000000"> </font><font color="#5a5a5a">;; check GRASS? switch.</font>
<font color="#000000"> </font><font color="#5a5a5a">;; if it is true, then grass grows and the sheep eat it</font>
<font color="#000000"> </font><font color="#5a5a5a">;; if it false, then the sheep don't need to eat</font>
<font color="#000000"> </font><font color="#0000aa">if</font><font color="#000000"> grass? [</font>
<font color="#000000"> </font><font color="#0000aa">ask</font><font color="#000000"> </font><font color="#660096">patches</font><font color="#000000"> [</font>
<font color="#000000"> </font><font color="#0000aa">set</font><font color="#000000"> </font><font color="#660096">pcolor</font><font color="#000000"> </font><font color="#660096">one-of</font><font color="#000000"> [</font><font color="#963700">green</font><font color="#000000"> </font><font color="#963700">brown</font><font color="#000000">]</font>
<font color="#000000"> </font><font color="#0000aa">if-else</font><font color="#000000"> </font><font color="#660096">pcolor</font><font color="#000000"> </font><font color="#660096">=</font><font color="#000000"> </font><font color="#963700">green</font>
<font color="#000000"> [ </font><font color="#0000aa">set</font><font color="#000000"> countdown grass-regrowth-time ]</font>
<font color="#000000"> [ </font><font color="#0000aa">set</font><font color="#000000"> countdown </font><font color="#660096">random</font><font color="#000000"> grass-regrowth-time ] </font><font color="#5a5a5a">;; initialize grass grow clocks randomly for brown patches</font>
<font color="#000000"> ]</font>
<font color="#000000"> ]</font>
<font color="#000000"> </font><font color="#0000aa">set-default-shape</font><font color="#000000"> sheep </font><font color="#963700">&quot;sheep&quot;</font>
<font color="#000000"> create-sheep initial-number-sheep </font><font color="#5a5a5a">;; create the sheep, then initialize their variables</font>
<font color="#000000"> [</font>
<font color="#000000"> </font><font color="#0000aa">set</font><font color="#000000"> </font><font color="#660096">color</font><font color="#000000"> </font><font color="#963700">white</font>
<font color="#000000"> </font><font color="#0000aa">set</font><font color="#000000"> </font><font color="#660096">size</font><font color="#000000"> </font><font color="#963700">1.5</font><font color="#000000"> </font><font color="#5a5a5a">;; easier to see</font>
<font color="#000000"> </font><font color="#0000aa">set</font><font color="#000000"> </font><font color="#660096">label-color</font><font color="#000000"> </font><font color="#963700">blue</font><font color="#000000"> </font><font color="#660096">-</font><font color="#000000"> </font><font color="#963700">2</font>
<font color="#000000"> </font><font color="#0000aa">set</font><font color="#000000"> energy </font><font color="#660096">random</font><font color="#000000"> (</font><font color="#963700">2</font><font color="#000000"> </font><font color="#660096">*</font><font color="#000000"> sheep-gain-from-food)</font>
<font color="#000000"> </font><font color="#0000aa">setxy</font><font color="#000000"> </font><font color="#660096">random-xcor</font><font color="#000000"> </font><font color="#660096">random-ycor</font>
<font color="#000000"> ]</font>
<font color="#000000"> </font><font color="#0000aa">set-default-shape</font><font color="#000000"> wolves </font><font color="#963700">&quot;wolf&quot;</font>
<font color="#000000"> create-wolves initial-number-wolves </font><font color="#5a5a5a">;; create the wolves, then initialize their variables</font>
<font color="#000000"> [</font>
<font color="#000000"> </font><font color="#0000aa">set</font><font color="#000000"> </font><font color="#660096">color</font><font color="#000000"> </font><font color="#963700">black</font>
<font color="#000000"> </font><font color="#0000aa">set</font><font color="#000000"> </font><font color="#660096">size</font><font color="#000000"> </font><font color="#963700">2</font><font color="#000000"> </font><font color="#5a5a5a">;; easier to see</font>
<font color="#000000"> </font><font color="#0000aa">set</font><font color="#000000"> energy </font><font color="#660096">random</font><font color="#000000"> (</font><font color="#963700">2</font><font color="#000000"> </font><font color="#660096">*</font><font color="#000000"> wolf-gain-from-food)</font>
<font color="#000000"> </font><font color="#0000aa">setxy</font><font color="#000000"> </font><font color="#660096">random-xcor</font><font color="#000000"> </font><font color="#660096">random-ycor</font>
<font color="#000000"> ]</font>
<font color="#000000"> display-labels</font>
<font color="#000000"> </font><font color="#0000aa">set</font><font color="#000000"> grass </font><font color="#660096">count</font><font color="#000000"> </font><font color="#660096">patches</font><font color="#000000"> </font><font color="#660096">with</font><font color="#000000"> [</font><font color="#660096">pcolor</font><font color="#000000"> </font><font color="#660096">=</font><font color="#000000"> </font><font color="#963700">green</font><font color="#000000">]</font>
<font color="#000000"> </font><font color="#0000aa">reset-ticks</font>
<font color="#007f69">end</font>
<font color="#007f69">to</font><font color="#000000"> go</font>
<font color="#000000"> </font><font color="#0000aa">if</font><font color="#000000"> </font><font color="#660096">not</font><font color="#000000"> </font><font color="#660096">any?</font><font color="#000000"> </font><font color="#660096">turtles</font><font color="#000000"> [ </font><font color="#0000aa">stop</font><font color="#000000"> ]</font>
<font color="#000000"> </font><font color="#0000aa">ask</font><font color="#000000"> sheep [</font>
<font color="#000000"> move</font>
<font color="#000000"> </font><font color="#0000aa">if</font><font color="#000000"> grass? [</font>
<font color="#000000"> </font><font color="#0000aa">set</font><font color="#000000"> energy energy </font><font color="#660096">-</font><font color="#000000"> </font><font color="#963700">1</font><font color="#000000"> </font><font color="#5a5a5a">;; deduct energy for sheep only if grass? switch is on</font>
<font color="#000000"> eat-grass</font>
<font color="#000000"> ]</font>
<font color="#000000"> death</font>
<font color="#000000"> reproduce-sheep</font>
<font color="#000000"> ]</font>
<font color="#000000"> </font><font color="#0000aa">ask</font><font color="#000000"> wolves [</font>
<font color="#000000"> move</font>
<font color="#000000"> </font><font color="#0000aa">set</font><font color="#000000"> energy energy </font><font color="#660096">-</font><font color="#000000"> </font><font color="#963700">1</font><font color="#000000"> </font><font color="#5a5a5a">;; wolves lose energy as they move</font>
<font color="#000000"> catch-sheep</font>
<font color="#000000"> death</font>
<font color="#000000"> reproduce-wolves</font>
<font color="#000000"> ]</font>
<font color="#000000"> </font><font color="#0000aa">if</font><font color="#000000"> grass? [ </font><font color="#0000aa">ask</font><font color="#000000"> </font><font color="#660096">patches</font><font color="#000000"> [ grow-grass ] ]</font>
<font color="#000000"> </font><font color="#0000aa">set</font><font color="#000000"> grass </font><font color="#660096">count</font><font color="#000000"> </font><font color="#660096">patches</font><font color="#000000"> </font><font color="#660096">with</font><font color="#000000"> [</font><font color="#660096">pcolor</font><font color="#000000"> </font><font color="#660096">=</font><font color="#000000"> </font><font color="#963700">green</font><font color="#000000">]</font>
<font color="#000000"> </font><font color="#0000aa">tick</font>
<font color="#000000"> display-labels</font>
<font color="#007f69">end</font>
<font color="#007f69">to</font><font color="#000000"> move </font><font color="#5a5a5a">;; turtle procedure</font>
<font color="#000000"> </font><font color="#0000aa">rt</font><font color="#000000"> </font><font color="#660096">random</font><font color="#000000"> </font><font color="#963700">50</font>
<font color="#000000"> </font><font color="#0000aa">lt</font><font color="#000000"> </font><font color="#660096">random</font><font color="#000000"> </font><font color="#963700">50</font>
<font color="#000000"> </font><font color="#0000aa">fd</font><font color="#000000"> </font><font color="#963700">1</font>
<font color="#007f69">end</font>
<font color="#007f69">to</font><font color="#000000"> eat-grass </font><font color="#5a5a5a">;; sheep procedure</font>
<font color="#000000"> </font><font color="#5a5a5a">;; sheep eat grass, turn the patch brown</font>
<font color="#000000"> </font><font color="#0000aa">if</font><font color="#000000"> </font><font color="#660096">pcolor</font><font color="#000000"> </font><font color="#660096">=</font><font color="#000000"> </font><font color="#963700">green</font><font color="#000000"> [</font>
<font color="#000000"> </font><font color="#0000aa">set</font><font color="#000000"> </font><font color="#660096">pcolor</font><font color="#000000"> </font><font color="#963700">brown</font>
<font color="#000000"> </font><font color="#0000aa">set</font><font color="#000000"> energy energy </font><font color="#660096">+</font><font color="#000000"> sheep-gain-from-food </font><font color="#5a5a5a">;; sheep gain energy by eating</font>
<font color="#000000"> ]</font>
<font color="#007f69">end</font>
<font color="#007f69">to</font><font color="#000000"> reproduce-sheep </font><font color="#5a5a5a">;; sheep procedure</font>
<font color="#000000"> </font><font color="#0000aa">if</font><font color="#000000"> </font><font color="#660096">random-float</font><font color="#000000"> </font><font color="#963700">100</font><font color="#000000"> </font><font color="#660096">&lt;</font><font color="#000000"> sheep-reproduce [ </font><font color="#5a5a5a">;; throw &quot;dice&quot; to see if you will reproduce</font>
<font color="#000000"> </font><font color="#0000aa">set</font><font color="#000000"> energy (energy </font><font color="#660096">/</font><font color="#000000"> </font><font color="#963700">2</font><font color="#000000">) </font><font color="#5a5a5a">;; divide energy between parent and offspring</font>
<font color="#000000"> </font><font color="#0000aa">hatch</font><font color="#000000"> </font><font color="#963700">1</font><font color="#000000"> [ </font><font color="#0000aa">rt</font><font color="#000000"> </font><font color="#660096">random-float</font><font color="#000000"> </font><font color="#963700">360</font><font color="#000000"> </font><font color="#0000aa">fd</font><font color="#000000"> </font><font color="#963700">1</font><font color="#000000"> ] </font><font color="#5a5a5a">;; hatch an offspring and move it forward 1 step</font>
<font color="#000000"> ]</font>
<font color="#007f69">end</font>
<font color="#007f69">to</font><font color="#000000"> reproduce-wolves </font><font color="#5a5a5a">;; wolf procedure</font>
<font color="#000000"> </font><font color="#0000aa">if</font><font color="#000000"> </font><font color="#660096">random-float</font><font color="#000000"> </font><font color="#963700">100</font><font color="#000000"> </font><font color="#660096">&lt;</font><font color="#000000"> wolf-reproduce [ </font><font color="#5a5a5a">;; throw &quot;dice&quot; to see if you will reproduce</font>
<font color="#000000"> </font><font color="#0000aa">set</font><font color="#000000"> energy (energy </font><font color="#660096">/</font><font color="#000000"> </font><font color="#963700">2</font><font color="#000000">) </font><font color="#5a5a5a">;; divide energy between parent and offspring</font>
<font color="#000000"> </font><font color="#0000aa">hatch</font><font color="#000000"> </font><font color="#963700">1</font><font color="#000000"> [ </font><font color="#0000aa">rt</font><font color="#000000"> </font><font color="#660096">random-float</font><font color="#000000"> </font><font color="#963700">360</font><font color="#000000"> </font><font color="#0000aa">fd</font><font color="#000000"> </font><font color="#963700">1</font><font color="#000000"> ] </font><font color="#5a5a5a">;; hatch an offspring and move it forward 1 step</font>
<font color="#000000"> ]</font>
<font color="#007f69">end</font>
<font color="#007f69">to</font><font color="#000000"> catch-sheep </font><font color="#5a5a5a">;; wolf procedure</font>
<font color="#000000"> </font><font color="#0000aa">let</font><font color="#000000"> prey </font><font color="#660096">one-of</font><font color="#000000"> sheep-here </font><font color="#5a5a5a">;; grab a random sheep</font>
<font color="#000000"> </font><font color="#0000aa">if</font><font color="#000000"> prey </font><font color="#660096">!=</font><font color="#000000"> </font><font color="#963700">nobody</font><font color="#000000"> </font><font color="#5a5a5a">;; did we get one? if so,</font>
<font color="#000000"> [ </font><font color="#0000aa">ask</font><font color="#000000"> prey [ </font><font color="#0000aa">die</font><font color="#000000"> ] </font><font color="#5a5a5a">;; kill it</font>
<font color="#000000"> </font><font color="#0000aa">set</font><font color="#000000"> energy energy </font><font color="#660096">+</font><font color="#000000"> wolf-gain-from-food ] </font><font color="#5a5a5a">;; get energy from eating</font>
<font color="#007f69">end</font>
<font color="#007f69">to</font><font color="#000000"> death </font><font color="#5a5a5a">;; turtle procedure</font>
<font color="#000000"> </font><font color="#5a5a5a">;; when energy dips below zero, die</font>
<font color="#000000"> </font><font color="#0000aa">if</font><font color="#000000"> energy </font><font color="#660096">&lt;</font><font color="#000000"> </font><font color="#963700">0</font><font color="#000000"> [ </font><font color="#0000aa">die</font><font color="#000000"> ]</font>
<font color="#007f69">end</font>
<font color="#007f69">to</font><font color="#000000"> grow-grass </font><font color="#5a5a5a">;; patch procedure</font>
<font color="#000000"> </font><font color="#5a5a5a">;; countdown on brown patches: if reach 0, grow some grass</font>
<font color="#000000"> </font><font color="#0000aa">if</font><font color="#000000"> </font><font color="#660096">pcolor</font><font color="#000000"> </font><font color="#660096">=</font><font color="#000000"> </font><font color="#963700">brown</font><font color="#000000"> [</font>
<font color="#000000"> </font><font color="#0000aa">ifelse</font><font color="#000000"> countdown </font><font color="#660096">&lt;=</font><font color="#000000"> </font><font color="#963700">0</font>
<font color="#000000"> [ </font><font color="#0000aa">set</font><font color="#000000"> </font><font color="#660096">pcolor</font><font color="#000000"> </font><font color="#963700">green</font>
<font color="#000000"> </font><font color="#0000aa">set</font><font color="#000000"> countdown grass-regrowth-time ]</font>
<font color="#000000"> [ </font><font color="#0000aa">set</font><font color="#000000"> countdown countdown </font><font color="#660096">-</font><font color="#000000"> </font><font color="#963700">1</font><font color="#000000"> ]</font>
<font color="#000000"> ]</font>
<font color="#007f69">end</font>
<font color="#007f69">to</font><font color="#000000"> display-labels</font>
<font color="#000000"> </font><font color="#0000aa">ask</font><font color="#000000"> </font><font color="#660096">turtles</font><font color="#000000"> [ </font><font color="#0000aa">set</font><font color="#000000"> </font><font color="#660096">label</font><font color="#000000"> </font><font color="#963700">&quot;&quot;</font><font color="#000000"> ]</font>
<font color="#000000"> </font><font color="#0000aa">if</font><font color="#000000"> show-energy? [</font>
<font color="#000000"> </font><font color="#0000aa">ask</font><font color="#000000"> wolves [ </font><font color="#0000aa">set</font><font color="#000000"> </font><font color="#660096">label</font><font color="#000000"> </font><font color="#660096">round</font><font color="#000000"> energy ]</font>
<font color="#000000"> </font><font color="#0000aa">if</font><font color="#000000"> grass? [ </font><font color="#0000aa">ask</font><font color="#000000"> sheep [ </font><font color="#0000aa">set</font><font color="#000000"> </font><font color="#660096">label</font><font color="#000000"> </font><font color="#660096">round</font><font color="#000000"> energy ] ]</font>
<font color="#000000"> ]</font>
<font color="#007f69">end</font>
<font color="#5a5a5a">; Copyright 1997 Uri Wilensky.</font>
<font color="#5a5a5a">; See Info tab for full copyright and license.</font>
</pre>
</div>
<div id='netlogo-info-wrapper' style="margin-top: 20px; flex: 1 1; -webkit-box-flex: 1; width: 50%;" >
<input id='toggle-info-button' type="button" onclick="toggleInfoVisibility();" value="Show Model Info">
<div id='netlogo-info' style="margin: 0; display: none; border: 2px solid gray; padding: 15px;">
## WHAT IS IT?
This model explores the stability of predator-prey ecosystems. Such a system is called unstable if it tends to result in extinction for one or more species involved. In contrast, a system is stable if it tends to maintain itself over time, despite fluctuations in population sizes.
## HOW IT WORKS
There are two main variations to this model.
In the first variation, wolves and sheep wander randomly around the landscape, while the wolves look for sheep to prey on. Each step costs the wolves energy, and they must eat sheep in order to replenish their energy - when they run out of energy they die. To allow the population to continue, each wolf or sheep has a fixed probability of reproducing at each time step. This variation produces interesting population dynamics, but is ultimately unstable.
The second variation includes grass (green) in addition to wolves and sheep. The behavior of the wolves is identical to the first variation, however this time the sheep must eat grass in order to maintain their energy - when they run out of energy they die. Once grass is eaten it will only regrow after a fixed amount of time. This variation is more complex than the first, but it is generally stable.
The construction of this model is described in two papers by Wilensky &amp; Reisman referenced below.
## HOW TO USE IT
1. Set the GRASS? switch to TRUE to include grass in the model, or to FALSE to only include wolves (red) and sheep (white).
2. Adjust the slider parameters (see below), or use the default settings.
3. Press the SETUP button.
4. Press the GO button to begin the simulation.
5. Look at the monitors to see the current population sizes
6. Look at the POPULATIONS plot to watch the populations fluctuate over time
Parameters:
INITIAL-NUMBER-SHEEP: The initial size of sheep population
INITIAL-NUMBER-WOLVES: The initial size of wolf population
SHEEP-GAIN-FROM-FOOD: The amount of energy sheep get for every grass patch eaten
WOLF-GAIN-FROM-FOOD: The amount of energy wolves get for every sheep eaten
SHEEP-REPRODUCE: The probability of a sheep reproducing at each time step
WOLF-REPRODUCE: The probability of a wolf reproducing at each time step
GRASS?: Whether or not to include grass in the model
GRASS-REGROWTH-TIME: How long it takes for grass to regrow once it is eaten
SHOW-ENERGY?: Whether or not to show the energy of each animal as a number
Notes:
- one unit of energy is deducted for every step a wolf takes
- when grass is included, one unit of energy is deducted for every step a sheep takes
## THINGS TO NOTICE
When grass is not included, watch as the sheep and wolf populations fluctuate. Notice that increases and decreases in the sizes of each population are related. In what way are they related? What eventually happens?
Once grass is added, notice the green line added to the population plot representing fluctuations in the amount of grass. How do the sizes of the three populations appear to relate now? What is the explanation for this?
Why do you suppose that some variations of the model might be stable while others are not?
## THINGS TO TRY
Try adjusting the parameters under various settings. How sensitive is the stability of the model to the particular parameters?
Can you find any parameters that generate a stable ecosystem that includes only wolves and sheep?
Try setting GRASS? to TRUE, but setting INITIAL-NUMBER-WOLVES to 0. This gives a stable ecosystem with only sheep and grass. Why might this be stable while the variation with only sheep and wolves is not?
Notice that under stable settings, the populations tend to fluctuate at a predictable pace. Can you find any parameters that will speed this up or slow it down?
Try changing the reproduction rules -- for example, what would happen if reproduction depended on energy rather than being determined by a fixed probability?
## EXTENDING THE MODEL
There are a number ways to alter the model so that it will be stable with only wolves and sheep (no grass). Some will require new elements to be coded in or existing behaviors to be changed. Can you develop such a version?
## NETLOGO FEATURES
Note the use of breeds to model two different kinds of &quot;turtles&quot;: wolves and sheep. Note the use of patches to model grass.
Note use of the ONE-OF agentset reporter to select a random sheep to be eaten by a wolf.
## RELATED MODELS
Look at Rabbits Grass Weeds for another model of interacting populations with different rules.
## CREDITS AND REFERENCES
Wilensky, U. &amp; Reisman, K. (1999). Connected Science: Learning Biology through Constructing and Testing Computational Theories -- an Embodied Modeling Approach. International Journal of Complex Systems, M. 234, pp. 1 - 12. (This model is a slightly extended version of the model described in the paper.)
Wilensky, U. &amp; Reisman, K. (2006). Thinking like a Wolf, a Sheep or a Firefly: Learning Biology through Constructing and Testing Computational Theories -- an Embodied Modeling Approach. Cognition &amp; Instruction, 24(2), pp. 171-209. http://ccl.northwestern.edu/papers/wolfsheep.pdf
## HOW TO CITE
If you mention this model in a publication, we ask that you include these citations for the model itself and for the NetLogo software:
* Wilensky, U. (1997). NetLogo Wolf Sheep Predation model. http://ccl.northwestern.edu/netlogo/models/WolfSheepPredation. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL.
* Wilensky, U. (1999). NetLogo. http://ccl.northwestern.edu/netlogo/. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL.
## COPYRIGHT AND LICENSE
Copyright 1997 Uri Wilensky.
![CC BY-NC-SA 3.0](http://i.creativecommons.org/l/by-nc-sa/3.0/88x31.png)
This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
Commercial licenses are also available. To inquire about commercial licenses, please contact Uri Wilensky at uri@northwestern.edu.
This model was created as part of the project: CONNECTED MATHEMATICS: MAKING SENSE OF COMPLEX PHENOMENA THROUGH BUILDING OBJECT-BASED PARALLEL MODELS (OBPML). The project gratefully acknowledges the support of the National Science Foundation (Applications of Advanced Technologies Program) -- grant numbers RED #9552950 and REC #9632612.
This model was converted to NetLogo as part of the projects: PARTICIPATORY SIMULATIONS: NETWORK-BASED DESIGN FOR SYSTEMS LEARNING IN CLASSROOMS and/or INTEGRATED SIMULATION AND MODELING ENVIRONMENT. The project gratefully acknowledges the support of the National Science Foundation (REPP &amp; ROLE programs) -- grant numbers REC #9814682 and REC-0126227. Converted from StarLogoT to NetLogo, 2000.
</div>
</div>
</div>
<script type="text/javascript">
// Released under MIT license
// Copyright (c) 2009-2010 Dominic Baggott
// Copyright (c) 2009-2010 Ash Berlin
// Copyright (c) 2011 Christoph Dorn <christoph@christophdorn.com> (http://www.christophdorn.com)
/*jshint browser:true, devel:true */
(function( expose ) {
/**
* class Markdown
*
* Markdown processing in Javascript done right. We have very particular views
* on what constitutes 'right' which include:
*
* - produces well-formed HTML (this means that em and strong nesting is
* important)
*
* - has an intermediate representation to allow processing of parsed data (We
* in fact have two, both as [JsonML]: a markdown tree and an HTML tree).
*
* - is easily extensible to add new dialects without having to rewrite the
* entire parsing mechanics
*
* - has a good test suite
*
* This implementation fulfills all of these (except that the test suite could
* do with expanding to automatically run all the fixtures from other Markdown
* implementations.)
*
* ##### Intermediate Representation
*
* *TODO* Talk about this :) Its JsonML, but document the node names we use.
*
* [JsonML]: http://jsonml.org/ "JSON Markup Language"
**/
var Markdown = expose.Markdown = function(dialect) {
switch (typeof dialect) {
case "undefined":
this.dialect = Markdown.dialects.Gruber;
break;
case "object":
this.dialect = dialect;
break;
default:
if ( dialect in Markdown.dialects ) {
this.dialect = Markdown.dialects[dialect];
}
else {
throw new Error("Unknown Markdown dialect '" + String(dialect) + "'");
}
break;
}
this.em_state = [];
this.strong_state = [];
this.debug_indent = "";
};
/**
* parse( markdown, [dialect] ) -> JsonML
* - markdown (String): markdown string to parse
* - dialect (String | Dialect): the dialect to use, defaults to gruber
*
* Parse `markdown` and return a markdown document as a Markdown.JsonML tree.
**/
expose.parse = function( source, dialect ) {
// dialect will default if undefined
var md = new Markdown( dialect );
return md.toTree( source );
};
/**
* toHTML( markdown, [dialect] ) -> String
* toHTML( md_tree ) -> String
* - markdown (String): markdown string to parse
* - md_tree (Markdown.JsonML): parsed markdown tree
*
* Take markdown (either as a string or as a JsonML tree) and run it through
* [[toHTMLTree]] then turn it into a well-formated HTML fragment.
**/
expose.toHTML = function toHTML( source , dialect , options ) {
var input = expose.toHTMLTree( source , dialect , options );
return expose.renderJsonML( input );
};
/**
* toHTMLTree( markdown, [dialect] ) -> JsonML
* toHTMLTree( md_tree ) -> JsonML
* - markdown (String): markdown string to parse
* - dialect (String | Dialect): the dialect to use, defaults to gruber
* - md_tree (Markdown.JsonML): parsed markdown tree
*
* Turn markdown into HTML, represented as a JsonML tree. If a string is given
* to this function, it is first parsed into a markdown tree by calling
* [[parse]].
**/
expose.toHTMLTree = function toHTMLTree( input, dialect , options ) {
// convert string input to an MD tree
if ( typeof input ==="string" ) input = this.parse( input, dialect );
// Now convert the MD tree to an HTML tree
// remove references from the tree
var attrs = extract_attr( input ),
refs = {};
if ( attrs && attrs.references ) {
refs = attrs.references;
}
var html = convert_tree_to_html( input, refs , options );
merge_text_nodes( html );
return html;
};
// For Spidermonkey based engines
function mk_block_toSource() {
return "Markdown.mk_block( " +
uneval(this.toString()) +
", " +
uneval(this.trailing) +
", " +
uneval(this.lineNumber) +
" )";
}
// node
function mk_block_inspect() {
var util = require("util");
return "Markdown.mk_block( " +
util.inspect(this.toString()) +
", " +
util.inspect(this.trailing) +
", " +
util.inspect(this.lineNumber) +
" )";
}
var mk_block = Markdown.mk_block = function(block, trail, line) {
// Be helpful for default case in tests.
if ( arguments.length == 1 ) trail = "\n\n";
var s = new String(block);
s.trailing = trail;
// To make it clear its not just a string
s.inspect = mk_block_inspect;
s.toSource = mk_block_toSource;
if ( line != undefined )
s.lineNumber = line;
return s;
};
function count_lines( str ) {
var n = 0, i = -1;
while ( ( i = str.indexOf("\n", i + 1) ) !== -1 ) n++;
return n;
}
// Internal - split source into rough blocks
Markdown.prototype.split_blocks = function splitBlocks( input, startLine ) {
input = input.replace(/(\r\n|\n|\r)/g, "\n");
// [\s\S] matches _anything_ (newline or space)
// [^] is equivalent but doesn't work in IEs.
var re = /([\s\S]+?)($|\n#|\n(?:\s*\n|$)+)/g,
blocks = [],
m;
var line_no = 1;
if ( ( m = /^(\s*\n)/.exec(input) ) != null ) {
// skip (but count) leading blank lines
line_no += count_lines( m[0] );
re.lastIndex = m[0].length;
}
while ( ( m = re.exec(input) ) !== null ) {
if (m[2] == "\n#") {
m[2] = "\n";
re.lastIndex--;
}
blocks.push( mk_block( m[1], m[2], line_no ) );
line_no += count_lines( m[0] );
}
return blocks;
};
/**
* Markdown#processBlock( block, next ) -> undefined | [ JsonML, ... ]
* - block (String): the block to process
* - next (Array): the following blocks
*
* Process `block` and return an array of JsonML nodes representing `block`.
*
* It does this by asking each block level function in the dialect to process
* the block until one can. Succesful handling is indicated by returning an
* array (with zero or more JsonML nodes), failure by a false value.
*
* Blocks handlers are responsible for calling [[Markdown#processInline]]
* themselves as appropriate.
*
* If the blocks were split incorrectly or adjacent blocks need collapsing you
* can adjust `next` in place using shift/splice etc.
*
* If any of this default behaviour is not right for the dialect, you can
* define a `__call__` method on the dialect that will get invoked to handle
* the block processing.
*/
Markdown.prototype.processBlock = function processBlock( block, next ) {
var cbs = this.dialect.block,
ord = cbs.__order__;
if ( "__call__" in cbs ) {
return cbs.__call__.call(this, block, next);
}
for ( var i = 0; i < ord.length; i++ ) {
//D:this.debug( "Testing", ord[i] );
var res = cbs[ ord[i] ].call( this, block, next );
if ( res ) {
//D:this.debug(" matched");
if ( !isArray(res) || ( res.length > 0 && !( isArray(res[0]) ) ) )
this.debug(ord[i], "didn't return a proper array");
//D:this.debug( "" );
return res;
}
}
// Uhoh! no match! Should we throw an error?
return [];
};
Markdown.prototype.processInline = function processInline( block ) {
return this.dialect.inline.__call__.call( this, String( block ) );
};
/**
* Markdown#toTree( source ) -> JsonML
* - source (String): markdown source to parse
*
* Parse `source` into a JsonML tree representing the markdown document.
**/
// custom_tree means set this.tree to `custom_tree` and restore old value on return
Markdown.prototype.toTree = function toTree( source, custom_root ) {
var blocks = source instanceof Array ? source : this.split_blocks( source );
// Make tree a member variable so its easier to mess with in extensions
var old_tree = this.tree;
try {
this.tree = custom_root || this.tree || [ "markdown" ];
blocks:
while ( blocks.length ) {
var b = this.processBlock( blocks.shift(), blocks );
// Reference blocks and the like won't return any content
if ( !b.length ) continue blocks;
this.tree.push.apply( this.tree, b );
}
return this.tree;
}
finally {
if ( custom_root ) {
this.tree = old_tree;
}
}
};
// Noop by default
Markdown.prototype.debug = function () {
var args = Array.prototype.slice.call( arguments);
args.unshift(this.debug_indent);
if ( typeof print !== "undefined" )
print.apply( print, args );
if ( typeof console !== "undefined" && typeof console.log !== "undefined" )
console.log.apply( null, args );
}
Markdown.prototype.loop_re_over_block = function( re, block, cb ) {
// Dont use /g regexps with this
var m,
b = block.valueOf();
while ( b.length && (m = re.exec(b) ) != null ) {
b = b.substr( m[0].length );
cb.call(this, m);
}
return b;
};
/**
* Markdown.dialects
*
* Namespace of built-in dialects.
**/
Markdown.dialects = {};
/**
* Markdown.dialects.Gruber
*
* The default dialect that follows the rules set out by John Gruber's
* markdown.pl as closely as possible. Well actually we follow the behaviour of
* that script which in some places is not exactly what the syntax web page
* says.
**/
Markdown.dialects.Gruber = {
block: {
atxHeader: function atxHeader( block, next ) {
var m = block.match( /^(#{1,6})\s*(.*?)\s*#*\s*(?:\n|$)/ );
if ( !m ) return undefined;
var header = [ "header", { level: m[ 1 ].length } ];
Array.prototype.push.apply(header, this.processInline(m[ 2 ]));
if ( m[0].length < block.length )
next.unshift( mk_block( block.substr( m[0].length ), block.trailing, block.lineNumber + 2 ) );
return [ header ];
},
setextHeader: function setextHeader( block, next ) {
var m = block.match( /^(.*)\n([-=])\2\2+(?:\n|$)/ );
if ( !m ) return undefined;
var level = ( m[ 2 ] === "=" ) ? 1 : 2;
var header = [ "header", { level : level }, m[ 1 ] ];
if ( m[0].length < block.length )
next.unshift( mk_block( block.substr( m[0].length ), block.trailing, block.lineNumber + 2 ) );
return [ header ];
},
code: function code( block, next ) {
// | Foo
// |bar
// should be a code block followed by a paragraph. Fun
//
// There might also be adjacent code block to merge.
var ret = [],
re = /^(?: {0,3}\t| {4})(.*)\n?/,
lines;
// 4 spaces + content
if ( !block.match( re ) ) return undefined;
block_search:
do {
// Now pull out the rest of the lines
var b = this.loop_re_over_block(
re, block.valueOf(), function( m ) { ret.push( m[1] ); } );
if ( b.length ) {
// Case alluded to in first comment. push it back on as a new block
next.unshift( mk_block(b, block.trailing) );
break block_search;
}
else if ( next.length ) {
// Check the next block - it might be code too
if ( !next[0].match( re ) ) break block_search;
// Pull how how many blanks lines follow - minus two to account for .join
ret.push ( block.trailing.replace(/[^\n]/g, "").substring(2) );
block = next.shift();
}
else {
break block_search;
}
} while ( true );
return [ [ "code_block", ret.join("\n") ] ];
},
horizRule: function horizRule( block, next ) {
// this needs to find any hr in the block to handle abutting blocks
var m = block.match( /^(?:([\s\S]*?)\n)?[ \t]*([-_*])(?:[ \t]*\2){2,}[ \t]*(?:\n([\s\S]*))?$/ );
if ( !m ) {
return undefined;
}
var jsonml = [ [ "hr" ] ];
// if there's a leading abutting block, process it
if ( m[ 1 ] ) {
jsonml.unshift.apply( jsonml, this.processBlock( m[ 1 ], [] ) );
}
// if there's a trailing abutting block, stick it into next
if ( m[ 3 ] ) {
next.unshift( mk_block( m[ 3 ] ) );
}
return jsonml;
},
// There are two types of lists. Tight and loose. Tight lists have no whitespace
// between the items (and result in text just in the <li>) and loose lists,
// which have an empty line between list items, resulting in (one or more)
// paragraphs inside the <li>.
//
// There are all sorts weird edge cases about the original markdown.pl's
// handling of lists:
//
// * Nested lists are supposed to be indented by four chars per level. But
// if they aren't, you can get a nested list by indenting by less than
// four so long as the indent doesn't match an indent of an existing list
// item in the 'nest stack'.
//
// * The type of the list (bullet or number) is controlled just by the
// first item at the indent. Subsequent changes are ignored unless they
// are for nested lists
//
lists: (function( ) {
// Use a closure to hide a few variables.
var any_list = "[*+-]|\\d+\\.",
bullet_list = /[*+-]/,
number_list = /\d+\./,
// Capture leading indent as it matters for determining nested lists.
is_list_re = new RegExp( "^( {0,3})(" + any_list + ")[ \t]+" ),
indent_re = "(?: {0,3}\\t| {4})";
// TODO: Cache this regexp for certain depths.
// Create a regexp suitable for matching an li for a given stack depth
function regex_for_depth( depth ) {
return new RegExp(
// m[1] = indent, m[2] = list_type
"(?:^(" + indent_re + "{0," + depth + "} {0,3})(" + any_list + ")\\s+)|" +
// m[3] = cont
"(^" + indent_re + "{0," + (depth-1) + "}[ ]{0,4})"
);
}
function expand_tab( input ) {
return input.replace( / {0,3}\t/g, " " );
}
// Add inline content `inline` to `li`. inline comes from processInline
// so is an array of content
function add(li, loose, inline, nl) {
if ( loose ) {
li.push( [ "para" ].concat(inline) );
return;
}
// Hmmm, should this be any block level element or just paras?
var add_to = li[li.length -1] instanceof Array && li[li.length - 1][0] == "para"
? li[li.length -1]
: li;
// If there is already some content in this list, add the new line in
if ( nl && li.length > 1 ) inline.unshift(nl);
for ( var i = 0; i < inline.length; i++ ) {
var what = inline[i],
is_str = typeof what == "string";
if ( is_str && add_to.length > 1 && typeof add_to[add_to.length-1] == "string" ) {
add_to[ add_to.length-1 ] += what;
}
else {
add_to.push( what );
}
}
}
// contained means have an indent greater than the current one. On
// *every* line in the block
function get_contained_blocks( depth, blocks ) {
var re = new RegExp( "^(" + indent_re + "{" + depth + "}.*?\\n?)*$" ),
replace = new RegExp("^" + indent_re + "{" + depth + "}", "gm"),
ret = [];
while ( blocks.length > 0 ) {
if ( re.exec( blocks[0] ) ) {
var b = blocks.shift(),
// Now remove that indent
x = b.replace( replace, "");
ret.push( mk_block( x, b.trailing, b.lineNumber ) );
}
else {
break;
}
}
return ret;
}
// passed to stack.forEach to turn list items up the stack into paras
function paragraphify(s, i, stack) {
var list = s.list;
var last_li = list[list.length-1];
if ( last_li[1] instanceof Array && last_li[1][0] == "para" ) {
return;
}
if ( i + 1 == stack.length ) {
// Last stack frame
// Keep the same array, but replace the contents
last_li.push( ["para"].concat( last_li.splice(1, last_li.length - 1) ) );
}
else {
var sublist = last_li.pop();
last_li.push( ["para"].concat( last_li.splice(1, last_li.length - 1) ), sublist );
}
}
// The matcher function
return function( block, next ) {
var m = block.match( is_list_re );
if ( !m ) return undefined;
function make_list( m ) {
var list = bullet_list.exec( m[2] )
? ["bulletlist"]
: ["numberlist"];
stack.push( { list: list, indent: m[1] } );
return list;
}
var stack = [], // Stack of lists for nesting.
list = make_list( m ),
last_li,
loose = false,
ret = [ stack[0].list ],
i;
// Loop to search over block looking for inner block elements and loose lists
loose_search:
while ( true ) {
// Split into lines preserving new lines at end of line
var lines = block.split( /(?=\n)/ );
// We have to grab all lines for a li and call processInline on them
// once as there are some inline things that can span lines.
var li_accumulate = "";
// Loop over the lines in this block looking for tight lists.
tight_search:
for ( var line_no = 0; line_no < lines.length; line_no++ ) {
var nl = "",
l = lines[line_no].replace(/^\n/, function(n) { nl = n; return ""; });
// TODO: really should cache this
var line_re = regex_for_depth( stack.length );
m = l.match( line_re );
//print( "line:", uneval(l), "\nline match:", uneval(m) );
// We have a list item
if ( m[1] !== undefined ) {
// Process the previous list item, if any
if ( li_accumulate.length ) {
add( last_li, loose, this.processInline( li_accumulate ), nl );
// Loose mode will have been dealt with. Reset it
loose = false;
li_accumulate = "";
}
m[1] = expand_tab( m[1] );
var wanted_depth = Math.floor(m[1].length/4)+1;
//print( "want:", wanted_depth, "stack:", stack.length);
if ( wanted_depth > stack.length ) {
// Deep enough for a nested list outright
//print ( "new nested list" );
list = make_list( m );
last_li.push( list );
last_li = list[1] = [ "listitem" ];
}
else {
// We aren't deep enough to be strictly a new level. This is
// where Md.pl goes nuts. If the indent matches a level in the
// stack, put it there, else put it one deeper then the
// wanted_depth deserves.
var found = false;
for ( i = 0; i < stack.length; i++ ) {
if ( stack[ i ].indent != m[1] ) continue;
list = stack[ i ].list;
stack.splice( i+1, stack.length - (i+1) );
found = true;
break;
}
if (!found) {
//print("not found. l:", uneval(l));
wanted_depth++;
if ( wanted_depth <= stack.length ) {
stack.splice(wanted_depth, stack.length - wanted_depth);
//print("Desired depth now", wanted_depth, "stack:", stack.length);
list = stack[wanted_depth-1].list;
//print("list:", uneval(list) );
}
else {
//print ("made new stack for messy indent");
list = make_list(m);
last_li.push(list);
}
}
//print( uneval(list), "last", list === stack[stack.length-1].list );
last_li = [ "listitem" ];
list.push(last_li);
} // end depth of shenegains
nl = "";
}
// Add content
if ( l.length > m[0].length ) {
li_accumulate += nl + l.substr( m[0].length );
}
} // tight_search
if ( li_accumulate.length ) {
add( last_li, loose, this.processInline( li_accumulate ), nl );
// Loose mode will have been dealt with. Reset it
loose = false;
li_accumulate = "";
}
// Look at the next block - we might have a loose list. Or an extra
// paragraph for the current li
var contained = get_contained_blocks( stack.length, next );
// Deal with code blocks or properly nested lists
if ( contained.length > 0 ) {
// Make sure all listitems up the stack are paragraphs
forEach( stack, paragraphify, this);
last_li.push.apply( last_li, this.toTree( contained, [] ) );
}
var next_block = next[0] && next[0].valueOf() || "";
if ( next_block.match(is_list_re) || next_block.match( /^ / ) ) {
block = next.shift();
// Check for an HR following a list: features/lists/hr_abutting
var hr = this.dialect.block.horizRule( block, next );
if ( hr ) {
ret.push.apply(ret, hr);
break;
}
// Make sure all listitems up the stack are paragraphs
forEach( stack, paragraphify, this);
loose = true;
continue loose_search;
}
break;
} // loose_search
return ret;
};
})(),
blockquote: function blockquote( block, next ) {
if ( !block.match( /^>/m ) )
return undefined;
var jsonml = [];
// separate out the leading abutting block, if any. I.e. in this case:
//
// a
// > b
//
if ( block[ 0 ] != ">" ) {
var lines = block.split( /\n/ ),
prev = [],
line_no = block.lineNumber;
// keep shifting lines until you find a crotchet
while ( lines.length && lines[ 0 ][ 0 ] != ">" ) {
prev.push( lines.shift() );
line_no++;
}
var abutting = mk_block( prev.join( "\n" ), "\n", block.lineNumber );
jsonml.push.apply( jsonml, this.processBlock( abutting, [] ) );
// reassemble new block of just block quotes!
block = mk_block( lines.join( "\n" ), block.trailing, line_no );
}
// if the next block is also a blockquote merge it in
while ( next.length && next[ 0 ][ 0 ] == ">" ) {
var b = next.shift();
block = mk_block( block + block.trailing + b, b.trailing, block.lineNumber );
}
// Strip off the leading "> " and re-process as a block.
var input = block.replace( /^> ?/gm, "" ),
old_tree = this.tree,
processedBlock = this.toTree( input, [ "blockquote" ] ),
attr = extract_attr( processedBlock );
// If any link references were found get rid of them
if ( attr && attr.references ) {
delete attr.references;
// And then remove the attribute object if it's empty
if ( isEmpty( attr ) ) {
processedBlock.splice( 1, 1 );
}
}
jsonml.push( processedBlock );
return jsonml;
},
referenceDefn: function referenceDefn( block, next) {
var re = /^\s*\[(.*?)\]:\s*(\S+)(?:\s+(?:(['"])(.*?)\3|\((.*?)\)))?\n?/;
// interesting matches are [ , ref_id, url, , title, title ]
if ( !block.match(re) )
return undefined;
// make an attribute node if it doesn't exist
if ( !extract_attr( this.tree ) ) {
this.tree.splice( 1, 0, {} );
}
var attrs = extract_attr( this.tree );
// make a references hash if it doesn't exist
if ( attrs.references === undefined ) {
attrs.references = {};
}
var b = this.loop_re_over_block(re, block, function( m ) {
if ( m[2] && m[2][0] == "<" && m[2][m[2].length-1] == ">" )
m[2] = m[2].substring( 1, m[2].length - 1 );
var ref = attrs.references[ m[1].toLowerCase() ] = {
href: m[2]
};
if ( m[4] !== undefined )
ref.title = m[4];
else if ( m[5] !== undefined )
ref.title = m[5];
} );
if ( b.length )
next.unshift( mk_block( b, block.trailing ) );
return [];
},
para: function para( block, next ) {
// everything's a para!
return [ ["para"].concat( this.processInline( block ) ) ];
}
}
};
Markdown.dialects.Gruber.inline = {
__oneElement__: function oneElement( text, patterns_or_re, previous_nodes ) {
var m,
res,
lastIndex = 0;
patterns_or_re = patterns_or_re || this.dialect.inline.__patterns__;
var re = new RegExp( "([\\s\\S]*?)(" + (patterns_or_re.source || patterns_or_re) + ")" );
m = re.exec( text );
if (!m) {
// Just boring text
return [ text.length, text ];
}
else if ( m[1] ) {
// Some un-interesting text matched. Return that first
return [ m[1].length, m[1] ];
}
var res;
if ( m[2] in this.dialect.inline ) {
res = this.dialect.inline[ m[2] ].call(
this,
text.substr( m.index ), m, previous_nodes || [] );
}
// Default for now to make dev easier. just slurp special and output it.
res = res || [ m[2].length, m[2] ];
return res;
},
__call__: function inline( text, patterns ) {
var out = [],
res;
function add(x) {
//D:self.debug(" adding output", uneval(x));
if ( typeof x == "string" && typeof out[out.length-1] == "string" )
out[ out.length-1 ] += x;
else
out.push(x);
}
while ( text.length > 0 ) {
res = this.dialect.inline.__oneElement__.call(this, text, patterns, out );
text = text.substr( res.shift() );
forEach(res, add )
}
return out;
},
// These characters are intersting elsewhere, so have rules for them so that
// chunks of plain text blocks don't include them
"]": function () {},
"}": function () {},
__escape__ : /^\\[\\`\*_{}\[\]()#\+.!\-]/,
"\\": function escaped( text ) {
// [ length of input processed, node/children to add... ]
// Only esacape: \ ` * _ { } [ ] ( ) # * + - . !
if ( this.dialect.inline.__escape__.exec( text ) )
return [ 2, text.charAt( 1 ) ];
else
// Not an esacpe
return [ 1, "\\" ];
},
"![": function image( text ) {
// Unlike images, alt text is plain text only. no other elements are
// allowed in there
// ![Alt text](/path/to/img.jpg "Optional title")
// 1 2 3 4 <--- captures
var m = text.match( /^!\[(.*?)\][ \t]*\([ \t]*([^")]*?)(?:[ \t]+(["'])(.*?)\3)?[ \t]*\)/ );
if ( m ) {
if ( m[2] && m[2][0] == "<" && m[2][m[2].length-1] == ">" )
m[2] = m[2].substring( 1, m[2].length - 1 );
m[2] = this.dialect.inline.__call__.call( this, m[2], /\\/ )[0];
var attrs = { alt: m[1], href: m[2] || "" };
if ( m[4] !== undefined)
attrs.title = m[4];
return [ m[0].length, [ "img", attrs ] ];
}
// ![Alt text][id]
m = text.match( /^!\[(.*?)\][ \t]*\[(.*?)\]/ );
if ( m ) {
// We can't check if the reference is known here as it likely wont be
// found till after. Check it in md tree->hmtl tree conversion
return [ m[0].length, [ "img_ref", { alt: m[1], ref: m[2].toLowerCase(), original: m[0] } ] ];
}
// Just consume the '!['
return [ 2, "![" ];
},
"[": function link( text ) {
var orig = String(text);
// Inline content is possible inside `link text`
var res = Markdown.DialectHelpers.inline_until_char.call( this, text.substr(1), "]" );
// No closing ']' found. Just consume the [
if ( !res ) return [ 1, "[" ];
var consumed = 1 + res[ 0 ],
children = res[ 1 ],
link,
attrs;
// At this point the first [...] has been parsed. See what follows to find
// out which kind of link we are (reference or direct url)
text = text.substr( consumed );
// [link text](/path/to/img.jpg "Optional title")
// 1 2 3 <--- captures
// This will capture up to the last paren in the block. We then pull
// back based on if there a matching ones in the url
// ([here](/url/(test))
// The parens have to be balanced
var m = text.match( /^\s*\([ \t]*([^"']*)(?:[ \t]+(["'])(.*?)\2)?[ \t]*\)/ );
if ( m ) {
var url = m[1];
consumed += m[0].length;
if ( url && url[0] == "<" && url[url.length-1] == ">" )
url = url.substring( 1, url.length - 1 );
// If there is a title we don't have to worry about parens in the url
if ( !m[3] ) {
var open_parens = 1; // One open that isn't in the capture
for ( var len = 0; len < url.length; len++ ) {
switch ( url[len] ) {
case "(":
open_parens++;
break;
case ")":
if ( --open_parens == 0) {
consumed -= url.length - len;
url = url.substring(0, len);
}
break;
}
}
}
// Process escapes only
url = this.dialect.inline.__call__.call( this, url, /\\/ )[0];
attrs = { href: url || "" };
if ( m[3] !== undefined)
attrs.title = m[3];
link = [ "link", attrs ].concat( children );
return [ consumed, link ];
}
// [Alt text][id]
// [Alt text] [id]
m = text.match( /^\s*\[(.*?)\]/ );
if ( m ) {
consumed += m[ 0 ].length;
// [links][] uses links as its reference
attrs = { ref: ( m[ 1 ] || String(children) ).toLowerCase(), original: orig.substr( 0, consumed ) };
link = [ "link_ref", attrs ].concat( children );
// We can't check if the reference is known here as it likely wont be
// found till after. Check it in md tree->hmtl tree conversion.
// Store the original so that conversion can revert if the ref isn't found.
return [ consumed, link ];
}
// [id]
// Only if id is plain (no formatting.)
if ( children.length == 1 && typeof children[0] == "string" ) {
attrs = { ref: children[0].toLowerCase(), original: orig.substr( 0, consumed ) };
link = [ "link_ref", attrs, children[0] ];
return [ consumed, link ];
}
// Just consume the "["
return [ 1, "[" ];
},
"<": function autoLink( text ) {
var m;
if ( ( m = text.match( /^<(?:((https?|ftp|mailto):[^>]+)|(.*?@.*?\.[a-zA-Z]+))>/ ) ) != null ) {
if ( m[3] ) {
return [ m[0].length, [ "link", { href: "mailto:" + m[3] }, m[3] ] ];
}
else if ( m[2] == "mailto" ) {
return [ m[0].length, [ "link", { href: m[1] }, m[1].substr("mailto:".length ) ] ];
}
else
return [ m[0].length, [ "link", { href: m[1] }, m[1] ] ];
}
return [ 1, "<" ];
},
"`": function inlineCode( text ) {
// Inline code block. as many backticks as you like to start it
// Always skip over the opening ticks.
var m = text.match( /(`+)(([\s\S]*?)\1)/ );
if ( m && m[2] )
return [ m[1].length + m[2].length, [ "inlinecode", m[3] ] ];
else {
// TODO: No matching end code found - warn!
return [ 1, "`" ];
}
},
" \n": function lineBreak( text ) {
return [ 3, [ "linebreak" ] ];
}
};
// Meta Helper/generator method for em and strong handling
function strong_em( tag, md ) {
var state_slot = tag + "_state",
other_slot = tag == "strong" ? "em_state" : "strong_state";
function CloseTag(len) {
this.len_after = len;
this.name = "close_" + md;
}
return function ( text, orig_match ) {
if ( this[state_slot][0] == md ) {
// Most recent em is of this type
//D:this.debug("closing", md);
this[state_slot].shift();
// "Consume" everything to go back to the recrusion in the else-block below
return[ text.length, new CloseTag(text.length-md.length) ];
}
else {
// Store a clone of the em/strong states
var other = this[other_slot].slice(),
state = this[state_slot].slice();
this[state_slot].unshift(md);
//D:this.debug_indent += " ";
// Recurse
var res = this.processInline( text.substr( md.length ) );
//D:this.debug_indent = this.debug_indent.substr(2);
var last = res[res.length - 1];
//D:this.debug("processInline from", tag + ": ", uneval( res ) );
var check = this[state_slot].shift();
if ( last instanceof CloseTag ) {
res.pop();
// We matched! Huzzah.
var consumed = text.length - last.len_after;
return [ consumed, [ tag ].concat(res) ];
}
else {
// Restore the state of the other kind. We might have mistakenly closed it.
this[other_slot] = other;
this[state_slot] = state;
// We can't reuse the processed result as it could have wrong parsing contexts in it.
return [ md.length, md ];
}
}
}; // End returned function
}
Markdown.dialects.Gruber.inline["**"] = strong_em("strong", "**");
Markdown.dialects.Gruber.inline["__"] = strong_em("strong", "__");
Markdown.dialects.Gruber.inline["*"] = strong_em("em", "*");
Markdown.dialects.Gruber.inline["_"] = strong_em("em", "_");
// Build default order from insertion order.
Markdown.buildBlockOrder = function(d) {
var ord = [];
for ( var i in d ) {
if ( i == "__order__" || i == "__call__" ) continue;
ord.push( i );
}
d.__order__ = ord;
};
// Build patterns for inline matcher
Markdown.buildInlinePatterns = function(d) {
var patterns = [];
for ( var i in d ) {
// __foo__ is reserved and not a pattern
if ( i.match( /^__.*__$/) ) continue;
var l = i.replace( /([\\.*+?|()\[\]{}])/g, "\\$1" )
.replace( /\n/, "\\n" );
patterns.push( i.length == 1 ? l : "(?:" + l + ")" );
}
patterns = patterns.join("|");
d.__patterns__ = patterns;
//print("patterns:", uneval( patterns ) );
var fn = d.__call__;
d.__call__ = function(text, pattern) {
if ( pattern != undefined ) {
return fn.call(this, text, pattern);
}
else
{
return fn.call(this, text, patterns);
}
};
};
Markdown.DialectHelpers = {};
Markdown.DialectHelpers.inline_until_char = function( text, want ) {
var consumed = 0,
nodes = [];
while ( true ) {
if ( text.charAt( consumed ) == want ) {
// Found the character we were looking for
consumed++;
return [ consumed, nodes ];
}
if ( consumed >= text.length ) {
// No closing char found. Abort.
return null;
}
var res = this.dialect.inline.__oneElement__.call(this, text.substr( consumed ) );
consumed += res[ 0 ];
// Add any returned nodes.
nodes.push.apply( nodes, res.slice( 1 ) );
}
}
// Helper function to make sub-classing a dialect easier
Markdown.subclassDialect = function( d ) {
function Block() {}
Block.prototype = d.block;
function Inline() {}
Inline.prototype = d.inline;
return { block: new Block(), inline: new Inline() };
};
Markdown.buildBlockOrder ( Markdown.dialects.Gruber.block );
Markdown.buildInlinePatterns( Markdown.dialects.Gruber.inline );
Markdown.dialects.Maruku = Markdown.subclassDialect( Markdown.dialects.Gruber );
Markdown.dialects.Maruku.processMetaHash = function processMetaHash( meta_string ) {
var meta = split_meta_hash( meta_string ),
attr = {};
for ( var i = 0; i < meta.length; ++i ) {
// id: #foo
if ( /^#/.test( meta[ i ] ) ) {
attr.id = meta[ i ].substring( 1 );
}
// class: .foo
else if ( /^\./.test( meta[ i ] ) ) {
// if class already exists, append the new one
if ( attr["class"] ) {
attr["class"] = attr["class"] + meta[ i ].replace( /./, " " );
}
else {
attr["class"] = meta[ i ].substring( 1 );
}
}
// attribute: foo=bar
else if ( /\=/.test( meta[ i ] ) ) {
var s = meta[ i ].split( /\=/ );
attr[ s[ 0 ] ] = s[ 1 ];
}
}
return attr;
}
function split_meta_hash( meta_string ) {
var meta = meta_string.split( "" ),
parts = [ "" ],
in_quotes = false;
while ( meta.length ) {
var letter = meta.shift();
switch ( letter ) {
case " " :
// if we're in a quoted section, keep it
if ( in_quotes ) {
parts[ parts.length - 1 ] += letter;
}
// otherwise make a new part
else {
parts.push( "" );
}
break;
case "'" :
case '"' :
// reverse the quotes and move straight on
in_quotes = !in_quotes;
break;
case "\\" :
// shift off the next letter to be used straight away.
// it was escaped so we'll keep it whatever it is
letter = meta.shift();
default :
parts[ parts.length - 1 ] += letter;
break;
}
}
return parts;
}
Markdown.dialects.Maruku.block.document_meta = function document_meta( block, next ) {
// we're only interested in the first block
if ( block.lineNumber > 1 ) return undefined;
// document_meta blocks consist of one or more lines of `Key: Value\n`
if ( ! block.match( /^(?:\w+:.*\n)*\w+:.*$/ ) ) return undefined;
// make an attribute node if it doesn't exist
if ( !extract_attr( this.tree ) ) {
this.tree.splice( 1, 0, {} );
}
var pairs = block.split( /\n/ );
for ( p in pairs ) {
var m = pairs[ p ].match( /(\w+):\s*(.*)$/ ),
key = m[ 1 ].toLowerCase(),
value = m[ 2 ];
this.tree[ 1 ][ key ] = value;
}
// document_meta produces no content!
return [];
};
Markdown.dialects.Maruku.block.block_meta = function block_meta( block, next ) {
// check if the last line of the block is an meta hash
var m = block.match( /(^|\n) {0,3}\{:\s*((?:\\\}|[^\}])*)\s*\}$/ );
if ( !m ) return undefined;
// process the meta hash
var attr = this.dialect.processMetaHash( m[ 2 ] );
var hash;
// if we matched ^ then we need to apply meta to the previous block
if ( m[ 1 ] === "" ) {
var node = this.tree[ this.tree.length - 1 ];
hash = extract_attr( node );
// if the node is a string (rather than JsonML), bail
if ( typeof node === "string" ) return undefined;
// create the attribute hash if it doesn't exist
if ( !hash ) {
hash = {};
node.splice( 1, 0, hash );
}
// add the attributes in
for ( a in attr ) {
hash[ a ] = attr[ a ];
}
// return nothing so the meta hash is removed
return [];
}
// pull the meta hash off the block and process what's left
var b = block.replace( /\n.*$/, "" ),
result = this.processBlock( b, [] );
// get or make the attributes hash
hash = extract_attr( result[ 0 ] );
if ( !hash ) {
hash = {};
result[ 0 ].splice( 1, 0, hash );
}
// attach the attributes to the block
for ( a in attr ) {
hash[ a ] = attr[ a ];
}
return result;
};
Markdown.dialects.Maruku.block.definition_list = function definition_list( block, next ) {
// one or more terms followed by one or more definitions, in a single block
var tight = /^((?:[^\s:].*\n)+):\s+([\s\S]+)$/,
list = [ "dl" ],
i, m;
// see if we're dealing with a tight or loose block
if ( ( m = block.match( tight ) ) ) {
// pull subsequent tight DL blocks out of `next`
var blocks = [ block ];
while ( next.length && tight.exec( next[ 0 ] ) ) {
blocks.push( next.shift() );
}
for ( var b = 0; b < blocks.length; ++b ) {
var m = blocks[ b ].match( tight ),
terms = m[ 1 ].replace( /\n$/, "" ).split( /\n/ ),
defns = m[ 2 ].split( /\n:\s+/ );
// print( uneval( m ) );
for ( i = 0; i < terms.length; ++i ) {
list.push( [ "dt", terms[ i ] ] );
}
for ( i = 0; i < defns.length; ++i ) {
// run inline processing over the definition
list.push( [ "dd" ].concat( this.processInline( defns[ i ].replace( /(\n)\s+/, "$1" ) ) ) );
}
}
}
else {
return undefined;
}
return [ list ];
};
// splits on unescaped instances of @ch. If @ch is not a character the result
// can be unpredictable
Markdown.dialects.Maruku.block.table = function table (block, next) {
var _split_on_unescaped = function(s, ch) {
ch = ch || '\\s';
if (ch.match(/^[\\|\[\]{}?*.+^$]$/)) { ch = '\\' + ch; }
var res = [ ],
r = new RegExp('^((?:\\\\.|[^\\\\' + ch + '])*)' + ch + '(.*)'),
m;
while(m = s.match(r)) {
res.push(m[1]);
s = m[2];
}
res.push(s);
return res;
}
var leading_pipe = /^ {0,3}\|(.+)\n {0,3}\|\s*([\-:]+[\-| :]*)\n((?:\s*\|.*(?:\n|$))*)(?=\n|$)/,
// find at least an unescaped pipe in each line
no_leading_pipe = /^ {0,3}(\S(?:\\.|[^\\|])*\|.*)\n {0,3}([\-:]+\s*\|[\-| :]*)\n((?:(?:\\.|[^\\|])*\|.*(?:\n|$))*)(?=\n|$)/,
i, m;
if (m = block.match(leading_pipe)) {
// remove leading pipes in contents
// (header and horizontal rule already have the leading pipe left out)
m[3] = m[3].replace(/^\s*\|/gm, '');
} else if (! ( m = block.match(no_leading_pipe))) {
return undefined;
}
var table = [ "table", [ "thead", [ "tr" ] ], [ "tbody" ] ];
// remove trailing pipes, then split on pipes
// (no escaped pipes are allowed in horizontal rule)
m[2] = m[2].replace(/\|\s*$/, '').split('|');
// process alignment
var html_attrs = [ ];
forEach (m[2], function (s) {
if (s.match(/^\s*-+:\s*$/)) html_attrs.push({align: "right"});
else if (s.match(/^\s*:-+\s*$/)) html_attrs.push({align: "left"});
else if (s.match(/^\s*:-+:\s*$/)) html_attrs.push({align: "center"});
else html_attrs.push({});
});
// now for the header, avoid escaped pipes
m[1] = _split_on_unescaped(m[1].replace(/\|\s*$/, ''), '|');
for (i = 0; i < m[1].length; i++) {
table[1][1].push(['th', html_attrs[i] || {}].concat(
this.processInline(m[1][i].trim())));
}
// now for body contents
forEach (m[3].replace(/\|\s*$/mg, '').split('\n'), function (row) {
var html_row = ['tr'];
row = _split_on_unescaped(row, '|');
for (i = 0; i < row.length; i++) {
html_row.push(['td', html_attrs[i] || {}].concat(this.processInline(row[i].trim())));
}
table[2].push(html_row);
}, this);
return [table];
}
Markdown.dialects.Maruku.inline[ "{:" ] = function inline_meta( text, matches, out ) {
if ( !out.length ) {
return [ 2, "{:" ];
}
// get the preceeding element
var before = out[ out.length - 1 ];
if ( typeof before === "string" ) {
return [ 2, "{:" ];
}
// match a meta hash
var m = text.match( /^\{:\s*((?:\\\}|[^\}])*)\s*\}/ );
// no match, false alarm
if ( !m ) {
return [ 2, "{:" ];
}
// attach the attributes to the preceeding element
var meta = this.dialect.processMetaHash( m[ 1 ] ),
attr = extract_attr( before );
if ( !attr ) {
attr = {};
before.splice( 1, 0, attr );
}
for ( var k in meta ) {
attr[ k ] = meta[ k ];
}
// cut out the string and replace it with nothing
return [ m[ 0 ].length, "" ];
};
Markdown.dialects.Maruku.inline.__escape__ = /^\\[\\`\*_{}\[\]()#\+.!\-|:]/;
Markdown.buildBlockOrder ( Markdown.dialects.Maruku.block );
Markdown.buildInlinePatterns( Markdown.dialects.Maruku.inline );
var isArray = Array.isArray || function(obj) {
return Object.prototype.toString.call(obj) == "[object Array]";
};
var forEach;
// Don't mess with Array.prototype. Its not friendly
if ( Array.prototype.forEach ) {
forEach = function( arr, cb, thisp ) {
return arr.forEach( cb, thisp );
};
}
else {
forEach = function(arr, cb, thisp) {
for (var i = 0; i < arr.length; i++) {
cb.call(thisp || arr, arr[i], i, arr);
}
}
}
var isEmpty = function( obj ) {
for ( var key in obj ) {
if ( hasOwnProperty.call( obj, key ) ) {
return false;
}
}
return true;
}
function extract_attr( jsonml ) {
return isArray(jsonml)
&& jsonml.length > 1
&& typeof jsonml[ 1 ] === "object"
&& !( isArray(jsonml[ 1 ]) )
? jsonml[ 1 ]
: undefined;
}
/**
* renderJsonML( jsonml[, options] ) -> String
* - jsonml (Array): JsonML array to render to XML
* - options (Object): options
*
* Converts the given JsonML into well-formed XML.
*
* The options currently understood are:
*
* - root (Boolean): wether or not the root node should be included in the
* output, or just its children. The default `false` is to not include the
* root itself.
*/
expose.renderJsonML = function( jsonml, options ) {
options = options || {};
// include the root element in the rendered output?
options.root = options.root || false;
var content = [];
if ( options.root ) {
content.push( render_tree( jsonml ) );
}
else {
jsonml.shift(); // get rid of the tag
if ( jsonml.length && typeof jsonml[ 0 ] === "object" && !( jsonml[ 0 ] instanceof Array ) ) {
jsonml.shift(); // get rid of the attributes
}
while ( jsonml.length ) {
content.push( render_tree( jsonml.shift() ) );
}
}
return content.join( "\n\n" );
};
function escapeHTML( text ) {
return text.replace( /&/g, "&amp;" )
.replace( /</g, "&lt;" )
.replace( />/g, "&gt;" )
.replace( /"/g, "&quot;" )
.replace( /'/g, "&#39;" );
}
function render_tree( jsonml ) {
// basic case
if ( typeof jsonml === "string" ) {
return escapeHTML( jsonml );
}
var tag = jsonml.shift(),
attributes = {},
content = [];
if ( jsonml.length && typeof jsonml[ 0 ] === "object" && !( jsonml[ 0 ] instanceof Array ) ) {
attributes = jsonml.shift();
}
while ( jsonml.length ) {
content.push( render_tree( jsonml.shift() ) );
}
var tag_attrs = "";
for ( var a in attributes ) {
tag_attrs += " " + a + '="' + escapeHTML( attributes[ a ] ) + '"';
}
// be careful about adding whitespace here for inline elements
if ( tag == "img" || tag == "br" || tag == "hr" ) {
return "<"+ tag + tag_attrs + "/>";
}
else {
return "<"+ tag + tag_attrs + ">" + content.join( "" ) + "</" + tag + ">";
}
}
function convert_tree_to_html( tree, references, options ) {
var i;
options = options || {};
// shallow clone
var jsonml = tree.slice( 0 );
if ( typeof options.preprocessTreeNode === "function" ) {
jsonml = options.preprocessTreeNode(jsonml, references);
}
// Clone attributes if they exist
var attrs = extract_attr( jsonml );
if ( attrs ) {
jsonml[ 1 ] = {};
for ( i in attrs ) {
jsonml[ 1 ][ i ] = attrs[ i ];
}
attrs = jsonml[ 1 ];
}
// basic case
if ( typeof jsonml === "string" ) {
return jsonml;
}
// convert this node
switch ( jsonml[ 0 ] ) {
case "header":
jsonml[ 0 ] = "h" + jsonml[ 1 ].level;
delete jsonml[ 1 ].level;
break;
case "bulletlist":
jsonml[ 0 ] = "ul";
break;
case "numberlist":
jsonml[ 0 ] = "ol";
break;
case "listitem":
jsonml[ 0 ] = "li";
break;
case "para":
jsonml[ 0 ] = "p";
break;
case "markdown":
jsonml[ 0 ] = "html";
if ( attrs ) delete attrs.references;
break;
case "code_block":
jsonml[ 0 ] = "pre";
i = attrs ? 2 : 1;
var code = [ "code" ];
code.push.apply( code, jsonml.splice( i, jsonml.length - i ) );
jsonml[ i ] = code;
break;
case "inlinecode":
jsonml[ 0 ] = "code";
break;
case "img":
jsonml[ 1 ].src = jsonml[ 1 ].href;
delete jsonml[ 1 ].href;
break;
case "linebreak":
jsonml[ 0 ] = "br";
break;
case "link":
jsonml[ 0 ] = "a";
break;
case "link_ref":
jsonml[ 0 ] = "a";
// grab this ref and clean up the attribute node
var ref = references[ attrs.ref ];
// if the reference exists, make the link
if ( ref ) {
delete attrs.ref;
// add in the href and title, if present
attrs.href = ref.href;
if ( ref.title ) {
attrs.title = ref.title;
}
// get rid of the unneeded original text
delete attrs.original;
}
// the reference doesn't exist, so revert to plain text
else {
return attrs.original;
}
break;
case "img_ref":
jsonml[ 0 ] = "img";
// grab this ref and clean up the attribute node
var ref = references[ attrs.ref ];
// if the reference exists, make the link
if ( ref ) {
delete attrs.ref;
// add in the href and title, if present
attrs.src = ref.href;
if ( ref.title ) {
attrs.title = ref.title;
}
// get rid of the unneeded original text
delete attrs.original;
}
// the reference doesn't exist, so revert to plain text
else {
return attrs.original;
}
break;
}
// convert all the children
i = 1;
// deal with the attribute node, if it exists
if ( attrs ) {
// if there are keys, skip over it
for ( var key in jsonml[ 1 ] ) {
i = 2;
break;
}
// if there aren't, remove it
if ( i === 1 ) {
jsonml.splice( i, 1 );
}
}
for ( ; i < jsonml.length; ++i ) {
jsonml[ i ] = convert_tree_to_html( jsonml[ i ], references, options );
}
return jsonml;
}
// merges adjacent text nodes into a single node
function merge_text_nodes( jsonml ) {
// skip the tag name and attribute hash
var i = extract_attr( jsonml ) ? 2 : 1;
while ( i < jsonml.length ) {
// if it's a string check the next item too
if ( typeof jsonml[ i ] === "string" ) {
if ( i + 1 < jsonml.length && typeof jsonml[ i + 1 ] === "string" ) {
// merge the second string into the first and remove it
jsonml[ i ] += jsonml.splice( i + 1, 1 )[ 0 ];
}
else {
++i;
}
}
// if it's not a string recurse
else {
merge_text_nodes( jsonml[ i ] );
++i;
}
}
}
} )( (function() {
if ( typeof exports === "undefined" ) {
window.markdown = {};
return window.markdown;
}
else {
return exports;
}
} )() );
;
tortoise_require=(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);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({"4HJaAd":[function(require,module,exports){
(function (global){
/**
* @license
* Lo-Dash 2.4.1 <http://lodash.com/>
* Copyright 2012-2013 The Dojo Foundation <http://dojofoundation.org/>
* Based on Underscore.js 1.5.2 <http://underscorejs.org/LICENSE>
* Copyright 2009-2013 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
* Available under MIT license <http://lodash.com/license>
*/
;(function() {
/** Used as a safe reference for `undefined` in pre ES5 environments */
var undefined;
/** Used to pool arrays and objects used internally */
var arrayPool = [],
objectPool = [];
/** Used to generate unique IDs */
var idCounter = 0;
/** Used internally to indicate various things */
var indicatorObject = {};
/** Used to prefix keys to avoid issues with `__proto__` and properties on `Object.prototype` */
var keyPrefix = +new Date + '';
/** Used as the size when optimizations are enabled for large arrays */
var largeArraySize = 75;
/** Used as the max size of the `arrayPool` and `objectPool` */
var maxPoolSize = 40;
/** Used to detect and test whitespace */
var whitespace = (
// whitespace
' \t\x0B\f\xA0\ufeff' +
// line terminators
'\n\r\u2028\u2029' +
// unicode category "Zs" space separators
'\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000'
);
/** Used to match empty string literals in compiled template source */
var reEmptyStringLeading = /\b__p \+= '';/g,
reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
/**
* Used to match ES6 template delimiters
* http://people.mozilla.org/~jorendorff/es6-draft.html#sec-literals-string-literals
*/
var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
/** Used to match regexp flags from their coerced string values */
var reFlags = /\w*$/;
/** Used to detected named functions */
var reFuncName = /^\s*function[ \n\r\t]+\w/;
/** Used to match "interpolate" template delimiters */
var reInterpolate = /<%=([\s\S]+?)%>/g;
/** Used to match leading whitespace and zeros to be removed */
var reLeadingSpacesAndZeros = RegExp('^[' + whitespace + ']*0+(?=.$)');
/** Used to ensure capturing order of template delimiters */
var reNoMatch = /($^)/;
/** Used to detect functions containing a `this` reference */
var reThis = /\bthis\b/;
/** Used to match unescaped characters in compiled string literals */
var reUnescapedString = /['\n\r\t\u2028\u2029\\]/g;
/** Used to assign default `context` object properties */
var contextProps = [
'Array', 'Boolean', 'Date', 'Error', 'Function', 'Math', 'Number', 'Object',
'RegExp', 'String', '_', 'attachEvent', 'clearTimeout', 'isFinite', 'isNaN',
'parseInt', 'setTimeout'
];
/** Used to fix the JScript [[DontEnum]] bug */
var shadowedProps = [
'constructor', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable',
'toLocaleString', 'toString', 'valueOf'
];
/** Used to make template sourceURLs easier to identify */
var templateCounter = 0;
/** `Object#toString` result shortcuts */
var argsClass = '[object Arguments]',
arrayClass = '[object Array]',
boolClass = '[object Boolean]',
dateClass = '[object Date]',
errorClass = '[object Error]',
funcClass = '[object Function]',
numberClass = '[object Number]',
objectClass = '[object Object]',
regexpClass = '[object RegExp]',
stringClass = '[object String]';
/** Used to identify object classifications that `_.clone` supports */
var cloneableClasses = {};
cloneableClasses[funcClass] = false;
cloneableClasses[argsClass] = cloneableClasses[arrayClass] =
cloneableClasses[boolClass] = cloneableClasses[dateClass] =
cloneableClasses[numberClass] = cloneableClasses[objectClass] =
cloneableClasses[regexpClass] = cloneableClasses[stringClass] = true;
/** Used as an internal `_.debounce` options object */
var debounceOptions = {
'leading': false,
'maxWait': 0,
'trailing': false
};
/** Used as the property descriptor for `__bindData__` */
var descriptor = {
'configurable': false,
'enumerable': false,
'value': null,
'writable': false
};
/** Used as the data object for `iteratorTemplate` */
var iteratorData = {
'args': '',
'array': null,
'bottom': '',
'firstArg': '',
'init': '',
'keys': null,
'loop': '',
'shadowedProps': null,
'support': null,
'top': '',
'useHas': false
};
/** Used to determine if values are of the language type Object */
var objectTypes = {
'boolean': false,
'function': true,
'object': true,
'number': false,
'string': false,
'undefined': false
};
/** Used to escape characters for inclusion in compiled string literals */
var stringEscapes = {
'\\': '\\',
"'": "'",
'\n': 'n',
'\r': 'r',
'\t': 't',
'\u2028': 'u2028',
'\u2029': 'u2029'
};
/** Used as a reference to the global object */
var root = (objectTypes[typeof window] && window) || this;
/** Detect free variable `exports` */
var freeExports = objectTypes[typeof exports] && exports && !exports.nodeType && exports;
/** Detect free variable `module` */
var freeModule = objectTypes[typeof module] && module && !module.nodeType && module;
/** Detect the popular CommonJS extension `module.exports` */
var moduleExports = freeModule && freeModule.exports === freeExports && freeExports;
/** Detect free variable `global` from Node.js or Browserified code and use it as `root` */
var freeGlobal = objectTypes[typeof global] && global;
if (freeGlobal && (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal)) {
root = freeGlobal;
}
/*--------------------------------------------------------------------------*/
/**
* The base implementation of `_.indexOf` without support for binary searches
* or `fromIndex` constraints.
*
* @private
* @param {Array} array The array to search.
* @param {*} value The value to search for.
* @param {number} [fromIndex=0] The index to search from.
* @returns {number} Returns the index of the matched value or `-1`.
*/
function baseIndexOf(array, value, fromIndex) {
var index = (fromIndex || 0) - 1,
length = array ? array.length : 0;
while (++index < length) {
if (array[index] === value) {
return index;
}
}
return -1;
}
/**
* An implementation of `_.contains` for cache objects that mimics the return
* signature of `_.indexOf` by returning `0` if the value is found, else `-1`.
*
* @private
* @param {Object} cache The cache object to inspect.
* @param {*} value The value to search for.
* @returns {number} Returns `0` if `value` is found, else `-1`.
*/
function cacheIndexOf(cache, value) {
var type = typeof value;
cache = cache.cache;
if (type == 'boolean' || value == null) {
return cache[value] ? 0 : -1;
}
if (type != 'number' && type != 'string') {
type = 'object';
}
var key = type == 'number' ? value : keyPrefix + value;
cache = (cache = cache[type]) && cache[key];
return type == 'object'
? (cache && baseIndexOf(cache, value) > -1 ? 0 : -1)
: (cache ? 0 : -1);
}
/**
* Adds a given value to the corresponding cache object.
*
* @private
* @param {*} value The value to add to the cache.
*/
function cachePush(value) {
var cache = this.cache,
type = typeof value;
if (type == 'boolean' || value == null) {
cache[value] = true;
} else {
if (type != 'number' && type != 'string') {
type = 'object';
}
var key = type == 'number' ? value : keyPrefix + value,
typeCache = cache[type] || (cache[type] = {});
if (type == 'object') {
(typeCache[key] || (typeCache[key] = [])).push(value);
} else {
typeCache[key] = true;
}
}
}
/**
* Used by `_.max` and `_.min` as the default callback when a given
* collection is a string value.
*
* @private
* @param {string} value The character to inspect.
* @returns {number} Returns the code unit of given character.
*/
function charAtCallback(value) {
return value.charCodeAt(0);
}
/**
* Used by `sortBy` to compare transformed `collection` elements, stable sorting
* them in ascending order.
*
* @private
* @param {Object} a The object to compare to `b`.
* @param {Object} b The object to compare to `a`.
* @returns {number} Returns the sort order indicator of `1` or `-1`.
*/
function compareAscending(a, b) {
var ac = a.criteria,
bc = b.criteria,
index = -1,
length = ac.length;
while (++index < length) {
var value = ac[index],
other = bc[index];
if (value !== other) {
if (value > other || typeof value == 'undefined') {
return 1;
}
if (value < other || typeof other == 'undefined') {
return -1;
}
}
}
// Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
// that causes it, under certain circumstances, to return the same value for
// `a` and `b`. See https://github.com/jashkenas/underscore/pull/1247
//
// This also ensures a stable sort in V8 and other engines.
// See http://code.google.com/p/v8/issues/detail?id=90
return a.index - b.index;
}
/**
* Creates a cache object to optimize linear searches of large arrays.
*
* @private
* @param {Array} [array=[]] The array to search.
* @returns {null|Object} Returns the cache object or `null` if caching should not be used.
*/
function createCache(array) {
var index = -1,
length = array.length,
first = array[0],
mid = array[(length / 2) | 0],
last = array[length - 1];
if (first && typeof first == 'object' &&
mid && typeof mid == 'object' && last && typeof last == 'object') {
return false;
}
var cache = getObject();
cache['false'] = cache['null'] = cache['true'] = cache['undefined'] = false;
var result = getObject();
result.array = array;
result.cache = cache;
result.push = cachePush;
while (++index < length) {
result.push(array[index]);
}
return result;
}
/**
* Used by `template` to escape characters for inclusion in compiled
* string literals.
*
* @private
* @param {string} match The matched character to escape.
* @returns {string} Returns the escaped character.
*/
function escapeStringChar(match) {
return '\\' + stringEscapes[match];
}
/**
* Gets an array from the array pool or creates a new one if the pool is empty.
*
* @private
* @returns {Array} The array from the pool.
*/
function getArray() {
return arrayPool.pop() || [];
}
/**
* Gets an object from the object pool or creates a new one if the pool is empty.
*
* @private
* @returns {Object} The object from the pool.
*/
function getObject() {
return objectPool.pop() || {
'array': null,
'cache': null,
'criteria': null,
'false': false,
'index': 0,
'null': false,
'number': null,
'object': null,
'push': null,
'string': null,
'true': false,
'undefined': false,
'value': null
};
}
/**
* Checks if `value` is a DOM node in IE < 9.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if the `value` is a DOM node, else `false`.
*/
function isNode(value) {
// IE < 9 presents DOM nodes as `Object` objects except they have `toString`
// methods that are `typeof` "string" and still can coerce nodes to strings
return typeof value.toString != 'function' && typeof (value + '') == 'string';
}
/**
* Releases the given array back to the array pool.
*
* @private
* @param {Array} [array] The array to release.
*/
function releaseArray(array) {
array.length = 0;
if (arrayPool.length < maxPoolSize) {
arrayPool.push(array);
}
}
/**
* Releases the given object back to the object pool.
*
* @private
* @param {Object} [object] The object to release.
*/
function releaseObject(object) {
var cache = object.cache;
if (cache) {
releaseObject(cache);
}
object.array = object.cache = object.criteria = object.object = object.number = object.string = object.value = null;
if (objectPool.length < maxPoolSize) {
objectPool.push(object);
}
}
/**
* Slices the `collection` from the `start` index up to, but not including,
* the `end` index.
*
* Note: This function is used instead of `Array#slice` to support node lists
* in IE < 9 and to ensure dense arrays are returned.
*
* @private
* @param {Array|Object|string} collection The collection to slice.
* @param {number} start The start index.
* @param {number} end The end index.
* @returns {Array} Returns the new array.
*/
function slice(array, start, end) {
start || (start = 0);
if (typeof end == 'undefined') {
end = array ? array.length : 0;
}
var index = -1,
length = end - start || 0,
result = Array(length < 0 ? 0 : length);
while (++index < length) {
result[index] = array[start + index];
}
return result;
}
/*--------------------------------------------------------------------------*/
/**
* Create a new `lodash` function using the given context object.
*
* @static
* @memberOf _
* @category Utilities
* @param {Object} [context=root] The context object.
* @returns {Function} Returns the `lodash` function.
*/
function runInContext(context) {
// Avoid issues with some ES3 environments that attempt to use values, named
// after built-in constructors like `Object`, for the creation of literals.
// ES5 clears this up by stating that literals must use built-in constructors.
// See http://es5.github.io/#x11.1.5.
context = context ? _.defaults(root.Object(), context, _.pick(root, contextProps)) : root;
/** Native constructor references */
var Array = context.Array,
Boolean = context.Boolean,
Date = context.Date,
Error = context.Error,
Function = context.Function,
Math = context.Math,
Number = context.Number,
Object = context.Object,
RegExp = context.RegExp,
String = context.String,
TypeError = context.TypeError;
/**
* Used for `Array` method references.
*
* Normally `Array.prototype` would suffice, however, using an array literal
* avoids issues in Narwhal.
*/
var arrayRef = [];
/** Used for native method references */
var errorProto = Error.prototype,
objectProto = Object.prototype,
stringProto = String.prototype;
/** Used to restore the original `_` reference in `noConflict` */
var oldDash = context._;
/** Used to resolve the internal [[Class]] of values */
var toString = objectProto.toString;
/** Used to detect if a method is native */
var reNative = RegExp('^' +
String(toString)
.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
.replace(/toString| for [^\]]+/g, '.*?') + '$'
);
/** Native method shortcuts */
var ceil = Math.ceil,
clearTimeout = context.clearTimeout,
floor = Math.floor,
fnToString = Function.prototype.toString,
getPrototypeOf = isNative(getPrototypeOf = Object.getPrototypeOf) && getPrototypeOf,
hasOwnProperty = objectProto.hasOwnProperty,
push = arrayRef.push,
propertyIsEnumerable = objectProto.propertyIsEnumerable,
setTimeout = context.setTimeout,
splice = arrayRef.splice,
unshift = arrayRef.unshift;
/** Used to set meta data on functions */
var defineProperty = (function() {
// IE 8 only accepts DOM elements
try {
var o = {},
func = isNative(func = Object.defineProperty) && func,
result = func(o, o, o) && func;
} catch(e) { }
return result;
}());
/* Native method shortcuts for methods with the same name as other `lodash` methods */
var nativeCreate = isNative(nativeCreate = Object.create) && nativeCreate,
nativeIsArray = isNative(nativeIsArray = Array.isArray) && nativeIsArray,
nativeIsFinite = context.isFinite,
nativeIsNaN = context.isNaN,
nativeKeys = isNative(nativeKeys = Object.keys) && nativeKeys,
nativeMax = Math.max,
nativeMin = Math.min,
nativeParseInt = context.parseInt,
nativeRandom = Math.random;
/** Used to lookup a built-in constructor by [[Class]] */
var ctorByClass = {};
ctorByClass[arrayClass] = Array;
ctorByClass[boolClass] = Boolean;
ctorByClass[dateClass] = Date;
ctorByClass[funcClass] = Function;
ctorByClass[objectClass] = Object;
ctorByClass[numberClass] = Number;
ctorByClass[regexpClass] = RegExp;
ctorByClass[stringClass] = String;
/** Used to avoid iterating non-enumerable properties in IE < 9 */
var nonEnumProps = {};
nonEnumProps[arrayClass] = nonEnumProps[dateClass] = nonEnumProps[numberClass] = { 'constructor': true, 'toLocaleString': true, 'toString': true, 'valueOf': true };
nonEnumProps[boolClass] = nonEnumProps[stringClass] = { 'constructor': true, 'toString': true, 'valueOf': true };
nonEnumProps[errorClass] = nonEnumProps[funcClass] = nonEnumProps[regexpClass] = { 'constructor': true, 'toString': true };
nonEnumProps[objectClass] = { 'constructor': true };
(function() {
var length = shadowedProps.length;
while (length--) {
var key = shadowedProps[length];
for (var className in nonEnumProps) {
if (hasOwnProperty.call(nonEnumProps, className) && !hasOwnProperty.call(nonEnumProps[className], key)) {
nonEnumProps[className][key] = false;
}
}
}
}());
/*--------------------------------------------------------------------------*/
/**
* Creates a `lodash` object which wraps the given value to enable intuitive
* method chaining.
*
* In addition to Lo-Dash methods, wrappers also have the following `Array` methods:
* `concat`, `join`, `pop`, `push`, `reverse`, `shift`, `slice`, `sort`, `splice`,
* and `unshift`
*
* Chaining is supported in custom builds as long as the `value` method is
* implicitly or explicitly included in the build.
*
* The chainable wrapper functions are:
* `after`, `assign`, `bind`, `bindAll`, `bindKey`, `chain`, `compact`,
* `compose`, `concat`, `countBy`, `create`, `createCallback`, `curry`,
* `debounce`, `defaults`, `defer`, `delay`, `difference`, `filter`, `flatten`,
* `forEach`, `forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`,
* `functions`, `groupBy`, `indexBy`, `initial`, `intersection`, `invert`,
* `invoke`, `keys`, `map`, `max`, `memoize`, `merge`, `min`, `object`, `omit`,
* `once`, `pairs`, `partial`, `partialRight`, `pick`, `pluck`, `pull`, `push`,
* `range`, `reject`, `remove`, `rest`, `reverse`, `shuffle`, `slice`, `sort`,
* `sortBy`, `splice`, `tap`, `throttle`, `times`, `toArray`, `transform`,
* `union`, `uniq`, `unshift`, `unzip`, `values`, `where`, `without`, `wrap`,
* and `zip`
*
* The non-chainable wrapper functions are:
* `clone`, `cloneDeep`, `contains`, `escape`, `every`, `find`, `findIndex`,
* `findKey`, `findLast`, `findLastIndex`, `findLastKey`, `has`, `identity`,
* `indexOf`, `isArguments`, `isArray`, `isBoolean`, `isDate`, `isElement`,
* `isEmpty`, `isEqual`, `isFinite`, `isFunction`, `isNaN`, `isNull`, `isNumber`,
* `isObject`, `isPlainObject`, `isRegExp`, `isString`, `isUndefined`, `join`,
* `lastIndexOf`, `mixin`, `noConflict`, `parseInt`, `pop`, `random`, `reduce`,
* `reduceRight`, `result`, `shift`, `size`, `some`, `sortedIndex`, `runInContext`,
* `template`, `unescape`, `uniqueId`, and `value`
*
* The wrapper functions `first` and `last` return wrapped values when `n` is
* provided, otherwise they return unwrapped values.
*
* Explicit chaining can be enabled by using the `_.chain` method.
*
* @name _
* @constructor
* @category Chaining
* @param {*} value The value to wrap in a `lodash` instance.
* @returns {Object} Returns a `lodash` instance.
* @example
*
* var wrapped = _([1, 2, 3]);
*
* // returns an unwrapped value
* wrapped.reduce(function(sum, num) {
* return sum + num;
* });
* // => 6
*
* // returns a wrapped value
* var squares = wrapped.map(function(num) {
* return num * num;
* });
*
* _.isArray(squares);
* // => false
*
* _.isArray(squares.value());
* // => true
*/
function lodash(value) {
// don't wrap if already wrapped, even if wrapped by a different `lodash` constructor
return (value && typeof value == 'object' && !isArray(value) && hasOwnProperty.call(value, '__wrapped__'))
? value
: new lodashWrapper(value);
}
/**
* A fast path for creating `lodash` wrapper objects.
*
* @private
* @param {*} value The value to wrap in a `lodash` instance.
* @param {boolean} chainAll A flag to enable chaining for all methods
* @returns {Object} Returns a `lodash` instance.
*/
function lodashWrapper(value, chainAll) {
this.__chain__ = !!chainAll;
this.__wrapped__ = value;
}
// ensure `new lodashWrapper` is an instance of `lodash`
lodashWrapper.prototype = lodash.prototype;
/**
* An object used to flag environments features.
*
* @static
* @memberOf _
* @type Object
*/
var support = lodash.support = {};
(function() {
var ctor = function() { this.x = 1; },
object = { '0': 1, 'length': 1 },
props = [];
ctor.prototype = { 'valueOf': 1, 'y': 1 };
for (var key in new ctor) { props.push(key); }
for (key in arguments) { }
/**
* Detect if an `arguments` object's [[Class]] is resolvable (all but Firefox < 4, IE < 9).
*
* @memberOf _.support
* @type boolean
*/
support.argsClass = toString.call(arguments) == argsClass;
/**
* Detect if `arguments` objects are `Object` objects (all but Narwhal and Opera < 10.5).
*
* @memberOf _.support
* @type boolean
*/
support.argsObject = arguments.constructor == Object && !(arguments instanceof Array);
/**
* Detect if `name` or `message` properties of `Error.prototype` are
* enumerable by default. (IE < 9, Safari < 5.1)
*
* @memberOf _.support
* @type boolean
*/
support.enumErrorProps = propertyIsEnumerable.call(errorProto, 'message') || propertyIsEnumerable.call(errorProto, 'name');
/**
* Detect if `prototype` properties are enumerable by default.
*
* Firefox < 3.6, Opera > 9.50 - Opera < 11.60, and Safari < 5.1
* (if the prototype or a property on the prototype has been set)
* incorrectly sets a function's `prototype` property [[Enumerable]]
* value to `true`.
*
* @memberOf _.support
* @type boolean
*/
support.enumPrototypes = propertyIsEnumerable.call(ctor, 'prototype');
/**
* Detect if functions can be decompiled by `Function#toString`
* (all but PS3 and older Opera mobile browsers & avoided in Windows 8 apps).
*
* @memberOf _.support
* @type boolean
*/
support.funcDecomp = !isNative(context.WinRTError) && reThis.test(runInContext);
/**
* Detect if `Function#name` is supported (all but IE).
*
* @memberOf _.support
* @type boolean
*/
support.funcNames = typeof Function.name == 'string';
/**
* Detect if `arguments` object indexes are non-enumerable
* (Firefox < 4, IE < 9, PhantomJS, Safari < 5.1).
*
* @memberOf _.support
* @type boolean
*/
support.nonEnumArgs = key != 0;
/**
* Detect if properties shadowing those on `Object.prototype` are non-enumerable.
*
* In IE < 9 an objects own properties, shadowing non-enumerable ones, are
* made non-enumerable as well (a.k.a the JScript [[DontEnum]] bug).
*
* @memberOf _.support
* @type boolean
*/
support.nonEnumShadows = !/valueOf/.test(props);
/**
* Detect if own properties are iterated after inherited properties (all but IE < 9).
*
* @memberOf _.support
* @type boolean
*/
support.ownLast = props[0] != 'x';
/**
* Detect if `Array#shift` and `Array#splice` augment array-like objects correctly.
*
* Firefox < 10, IE compatibility mode, and IE < 9 have buggy Array `shift()`
* and `splice()` functions that fail to remove the last element, `value[0]`,
* of array-like objects even though the `length` property is set to `0`.
* The `shift()` method is buggy in IE 8 compatibility mode, while `splice()`
* is buggy regardless of mode in IE < 9 and buggy in compatibility mode in IE 9.
*
* @memberOf _.support
* @type boolean
*/
support.spliceObjects = (arrayRef.splice.call(object, 0, 1), !object[0]);
/**
* Detect lack of support for accessing string characters by index.
*
* IE < 8 can't access characters by index and IE 8 can only access
* characters by index on string literals.
*
* @memberOf _.support
* @type boolean
*/
support.unindexedChars = ('x'[0] + Object('x')[0]) != 'xx';
/**
* Detect if a DOM node's [[Class]] is resolvable (all but IE < 9)
* and that the JS engine errors when attempting to coerce an object to
* a string without a `toString` function.
*
* @memberOf _.support
* @type boolean
*/
try {
support.nodeClass = !(toString.call(document) == objectClass && !({ 'toString': 0 } + ''));
} catch(e) {
support.nodeClass = true;
}
}(1));
/**
* By default, the template delimiters used by Lo-Dash are similar to those in
* embedded Ruby (ERB). Change the following template settings to use alternative
* delimiters.
*
* @static
* @memberOf _
* @type Object
*/
lodash.templateSettings = {
/**
* Used to detect `data` property values to be HTML-escaped.
*
* @memberOf _.templateSettings
* @type RegExp
*/
'escape': /<%-([\s\S]+?)%>/g,
/**
* Used to detect code to be evaluated.
*
* @memberOf _.templateSettings
* @type RegExp
*/
'evaluate': /<%([\s\S]+?)%>/g,
/**
* Used to detect `data` property values to inject.
*
* @memberOf _.templateSettings
* @type RegExp
*/
'interpolate': reInterpolate,
/**
* Used to reference the data object in the template text.
*
* @memberOf _.templateSettings
* @type string
*/
'variable': '',
/**
* Used to import variables into the compiled template.
*
* @memberOf _.templateSettings
* @type Object
*/
'imports': {
/**
* A reference to the `lodash` function.
*
* @memberOf _.templateSettings.imports
* @type Function
*/
'_': lodash
}
};
/*--------------------------------------------------------------------------*/
/**
* The template used to create iterator functions.
*
* @private
* @param {Object} data The data object used to populate the text.
* @returns {string} Returns the interpolated text.
*/
var iteratorTemplate = template(
// the `iterable` may be reassigned by the `top` snippet
'var index, iterable = <%= firstArg %>, ' +
// assign the `result` variable an initial value
'result = <%= init %>;\n' +
// exit early if the first argument is falsey
'if (!iterable) return result;\n' +
// add code before the iteration branches
'<%= top %>;' +
// array-like iteration:
'<% if (array) { %>\n' +
'var length = iterable.length; index = -1;\n' +
'if (<%= array %>) {' +
// add support for accessing string characters by index if needed
' <% if (support.unindexedChars) { %>\n' +
' if (isString(iterable)) {\n' +
" iterable = iterable.split('')\n" +
' }' +
' <% } %>\n' +
// iterate over the array-like value
' while (++index < length) {\n' +
' <%= loop %>;\n' +
' }\n' +
'}\n' +
'else {' +
// object iteration:
// add support for iterating over `arguments` objects if needed
' <% } else if (support.nonEnumArgs) { %>\n' +
' var length = iterable.length; index = -1;\n' +
' if (length && isArguments(iterable)) {\n' +
' while (++index < length) {\n' +
" index += '';\n" +
' <%= loop %>;\n' +
' }\n' +
' } else {' +
' <% } %>' +
// avoid iterating over `prototype` properties in older Firefox, Opera, and Safari
' <% if (support.enumPrototypes) { %>\n' +
" var skipProto = typeof iterable == 'function';\n" +
' <% } %>' +
// avoid iterating over `Error.prototype` properties in older IE and Safari
' <% if (support.enumErrorProps) { %>\n' +
' var skipErrorProps = iterable === errorProto || iterable instanceof Error;\n' +
' <% } %>' +
// define conditions used in the loop
' <%' +
' var conditions = [];' +
' if (support.enumPrototypes) { conditions.push(\'!(skipProto && index == "prototype")\'); }' +
' if (support.enumErrorProps) { conditions.push(\'!(skipErrorProps && (index == "message" || index == "name"))\'); }' +
' %>' +
// iterate own properties using `Object.keys`
' <% if (useHas && keys) { %>\n' +
' var ownIndex = -1,\n' +
' ownProps = objectTypes[typeof iterable] && keys(iterable),\n' +
' length = ownProps ? ownProps.length : 0;\n\n' +
' while (++ownIndex < length) {\n' +
' index = ownProps[ownIndex];\n<%' +
" if (conditions.length) { %> if (<%= conditions.join(' && ') %>) {\n <% } %>" +
' <%= loop %>;' +
' <% if (conditions.length) { %>\n }<% } %>\n' +
' }' +
// else using a for-in loop
' <% } else { %>\n' +
' for (index in iterable) {\n<%' +
' if (useHas) { conditions.push("hasOwnProperty.call(iterable, index)"); }' +
" if (conditions.length) { %> if (<%= conditions.join(' && ') %>) {\n <% } %>" +
' <%= loop %>;' +
' <% if (conditions.length) { %>\n }<% } %>\n' +
' }' +
// Because IE < 9 can't set the `[[Enumerable]]` attribute of an
// existing property and the `constructor` property of a prototype
// defaults to non-enumerable, Lo-Dash skips the `constructor`
// property when it infers it's iterating over a `prototype` object.
' <% if (support.nonEnumShadows) { %>\n\n' +
' if (iterable !== objectProto) {\n' +
" var ctor = iterable.constructor,\n" +
' isProto = iterable === (ctor && ctor.prototype),\n' +
' className = iterable === stringProto ? stringClass : iterable === errorProto ? errorClass : toString.call(iterable),\n' +
' nonEnum = nonEnumProps[className];\n' +
' <% for (k = 0; k < 7; k++) { %>\n' +
" index = '<%= shadowedProps[k] %>';\n" +
' if ((!(isProto && nonEnum[index]) && hasOwnProperty.call(iterable, index))<%' +
' if (!useHas) { %> || (!nonEnum[index] && iterable[index] !== objectProto[index])<% }' +
' %>) {\n' +
' <%= loop %>;\n' +
' }' +
' <% } %>\n' +
' }' +
' <% } %>' +
' <% } %>' +
' <% if (array || support.nonEnumArgs) { %>\n}<% } %>\n' +
// add code to the bottom of the iteration function
'<%= bottom %>;\n' +
// finally, return the `result`
'return result'
);
/*--------------------------------------------------------------------------*/
/**
* The base implementation of `_.bind` that creates the bound function and
* sets its meta data.
*
* @private
* @param {Array} bindData The bind data array.
* @returns {Function} Returns the new bound function.
*/
function baseBind(bindData) {
var func = bindData[0],
partialArgs = bindData[2],
thisArg = bindData[4];
function bound() {
// `Function#bind` spec
// http://es5.github.io/#x15.3.4.5
if (partialArgs) {
// avoid `arguments` object deoptimizations by using `slice` instead
// of `Array.prototype.slice.call` and not assigning `arguments` to a
// variable as a ternary expression
var args = slice(partialArgs);
push.apply(args, arguments);
}
// mimic the constructor's `return` behavior
// http://es5.github.io/#x13.2.2
if (this instanceof bound) {
// ensure `new bound` is an instance of `func`
var thisBinding = baseCreate(func.prototype),
result = func.apply(thisBinding, args || arguments);
return isObject(result) ? result : thisBinding;
}
return func.apply(thisArg, args || arguments);
}
setBindData(bound, bindData);
return bound;
}
/**
* The base implementation of `_.clone` without argument juggling or support
* for `thisArg` binding.
*
* @private
* @param {*} value The value to clone.
* @param {boolean} [isDeep=false] Specify a deep clone.
* @param {Function} [callback] The function to customize cloning values.
* @param {Array} [stackA=[]] Tracks traversed source objects.
* @param {Array} [stackB=[]] Associates clones with source counterparts.
* @returns {*} Returns the cloned value.
*/
function baseClone(value, isDeep, callback, stackA, stackB) {
if (callback) {
var result = callback(value);
if (typeof result != 'undefined') {
return result;
}
}
// inspect [[Class]]
var isObj = isObject(value);
if (isObj) {
var className = toString.call(value);
if (!cloneableClasses[className] || (!support.nodeClass && isNode(value))) {
return value;
}
var ctor = ctorByClass[className];
switch (className) {
case boolClass:
case dateClass:
return new ctor(+value);
case numberClass:
case stringClass:
return new ctor(value);
case regexpClass:
result = ctor(value.source, reFlags.exec(value));
result.lastIndex = value.lastIndex;
return result;
}
} else {
return value;
}
var isArr = isArray(value);
if (isDeep) {
// check for circular references and return corresponding clone
var initedStack = !stackA;
stackA || (stackA = getArray());
stackB || (stackB = getArray());
var length = stackA.length;
while (length--) {
if (stackA[length] == value) {
return stackB[length];
}
}
result = isArr ? ctor(value.length) : {};
}
else {
result = isArr ? slice(value) : assign({}, value);
}
// add array properties assigned by `RegExp#exec`
if (isArr) {
if (hasOwnProperty.call(value, 'index')) {
result.index = value.index;
}
if (hasOwnProperty.call(value, 'input')) {
result.input = value.input;
}
}
// exit for shallow clone
if (!isDeep) {
return result;
}
// add the source value to the stack of traversed objects
// and associate it with its clone
stackA.push(value);
stackB.push(result);
// recursively populate clone (susceptible to call stack limits)
(isArr ? baseEach : forOwn)(value, function(objValue, key) {
result[key] = baseClone(objValue, isDeep, callback, stackA, stackB);
});
if (initedStack) {
releaseArray(stackA);
releaseArray(stackB);
}
return result;
}
/**
* The base implementation of `_.create` without support for assigning
* properties to the created object.
*
* @private
* @param {Object} prototype The object to inherit from.
* @returns {Object} Returns the new object.
*/
function baseCreate(prototype, properties) {
return isObject(prototype) ? nativeCreate(prototype) : {};
}
// fallback for browsers without `Object.create`
if (!nativeCreate) {
baseCreate = (function() {
function Object() {}
return function(prototype) {
if (isObject(prototype)) {
Object.prototype = prototype;
var result = new Object;
Object.prototype = null;
}
return result || context.Object();
};
}());
}
/**
* The base implementation of `_.createCallback` without support for creating
* "_.pluck" or "_.where" style callbacks.
*
* @private
* @param {*} [func=identity] The value to convert to a callback.
* @param {*} [thisArg] The `this` binding of the created callback.
* @param {number} [argCount] The number of arguments the callback accepts.
* @returns {Function} Returns a callback function.
*/
function baseCreateCallback(func, thisArg, argCount) {
if (typeof func != 'function') {
return identity;
}
// exit early for no `thisArg` or already bound by `Function#bind`
if (typeof thisArg == 'undefined' || !('prototype' in func)) {
return func;
}
var bindData = func.__bindData__;
if (typeof bindData == 'undefined') {
if (support.funcNames) {
bindData = !func.name;
}
bindData = bindData || !support.funcDecomp;
if (!bindData) {
var source = fnToString.call(func);
if (!support.funcNames) {
bindData = !reFuncName.test(source);
}
if (!bindData) {
// checks if `func` references the `this` keyword and stores the result
bindData = reThis.test(source);
setBindData(func, bindData);
}
}
}
// exit early if there are no `this` references or `func` is bound
if (bindData === false || (bindData !== true && bindData[1] & 1)) {
return func;
}
switch (argCount) {
case 1: return function(value) {
return func.call(thisArg, value);
};
case 2: return function(a, b) {
return func.call(thisArg, a, b);
};
case 3: return function(value, index, collection) {
return func.call(thisArg, value, index, collection);
};
case 4: return function(accumulator, value, index, collection) {
return func.call(thisArg, accumulator, value, index, collection);
};
}
return bind(func, thisArg);
}
/**
* The base implementation of `createWrapper` that creates the wrapper and
* sets its meta data.
*
* @private
* @param {Array} bindData The bind data array.
* @returns {Function} Returns the new function.
*/
function baseCreateWrapper(bindData) {
var func = bindData[0],
bitmask = bindData[1],
partialArgs = bindData[2],
partialRightArgs = bindData[3],
thisArg = bindData[4],
arity = bindData[5];
var isBind = bitmask & 1,
isBindKey = bitmask & 2,
isCurry = bitmask & 4,
isCurryBound = bitmask & 8,
key = func;
function bound() {
var thisBinding = isBind ? thisArg : this;
if (partialArgs) {
var args = slice(partialArgs);
push.apply(args, arguments);
}
if (partialRightArgs || isCurry) {
args || (args = slice(arguments));
if (partialRightArgs) {
push.apply(args, partialRightArgs);
}
if (isCurry && args.length < arity) {
bitmask |= 16 & ~32;
return baseCreateWrapper([func, (isCurryBound ? bitmask : bitmask & ~3), args, null, thisArg, arity]);
}
}
args || (args = arguments);
if (isBindKey) {
func = thisBinding[key];
}
if (this instanceof bound) {
thisBinding = baseCreate(func.prototype);
var result = func.apply(thisBinding, args);
return isObject(result) ? result : thisBinding;
}
return func.apply(thisBinding, args);
}
setBindData(bound, bindData);
return bound;
}
/**
* The base implementation of `_.difference` that accepts a single array
* of values to exclude.
*
* @private
* @param {Array} array The array to process.
* @param {Array} [values] The array of values to exclude.
* @returns {Array} Returns a new array of filtered values.
*/
function baseDifference(array, values) {
var index = -1,
indexOf = getIndexOf(),
length = array ? array.length : 0,
isLarge = length >= largeArraySize && indexOf === baseIndexOf,
result = [];
if (isLarge) {
var cache = createCache(values);
if (cache) {
indexOf = cacheIndexOf;
values = cache;
} else {
isLarge = false;
}
}
while (++index < length) {
var value = array[index];
if (indexOf(values, value) < 0) {
result.push(value);
}
}
if (isLarge) {
releaseObject(values);
}
return result;
}
/**
* The base implementation of `_.flatten` without support for callback
* shorthands or `thisArg` binding.
*
* @private
* @param {Array} array The array to flatten.
* @param {boolean} [isShallow=false] A flag to restrict flattening to a single level.
* @param {boolean} [isStrict=false] A flag to restrict flattening to arrays and `arguments` objects.
* @param {number} [fromIndex=0] The index to start from.
* @returns {Array} Returns a new flattened array.
*/
function baseFlatten(array, isShallow, isStrict, fromIndex) {
var index = (fromIndex || 0) - 1,
length = array ? array.length : 0,
result = [];
while (++index < length) {
var value = array[index];
if (value && typeof value == 'object' && typeof value.length == 'number'
&& (isArray(value) || isArguments(value))) {
// recursively flatten arrays (susceptible to call stack limits)
if (!isShallow) {
value = baseFlatten(value, isShallow, isStrict);
}
var valIndex = -1,
valLength = value.length,
resIndex = result.length;
result.length += valLength;
while (++valIndex < valLength) {
result[resIndex++] = value[valIndex];
}
} else if (!isStrict) {
result.push(value);
}
}
return result;
}
/**
* The base implementation of `_.isEqual`, without support for `thisArg` binding,
* that allows partial "_.where" style comparisons.
*
* @private
* @param {*} a The value to compare.
* @param {*} b The other value to compare.
* @param {Function} [callback] The function to customize comparing values.
* @param {Function} [isWhere=false] A flag to indicate performing partial comparisons.
* @param {Array} [stackA=[]] Tracks traversed `a` objects.
* @param {Array} [stackB=[]] Tracks traversed `b` objects.
* @returns {boolean} Returns `true` if the values are equivalent, else `false`.
*/
function baseIsEqual(a, b, callback, isWhere, stackA, stackB) {
// used to indicate that when comparing objects, `a` has at least the properties of `b`
if (callback) {
var result = callback(a, b);
if (typeof result != 'undefined') {
return !!result;
}
}
// exit early for identical values
if (a === b) {
// treat `+0` vs. `-0` as not equal
return a !== 0 || (1 / a == 1 / b);
}
var type = typeof a,
otherType = typeof b;
// exit early for unlike primitive values
if (a === a &&
!(a && objectTypes[type]) &&
!(b && objectTypes[otherType])) {
return false;
}
// exit early for `null` and `undefined` avoiding ES3's Function#call behavior
// http://es5.github.io/#x15.3.4.4
if (a == null || b == null) {
return a === b;
}
// compare [[Class]] names
var className = toString.call(a),
otherClass = toString.call(b);
if (className == argsClass) {
className = objectClass;
}
if (otherClass == argsClass) {
otherClass = objectClass;
}
if (className != otherClass) {
return false;
}
switch (className) {
case boolClass:
case dateClass:
// coerce dates and booleans to numbers, dates to milliseconds and booleans
// to `1` or `0` treating invalid dates coerced to `NaN` as not equal
return +a == +b;
case numberClass:
// treat `NaN` vs. `NaN` as equal
return (a != +a)
? b != +b
// but treat `+0` vs. `-0` as not equal
: (a == 0 ? (1 / a == 1 / b) : a == +b);
case regexpClass:
case stringClass:
// coerce regexes to strings (http://es5.github.io/#x15.10.6.4)
// treat string primitives and their corresponding object instances as equal
return a == String(b);
}
var isArr = className == arrayClass;
if (!isArr) {
// unwrap any `lodash` wrapped values
var aWrapped = hasOwnProperty.call(a, '__wrapped__'),
bWrapped = hasOwnProperty.call(b, '__wrapped__');
if (aWrapped || bWrapped) {
return baseIsEqual(aWrapped ? a.__wrapped__ : a, bWrapped ? b.__wrapped__ : b, callback, isWhere, stackA, stackB);
}
// exit for functions and DOM nodes
if (className != objectClass || (!support.nodeClass && (isNode(a) || isNode(b)))) {
return false;
}
// in older versions of Opera, `arguments` objects have `Array` constructors
var ctorA = !support.argsObject && isArguments(a) ? Object : a.constructor,
ctorB = !support.argsObject && isArguments(b) ? Object : b.constructor;
// non `Object` object instances with different constructors are not equal
if (ctorA != ctorB &&
!(isFunction(ctorA) && ctorA instanceof ctorA && isFunction(ctorB) && ctorB instanceof ctorB) &&
('constructor' in a && 'constructor' in b)
) {
return false;
}
}
// assume cyclic structures are equal
// the algorithm for detecting cyclic structures is adapted from ES 5.1
// section 15.12.3, abstract operation `JO` (http://es5.github.io/#x15.12.3)
var initedStack = !stackA;
stackA || (stackA = getArray());
stackB || (stackB = getArray());
var length = stackA.length;
while (length--) {
if (stackA[length] == a) {
return stackB[length] == b;
}
}
var size = 0;
result = true;
// add `a` and `b` to the stack of traversed objects
stackA.push(a);
stackB.push(b);
// recursively compare objects and arrays (susceptible to call stack limits)
if (isArr) {
// compare lengths to determine if a deep comparison is necessary
length = a.length;
size = b.length;
result = size == length;
if (result || isWhere) {
// deep compare the contents, ignoring non-numeric properties
while (size--) {
var index = length,
value = b[size];
if (isWhere) {
while (index--) {
if ((result = baseIsEqual(a[index], value, callback, isWhere, stackA, stackB))) {
break;
}
}
} else if (!(result = baseIsEqual(a[size], value, callback, isWhere, stackA, stackB))) {
break;
}
}
}
}
else {
// deep compare objects using `forIn`, instead of `forOwn`, to avoid `Object.keys`
// which, in this case, is more costly
forIn(b, function(value, key, b) {
if (hasOwnProperty.call(b, key)) {
// count the number of properties.
size++;
// deep compare each property value.
return (result = hasOwnProperty.call(a, key) && baseIsEqual(a[key], value, callback, isWhere, stackA, stackB));
}
});
if (result && !isWhere) {
// ensure both objects have the same number of properties
forIn(a, function(value, key, a) {
if (hasOwnProperty.call(a, key)) {
// `size` will be `-1` if `a` has more properties than `b`
return (result = --size > -1);
}
});
}
}
stackA.pop();
stackB.pop();
if (initedStack) {
releaseArray(stackA);
releaseArray(stackB);
}
return result;
}
/**
* The base implementation of `_.merge` without argument juggling or support
* for `thisArg` binding.
*
* @private
* @param {Object} object The destination object.
* @param {Object} source The source object.
* @param {Function} [callback] The function to customize merging properties.
* @param {Array} [stackA=[]] Tracks traversed source objects.
* @param {Array} [stackB=[]] Associates values with source counterparts.
*/
function baseMerge(object, source, callback, stackA, stackB) {
(isArray(source) ? forEach : forOwn)(source, function(source, key) {
var found,
isArr,
result = source,
value = object[key];
if (source && ((isArr = isArray(source)) || isPlainObject(source))) {
// avoid merging previously merged cyclic sources
var stackLength = stackA.length;
while (stackLength--) {
if ((found = stackA[stackLength] == source)) {
value = stackB[stackLength];
break;
}
}
if (!found) {
var isShallow;
if (callback) {
result = callback(value, source);
if ((isShallow = typeof result != 'undefined')) {
value = result;
}
}
if (!isShallow) {
value = isArr
? (isArray(value) ? value : [])
: (isPlainObject(value) ? value : {});
}
// add `source` and associated `value` to the stack of traversed objects
stackA.push(source);
stackB.push(value);
// recursively merge objects and arrays (susceptible to call stack limits)
if (!isShallow) {
baseMerge(value, source, callback, stackA, stackB);
}
}
}
else {
if (callback) {
result = callback(value, source);
if (typeof result == 'undefined') {
result = source;
}
}
if (typeof result != 'undefined') {
value = result;
}
}
object[key] = value;
});
}
/**
* The base implementation of `_.random` without argument juggling or support
* for returning floating-point numbers.
*
* @private
* @param {number} min The minimum possible value.
* @param {number} max The maximum possible value.
* @returns {number} Returns a random number.
*/
function baseRandom(min, max) {
return min + floor(nativeRandom() * (max - min + 1));
}
/**
* The base implementation of `_.uniq` without support for callback shorthands
* or `thisArg` binding.
*
* @private
* @param {Array} array The array to process.
* @param {boolean} [isSorted=false] A flag to indicate that `array` is sorted.
* @param {Function} [callback] The function called per iteration.
* @returns {Array} Returns a duplicate-value-free array.
*/
function baseUniq(array, isSorted, callback) {
var index = -1,
indexOf = getIndexOf(),
length = array ? array.length : 0,
result = [];
var isLarge = !isSorted && length >= largeArraySize && indexOf === baseIndexOf,
seen = (callback || isLarge) ? getArray() : result;
if (isLarge) {
var cache = createCache(seen);
indexOf = cacheIndexOf;
seen = cache;
}
while (++index < length) {
var value = array[index],
computed = callback ? callback(value, index, array) : value;
if (isSorted
? !index || seen[seen.length - 1] !== computed
: indexOf(seen, computed) < 0
) {
if (callback || isLarge) {
seen.push(computed);
}
result.push(value);
}
}
if (isLarge) {
releaseArray(seen.array);
releaseObject(seen);
} else if (callback) {
releaseArray(seen);
}
return result;
}
/**
* Creates a function that aggregates a collection, creating an object composed
* of keys generated from the results of running each element of the collection
* through a callback. The given `setter` function sets the keys and values
* of the composed object.
*
* @private
* @param {Function} setter The setter function.
* @returns {Function} Returns the new aggregator function.
*/
function createAggregator(setter) {
return function(collection, callback, thisArg) {
var result = {};
callback = lodash.createCallback(callback, thisArg, 3);
if (isArray(collection)) {
var index = -1,
length = collection.length;
while (++index < length) {
var value = collection[index];
setter(result, value, callback(value, index, collection), collection);
}
} else {
baseEach(collection, function(value, key, collection) {
setter(result, value, callback(value, key, collection), collection);
});
}
return result;
};
}
/**
* Creates a function that, when called, either curries or invokes `func`
* with an optional `this` binding and partially applied arguments.
*
* @private
* @param {Function|string} func The function or method name to reference.
* @param {number} bitmask The bitmask of method flags to compose.
* The bitmask may be composed of the following flags:
* 1 - `_.bind`
* 2 - `_.bindKey`
* 4 - `_.curry`
* 8 - `_.curry` (bound)
* 16 - `_.partial`
* 32 - `_.partialRight`
* @param {Array} [partialArgs] An array of arguments to prepend to those
* provided to the new function.
* @param {Array} [partialRightArgs] An array of arguments to append to those
* provided to the new function.
* @param {*} [thisArg] The `this` binding of `func`.
* @param {number} [arity] The arity of `func`.
* @returns {Function} Returns the new function.
*/
function createWrapper(func, bitmask, partialArgs, partialRightArgs, thisArg, arity) {
var isBind = bitmask & 1,
isBindKey = bitmask & 2,
isCurry = bitmask & 4,
isCurryBound = bitmask & 8,
isPartial = bitmask & 16,
isPartialRight = bitmask & 32;
if (!isBindKey && !isFunction(func)) {
throw new TypeError;
}
if (isPartial && !partialArgs.length) {
bitmask &= ~16;
isPartial = partialArgs = false;
}
if (isPartialRight && !partialRightArgs.length) {
bitmask &= ~32;
isPartialRight = partialRightArgs = false;
}
var bindData = func && func.__bindData__;
if (bindData && bindData !== true) {
// clone `bindData`
bindData = slice(bindData);
if (bindData[2]) {
bindData[2] = slice(bindData[2]);
}
if (bindData[3]) {
bindData[3] = slice(bindData[3]);
}
// set `thisBinding` is not previously bound
if (isBind && !(bindData[1] & 1)) {
bindData[4] = thisArg;
}
// set if previously bound but not currently (subsequent curried functions)
if (!isBind && bindData[1] & 1) {
bitmask |= 8;
}
// set curried arity if not yet set
if (isCurry && !(bindData[1] & 4)) {
bindData[5] = arity;
}
// append partial left arguments
if (isPartial) {
push.apply(bindData[2] || (bindData[2] = []), partialArgs);
}
// append partial right arguments
if (isPartialRight) {
unshift.apply(bindData[3] || (bindData[3] = []), partialRightArgs);
}
// merge flags
bindData[1] |= bitmask;
return createWrapper.apply(null, bindData);
}
// fast path for `_.bind`
var creater = (bitmask == 1 || bitmask === 17) ? baseBind : baseCreateWrapper;
return creater([func, bitmask, partialArgs, partialRightArgs, thisArg, arity]);
}
/**
* Creates compiled iteration functions.
*
* @private
* @param {...Object} [options] The compile options object(s).
* @param {string} [options.array] Code to determine if the iterable is an array or array-like.
* @param {boolean} [options.useHas] Specify using `hasOwnProperty` checks in the object loop.
* @param {Function} [options.keys] A reference to `_.keys` for use in own property iteration.
* @param {string} [options.args] A comma separated string of iteration function arguments.
* @param {string} [options.top] Code to execute before the iteration branches.
* @param {string} [options.loop] Code to execute in the object loop.
* @param {string} [options.bottom] Code to execute after the iteration branches.
* @returns {Function} Returns the compiled function.
*/
function createIterator() {
// data properties
iteratorData.shadowedProps = shadowedProps;
iteratorData.support = support;
// iterator options
iteratorData.array = iteratorData.bottom = iteratorData.loop = iteratorData.top = '';
iteratorData.init = 'iterable';
iteratorData.useHas = true;
// merge options into a template data object
for (var object, index = 0; object = arguments[index]; index++) {
for (var key in object) {
iteratorData[key] = object[key];
}
}
var args = iteratorData.args;
iteratorData.firstArg = /^[^,]+/.exec(args)[0];
// create the function factory
var factory = Function(
'baseCreateCallback, errorClass, errorProto, hasOwnProperty, ' +
'indicatorObject, isArguments, isArray, isString, keys, objectProto, ' +
'objectTypes, nonEnumProps, stringClass, stringProto, toString',
'return function(' + args + ') {\n' + iteratorTemplate(iteratorData) + '\n}'
);
// return the compiled function
return factory(
baseCreateCallback, errorClass, errorProto, hasOwnProperty,
indicatorObject, isArguments, isArray, isString, iteratorData.keys, objectProto,
objectTypes, nonEnumProps, stringClass, stringProto, toString
);
}
/**
* Used by `escape` to convert characters to HTML entities.
*
* @private
* @param {string} match The matched character to escape.
* @returns {string} Returns the escaped character.
*/
function escapeHtmlChar(match) {
return htmlEscapes[match];
}
/**
* Gets the appropriate "indexOf" function. If the `_.indexOf` method is
* customized, this method returns the custom method, otherwise it returns
* the `baseIndexOf` function.
*
* @private
* @returns {Function} Returns the "indexOf" function.
*/
function getIndexOf() {
var result = (result = lodash.indexOf) === indexOf ? baseIndexOf : result;
return result;
}
/**
* Checks if `value` is a native function.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if the `value` is a native function, else `false`.
*/
function isNative(value) {
return typeof value == 'function' && reNative.test(value);
}
/**
* Sets `this` binding data on a given function.
*
* @private
* @param {Function} func The function to set data on.
* @param {Array} value The data array to set.
*/
var setBindData = !defineProperty ? noop : function(func, value) {
descriptor.value = value;
defineProperty(func, '__bindData__', descriptor);
};
/**
* A fallback implementation of `isPlainObject` which checks if a given value
* is an object created by the `Object` constructor, assuming objects created
* by the `Object` constructor have no inherited enumerable properties and that
* there are no `Object.prototype` extensions.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
*/
function shimIsPlainObject(value) {
var ctor,
result;
// avoid non Object objects, `arguments` objects, and DOM elements
if (!(value && toString.call(value) == objectClass) ||
(ctor = value.constructor, isFunction(ctor) && !(ctor instanceof ctor)) ||
(!support.argsClass && isArguments(value)) ||
(!support.nodeClass && isNode(value))) {
return false;
}
// IE < 9 iterates inherited properties before own properties. If the first
// iterated property is an object's own property then there are no inherited
// enumerable properties.
if (support.ownLast) {
forIn(value, function(value, key, object) {
result = hasOwnProperty.call(object, key);
return false;
});
return result !== false;
}
// In most environments an object's own properties are iterated before
// its inherited properties. If the last iterated property is an object's
// own property then there are no inherited enumerable properties.
forIn(value, function(value, key) {
result = key;
});
return typeof result == 'undefined' || hasOwnProperty.call(value, result);
}
/**
* Used by `unescape` to convert HTML entities to characters.
*
* @private
* @param {string} match The matched character to unescape.
* @returns {string} Returns the unescaped character.
*/
function unescapeHtmlChar(match) {
return htmlUnescapes[match];
}
/*--------------------------------------------------------------------------*/
/**
* Checks if `value` is an `arguments` object.
*
* @static
* @memberOf _
* @category Objects
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if the `value` is an `arguments` object, else `false`.
* @example
*
* (function() { return _.isArguments(arguments); })(1, 2, 3);
* // => true
*
* _.isArguments([1, 2, 3]);
* // => false
*/
function isArguments(value) {
return value && typeof value == 'object' && typeof value.length == 'number' &&
toString.call(value) == argsClass || false;
}
// fallback for browsers that can't detect `arguments` objects by [[Class]]
if (!support.argsClass) {
isArguments = function(value) {
return value && typeof value == 'object' && typeof value.length == 'number' &&
hasOwnProperty.call(value, 'callee') && !propertyIsEnumerable.call(value, 'callee') || false;
};
}
/**
* Checks if `value` is an array.
*
* @static
* @memberOf _
* @type Function
* @category Objects
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if the `value` is an array, else `false`.
* @example
*
* (function() { return _.isArray(arguments); })();
* // => false
*
* _.isArray([1, 2, 3]);
* // => true
*/
var isArray = nativeIsArray || function(value) {
return value && typeof value == 'object' && typeof value.length == 'number' &&
toString.call(value) == arrayClass || false;
};
/**
* A fallback implementation of `Object.keys` which produces an array of the
* given object's own enumerable property names.
*
* @private
* @type Function
* @param {Object} object The object to inspect.
* @returns {Array} Returns an array of property names.
*/
var shimKeys = createIterator({
'args': 'object',
'init': '[]',
'top': 'if (!(objectTypes[typeof object])) return result',
'loop': 'result.push(index)'
});
/**
* Creates an array composed of the own enumerable property names of an object.
*
* @static
* @memberOf _
* @category Objects
* @param {Object} object The object to inspect.
* @returns {Array} Returns an array of property names.
* @example
*
* _.keys({ 'one': 1, 'two': 2, 'three': 3 });
* // => ['one', 'two', 'three'] (property order is not guaranteed across environments)
*/
var keys = !nativeKeys ? shimKeys : function(object) {
if (!isObject(object)) {
return [];
}
if ((support.enumPrototypes && typeof object == 'function') ||
(support.nonEnumArgs && object.length && isArguments(object))) {
return shimKeys(object);
}
return nativeKeys(object);
};
/** Reusable iterator options shared by `each`, `forIn`, and `forOwn` */
var eachIteratorOptions = {
'args': 'collection, callback, thisArg',
'top': "callback = callback && typeof thisArg == 'undefined' ? callback : baseCreateCallback(callback, thisArg, 3)",
'array': "typeof length == 'number'",
'keys': keys,
'loop': 'if (callback(iterable[index], index, collection) === false) return result'
};
/** Reusable iterator options for `assign` and `defaults` */
var defaultsIteratorOptions = {
'args': 'object, source, guard',
'top':
'var args = arguments,\n' +
' argsIndex = 0,\n' +
" argsLength = typeof guard == 'number' ? 2 : args.length;\n" +
'while (++argsIndex < argsLength) {\n' +
' iterable = args[argsIndex];\n' +
' if (iterable && objectTypes[typeof iterable]) {',
'keys': keys,
'loop': "if (typeof result[index] == 'undefined') result[index] = iterable[index]",
'bottom': ' }\n}'
};
/** Reusable iterator options for `forIn` and `forOwn` */
var forOwnIteratorOptions = {
'top': 'if (!objectTypes[typeof iterable]) return result;\n' + eachIteratorOptions.top,
'array': false
};
/**
* Used to convert characters to HTML entities:
*
* Though the `>` character is escaped for symmetry, characters like `>` and `/`
* don't require escaping in HTML and have no special meaning unless they're part
* of a tag or an unquoted attribute value.
* http://mathiasbynens.be/notes/ambiguous-ampersands (under "semi-related fun fact")
*/
var htmlEscapes = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#39;'
};
/** Used to convert HTML entities to characters */
var htmlUnescapes = invert(htmlEscapes);
/** Used to match HTML entities and HTML characters */
var reEscapedHtml = RegExp('(' + keys(htmlUnescapes).join('|') + ')', 'g'),
reUnescapedHtml = RegExp('[' + keys(htmlEscapes).join('') + ']', 'g');
/**
* A function compiled to iterate `arguments` objects, arrays, objects, and
* strings consistenly across environments, executing the callback for each
* element in the collection. The callback is bound to `thisArg` and invoked
* with three arguments; (value, index|key, collection). Callbacks may exit
* iteration early by explicitly returning `false`.
*
* @private
* @type Function
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function} [callback=identity] The function called per iteration.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {Array|Object|string} Returns `collection`.
*/
var baseEach = createIterator(eachIteratorOptions);
/*--------------------------------------------------------------------------*/
/**
* Assigns own enumerable properties of source object(s) to the destination
* object. Subsequent sources will overwrite property assignments of previous
* sources. If a callback is provided it will be executed to produce the
* assigned values. The callback is bound to `thisArg` and invoked with two
* arguments; (objectValue, sourceValue).
*
* @static
* @memberOf _
* @type Function
* @alias extend
* @category Objects
* @param {Object} object The destination object.
* @param {...Object} [source] The source objects.
* @param {Function} [callback] The function to customize assigning values.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {Object} Returns the destination object.
* @example
*
* _.assign({ 'name': 'fred' }, { 'employer': 'slate' });
* // => { 'name': 'fred', 'employer': 'slate' }
*
* var defaults = _.partialRight(_.assign, function(a, b) {
* return typeof a == 'undefined' ? b : a;
* });
*
* var object = { 'name': 'barney' };
* defaults(object, { 'name': 'fred', 'employer': 'slate' });
* // => { 'name': 'barney', 'employer': 'slate' }
*/
var assign = createIterator(defaultsIteratorOptions, {
'top':
defaultsIteratorOptions.top.replace(';',
';\n' +
"if (argsLength > 3 && typeof args[argsLength - 2] == 'function') {\n" +
' var callback = baseCreateCallback(args[--argsLength - 1], args[argsLength--], 2);\n' +
"} else if (argsLength > 2 && typeof args[argsLength - 1] == 'function') {\n" +
' callback = args[--argsLength];\n' +
'}'
),
'loop': 'result[index] = callback ? callback(result[index], iterable[index]) : iterable[index]'
});
/**
* Creates a clone of `value`. If `isDeep` is `true` nested objects will also
* be cloned, otherwise they will be assigned by reference. If a callback
* is provided it will be executed to produce the cloned values. If the
* callback returns `undefined` cloning will be handled by the method instead.
* The callback is bound to `thisArg` and invoked with one argument; (value).
*
* @static
* @memberOf _
* @category Objects
* @param {*} value The value to clone.
* @param {boolean} [isDeep=false] Specify a deep clone.
* @param {Function} [callback] The function to customize cloning values.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {*} Returns the cloned value.
* @example
*
* var characters = [
* { 'name': 'barney', 'age': 36 },
* { 'name': 'fred', 'age': 40 }
* ];
*
* var shallow = _.clone(characters);
* shallow[0] === characters[0];
* // => true
*
* var deep = _.clone(characters, true);
* deep[0] === characters[0];
* // => false
*
* _.mixin({
* 'clone': _.partialRight(_.clone, function(value) {
* return _.isElement(value) ? value.cloneNode(false) : undefined;
* })
* });
*
* var clone = _.clone(document.body);
* clone.childNodes.length;
* // => 0
*/
function clone(value, isDeep, callback, thisArg) {
// allows working with "Collections" methods without using their `index`
// and `collection` arguments for `isDeep` and `callback`
if (typeof isDeep != 'boolean' && isDeep != null) {
thisArg = callback;
callback = isDeep;
isDeep = false;
}
return baseClone(value, isDeep, typeof callback == 'function' && baseCreateCallback(callback, thisArg, 1));
}
/**
* Creates a deep clone of `value`. If a callback is provided it will be
* executed to produce the cloned values. If the callback returns `undefined`
* cloning will be handled by the method instead. The callback is bound to
* `thisArg` and invoked with one argument; (value).
*
* Note: This method is loosely based on the structured clone algorithm. Functions
* and DOM nodes are **not** cloned. The enumerable properties of `arguments` objects and
* objects created by constructors other than `Object` are cloned to plain `Object` objects.
* See http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-algorithm.
*
* @static
* @memberOf _
* @category Objects
* @param {*} value The value to deep clone.
* @param {Function} [callback] The function to customize cloning values.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {*} Returns the deep cloned value.
* @example
*
* var characters = [
* { 'name': 'barney', 'age': 36 },
* { 'name': 'fred', 'age': 40 }
* ];
*
* var deep = _.cloneDeep(characters);
* deep[0] === characters[0];
* // => false
*
* var view = {
* 'label': 'docs',
* 'node': element
* };
*
* var clone = _.cloneDeep(view, function(value) {
* return _.isElement(value) ? value.cloneNode(true) : undefined;
* });
*
* clone.node == view.node;
* // => false
*/
function cloneDeep(value, callback, thisArg) {
return baseClone(value, true, typeof callback == 'function' && baseCreateCallback(callback, thisArg, 1));
}
/**
* Creates an object that inherits from the given `prototype` object. If a
* `properties` object is provided its own enumerable properties are assigned
* to the created object.
*
* @static
* @memberOf _
* @category Objects
* @param {Object} prototype The object to inherit from.
* @param {Object} [properties] The properties to assign to the object.
* @returns {Object} Returns the new object.
* @example
*
* function Shape() {
* this.x = 0;
* this.y = 0;
* }
*
* function Circle() {
* Shape.call(this);
* }
*
* Circle.prototype = _.create(Shape.prototype, { 'constructor': Circle });
*
* var circle = new Circle;
* circle instanceof Circle;
* // => true
*
* circle instanceof Shape;
* // => true
*/
function create(prototype, properties) {
var result = baseCreate(prototype);
return properties ? assign(result, properties) : result;
}
/**
* Assigns own enumerable properties of source object(s) to the destination
* object for all destination properties that resolve to `undefined`. Once a
* property is set, additional defaults of the same property will be ignored.
*
* @static
* @memberOf _
* @type Function
* @category Objects
* @param {Object} object The destination object.
* @param {...Object} [source] The source objects.
* @param- {Object} [guard] Allows working with `_.reduce` without using its
* `key` and `object` arguments as sources.
* @returns {Object} Returns the destination object.
* @example
*
* var object = { 'name': 'barney' };
* _.defaults(object, { 'name': 'fred', 'employer': 'slate' });
* // => { 'name': 'barney', 'employer': 'slate' }
*/
var defaults = createIterator(defaultsIteratorOptions);
/**
* This method is like `_.findIndex` except that it returns the key of the
* first element that passes the callback check, instead of the element itself.
*
* If a property name is provided for `callback` the created "_.pluck" style
* callback will return the property value of the given element.
*
* If an object is provided for `callback` the created "_.where" style callback
* will return `true` for elements that have the properties of the given object,
* else `false`.
*
* @static
* @memberOf _
* @category Objects
* @param {Object} object The object to search.
* @param {Function|Object|string} [callback=identity] The function called per
* iteration. If a property name or object is provided it will be used to
* create a "_.pluck" or "_.where" style callback, respectively.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {string|undefined} Returns the key of the found element, else `undefined`.
* @example
*
* var characters = {
* 'barney': { 'age': 36, 'blocked': false },
* 'fred': { 'age': 40, 'blocked': true },
* 'pebbles': { 'age': 1, 'blocked': false }
* };
*
* _.findKey(characters, function(chr) {
* return chr.age < 40;
* });
* // => 'barney' (property order is not guaranteed across environments)
*
* // using "_.where" callback shorthand
* _.findKey(characters, { 'age': 1 });
* // => 'pebbles'
*
* // using "_.pluck" callback shorthand
* _.findKey(characters, 'blocked');
* // => 'fred'
*/
function findKey(object, callback, thisArg) {
var result;
callback = lodash.createCallback(callback, thisArg, 3);
forOwn(object, function(value, key, object) {
if (callback(value, key, object)) {
result = key;
return false;
}
});
return result;
}
/**
* This method is like `_.findKey` except that it iterates over elements
* of a `collection` in the opposite order.
*
* If a property name is provided for `callback` the created "_.pluck" style
* callback will return the property value of the given element.
*
* If an object is provided for `callback` the created "_.where" style callback
* will return `true` for elements that have the properties of the given object,
* else `false`.
*
* @static
* @memberOf _
* @category Objects
* @param {Object} object The object to search.
* @param {Function|Object|string} [callback=identity] The function called per
* iteration. If a property name or object is provided it will be used to
* create a "_.pluck" or "_.where" style callback, respectively.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {string|undefined} Returns the key of the found element, else `undefined`.
* @example
*
* var characters = {
* 'barney': { 'age': 36, 'blocked': true },
* 'fred': { 'age': 40, 'blocked': false },
* 'pebbles': { 'age': 1, 'blocked': true }
* };
*
* _.findLastKey(characters, function(chr) {
* return chr.age < 40;
* });
* // => returns `pebbles`, assuming `_.findKey` returns `barney`
*
* // using "_.where" callback shorthand
* _.findLastKey(characters, { 'age': 40 });
* // => 'fred'
*
* // using "_.pluck" callback shorthand
* _.findLastKey(characters, 'blocked');
* // => 'pebbles'
*/
function findLastKey(object, callback, thisArg) {
var result;
callback = lodash.createCallback(callback, thisArg, 3);
forOwnRight(object, function(value, key, object) {
if (callback(value, key, object)) {
result = key;
return false;
}
});
return result;
}
/**
* Iterates over own and inherited enumerable properties of an object,
* executing the callback for each property. The callback is bound to `thisArg`
* and invoked with three arguments; (value, key, object). Callbacks may exit
* iteration early by explicitly returning `false`.
*
* @static
* @memberOf _
* @type Function
* @category Objects
* @param {Object} object The object to iterate over.
* @param {Function} [callback=identity] The function called per iteration.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {Object} Returns `object`.
* @example
*
* function Shape() {
* this.x = 0;
* this.y = 0;
* }
*
* Shape.prototype.move = function(x, y) {
* this.x += x;
* this.y += y;
* };
*
* _.forIn(new Shape, function(value, key) {
* console.log(key);
* });
* // => logs 'x', 'y', and 'move' (property order is not guaranteed across environments)
*/
var forIn = createIterator(eachIteratorOptions, forOwnIteratorOptions, {
'useHas': false
});
/**
* This method is like `_.forIn` except that it iterates over elements
* of a `collection` in the opposite order.
*
* @static
* @memberOf _
* @category Objects
* @param {Object} object The object to iterate over.
* @param {Function} [callback=identity] The function called per iteration.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {Object} Returns `object`.
* @example
*
* function Shape() {
* this.x = 0;
* this.y = 0;
* }
*
* Shape.prototype.move = function(x, y) {
* this.x += x;
* this.y += y;
* };
*
* _.forInRight(new Shape, function(value, key) {
* console.log(key);
* });
* // => logs 'move', 'y', and 'x' assuming `_.forIn ` logs 'x', 'y', and 'move'
*/
function forInRight(object, callback, thisArg) {
var pairs = [];
forIn(object, function(value, key) {
pairs.push(key, value);
});
var length = pairs.length;
callback = baseCreateCallback(callback, thisArg, 3);
while (length--) {
if (callback(pairs[length--], pairs[length], object) === false) {
break;
}
}
return object;
}
/**
* Iterates over own enumerable properties of an object, executing the callback
* for each property. The callback is bound to `thisArg` and invoked with three
* arguments; (value, key, object). Callbacks may exit iteration early by
* explicitly returning `false`.
*
* @static
* @memberOf _
* @type Function
* @category Objects
* @param {Object} object The object to iterate over.
* @param {Function} [callback=identity] The function called per iteration.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {Object} Returns `object`.
* @example
*
* _.forOwn({ '0': 'zero', '1': 'one', 'length': 2 }, function(num, key) {
* console.log(key);
* });
* // => logs '0', '1', and 'length' (property order is not guaranteed across environments)
*/
var forOwn = createIterator(eachIteratorOptions, forOwnIteratorOptions);
/**
* This method is like `_.forOwn` except that it iterates over elements
* of a `collection` in the opposite order.
*
* @static
* @memberOf _
* @category Objects
* @param {Object} object The object to iterate over.
* @param {Function} [callback=identity] The function called per iteration.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {Object} Returns `object`.
* @example
*
* _.forOwnRight({ '0': 'zero', '1': 'one', 'length': 2 }, function(num, key) {
* console.log(key);
* });
* // => logs 'length', '1', and '0' assuming `_.forOwn` logs '0', '1', and 'length'
*/
function forOwnRight(object, callback, thisArg) {
var props = keys(object),
length = props.length;
callback = baseCreateCallback(callback, thisArg, 3);
while (length--) {
var key = props[length];
if (callback(object[key], key, object) === false) {
break;
}
}
return object;
}
/**
* Creates a sorted array of property names of all enumerable properties,
* own and inherited, of `object` that have function values.
*
* @static
* @memberOf _
* @alias methods
* @category Objects
* @param {Object} object The object to inspect.
* @returns {Array} Returns an array of property names that have function values.
* @example
*
* _.functions(_);
* // => ['all', 'any', 'bind', 'bindAll', 'clone', 'compact', 'compose', ...]
*/
function functions(object) {
var result = [];
forIn(object, function(value, key) {
if (isFunction(value)) {
result.push(key);
}
});
return result.sort();
}
/**
* Checks if the specified property name exists as a direct property of `object`,
* instead of an inherited property.
*
* @static
* @memberOf _
* @category Objects
* @param {Object} object The object to inspect.
* @param {string} key The name of the property to check.
* @returns {boolean} Returns `true` if key is a direct property, else `false`.
* @example
*
* _.has({ 'a': 1, 'b': 2, 'c': 3 }, 'b');
* // => true
*/
function has(object, key) {
return object ? hasOwnProperty.call(object, key) : false;
}
/**
* Creates an object composed of the inverted keys and values of the given object.
*
* @static
* @memberOf _
* @category Objects
* @param {Object} object The object to invert.
* @returns {Object} Returns the created inverted object.
* @example
*
* _.invert({ 'first': 'fred', 'second': 'barney' });
* // => { 'fred': 'first', 'barney': 'second' }
*/
function invert(object) {
var index = -1,
props = keys(object),
length = props.length,
result = {};
while (++index < length) {
var key = props[index];
result[object[key]] = key;
}
return result;
}
/**
* Checks if `value` is a boolean value.
*
* @static
* @memberOf _
* @category Objects
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if the `value` is a boolean value, else `false`.
* @example
*
* _.isBoolean(null);
* // => false
*/
function isBoolean(value) {
return value === true || value === false ||
value && typeof value == 'object' && toString.call(value) == boolClass || false;
}
/**
* Checks if `value` is a date.
*
* @static
* @memberOf _
* @category Objects
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if the `value` is a date, else `false`.
* @example
*
* _.isDate(new Date);
* // => true
*/
function isDate(value) {
return value && typeof value == 'object' && toString.call(value) == dateClass || false;
}
/**
* Checks if `value` is a DOM element.
*
* @static
* @memberOf _
* @category Objects
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if the `value` is a DOM element, else `false`.
* @example
*
* _.isElement(document.body);
* // => true
*/
function isElement(value) {
return value && value.nodeType === 1 || false;
}
/**
* Checks if `value` is empty. Arrays, strings, or `arguments` objects with a
* length of `0` and objects with no own enumerable properties are considered
* "empty".
*
* @static
* @memberOf _
* @category Objects
* @param {Array|Object|string} value The value to inspect.
* @returns {boolean} Returns `true` if the `value` is empty, else `false`.
* @example
*
* _.isEmpty([1, 2, 3]);
* // => false
*
* _.isEmpty({});
* // => true
*
* _.isEmpty('');
* // => true
*/
function isEmpty(value) {
var result = true;
if (!value) {
return result;
}
var className = toString.call(value),
length = value.length;
if ((className == arrayClass || className == stringClass ||
(support.argsClass ? className == argsClass : isArguments(value))) ||
(className == objectClass && typeof length == 'number' && isFunction(value.splice))) {
return !length;
}
forOwn(value, function() {
return (result = false);
});
return result;
}
/**
* Performs a deep comparison between two values to determine if they are
* equivalent to each other. If a callback is provided it will be executed
* to compare values. If the callback returns `undefined` comparisons will
* be handled by the method instead. The callback is bound to `thisArg` and
* invoked with two arguments; (a, b).
*
* @static
* @memberOf _
* @category Objects
* @param {*} a The value to compare.
* @param {*} b The other value to compare.
* @param {Function} [callback] The function to customize comparing values.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {boolean} Returns `true` if the values are equivalent, else `false`.
* @example
*
* var object = { 'name': 'fred' };
* var copy = { 'name': 'fred' };
*
* object == copy;
* // => false
*
* _.isEqual(object, copy);
* // => true
*
* var words = ['hello', 'goodbye'];
* var otherWords = ['hi', 'goodbye'];
*
* _.isEqual(words, otherWords, function(a, b) {
* var reGreet = /^(?:hello|hi)$/i,
* aGreet = _.isString(a) && reGreet.test(a),
* bGreet = _.isString(b) && reGreet.test(b);
*
* return (aGreet || bGreet) ? (aGreet == bGreet) : undefined;
* });
* // => true
*/
function isEqual(a, b, callback, thisArg) {
return baseIsEqual(a, b, typeof callback == 'function' && baseCreateCallback(callback, thisArg, 2));
}
/**
* Checks if `value` is, or can be coerced to, a finite number.
*
* Note: This is not the same as native `isFinite` which will return true for
* booleans and empty strings. See http://es5.github.io/#x15.1.2.5.
*
* @static
* @memberOf _
* @category Objects
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if the `value` is finite, else `false`.
* @example
*
* _.isFinite(-101);
* // => true
*
* _.isFinite('10');
* // => true
*
* _.isFinite(true);
* // => false
*
* _.isFinite('');
* // => false
*
* _.isFinite(Infinity);
* // => false
*/
function isFinite(value) {
return nativeIsFinite(value) && !nativeIsNaN(parseFloat(value));
}
/**
* Checks if `value` is a function.
*
* @static
* @memberOf _
* @category Objects
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if the `value` is a function, else `false`.
* @example
*
* _.isFunction(_);
* // => true
*/
function isFunction(value) {
return typeof value == 'function';
}
// fallback for older versions of Chrome and Safari
if (isFunction(/x/)) {
isFunction = function(value) {
return typeof value == 'function' && toString.call(value) == funcClass;
};
}
/**
* Checks if `value` is the language type of Object.
* (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
*
* @static
* @memberOf _
* @category Objects
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if the `value` is an object, else `false`.
* @example
*
* _.isObject({});
* // => true
*
* _.isObject([1, 2, 3]);
* // => true
*
* _.isObject(1);
* // => false
*/
function isObject(value) {
// check if the value is the ECMAScript language type of Object
// http://es5.github.io/#x8
// and avoid a V8 bug
// http://code.google.com/p/v8/issues/detail?id=2291
return !!(value && objectTypes[typeof value]);
}
/**
* Checks if `value` is `NaN`.
*
* Note: This is not the same as native `isNaN` which will return `true` for
* `undefined` and other non-numeric values. See http://es5.github.io/#x15.1.2.4.
*
* @static
* @memberOf _
* @category Objects
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if the `value` is `NaN`, else `false`.
* @example
*
* _.isNaN(NaN);
* // => true
*
* _.isNaN(new Number(NaN));
* // => true
*
* isNaN(undefined);
* // => true
*
* _.isNaN(undefined);
* // => false
*/
function isNaN(value) {
// `NaN` as a primitive is the only value that is not equal to itself
// (perform the [[Class]] check first to avoid errors with some host objects in IE)
return isNumber(value) && value != +value;
}
/**
* Checks if `value` is `null`.
*
* @static
* @memberOf _
* @category Objects
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if the `value` is `null`, else `false`.
* @example
*
* _.isNull(null);
* // => true
*
* _.isNull(undefined);
* // => false
*/
function isNull(value) {
return value === null;
}
/**
* Checks if `value` is a number.
*
* Note: `NaN` is considered a number. See http://es5.github.io/#x8.5.
*
* @static
* @memberOf _
* @category Objects
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if the `value` is a number, else `false`.
* @example
*
* _.isNumber(8.4 * 5);
* // => true
*/
function isNumber(value) {
return typeof value == 'number' ||
value && typeof value == 'object' && toString.call(value) == numberClass || false;
}
/**
* Checks if `value` is an object created by the `Object` constructor.
*
* @static
* @memberOf _
* @category Objects
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
* @example
*
* function Shape() {
* this.x = 0;
* this.y = 0;
* }
*
* _.isPlainObject(new Shape);
* // => false
*
* _.isPlainObject([1, 2, 3]);
* // => false
*
* _.isPlainObject({ 'x': 0, 'y': 0 });
* // => true
*/
var isPlainObject = !getPrototypeOf ? shimIsPlainObject : function(value) {
if (!(value && toString.call(value) == objectClass) || (!support.argsClass && isArguments(value))) {
return false;
}
var valueOf = value.valueOf,
objProto = isNative(valueOf) && (objProto = getPrototypeOf(valueOf)) && getPrototypeOf(objProto);
return objProto
? (value == objProto || getPrototypeOf(value) == objProto)
: shimIsPlainObject(value);
};
/**
* Checks if `value` is a regular expression.
*
* @static
* @memberOf _
* @category Objects
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if the `value` is a regular expression, else `false`.
* @example
*
* _.isRegExp(/fred/);
* // => true
*/
function isRegExp(value) {
return value && objectTypes[typeof value] && toString.call(value) == regexpClass || false;
}
/**
* Checks if `value` is a string.
*
* @static
* @memberOf _
* @category Objects
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if the `value` is a string, else `false`.
* @example
*
* _.isString('fred');
* // => true
*/
function isString(value) {
return typeof value == 'string' ||
value && typeof value == 'object' && toString.call(value) == stringClass || false;
}
/**
* Checks if `value` is `undefined`.
*
* @static
* @memberOf _
* @category Objects
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if the `value` is `undefined`, else `false`.
* @example
*
* _.isUndefined(void 0);
* // => true
*/
function isUndefined(value) {
return typeof value == 'undefined';
}
/**
* Creates an object with the same keys as `object` and values generated by
* running each own enumerable property of `object` through the callback.
* The callback is bound to `thisArg` and invoked with three arguments;
* (value, key, object).
*
* If a property name is provided for `callback` the created "_.pluck" style
* callback will return the property value of the given element.
*
* If an object is provided for `callback` the created "_.where" style callback
* will return `true` for elements that have the properties of the given object,
* else `false`.
*
* @static
* @memberOf _
* @category Objects
* @param {Object} object The object to iterate over.
* @param {Function|Object|string} [callback=identity] The function called
* per iteration. If a property name or object is provided it will be used
* to create a "_.pluck" or "_.where" style callback, respectively.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {Array} Returns a new object with values of the results of each `callback` execution.
* @example
*
* _.mapValues({ 'a': 1, 'b': 2, 'c': 3} , function(num) { return num * 3; });
* // => { 'a': 3, 'b': 6, 'c': 9 }
*
* var characters = {
* 'fred': { 'name': 'fred', 'age': 40 },
* 'pebbles': { 'name': 'pebbles', 'age': 1 }
* };
*
* // using "_.pluck" callback shorthand
* _.mapValues(characters, 'age');
* // => { 'fred': 40, 'pebbles': 1 }
*/
function mapValues(object, callback, thisArg) {
var result = {};
callback = lodash.createCallback(callback, thisArg, 3);
forOwn(object, function(value, key, object) {
result[key] = callback(value, key, object);
});
return result;
}
/**
* Recursively merges own enumerable properties of the source object(s), that
* don't resolve to `undefined` into the destination object. Subsequent sources
* will overwrite property assignments of previous sources. If a callback is
* provided it will be executed to produce the merged values of the destination
* and source properties. If the callback returns `undefined` merging will
* be handled by the method instead. The callback is bound to `thisArg` and
* invoked with two arguments; (objectValue, sourceValue).
*
* @static
* @memberOf _
* @category Objects
* @param {Object} object The destination object.
* @param {...Object} [source] The source objects.
* @param {Function} [callback] The function to customize merging properties.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {Object} Returns the destination object.
* @example
*
* var names = {
* 'characters': [
* { 'name': 'barney' },
* { 'name': 'fred' }
* ]
* };
*
* var ages = {
* 'characters': [
* { 'age': 36 },
* { 'age': 40 }
* ]
* };
*
* _.merge(names, ages);
* // => { 'characters': [{ 'name': 'barney', 'age': 36 }, { 'name': 'fred', 'age': 40 }] }
*
* var food = {
* 'fruits': ['apple'],
* 'vegetables': ['beet']
* };
*
* var otherFood = {
* 'fruits': ['banana'],
* 'vegetables': ['carrot']
* };
*
* _.merge(food, otherFood, function(a, b) {
* return _.isArray(a) ? a.concat(b) : undefined;
* });
* // => { 'fruits': ['apple', 'banana'], 'vegetables': ['beet', 'carrot] }
*/
function merge(object) {
var args = arguments,
length = 2;
if (!isObject(object)) {
return object;
}
// allows working with `_.reduce` and `_.reduceRight` without using
// their `index` and `collection` arguments
if (typeof args[2] != 'number') {
length = args.length;
}
if (length > 3 && typeof args[length - 2] == 'function') {
var callback = baseCreateCallback(args[--length - 1], args[length--], 2);
} else if (length > 2 && typeof args[length - 1] == 'function') {
callback = args[--length];
}
var sources = slice(arguments, 1, length),
index = -1,
stackA = getArray(),
stackB = getArray();
while (++index < length) {
baseMerge(object, sources[index], callback, stackA, stackB);
}
releaseArray(stackA);
releaseArray(stackB);
return object;
}
/**
* Creates a shallow clone of `object` excluding the specified properties.
* Property names may be specified as individual arguments or as arrays of
* property names. If a callback is provided it will be executed for each
* property of `object` omitting the properties the callback returns truey
* for. The callback is bound to `thisArg` and invoked with three arguments;
* (value, key, object).
*
* @static
* @memberOf _
* @category Objects
* @param {Object} object The source object.
* @param {Function|...string|string[]} [callback] The properties to omit or the
* function called per iteration.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {Object} Returns an object without the omitted properties.
* @example
*
* _.omit({ 'name': 'fred', 'age': 40 }, 'age');
* // => { 'name': 'fred' }
*
* _.omit({ 'name': 'fred', 'age': 40 }, function(value) {
* return typeof value == 'number';
* });
* // => { 'name': 'fred' }
*/
function omit(object, callback, thisArg) {
var result = {};
if (typeof callback != 'function') {
var props = [];
forIn(object, function(value, key) {
props.push(key);
});
props = baseDifference(props, baseFlatten(arguments, true, false, 1));
var index = -1,
length = props.length;
while (++index < length) {
var key = props[index];
result[key] = object[key];
}
} else {
callback = lodash.createCallback(callback, thisArg, 3);
forIn(object, function(value, key, object) {
if (!callback(value, key, object)) {
result[key] = value;
}
});
}
return result;
}
/**
* Creates a two dimensional array of an object's key-value pairs,
* i.e. `[[key1, value1], [key2, value2]]`.
*
* @static
* @memberOf _
* @category Objects
* @param {Object} object The object to inspect.
* @returns {Array} Returns new array of key-value pairs.
* @example
*
* _.pairs({ 'barney': 36, 'fred': 40 });
* // => [['barney', 36], ['fred', 40]] (property order is not guaranteed across environments)
*/
function pairs(object) {
var index = -1,
props = keys(object),
length = props.length,
result = Array(length);
while (++index < length) {
var key = props[index];
result[index] = [key, object[key]];
}
return result;
}
/**
* Creates a shallow clone of `object` composed of the specified properties.
* Property names may be specified as individual arguments or as arrays of
* property names. If a callback is provided it will be executed for each
* property of `object` picking the properties the callback returns truey
* for. The callback is bound to `thisArg` and invoked with three arguments;
* (value, key, object).
*
* @static
* @memberOf _
* @category Objects
* @param {Object} object The source object.
* @param {Function|...string|string[]} [callback] The function called per
* iteration or property names to pick, specified as individual property
* names or arrays of property names.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {Object} Returns an object composed of the picked properties.
* @example
*
* _.pick({ 'name': 'fred', '_userid': 'fred1' }, 'name');
* // => { 'name': 'fred' }
*
* _.pick({ 'name': 'fred', '_userid': 'fred1' }, function(value, key) {
* return key.charAt(0) != '_';
* });
* // => { 'name': 'fred' }
*/
function pick(object, callback, thisArg) {
var result = {};
if (typeof callback != 'function') {
var index = -1,
props = baseFlatten(arguments, true, false, 1),
length = isObject(object) ? props.length : 0;
while (++index < length) {
var key = props[index];
if (key in object) {
result[key] = object[key];
}
}
} else {
callback = lodash.createCallback(callback, thisArg, 3);
forIn(object, function(value, key, object) {
if (callback(value, key, object)) {
result[key] = value;
}
});
}
return result;
}
/**
* An alternative to `_.reduce` this method transforms `object` to a new
* `accumulator` object which is the result of running each of its own
* enumerable properties through a callback, with each callback execution
* potentially mutating the `accumulator` object. The callback is bound to
* `thisArg` and invoked with four arguments; (accumulator, value, key, object).
* Callbacks may exit iteration early by explicitly returning `false`.
*
* @static
* @memberOf _
* @category Objects
* @param {Array|Object} object The object to iterate over.
* @param {Function} [callback=identity] The function called per iteration.
* @param {*} [accumulator] The custom accumulator value.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {*} Returns the accumulated value.
* @example
*
* var squares = _.transform([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], function(result, num) {
* num *= num;
* if (num % 2) {
* return result.push(num) < 3;
* }
* });
* // => [1, 9, 25]
*
* var mapped = _.transform({ 'a': 1, 'b': 2, 'c': 3 }, function(result, num, key) {
* result[key] = num * 3;
* });
* // => { 'a': 3, 'b': 6, 'c': 9 }
*/
function transform(object, callback, accumulator, thisArg) {
var isArr = isArray(object);
if (accumulator == null) {
if (isArr) {
accumulator = [];
} else {
var ctor = object && object.constructor,
proto = ctor && ctor.prototype;
accumulator = baseCreate(proto);
}
}
if (callback) {
callback = lodash.createCallback(callback, thisArg, 4);
(isArr ? baseEach : forOwn)(object, function(value, index, object) {
return callback(accumulator, value, index, object);
});
}
return accumulator;
}
/**
* Creates an array composed of the own enumerable property values of `object`.
*
* @static
* @memberOf _
* @category Objects
* @param {Object} object The object to inspect.
* @returns {Array} Returns an array of property values.
* @example
*
* _.values({ 'one': 1, 'two': 2, 'three': 3 });
* // => [1, 2, 3] (property order is not guaranteed across environments)
*/
function values(object) {
var index = -1,
props = keys(object),
length = props.length,
result = Array(length);
while (++index < length) {
result[index] = object[props[index]];
}
return result;
}
/*--------------------------------------------------------------------------*/
/**
* Creates an array of elements from the specified indexes, or keys, of the
* `collection`. Indexes may be specified as individual arguments or as arrays
* of indexes.
*
* @static
* @memberOf _
* @category Collections
* @param {Array|Object|string} collection The collection to iterate over.
* @param {...(number|number[]|string|string[])} [index] The indexes of `collection`
* to retrieve, specified as individual indexes or arrays of indexes.
* @returns {Array} Returns a new array of elements corresponding to the
* provided indexes.
* @example
*
* _.at(['a', 'b', 'c', 'd', 'e'], [0, 2, 4]);
* // => ['a', 'c', 'e']
*
* _.at(['fred', 'barney', 'pebbles'], 0, 2);
* // => ['fred', 'pebbles']
*/
function at(collection) {
var args = arguments,
index = -1,
props = baseFlatten(args, true, false, 1),
length = (args[2] && args[2][args[1]] === collection) ? 1 : props.length,
result = Array(length);
if (support.unindexedChars && isString(collection)) {
collection = collection.split('');
}
while(++index < length) {
result[index] = collection[props[index]];
}
return result;
}
/**
* Checks if a given value is present in a collection using strict equality
* for comparisons, i.e. `===`. If `fromIndex` is negative, it is used as the
* offset from the end of the collection.
*
* @static
* @memberOf _
* @alias include
* @category Collections
* @param {Array|Object|string} collection The collection to iterate over.
* @param {*} target The value to check for.
* @param {number} [fromIndex=0] The index to search from.
* @returns {boolean} Returns `true` if the `target` element is found, else `false`.
* @example
*
* _.contains([1, 2, 3], 1);
* // => true
*
* _.contains([1, 2, 3], 1, 2);
* // => false
*
* _.contains({ 'name': 'fred', 'age': 40 }, 'fred');
* // => true
*
* _.contains('pebbles', 'eb');
* // => true
*/
function contains(collection, target, fromIndex) {
var index = -1,
indexOf = getIndexOf(),
length = collection ? collection.length : 0,
result = false;
fromIndex = (fromIndex < 0 ? nativeMax(0, length + fromIndex) : fromIndex) || 0;
if (isArray(collection)) {
result = indexOf(collection, target, fromIndex) > -1;
} else if (typeof length == 'number') {
result = (isString(collection) ? collection.indexOf(target, fromIndex) : indexOf(collection, target, fromIndex)) > -1;
} else {
baseEach(collection, function(value) {
if (++index >= fromIndex) {
return !(result = value === target);
}
});
}
return result;
}
/**
* Creates an object composed of keys generated from the results of running
* each element of `collection` through the callback. The corresponding value
* of each key is the number of times the key was returned by the callback.
* The callback is bound to `thisArg` and invoked with three arguments;
* (value, index|key, collection).
*
* If a property name is provided for `callback` the created "_.pluck" style
* callback will return the property value of the given element.
*
* If an object is provided for `callback` the created "_.where" style callback
* will return `true` for elements that have the properties of the given object,
* else `false`.
*
* @static
* @memberOf _
* @category Collections
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [callback=identity] The function called
* per iteration. If a property name or object is provided it will be used
* to create a "_.pluck" or "_.where" style callback, respectively.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {Object} Returns the composed aggregate object.
* @example
*
* _.countBy([4.3, 6.1, 6.4], function(num) { return Math.floor(num); });
* // => { '4': 1, '6': 2 }
*
* _.countBy([4.3, 6.1, 6.4], function(num) { return this.floor(num); }, Math);
* // => { '4': 1, '6': 2 }
*
* _.countBy(['one', 'two', 'three'], 'length');
* // => { '3': 2, '5': 1 }
*/
var countBy = createAggregator(function(result, value, key) {
(hasOwnProperty.call(result, key) ? result[key]++ : result[key] = 1);
});
/**
* Checks if the given callback returns truey value for **all** elements of
* a collection. The callback is bound to `thisArg` and invoked with three
* arguments; (value, index|key, collection).
*
* If a property name is provided for `callback` the created "_.pluck" style
* callback will return the property value of the given element.
*
* If an object is provided for `callback` the created "_.where" style callback
* will return `true` for elements that have the properties of the given object,
* else `false`.
*
* @static
* @memberOf _
* @alias all
* @category Collections
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [callback=identity] The function called
* per iteration. If a property name or object is provided it will be used
* to create a "_.pluck" or "_.where" style callback, respectively.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {boolean} Returns `true` if all elements passed the callback check,
* else `false`.
* @example
*
* _.every([true, 1, null, 'yes']);
* // => false
*
* var characters = [
* { 'name': 'barney', 'age': 36 },
* { 'name': 'fred', 'age': 40 }
* ];
*
* // using "_.pluck" callback shorthand
* _.every(characters, 'age');
* // => true
*
* // using "_.where" callback shorthand
* _.every(characters, { 'age': 36 });
* // => false
*/
function every(collection, callback, thisArg) {
var result = true;
callback = lodash.createCallback(callback, thisArg, 3);
if (isArray(collection)) {
var index = -1,
length = collection.length;
while (++index < length) {
if (!(result = !!callback(collection[index], index, collection))) {
break;
}
}
} else {
baseEach(collection, function(value, index, collection) {
return (result = !!callback(value, index, collection));
});
}
return result;
}
/**
* Iterates over elements of a collection, returning an array of all elements
* the callback returns truey for. The callback is bound to `thisArg` and
* invoked with three arguments; (value, index|key, collection).
*
* If a property name is provided for `callback` the created "_.pluck" style
* callback will return the property value of the given element.
*
* If an object is provided for `callback` the created "_.where" style callback
* will return `true` for elements that have the properties of the given object,
* else `false`.
*
* @static
* @memberOf _
* @alias select
* @category Collections
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [callback=identity] The function called
* per iteration. If a property name or object is provided it will be used
* to create a "_.pluck" or "_.where" style callback, respectively.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {Array} Returns a new array of elements that passed the callback check.
* @example
*
* var evens = _.filter([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; });
* // => [2, 4, 6]
*
* var characters = [
* { 'name': 'barney', 'age': 36, 'blocked': false },
* { 'name': 'fred', 'age': 40, 'blocked': true }
* ];
*
* // using "_.pluck" callback shorthand
* _.filter(characters, 'blocked');
* // => [{ 'name': 'fred', 'age': 40, 'blocked': true }]
*
* // using "_.where" callback shorthand
* _.filter(characters, { 'age': 36 });
* // => [{ 'name': 'barney', 'age': 36, 'blocked': false }]
*/
function filter(collection, callback, thisArg) {
var result = [];
callback = lodash.createCallback(callback, thisArg, 3);
if (isArray(collection)) {
var index = -1,
length = collection.length;
while (++index < length) {
var value = collection[index];
if (callback(value, index, collection)) {
result.push(value);
}
}
} else {
baseEach(collection, function(value, index, collection) {
if (callback(value, index, collection)) {
result.push(value);
}
});
}
return result;
}
/**
* Iterates over elements of a collection, returning the first element that
* the callback returns truey for. The callback is bound to `thisArg` and
* invoked with three arguments; (value, index|key, collection).
*
* If a property name is provided for `callback` the created "_.pluck" style
* callback will return the property value of the given element.
*
* If an object is provided for `callback` the created "_.where" style callback
* will return `true` for elements that have the properties of the given object,
* else `false`.
*
* @static
* @memberOf _
* @alias detect, findWhere
* @category Collections
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [callback=identity] The function called
* per iteration. If a property name or object is provided it will be used
* to create a "_.pluck" or "_.where" style callback, respectively.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {*} Returns the found element, else `undefined`.
* @example
*
* var characters = [
* { 'name': 'barney', 'age': 36, 'blocked': false },
* { 'name': 'fred', 'age': 40, 'blocked': true },
* { 'name': 'pebbles', 'age': 1, 'blocked': false }
* ];
*
* _.find(characters, function(chr) {
* return chr.age < 40;
* });
* // => { 'name': 'barney', 'age': 36, 'blocked': false }
*
* // using "_.where" callback shorthand
* _.find(characters, { 'age': 1 });
* // => { 'name': 'pebbles', 'age': 1, 'blocked': false }
*
* // using "_.pluck" callback shorthand
* _.find(characters, 'blocked');
* // => { 'name': 'fred', 'age': 40, 'blocked': true }
*/
function find(collection, callback, thisArg) {
callback = lodash.createCallback(callback, thisArg, 3);
if (isArray(collection)) {
var index = -1,
length = collection.length;
while (++index < length) {
var value = collection[index];
if (callback(value, index, collection)) {
return value;
}
}
} else {
var result;
baseEach(collection, function(value, index, collection) {
if (callback(value, index, collection)) {
result = value;
return false;
}
});
return result;
}
}
/**
* This method is like `_.find` except that it iterates over elements
* of a `collection` from right to left.
*
* @static
* @memberOf _
* @category Collections
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [callback=identity] The function called
* per iteration. If a property name or object is provided it will be used
* to create a "_.pluck" or "_.where" style callback, respectively.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {*} Returns the found element, else `undefined`.
* @example
*
* _.findLast([1, 2, 3, 4], function(num) {
* return num % 2 == 1;
* });
* // => 3
*/
function findLast(collection, callback, thisArg) {
var result;
callback = lodash.createCallback(callback, thisArg, 3);
forEachRight(collection, function(value, index, collection) {
if (callback(value, index, collection)) {
result = value;
return false;
}
});
return result;
}
/**
* Iterates over elements of a collection, executing the callback for each
* element. The callback is bound to `thisArg` and invoked with three arguments;
* (value, index|key, collection). Callbacks may exit iteration early by
* explicitly returning `false`.
*
* Note: As with other "Collections" methods, objects with a `length` property
* are iterated like arrays. To avoid this behavior `_.forIn` or `_.forOwn`
* may be used for object iteration.
*
* @static
* @memberOf _
* @alias each
* @category Collections
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function} [callback=identity] The function called per iteration.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {Array|Object|string} Returns `collection`.
* @example
*
* _([1, 2, 3]).forEach(function(num) { console.log(num); }).join(',');
* // => logs each number and returns '1,2,3'
*
* _.forEach({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { console.log(num); });
* // => logs each number and returns the object (property order is not guaranteed across environments)
*/
function forEach(collection, callback, thisArg) {
if (callback && typeof thisArg == 'undefined' && isArray(collection)) {
var index = -1,
length = collection.length;
while (++index < length) {
if (callback(collection[index], index, collection) === false) {
break;
}
}
} else {
baseEach(collection, callback, thisArg);
}
return collection;
}
/**
* This method is like `_.forEach` except that it iterates over elements
* of a `collection` from right to left.
*
* @static
* @memberOf _
* @alias eachRight
* @category Collections
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function} [callback=identity] The function called per iteration.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {Array|Object|string} Returns `collection`.
* @example
*
* _([1, 2, 3]).forEachRight(function(num) { console.log(num); }).join(',');
* // => logs each number from right to left and returns '3,2,1'
*/
function forEachRight(collection, callback, thisArg) {
var iterable = collection,
length = collection ? collection.length : 0;
callback = callback && typeof thisArg == 'undefined' ? callback : baseCreateCallback(callback, thisArg, 3);
if (isArray(collection)) {
while (length--) {
if (callback(collection[length], length, collection) === false) {
break;
}
}
} else {
if (typeof length != 'number') {
var props = keys(collection);
length = props.length;
} else if (support.unindexedChars && isString(collection)) {
iterable = collection.split('');
}
baseEach(collection, function(value, key, collection) {
key = props ? props[--length] : --length;
return callback(iterable[key], key, collection);
});
}
return collection;
}
/**
* Creates an object composed of keys generated from the results of running
* each element of a collection through the callback. The corresponding value
* of each key is an array of the elements responsible for generating the key.
* The callback is bound to `thisArg` and invoked with three arguments;
* (value, index|key, collection).
*
* If a property name is provided for `callback` the created "_.pluck" style
* callback will return the property value of the given element.
*
* If an object is provided for `callback` the created "_.where" style callback
* will return `true` for elements that have the properties of the given object,
* else `false`
*
* @static
* @memberOf _
* @category Collections
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [callback=identity] The function called
* per iteration. If a property name or object is provided it will be used
* to create a "_.pluck" or "_.where" style callback, respectively.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {Object} Returns the composed aggregate object.
* @example
*
* _.groupBy([4.2, 6.1, 6.4], function(num) { return Math.floor(num); });
* // => { '4': [4.2], '6': [6.1, 6.4] }
*
* _.groupBy([4.2, 6.1, 6.4], function(num) { return this.floor(num); }, Math);
* // => { '4': [4.2], '6': [6.1, 6.4] }
*
* // using "_.pluck" callback shorthand
* _.groupBy(['one', 'two', 'three'], 'length');
* // => { '3': ['one', 'two'], '5': ['three'] }
*/
var groupBy = createAggregator(function(result, value, key) {
(hasOwnProperty.call(result, key) ? result[key] : result[key] = []).push(value);
});
/**
* Creates an object composed of keys generated from the results of running
* each element of the collection through the given callback. The corresponding
* value of each key is the last element responsible for generating the key.
* The callback is bound to `thisArg` and invoked with three arguments;
* (value, index|key, collection).
*
* If a property name is provided for `callback` the created "_.pluck" style
* callback will return the property value of the given element.
*
* If an object is provided for `callback` the created "_.where" style callback
* will return `true` for elements that have the properties of the given object,
* else `false`.
*
* @static
* @memberOf _
* @category Collections
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [callback=identity] The function called
* per iteration. If a property name or object is provided it will be used
* to create a "_.pluck" or "_.where" style callback, respectively.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {Object} Returns the composed aggregate object.
* @example
*
* var keys = [
* { 'dir': 'left', 'code': 97 },
* { 'dir': 'right', 'code': 100 }
* ];
*
* _.indexBy(keys, 'dir');
* // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
*
* _.indexBy(keys, function(key) { return String.fromCharCode(key.code); });
* // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
*
* _.indexBy(characters, function(key) { this.fromCharCode(key.code); }, String);
* // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
*/
var indexBy = createAggregator(function(result, value, key) {
result[key] = value;
});
/**
* Invokes the method named by `methodName` on each element in the `collection`
* returning an array of the results of each invoked method. Additional arguments
* will be provided to each invoked method. If `methodName` is a function it
* will be invoked for, and `this` bound to, each element in the `collection`.
*
* @static
* @memberOf _
* @category Collections
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|string} methodName The name of the method to invoke or
* the function invoked per iteration.
* @param {...*} [arg] Arguments to invoke the method with.
* @returns {Array} Returns a new array of the results of each invoked method.
* @example
*
* _.invoke([[5, 1, 7], [3, 2, 1]], 'sort');
* // => [[1, 5, 7], [1, 2, 3]]
*
* _.invoke([123, 456], String.prototype.split, '');
* // => [['1', '2', '3'], ['4', '5', '6']]
*/
function invoke(collection, methodName) {
var args = slice(arguments, 2),
index = -1,
isFunc = typeof methodName == 'function',
length = collection ? collection.length : 0,
result = Array(typeof length == 'number' ? length : 0);
forEach(collection, function(value) {
result[++index] = (isFunc ? methodName : value[methodName]).apply(value, args);
});
return result;
}
/**
* Creates an array of values by running each element in the collection
* through the callback. The callback is bound to `thisArg` and invoked with
* three arguments; (value, index|key, collection).
*
* If a property name is provided for `callback` the created "_.pluck" style
* callback will return the property value of the given element.
*
* If an object is provided for `callback` the created "_.where" style callback
* will return `true` for elements that have the properties of the given object,
* else `false`.
*
* @static
* @memberOf _
* @alias collect
* @category Collections
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [callback=identity] The function called
* per iteration. If a property name or object is provided it will be used
* to create a "_.pluck" or "_.where" style callback, respectively.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {Array} Returns a new array of the results of each `callback` execution.
* @example
*
* _.map([1, 2, 3], function(num) { return num * 3; });
* // => [3, 6, 9]
*
* _.map({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { return num * 3; });
* // => [3, 6, 9] (property order is not guaranteed across environments)
*
* var characters = [
* { 'name': 'barney', 'age': 36 },
* { 'name': 'fred', 'age': 40 }
* ];
*
* // using "_.pluck" callback shorthand
* _.map(characters, 'name');
* // => ['barney', 'fred']
*/
function map(collection, callback, thisArg) {
var index = -1,
length = collection ? collection.length : 0,
result = Array(typeof length == 'number' ? length : 0);
callback = lodash.createCallback(callback, thisArg, 3);
if (isArray(collection)) {
while (++index < length) {
result[index] = callback(collection[index], index, collection);
}
} else {
baseEach(collection, function(value, key, collection) {
result[++index] = callback(value, key, collection);
});
}
return result;
}
/**
* Retrieves the maximum value of a collection. If the collection is empty or
* falsey `-Infinity` is returned. If a callback is provided it will be executed
* for each value in the collection to generate the criterion by which the value
* is ranked. The callback is bound to `thisArg` and invoked with three
* arguments; (value, index, collection).
*
* If a property name is provided for `callback` the created "_.pluck" style
* callback will return the property value of the given element.
*
* If an object is provided for `callback` the created "_.where" style callback
* will return `true` for elements that have the properties of the given object,
* else `false`.
*
* @static
* @memberOf _
* @category Collections
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [callback=identity] The function called
* per iteration. If a property name or object is provided it will be used
* to create a "_.pluck" or "_.where" style callback, respectively.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {*} Returns the maximum value.
* @example
*
* _.max([4, 2, 8, 6]);
* // => 8
*
* var characters = [
* { 'name': 'barney', 'age': 36 },
* { 'name': 'fred', 'age': 40 }
* ];
*
* _.max(characters, function(chr) { return chr.age; });
* // => { 'name': 'fred', 'age': 40 };
*
* // using "_.pluck" callback shorthand
* _.max(characters, 'age');
* // => { 'name': 'fred', 'age': 40 };
*/
function max(collection, callback, thisArg) {
var computed = -Infinity,
result = computed;
// allows working with functions like `_.map` without using
// their `index` argument as a callback
if (typeof callback != 'function' && thisArg && thisArg[callback] === collection) {
callback = null;
}
if (callback == null && isArray(collection)) {
var index = -1,
length = collection.length;
while (++index < length) {
var value = collection[index];
if (value > result) {
result = value;
}
}
} else {
callback = (callback == null && isString(collection))
? charAtCallback
: lodash.createCallback(callback, thisArg, 3);
baseEach(collection, function(value, index, collection) {
var current = callback(value, index, collection);
if (current > computed) {
computed = current;
result = value;
}
});
}
return result;
}
/**
* Retrieves the minimum value of a collection. If the collection is empty or
* falsey `Infinity` is returned. If a callback is provided it will be executed
* for each value in the collection to generate the criterion by which the value
* is ranked. The callback is bound to `thisArg` and invoked with three
* arguments; (value, index, collection).
*
* If a property name is provided for `callback` the created "_.pluck" style
* callback will return the property value of the given element.
*
* If an object is provided for `callback` the created "_.where" style callback
* will return `true` for elements that have the properties of the given object,
* else `false`.
*
* @static
* @memberOf _
* @category Collections
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [callback=identity] The function called
* per iteration. If a property name or object is provided it will be used
* to create a "_.pluck" or "_.where" style callback, respectively.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {*} Returns the minimum value.
* @example
*
* _.min([4, 2, 8, 6]);
* // => 2
*
* var characters = [
* { 'name': 'barney', 'age': 36 },
* { 'name': 'fred', 'age': 40 }
* ];
*
* _.min(characters, function(chr) { return chr.age; });
* // => { 'name': 'barney', 'age': 36 };
*
* // using "_.pluck" callback shorthand
* _.min(characters, 'age');
* // => { 'name': 'barney', 'age': 36 };
*/
function min(collection, callback, thisArg) {
var computed = Infinity,
result = computed;
// allows working with functions like `_.map` without using
// their `index` argument as a callback
if (typeof callback != 'function' && thisArg && thisArg[callback] === collection) {
callback = null;
}
if (callback == null && isArray(collection)) {
var index = -1,
length = collection.length;
while (++index < length) {
var value = collection[index];
if (value < result) {
result = value;
}
}
} else {
callback = (callback == null && isString(collection))
? charAtCallback
: lodash.createCallback(callback, thisArg, 3);
baseEach(collection, function(value, index, collection) {
var current = callback(value, index, collection);
if (current < computed) {
computed = current;
result = value;
}
});
}
return result;
}
/**
* Retrieves the value of a specified property from all elements in the collection.
*
* @static
* @memberOf _
* @type Function
* @category Collections
* @param {Array|Object|string} collection The collection to iterate over.
* @param {string} property The name of the property to pluck.
* @returns {Array} Returns a new array of property values.
* @example
*
* var characters = [
* { 'name': 'barney', 'age': 36 },
* { 'name': 'fred', 'age': 40 }
* ];
*
* _.pluck(characters, 'name');
* // => ['barney', 'fred']
*/
var pluck = map;
/**
* Reduces a collection to a value which is the accumulated result of running
* each element in the collection through the callback, where each successive
* callback execution consumes the return value of the previous execution. If
* `accumulator` is not provided the first element of the collection will be
* used as the initial `accumulator` value. The callback is bound to `thisArg`
* and invoked with four arguments; (accumulator, value, index|key, collection).
*
* @static
* @memberOf _
* @alias foldl, inject
* @category Collections
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function} [callback=identity] The function called per iteration.
* @param {*} [accumulator] Initial value of the accumulator.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {*} Returns the accumulated value.
* @example
*
* var sum = _.reduce([1, 2, 3], function(sum, num) {
* return sum + num;
* });
* // => 6
*
* var mapped = _.reduce({ 'a': 1, 'b': 2, 'c': 3 }, function(result, num, key) {
* result[key] = num * 3;
* return result;
* }, {});
* // => { 'a': 3, 'b': 6, 'c': 9 }
*/
function reduce(collection, callback, accumulator, thisArg) {
var noaccum = arguments.length < 3;
callback = lodash.createCallback(callback, thisArg, 4);
if (isArray(collection)) {
var index = -1,
length = collection.length;
if (noaccum) {
accumulator = collection[++index];
}
while (++index < length) {
accumulator = callback(accumulator, collection[index], index, collection);
}
} else {
baseEach(collection, function(value, index, collection) {
accumulator = noaccum
? (noaccum = false, value)
: callback(accumulator, value, index, collection)
});
}
return accumulator;
}
/**
* This method is like `_.reduce` except that it iterates over elements
* of a `collection` from right to left.
*
* @static
* @memberOf _
* @alias foldr
* @category Collections
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function} [callback=identity] The function called per iteration.
* @param {*} [accumulator] Initial value of the accumulator.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {*} Returns the accumulated value.
* @example
*
* var list = [[0, 1], [2, 3], [4, 5]];
* var flat = _.reduceRight(list, function(a, b) { return a.concat(b); }, []);
* // => [4, 5, 2, 3, 0, 1]
*/
function reduceRight(collection, callback, accumulator, thisArg) {
var noaccum = arguments.length < 3;
callback = lodash.createCallback(callback, thisArg, 4);
forEachRight(collection, function(value, index, collection) {
accumulator = noaccum
? (noaccum = false, value)
: callback(accumulator, value, index, collection);
});
return accumulator;
}
/**
* The opposite of `_.filter` this method returns the elements of a
* collection that the callback does **not** return truey for.
*
* If a property name is provided for `callback` the created "_.pluck" style
* callback will return the property value of the given element.
*
* If an object is provided for `callback` the created "_.where" style callback
* will return `true` for elements that have the properties of the given object,
* else `false`.
*
* @static
* @memberOf _
* @category Collections
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [callback=identity] The function called
* per iteration. If a property name or object is provided it will be used
* to create a "_.pluck" or "_.where" style callback, respectively.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {Array} Returns a new array of elements that failed the callback check.
* @example
*
* var odds = _.reject([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; });
* // => [1, 3, 5]
*
* var characters = [
* { 'name': 'barney', 'age': 36, 'blocked': false },
* { 'name': 'fred', 'age': 40, 'blocked': true }
* ];
*
* // using "_.pluck" callback shorthand
* _.reject(characters, 'blocked');
* // => [{ 'name': 'barney', 'age': 36, 'blocked': false }]
*
* // using "_.where" callback shorthand
* _.reject(characters, { 'age': 36 });
* // => [{ 'name': 'fred', 'age': 40, 'blocked': true }]
*/
function reject(collection, callback, thisArg) {
callback = lodash.createCallback(callback, thisArg, 3);
return filter(collection, function(value, index, collection) {
return !callback(value, index, collection);
});
}
/**
* Retrieves a random element or `n` random elements from a collection.
*
* @static
* @memberOf _
* @category Collections
* @param {Array|Object|string} collection The collection to sample.
* @param {number} [n] The number of elements to sample.
* @param- {Object} [guard] Allows working with functions like `_.map`
* without using their `index` arguments as `n`.
* @returns {Array} Returns the random sample(s) of `collection`.
* @example
*
* _.sample([1, 2, 3, 4]);
* // => 2
*
* _.sample([1, 2, 3, 4], 2);
* // => [3, 1]
*/
function sample(collection, n, guard) {
if (collection && typeof collection.length != 'number') {
collection = values(collection);
} else if (support.unindexedChars && isString(collection)) {
collection = collection.split('');
}
if (n == null || guard) {
return collection ? collection[baseRandom(0, collection.length - 1)] : undefined;
}
var result = shuffle(collection);
result.length = nativeMin(nativeMax(0, n), result.length);
return result;
}
/**
* Creates an array of shuffled values, using a version of the Fisher-Yates
* shuffle. See http://en.wikipedia.org/wiki/Fisher-Yates_shuffle.
*
* @static
* @memberOf _
* @category Collections
* @param {Array|Object|string} collection The collection to shuffle.
* @returns {Array} Returns a new shuffled collection.
* @example
*
* _.shuffle([1, 2, 3, 4, 5, 6]);
* // => [4, 1, 6, 3, 5, 2]
*/
function shuffle(collection) {
var index = -1,
length = collection ? collection.length : 0,
result = Array(typeof length == 'number' ? length : 0);
forEach(collection, function(value) {
var rand = baseRandom(0, ++index);
result[index] = result[rand];
result[rand] = value;
});
return result;
}
/**
* Gets the size of the `collection` by returning `collection.length` for arrays
* and array-like objects or the number of own enumerable properties for objects.
*
* @static
* @memberOf _
* @category Collections
* @param {Array|Object|string} collection The collection to inspect.
* @returns {number} Returns `collection.length` or number of own enumerable properties.
* @example
*
* _.size([1, 2]);
* // => 2
*
* _.size({ 'one': 1, 'two': 2, 'three': 3 });
* // => 3
*
* _.size('pebbles');
* // => 7
*/
function size(collection) {
var length = collection ? collection.length : 0;
return typeof length == 'number' ? length : keys(collection).length;
}
/**
* Checks if the callback returns a truey value for **any** element of a
* collection. The function returns as soon as it finds a passing value and
* does not iterate over the entire collection. The callback is bound to
* `thisArg` and invoked with three arguments; (value, index|key, collection).
*
* If a property name is provided for `callback` the created "_.pluck" style
* callback will return the property value of the given element.
*
* If an object is provided for `callback` the created "_.where" style callback
* will return `true` for elements that have the properties of the given object,
* else `false`.
*
* @static
* @memberOf _
* @alias any
* @category Collections
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Function|Object|string} [callback=identity] The function called
* per iteration. If a property name or object is provided it will be used
* to create a "_.pluck" or "_.where" style callback, respectively.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {boolean} Returns `true` if any element passed the callback check,
* else `false`.
* @example
*
* _.some([null, 0, 'yes', false], Boolean);
* // => true
*
* var characters = [
* { 'name': 'barney', 'age': 36, 'blocked': false },
* { 'name': 'fred', 'age': 40, 'blocked': true }
* ];
*
* // using "_.pluck" callback shorthand
* _.some(characters, 'blocked');
* // => true
*
* // using "_.where" callback shorthand
* _.some(characters, { 'age': 1 });
* // => false
*/
function some(collection, callback, thisArg) {
var result;
callback = lodash.createCallback(callback, thisArg, 3);
if (isArray(collection)) {
var index = -1,
length = collection.length;
while (++index < length) {
if ((result = callback(collection[index], index, collection))) {
break;
}
}
} else {
baseEach(collection, function(value, index, collection) {
return !(result = callback(value, index, collection));
});
}
return !!result;
}
/**
* Creates an array of elements, sorted in ascending order by the results of
* running each element in a collection through the callback. This method
* performs a stable sort, that is, it will preserve the original sort order
* of equal elements. The callback is bound to `thisArg` and invoked with
* three arguments; (value, index|key, collection).
*
* If a property name is provided for `callback` the created "_.pluck" style
* callback will return the property value of the given element.
*
* If an array of property names is provided for `callback` the collection
* will be sorted by each property value.
*
* If an object is provided for `callback` the created "_.where" style callback
* will return `true` for elements that have the properties of the given object,
* else `false`.
*
* @static
* @memberOf _
* @category Collections
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Array|Function|Object|string} [callback=identity] The function called
* per iteration. If a property name or object is provided it will be used
* to create a "_.pluck" or "_.where" style callback, respectively.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {Array} Returns a new array of sorted elements.
* @example
*
* _.sortBy([1, 2, 3], function(num) { return Math.sin(num); });
* // => [3, 1, 2]
*
* _.sortBy([1, 2, 3], function(num) { return this.sin(num); }, Math);
* // => [3, 1, 2]
*
* var characters = [
* { 'name': 'barney', 'age': 36 },
* { 'name': 'fred', 'age': 40 },
* { 'name': 'barney', 'age': 26 },
* { 'name': 'fred', 'age': 30 }
* ];
*
* // using "_.pluck" callback shorthand
* _.map(_.sortBy(characters, 'age'), _.values);
* // => [['barney', 26], ['fred', 30], ['barney', 36], ['fred', 40]]
*
* // sorting by multiple properties
* _.map(_.sortBy(characters, ['name', 'age']), _.values);
* // = > [['barney', 26], ['barney', 36], ['fred', 30], ['fred', 40]]
*/
function sortBy(collection, callback, thisArg) {
var index = -1,
isArr = isArray(callback),
length = collection ? collection.length : 0,
result = Array(typeof length == 'number' ? length : 0);
if (!isArr) {
callback = lodash.createCallback(callback, thisArg, 3);
}
forEach(collection, function(value, key, collection) {
var object = result[++index] = getObject();
if (isArr) {
object.criteria = map(callback, function(key) { return value[key]; });
} else {
(object.criteria = getArray())[0] = callback(value, key, collection);
}
object.index = index;
object.value = value;
});
length = result.length;
result.sort(compareAscending);
while (length--) {
var object = result[length];
result[length] = object.value;
if (!isArr) {
releaseArray(object.criteria);
}
releaseObject(object);
}
return result;
}
/**
* Converts the `collection` to an array.
*
* @static
* @memberOf _
* @category Collections
* @param {Array|Object|string} collection The collection to convert.
* @returns {Array} Returns the new converted array.
* @example
*
* (function() { return _.toArray(arguments).slice(1); })(1, 2, 3, 4);
* // => [2, 3, 4]
*/
function toArray(collection) {
if (collection && typeof collection.length == 'number') {
return (support.unindexedChars && isString(collection))
? collection.split('')
: slice(collection);
}
return values(collection);
}
/**
* Performs a deep comparison of each element in a `collection` to the given
* `properties` object, returning an array of all elements that have equivalent
* property values.
*
* @static
* @memberOf _
* @type Function
* @category Collections
* @param {Array|Object|string} collection The collection to iterate over.
* @param {Object} props The object of property values to filter by.
* @returns {Array} Returns a new array of elements that have the given properties.
* @example
*
* var characters = [
* { 'name': 'barney', 'age': 36, 'pets': ['hoppy'] },
* { 'name': 'fred', 'age': 40, 'pets': ['baby puss', 'dino'] }
* ];
*
* _.where(characters, { 'age': 36 });
* // => [{ 'name': 'barney', 'age': 36, 'pets': ['hoppy'] }]
*
* _.where(characters, { 'pets': ['dino'] });
* // => [{ 'name': 'fred', 'age': 40, 'pets': ['baby puss', 'dino'] }]
*/
var where = filter;
/*--------------------------------------------------------------------------*/
/**
* Creates an array with all falsey values removed. The values `false`, `null`,
* `0`, `""`, `undefined`, and `NaN` are all falsey.
*
* @static
* @memberOf _
* @category Arrays
* @param {Array} array The array to compact.
* @returns {Array} Returns a new array of filtered values.
* @example
*
* _.compact([0, 1, false, 2, '', 3]);
* // => [1, 2, 3]
*/
function compact(array) {
var index = -1,
length = array ? array.length : 0,
result = [];
while (++index < length) {
var value = array[index];
if (value) {
result.push(value);
}
}
return result;
}
/**
* Creates an array excluding all values of the provided arrays using strict
* equality for comparisons, i.e. `===`.
*
* @static
* @memberOf _
* @category Arrays
* @param {Array} array The array to process.
* @param {...Array} [values] The arrays of values to exclude.
* @returns {Array} Returns a new array of filtered values.
* @example
*
* _.difference([1, 2, 3, 4, 5], [5, 2, 10]);
* // => [1, 3, 4]
*/
function difference(array) {
return baseDifference(array, baseFlatten(arguments, true, true, 1));
}
/**
* This method is like `_.find` except that it returns the index of the first
* element that passes the callback check, instead of the element itself.
*
* If a property name is provided for `callback` the created "_.pluck" style
* callback will return the property value of the given element.
*
* If an object is provided for `callback` the created "_.where" style callback
* will return `true` for elements that have the properties of the given object,
* else `false`.
*
* @static
* @memberOf _
* @category Arrays
* @param {Array} array The array to search.
* @param {Function|Object|string} [callback=identity] The function called
* per iteration. If a property name or object is provided it will be used
* to create a "_.pluck" or "_.where" style callback, respectively.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {number} Returns the index of the found element, else `-1`.
* @example
*
* var characters = [
* { 'name': 'barney', 'age': 36, 'blocked': false },
* { 'name': 'fred', 'age': 40, 'blocked': true },
* { 'name': 'pebbles', 'age': 1, 'blocked': false }
* ];
*
* _.findIndex(characters, function(chr) {
* return chr.age < 20;
* });
* // => 2
*
* // using "_.where" callback shorthand
* _.findIndex(characters, { 'age': 36 });
* // => 0
*
* // using "_.pluck" callback shorthand
* _.findIndex(characters, 'blocked');
* // => 1
*/
function findIndex(array, callback, thisArg) {
var index = -1,
length = array ? array.length : 0;
callback = lodash.createCallback(callback, thisArg, 3);
while (++index < length) {
if (callback(array[index], index, array)) {
return index;
}
}
return -1;
}
/**
* This method is like `_.findIndex` except that it iterates over elements
* of a `collection` from right to left.
*
* If a property name is provided for `callback` the created "_.pluck" style
* callback will return the property value of the given element.
*
* If an object is provided for `callback` the created "_.where" style callback
* will return `true` for elements that have the properties of the given object,
* else `false`.
*
* @static
* @memberOf _
* @category Arrays
* @param {Array} array The array to search.
* @param {Function|Object|string} [callback=identity] The function called
* per iteration. If a property name or object is provided it will be used
* to create a "_.pluck" or "_.where" style callback, respectively.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {number} Returns the index of the found element, else `-1`.
* @example
*
* var characters = [
* { 'name': 'barney', 'age': 36, 'blocked': true },
* { 'name': 'fred', 'age': 40, 'blocked': false },
* { 'name': 'pebbles', 'age': 1, 'blocked': true }
* ];
*
* _.findLastIndex(characters, function(chr) {
* return chr.age > 30;
* });
* // => 1
*
* // using "_.where" callback shorthand
* _.findLastIndex(characters, { 'age': 36 });
* // => 0
*
* // using "_.pluck" callback shorthand
* _.findLastIndex(characters, 'blocked');
* // => 2
*/
function findLastIndex(array, callback, thisArg) {
var length = array ? array.length : 0;
callback = lodash.createCallback(callback, thisArg, 3);
while (length--) {
if (callback(array[length], length, array)) {
return length;
}
}
return -1;
}
/**
* Gets the first element or first `n` elements of an array. If a callback
* is provided elements at the beginning of the array are returned as long
* as the callback returns truey. The callback is bound to `thisArg` and
* invoked with three arguments; (value, index, array).
*
* If a property name is provided for `callback` the created "_.pluck" style
* callback will return the property value of the given element.
*
* If an object is provided for `callback` the created "_.where" style callback
* will return `true` for elements that have the properties of the given object,
* else `false`.
*
* @static
* @memberOf _
* @alias head, take
* @category Arrays
* @param {Array} array The array to query.
* @param {Function|Object|number|string} [callback] The function called
* per element or the number of elements to return. If a property name or
* object is provided it will be used to create a "_.pluck" or "_.where"
* style callback, respectively.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {*} Returns the first element(s) of `array`.
* @example
*
* _.first([1, 2, 3]);
* // => 1
*
* _.first([1, 2, 3], 2);
* // => [1, 2]
*
* _.first([1, 2, 3], function(num) {
* return num < 3;
* });
* // => [1, 2]
*
* var characters = [
* { 'name': 'barney', 'blocked': true, 'employer': 'slate' },
* { 'name': 'fred', 'blocked': false, 'employer': 'slate' },
* { 'name': 'pebbles', 'blocked': true, 'employer': 'na' }
* ];
*
* // using "_.pluck" callback shorthand
* _.first(characters, 'blocked');
* // => [{ 'name': 'barney', 'blocked': true, 'employer': 'slate' }]
*
* // using "_.where" callback shorthand
* _.pluck(_.first(characters, { 'employer': 'slate' }), 'name');
* // => ['barney', 'fred']
*/
function first(array, callback, thisArg) {
var n = 0,
length = array ? array.length : 0;
if (typeof callback != 'number' && callback != null) {
var index = -1;
callback = lodash.createCallback(callback, thisArg, 3);
while (++index < length && callback(array[index], index, array)) {
n++;
}
} else {
n = callback;
if (n == null || thisArg) {
return array ? array[0] : undefined;
}
}
return slice(array, 0, nativeMin(nativeMax(0, n), length));
}
/**
* Flattens a nested array (the nesting can be to any depth). If `isShallow`
* is truey, the array will only be flattened a single level. If a callback
* is provided each element of the array is passed through the callback before
* flattening. The callback is bound to `thisArg` and invoked with three
* arguments; (value, index, array).
*
* If a property name is provided for `callback` the created "_.pluck" style
* callback will return the property value of the given element.
*
* If an object is provided for `callback` the created "_.where" style callback
* will return `true` for elements that have the properties of the given object,
* else `false`.
*
* @static
* @memberOf _
* @category Arrays
* @param {Array} array The array to flatten.
* @param {boolean} [isShallow=false] A flag to restrict flattening to a single level.
* @param {Function|Object|string} [callback=identity] The function called
* per iteration. If a property name or object is provided it will be used
* to create a "_.pluck" or "_.where" style callback, respectively.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {Array} Returns a new flattened array.
* @example
*
* _.flatten([1, [2], [3, [[4]]]]);
* // => [1, 2, 3, 4];
*
* _.flatten([1, [2], [3, [[4]]]], true);
* // => [1, 2, 3, [[4]]];
*
* var characters = [
* { 'name': 'barney', 'age': 30, 'pets': ['hoppy'] },
* { 'name': 'fred', 'age': 40, 'pets': ['baby puss', 'dino'] }
* ];
*
* // using "_.pluck" callback shorthand
* _.flatten(characters, 'pets');
* // => ['hoppy', 'baby puss', 'dino']
*/
function flatten(array, isShallow, callback, thisArg) {
// juggle arguments
if (typeof isShallow != 'boolean' && isShallow != null) {
thisArg = callback;
callback = (typeof isShallow != 'function' && thisArg && thisArg[isShallow] === array) ? null : isShallow;
isShallow = false;
}
if (callback != null) {
array = map(array, callback, thisArg);
}
return baseFlatten(array, isShallow);
}
/**
* Gets the index at which the first occurrence of `value` is found using
* strict equality for comparisons, i.e. `===`. If the array is already sorted
* providing `true` for `fromIndex` will run a faster binary search.
*
* @static
* @memberOf _
* @category Arrays
* @param {Array} array The array to search.
* @param {*} value The value to search for.
* @param {boolean|number} [fromIndex=0] The index to search from or `true`
* to perform a binary search on a sorted array.
* @returns {number} Returns the index of the matched value or `-1`.
* @example
*
* _.indexOf([1, 2, 3, 1, 2, 3], 2);
* // => 1
*
* _.indexOf([1, 2, 3, 1, 2, 3], 2, 3);
* // => 4
*
* _.indexOf([1, 1, 2, 2, 3, 3], 2, true);
* // => 2
*/
function indexOf(array, value, fromIndex) {
if (typeof fromIndex == 'number') {
var length = array ? array.length : 0;
fromIndex = (fromIndex < 0 ? nativeMax(0, length + fromIndex) : fromIndex || 0);
} else if (fromIndex) {
var index = sortedIndex(array, value);
return array[index] === value ? index : -1;
}
return baseIndexOf(array, value, fromIndex);
}
/**
* Gets all but the last element or last `n` elements of an array. If a
* callback is provided elements at the end of the array are excluded from
* the result as long as the callback returns truey. The callback is bound
* to `thisArg` and invoked with three arguments; (value, index, array).
*
* If a property name is provided for `callback` the created "_.pluck" style
* callback will return the property value of the given element.
*
* If an object is provided for `callback` the created "_.where" style callback
* will return `true` for elements that have the properties of the given object,
* else `false`.
*
* @static
* @memberOf _
* @category Arrays
* @param {Array} array The array to query.
* @param {Function|Object|number|string} [callback=1] The function called
* per element or the number of elements to exclude. If a property name or
* object is provided it will be used to create a "_.pluck" or "_.where"
* style callback, respectively.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {Array} Returns a slice of `array`.
* @example
*
* _.initial([1, 2, 3]);
* // => [1, 2]
*
* _.initial([1, 2, 3], 2);
* // => [1]
*
* _.initial([1, 2, 3], function(num) {
* return num > 1;
* });
* // => [1]
*
* var characters = [
* { 'name': 'barney', 'blocked': false, 'employer': 'slate' },
* { 'name': 'fred', 'blocked': true, 'employer': 'slate' },
* { 'name': 'pebbles', 'blocked': true, 'employer': 'na' }
* ];
*
* // using "_.pluck" callback shorthand
* _.initial(characters, 'blocked');
* // => [{ 'name': 'barney', 'blocked': false, 'employer': 'slate' }]
*
* // using "_.where" callback shorthand
* _.pluck(_.initial(characters, { 'employer': 'na' }), 'name');
* // => ['barney', 'fred']
*/
function initial(array, callback, thisArg) {
var n = 0,
length = array ? array.length : 0;
if (typeof callback != 'number' && callback != null) {
var index = length;
callback = lodash.createCallback(callback, thisArg, 3);
while (index-- && callback(array[index], index, array)) {
n++;
}
} else {
n = (callback == null || thisArg) ? 1 : callback || n;
}
return slice(array, 0, nativeMin(nativeMax(0, length - n), length));
}
/**
* Creates an array of unique values present in all provided arrays using
* strict equality for comparisons, i.e. `===`.
*
* @static
* @memberOf _
* @category Arrays
* @param {...Array} [array] The arrays to inspect.
* @returns {Array} Returns an array of shared values.
* @example
*
* _.intersection([1, 2, 3], [5, 2, 1, 4], [2, 1]);
* // => [1, 2]
*/
function intersection() {
var args = [],
argsIndex = -1,
argsLength = arguments.length,
caches = getArray(),
indexOf = getIndexOf(),
trustIndexOf = indexOf === baseIndexOf,
seen = getArray();
while (++argsIndex < argsLength) {
var value = arguments[argsIndex];
if (isArray(value) || isArguments(value)) {
args.push(value);
caches.push(trustIndexOf && value.length >= largeArraySize &&
createCache(argsIndex ? args[argsIndex] : seen));
}
}
var array = args[0],
index = -1,
length = array ? array.length : 0,
result = [];
outer:
while (++index < length) {
var cache = caches[0];
value = array[index];
if ((cache ? cacheIndexOf(cache, value) : indexOf(seen, value)) < 0) {
argsIndex = argsLength;
(cache || seen).push(value);
while (--argsIndex) {
cache = caches[argsIndex];
if ((cache ? cacheIndexOf(cache, value) : indexOf(args[argsIndex], value)) < 0) {
continue outer;
}
}
result.push(value);
}
}
while (argsLength--) {
cache = caches[argsLength];
if (cache) {
releaseObject(cache);
}
}
releaseArray(caches);
releaseArray(seen);
return result;
}
/**
* Gets the last element or last `n` elements of an array. If a callback is
* provided elements at the end of the array are returned as long as the
* callback returns truey. The callback is bound to `thisArg` and invoked
* with three arguments; (value, index, array).
*
* If a property name is provided for `callback` the created "_.pluck" style
* callback will return the property value of the given element.
*
* If an object is provided for `callback` the created "_.where" style callback
* will return `true` for elements that have the properties of the given object,
* else `false`.
*
* @static
* @memberOf _
* @category Arrays
* @param {Array} array The array to query.
* @param {Function|Object|number|string} [callback] The function called
* per element or the number of elements to return. If a property name or
* object is provided it will be used to create a "_.pluck" or "_.where"
* style callback, respectively.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {*} Returns the last element(s) of `array`.
* @example
*
* _.last([1, 2, 3]);
* // => 3
*
* _.last([1, 2, 3], 2);
* // => [2, 3]
*
* _.last([1, 2, 3], function(num) {
* return num > 1;
* });
* // => [2, 3]
*
* var characters = [
* { 'name': 'barney', 'blocked': false, 'employer': 'slate' },
* { 'name': 'fred', 'blocked': true, 'employer': 'slate' },
* { 'name': 'pebbles', 'blocked': true, 'employer': 'na' }
* ];
*
* // using "_.pluck" callback shorthand
* _.pluck(_.last(characters, 'blocked'), 'name');
* // => ['fred', 'pebbles']
*
* // using "_.where" callback shorthand
* _.last(characters, { 'employer': 'na' });
* // => [{ 'name': 'pebbles', 'blocked': true, 'employer': 'na' }]
*/
function last(array, callback, thisArg) {
var n = 0,
length = array ? array.length : 0;
if (typeof callback != 'number' && callback != null) {
var index = length;
callback = lodash.createCallback(callback, thisArg, 3);
while (index-- && callback(array[index], index, array)) {
n++;
}
} else {
n = callback;
if (n == null || thisArg) {
return array ? array[length - 1] : undefined;
}
}
return slice(array, nativeMax(0, length - n));
}
/**
* Gets the index at which the last occurrence of `value` is found using strict
* equality for comparisons, i.e. `===`. If `fromIndex` is negative, it is used
* as the offset from the end of the collection.
*
* If a property name is provided for `callback` the created "_.pluck" style
* callback will return the property value of the given element.
*
* If an object is provided for `callback` the created "_.where" style callback
* will return `true` for elements that have the properties of the given object,
* else `false`.
*
* @static
* @memberOf _
* @category Arrays
* @param {Array} array The array to search.
* @param {*} value The value to search for.
* @param {number} [fromIndex=array.length-1] The index to search from.
* @returns {number} Returns the index of the matched value or `-1`.
* @example
*
* _.lastIndexOf([1, 2, 3, 1, 2, 3], 2);
* // => 4
*
* _.lastIndexOf([1, 2, 3, 1, 2, 3], 2, 3);
* // => 1
*/
function lastIndexOf(array, value, fromIndex) {
var index = array ? array.length : 0;
if (typeof fromIndex == 'number') {
index = (fromIndex < 0 ? nativeMax(0, index + fromIndex) : nativeMin(fromIndex, index - 1)) + 1;
}
while (index--) {
if (array[index] === value) {
return index;
}
}
return -1;
}
/**
* Removes all provided values from the given array using strict equality for
* comparisons, i.e. `===`.
*
* @static
* @memberOf _
* @category Arrays
* @param {Array} array The array to modify.
* @param {...*} [value] The values to remove.
* @returns {Array} Returns `array`.
* @example
*
* var array = [1, 2, 3, 1, 2, 3];
* _.pull(array, 2, 3);
* console.log(array);
* // => [1, 1]
*/
function pull(array) {
var args = arguments,
argsIndex = 0,
argsLength = args.length,
length = array ? array.length : 0;
while (++argsIndex < argsLength) {
var index = -1,
value = args[argsIndex];
while (++index < length) {
if (array[index] === value) {
splice.call(array, index--, 1);
length--;
}
}
}
return array;
}
/**
* Creates an array of numbers (positive and/or negative) progressing from
* `start` up to but not including `end`. If `start` is less than `stop` a
* zero-length range is created unless a negative `step` is specified.
*
* @static
* @memberOf _
* @category Arrays
* @param {number} [start=0] The start of the range.
* @param {number} end The end of the range.
* @param {number} [step=1] The value to increment or decrement by.
* @returns {Array} Returns a new range array.
* @example
*
* _.range(4);
* // => [0, 1, 2, 3]
*
* _.range(1, 5);
* // => [1, 2, 3, 4]
*
* _.range(0, 20, 5);
* // => [0, 5, 10, 15]
*
* _.range(0, -4, -1);
* // => [0, -1, -2, -3]
*
* _.range(1, 4, 0);
* // => [1, 1, 1]
*
* _.range(0);
* // => []
*/
function range(start, end, step) {
start = +start || 0;
step = typeof step == 'number' ? step : (+step || 1);
if (end == null) {
end = start;
start = 0;
}
// use `Array(length)` so engines like Chakra and V8 avoid slower modes
// http://youtu.be/XAqIpGU8ZZk#t=17m25s
var index = -1,
length = nativeMax(0, ceil((end - start) / (step || 1))),
result = Array(length);
while (++index < length) {
result[index] = start;
start += step;
}
return result;
}
/**
* Removes all elements from an array that the callback returns truey for
* and returns an array of removed elements. The callback is bound to `thisArg`
* and invoked with three arguments; (value, index, array).
*
* If a property name is provided for `callback` the created "_.pluck" style
* callback will return the property value of the given element.
*
* If an object is provided for `callback` the created "_.where" style callback
* will return `true` for elements that have the properties of the given object,
* else `false`.
*
* @static
* @memberOf _
* @category Arrays
* @param {Array} array The array to modify.
* @param {Function|Object|string} [callback=identity] The function called
* per iteration. If a property name or object is provided it will be used
* to create a "_.pluck" or "_.where" style callback, respectively.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {Array} Returns a new array of removed elements.
* @example
*
* var array = [1, 2, 3, 4, 5, 6];
* var evens = _.remove(array, function(num) { return num % 2 == 0; });
*
* console.log(array);
* // => [1, 3, 5]
*
* console.log(evens);
* // => [2, 4, 6]
*/
function remove(array, callback, thisArg) {
var index = -1,
length = array ? array.length : 0,
result = [];
callback = lodash.createCallback(callback, thisArg, 3);
while (++index < length) {
var value = array[index];
if (callback(value, index, array)) {
result.push(value);
splice.call(array, index--, 1);
length--;
}
}
return result;
}
/**
* The opposite of `_.initial` this method gets all but the first element or
* first `n` elements of an array. If a callback function is provided elements
* at the beginning of the array are excluded from the result as long as the
* callback returns truey. The callback is bound to `thisArg` and invoked
* with three arguments; (value, index, array).
*
* If a property name is provided for `callback` the created "_.pluck" style
* callback will return the property value of the given element.
*
* If an object is provided for `callback` the created "_.where" style callback
* will return `true` for elements that have the properties of the given object,
* else `false`.
*
* @static
* @memberOf _
* @alias drop, tail
* @category Arrays
* @param {Array} array The array to query.
* @param {Function|Object|number|string} [callback=1] The function called
* per element or the number of elements to exclude. If a property name or
* object is provided it will be used to create a "_.pluck" or "_.where"
* style callback, respectively.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {Array} Returns a slice of `array`.
* @example
*
* _.rest([1, 2, 3]);
* // => [2, 3]
*
* _.rest([1, 2, 3], 2);
* // => [3]
*
* _.rest([1, 2, 3], function(num) {
* return num < 3;
* });
* // => [3]
*
* var characters = [
* { 'name': 'barney', 'blocked': true, 'employer': 'slate' },
* { 'name': 'fred', 'blocked': false, 'employer': 'slate' },
* { 'name': 'pebbles', 'blocked': true, 'employer': 'na' }
* ];
*
* // using "_.pluck" callback shorthand
* _.pluck(_.rest(characters, 'blocked'), 'name');
* // => ['fred', 'pebbles']
*
* // using "_.where" callback shorthand
* _.rest(characters, { 'employer': 'slate' });
* // => [{ 'name': 'pebbles', 'blocked': true, 'employer': 'na' }]
*/
function rest(array, callback, thisArg) {
if (typeof callback != 'number' && callback != null) {
var n = 0,
index = -1,
length = array ? array.length : 0;
callback = lodash.createCallback(callback, thisArg, 3);
while (++index < length && callback(array[index], index, array)) {
n++;
}
} else {
n = (callback == null || thisArg) ? 1 : nativeMax(0, callback);
}
return slice(array, n);
}
/**
* Uses a binary search to determine the smallest index at which a value
* should be inserted into a given sorted array in order to maintain the sort
* order of the array. If a callback is provided it will be executed for
* `value` and each element of `array` to compute their sort ranking. The
* callback is bound to `thisArg` and invoked with one argument; (value).
*
* If a property name is provided for `callback` the created "_.pluck" style
* callback will return the property value of the given element.
*
* If an object is provided for `callback` the created "_.where" style callback
* will return `true` for elements that have the properties of the given object,
* else `false`.
*
* @static
* @memberOf _
* @category Arrays
* @param {Array} array The array to inspect.
* @param {*} value The value to evaluate.
* @param {Function|Object|string} [callback=identity] The function called
* per iteration. If a property name or object is provided it will be used
* to create a "_.pluck" or "_.where" style callback, respectively.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {number} Returns the index at which `value` should be inserted
* into `array`.
* @example
*
* _.sortedIndex([20, 30, 50], 40);
* // => 2
*
* // using "_.pluck" callback shorthand
* _.sortedIndex([{ 'x': 20 }, { 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x');
* // => 2
*
* var dict = {
* 'wordToNumber': { 'twenty': 20, 'thirty': 30, 'fourty': 40, 'fifty': 50 }
* };
*
* _.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function(word) {
* return dict.wordToNumber[word];
* });
* // => 2
*
* _.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function(word) {
* return this.wordToNumber[word];
* }, dict);
* // => 2
*/
function sortedIndex(array, value, callback, thisArg) {
var low = 0,
high = array ? array.length : low;
// explicitly reference `identity` for better inlining in Firefox
callback = callback ? lodash.createCallback(callback, thisArg, 1) : identity;
value = callback(value);
while (low < high) {
var mid = (low + high) >>> 1;
(callback(array[mid]) < value)
? low = mid + 1
: high = mid;
}
return low;
}
/**
* Creates an array of unique values, in order, of the provided arrays using
* strict equality for comparisons, i.e. `===`.
*
* @static
* @memberOf _
* @category Arrays
* @param {...Array} [array] The arrays to inspect.
* @returns {Array} Returns an array of combined values.
* @example
*
* _.union([1, 2, 3], [5, 2, 1, 4], [2, 1]);
* // => [1, 2, 3, 5, 4]
*/
function union() {
return baseUniq(baseFlatten(arguments, true, true));
}
/**
* Creates a duplicate-value-free version of an array using strict equality
* for comparisons, i.e. `===`. If the array is sorted, providing
* `true` for `isSorted` will use a faster algorithm. If a callback is provided
* each element of `array` is passed through the callback before uniqueness
* is computed. The callback is bound to `thisArg` and invoked with three
* arguments; (value, index, array).
*
* If a property name is provided for `callback` the created "_.pluck" style
* callback will return the property value of the given element.
*
* If an object is provided for `callback` the created "_.where" style callback
* will return `true` for elements that have the properties of the given object,
* else `false`.
*
* @static
* @memberOf _
* @alias unique
* @category Arrays
* @param {Array} array The array to process.
* @param {boolean} [isSorted=false] A flag to indicate that `array` is sorted.
* @param {Function|Object|string} [callback=identity] The function called
* per iteration. If a property name or object is provided it will be used
* to create a "_.pluck" or "_.where" style callback, respectively.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {Array} Returns a duplicate-value-free array.
* @example
*
* _.uniq([1, 2, 1, 3, 1]);
* // => [1, 2, 3]
*
* _.uniq([1, 1, 2, 2, 3], true);
* // => [1, 2, 3]
*
* _.uniq(['A', 'b', 'C', 'a', 'B', 'c'], function(letter) { return letter.toLowerCase(); });
* // => ['A', 'b', 'C']
*
* _.uniq([1, 2.5, 3, 1.5, 2, 3.5], function(num) { return this.floor(num); }, Math);
* // => [1, 2.5, 3]
*
* // using "_.pluck" callback shorthand
* _.uniq([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
* // => [{ 'x': 1 }, { 'x': 2 }]
*/
function uniq(array, isSorted, callback, thisArg) {
// juggle arguments
if (typeof isSorted != 'boolean' && isSorted != null) {
thisArg = callback;
callback = (typeof isSorted != 'function' && thisArg && thisArg[isSorted] === array) ? null : isSorted;
isSorted = false;
}
if (callback != null) {
callback = lodash.createCallback(callback, thisArg, 3);
}
return baseUniq(array, isSorted, callback);
}
/**
* Creates an array excluding all provided values using strict equality for
* comparisons, i.e. `===`.
*
* @static
* @memberOf _
* @category Arrays
* @param {Array} array The array to filter.
* @param {...*} [value] The values to exclude.
* @returns {Array} Returns a new array of filtered values.
* @example
*
* _.without([1, 2, 1, 0, 3, 1, 4], 0, 1);
* // => [2, 3, 4]
*/
function without(array) {
return baseDifference(array, slice(arguments, 1));
}
/**
* Creates an array that is the symmetric difference of the provided arrays.
* See http://en.wikipedia.org/wiki/Symmetric_difference.
*
* @static
* @memberOf _
* @category Arrays
* @param {...Array} [array] The arrays to inspect.
* @returns {Array} Returns an array of values.
* @example
*
* _.xor([1, 2, 3], [5, 2, 1, 4]);
* // => [3, 5, 4]
*
* _.xor([1, 2, 5], [2, 3, 5], [3, 4, 5]);
* // => [1, 4, 5]
*/
function xor() {
var index = -1,
length = arguments.length;
while (++index < length) {
var array = arguments[index];
if (isArray(array) || isArguments(array)) {
var result = result
? baseUniq(baseDifference(result, array).concat(baseDifference(array, result)))
: array;
}
}
return result || [];
}
/**
* Creates an array of grouped elements, the first of which contains the first
* elements of the given arrays, the second of which contains the second
* elements of the given arrays, and so on.
*
* @static
* @memberOf _
* @alias unzip
* @category Arrays
* @param {...Array} [array] Arrays to process.
* @returns {Array} Returns a new array of grouped elements.
* @example
*
* _.zip(['fred', 'barney'], [30, 40], [true, false]);
* // => [['fred', 30, true], ['barney', 40, false]]
*/
function zip() {
var array = arguments.length > 1 ? arguments : arguments[0],
index = -1,
length = array ? max(pluck(array, 'length')) : 0,
result = Array(length < 0 ? 0 : length);
while (++index < length) {
result[index] = pluck(array, index);
}
return result;
}
/**
* Creates an object composed from arrays of `keys` and `values`. Provide
* either a single two dimensional array, i.e. `[[key1, value1], [key2, value2]]`
* or two arrays, one of `keys` and one of corresponding `values`.
*
* @static
* @memberOf _
* @alias object
* @category Arrays
* @param {Array} keys The array of keys.
* @param {Array} [values=[]] The array of values.
* @returns {Object} Returns an object composed of the given keys and
* corresponding values.
* @example
*
* _.zipObject(['fred', 'barney'], [30, 40]);
* // => { 'fred': 30, 'barney': 40 }
*/
function zipObject(keys, values) {
var index = -1,
length = keys ? keys.length : 0,
result = {};
if (!values && length && !isArray(keys[0])) {
values = [];
}
while (++index < length) {
var key = keys[index];
if (values) {
result[key] = values[index];
} else if (key) {
result[key[0]] = key[1];
}
}
return result;
}
/*--------------------------------------------------------------------------*/
/**
* Creates a function that executes `func`, with the `this` binding and
* arguments of the created function, only after being called `n` times.
*
* @static
* @memberOf _
* @category Functions
* @param {number} n The number of times the function must be called before
* `func` is executed.
* @param {Function} func The function to restrict.
* @returns {Function} Returns the new restricted function.
* @example
*
* var saves = ['profile', 'settings'];
*
* var done = _.after(saves.length, function() {
* console.log('Done saving!');
* });
*
* _.forEach(saves, function(type) {
* asyncSave({ 'type': type, 'complete': done });
* });
* // => logs 'Done saving!', after all saves have completed
*/
function after(n, func) {
if (!isFunction(func)) {
throw new TypeError;
}
return function() {
if (--n < 1) {
return func.apply(this, arguments);
}
};
}
/**
* Creates a function that, when called, invokes `func` with the `this`
* binding of `thisArg` and prepends any additional `bind` arguments to those
* provided to the bound function.
*
* @static
* @memberOf _
* @category Functions
* @param {Function} func The function to bind.
* @param {*} [thisArg] The `this` binding of `func`.
* @param {...*} [arg] Arguments to be partially applied.
* @returns {Function} Returns the new bound function.
* @example
*
* var func = function(greeting) {
* return greeting + ' ' + this.name;
* };
*
* func = _.bind(func, { 'name': 'fred' }, 'hi');
* func();
* // => 'hi fred'
*/
function bind(func, thisArg) {
return arguments.length > 2
? createWrapper(func, 17, slice(arguments, 2), null, thisArg)
: createWrapper(func, 1, null, null, thisArg);
}
/**
* Binds methods of an object to the object itself, overwriting the existing
* method. Method names may be specified as individual arguments or as arrays
* of method names. If no method names are provided all the function properties
* of `object` will be bound.
*
* @static
* @memberOf _
* @category Functions
* @param {Object} object The object to bind and assign the bound methods to.
* @param {...string} [methodName] The object method names to
* bind, specified as individual method names or arrays of method names.
* @returns {Object} Returns `object`.
* @example
*
* var view = {
* 'label': 'docs',
* 'onClick': function() { console.log('clicked ' + this.label); }
* };
*
* _.bindAll(view);
* jQuery('#docs').on('click', view.onClick);
* // => logs 'clicked docs', when the button is clicked
*/
function bindAll(object) {
var funcs = arguments.length > 1 ? baseFlatten(arguments, true, false, 1) : functions(object),
index = -1,
length = funcs.length;
while (++index < length) {
var key = funcs[index];
object[key] = createWrapper(object[key], 1, null, null, object);
}
return object;
}
/**
* Creates a function that, when called, invokes the method at `object[key]`
* and prepends any additional `bindKey` arguments to those provided to the bound
* function. This method differs from `_.bind` by allowing bound functions to
* reference methods that will be redefined or don't yet exist.
* See http://michaux.ca/articles/lazy-function-definition-pattern.
*
* @static
* @memberOf _
* @category Functions
* @param {Object} object The object the method belongs to.
* @param {string} key The key of the method.
* @param {...*} [arg] Arguments to be partially applied.
* @returns {Function} Returns the new bound function.
* @example
*
* var object = {
* 'name': 'fred',
* 'greet': function(greeting) {
* return greeting + ' ' + this.name;
* }
* };
*
* var func = _.bindKey(object, 'greet', 'hi');
* func();
* // => 'hi fred'
*
* object.greet = function(greeting) {
* return greeting + 'ya ' + this.name + '!';
* };
*
* func();
* // => 'hiya fred!'
*/
function bindKey(object, key) {
return arguments.length > 2
? createWrapper(key, 19, slice(arguments, 2), null, object)
: createWrapper(key, 3, null, null, object);
}
/**
* Creates a function that is the composition of the provided functions,
* where each function consumes the return value of the function that follows.
* For example, composing the functions `f()`, `g()`, and `h()` produces `f(g(h()))`.
* Each function is executed with the `this` binding of the composed function.
*
* @static
* @memberOf _
* @category Functions
* @param {...Function} [func] Functions to compose.
* @returns {Function} Returns the new composed function.
* @example
*
* var realNameMap = {
* 'pebbles': 'penelope'
* };
*
* var format = function(name) {
* name = realNameMap[name.toLowerCase()] || name;
* return name.charAt(0).toUpperCase() + name.slice(1).toLowerCase();
* };
*
* var greet = function(formatted) {
* return 'Hiya ' + formatted + '!';
* };
*
* var welcome = _.compose(greet, format);
* welcome('pebbles');
* // => 'Hiya Penelope!'
*/
function compose() {
var funcs = arguments,
length = funcs.length;
while (length--) {
if (!isFunction(funcs[length])) {
throw new TypeError;
}
}
return function() {
var args = arguments,
length = funcs.length;
while (length--) {
args = [funcs[length].apply(this, args)];
}
return args[0];
};
}
/**
* Creates a function which accepts one or more arguments of `func` that when
* invoked either executes `func` returning its result, if all `func` arguments
* have been provided, or returns a function that accepts one or more of the
* remaining `func` arguments, and so on. The arity of `func` can be specified
* if `func.length` is not sufficient.
*
* @static
* @memberOf _
* @category Functions
* @param {Function} func The function to curry.
* @param {number} [arity=func.length] The arity of `func`.
* @returns {Function} Returns the new curried function.
* @example
*
* var curried = _.curry(function(a, b, c) {
* console.log(a + b + c);
* });
*
* curried(1)(2)(3);
* // => 6
*
* curried(1, 2)(3);
* // => 6
*
* curried(1, 2, 3);
* // => 6
*/
function curry(func, arity) {
arity = typeof arity == 'number' ? arity : (+arity || func.length);
return createWrapper(func, 4, null, null, null, arity);
}
/**
* Creates a function that will delay the execution of `func` until after
* `wait` milliseconds have elapsed since the last time it was invoked.
* Provide an options object to indicate that `func` should be invoked on
* the leading and/or trailing edge of the `wait` timeout. Subsequent calls
* to the debounced function will return the result of the last `func` call.
*
* Note: If `leading` and `trailing` options are `true` `func` will be called
* on the trailing edge of the timeout only if the the debounced function is
* invoked more than once during the `wait` timeout.
*
* @static
* @memberOf _
* @category Functions
* @param {Function} func The function to debounce.
* @param {number} wait The number of milliseconds to delay.
* @param {Object} [options] The options object.
* @param {boolean} [options.leading=false] Specify execution on the leading edge of the timeout.
* @param {number} [options.maxWait] The maximum time `func` is allowed to be delayed before it's called.
* @param {boolean} [options.trailing=true] Specify execution on the trailing edge of the timeout.
* @returns {Function} Returns the new debounced function.
* @example
*
* // avoid costly calculations while the window size is in flux
* var lazyLayout = _.debounce(calculateLayout, 150);
* jQuery(window).on('resize', lazyLayout);
*
* // execute `sendMail` when the click event is fired, debouncing subsequent calls
* jQuery('#postbox').on('click', _.debounce(sendMail, 300, {
* 'leading': true,
* 'trailing': false
* });
*
* // ensure `batchLog` is executed once after 1 second of debounced calls
* var source = new EventSource('/stream');
* source.addEventListener('message', _.debounce(batchLog, 250, {
* 'maxWait': 1000
* }, false);
*/
function debounce(func, wait, options) {
var args,
maxTimeoutId,
result,
stamp,
thisArg,
timeoutId,
trailingCall,
lastCalled = 0,
maxWait = false,
trailing = true;
if (!isFunction(func)) {
throw new TypeError;
}
wait = nativeMax(0, wait) || 0;
if (options === true) {
var leading = true;
trailing = false;
} else if (isObject(options)) {
leading = options.leading;
maxWait = 'maxWait' in options && (nativeMax(wait, options.maxWait) || 0);
trailing = 'trailing' in options ? options.trailing : trailing;
}
var delayed = function() {
var remaining = wait - (now() - stamp);
if (remaining <= 0) {
if (maxTimeoutId) {
clearTimeout(maxTimeoutId);
}
var isCalled = trailingCall;
maxTimeoutId = timeoutId = trailingCall = undefined;
if (isCalled) {
lastCalled = now();
result = func.apply(thisArg, args);
if (!timeoutId && !maxTimeoutId) {
args = thisArg = null;
}
}
} else {
timeoutId = setTimeout(delayed, remaining);
}
};
var maxDelayed = function() {
if (timeoutId) {
clearTimeout(timeoutId);
}
maxTimeoutId = timeoutId = trailingCall = undefined;
if (trailing || (maxWait !== wait)) {
lastCalled = now();
result = func.apply(thisArg, args);
if (!timeoutId && !maxTimeoutId) {
args = thisArg = null;
}
}
};
return function() {
args = arguments;
stamp = now();
thisArg = this;
trailingCall = trailing && (timeoutId || !leading);
if (maxWait === false) {
var leadingCall = leading && !timeoutId;
} else {
if (!maxTimeoutId && !leading) {
lastCalled = stamp;
}
var remaining = maxWait - (stamp - lastCalled),
isCalled = remaining <= 0;
if (isCalled) {
if (maxTimeoutId) {
maxTimeoutId = clearTimeout(maxTimeoutId);
}
lastCalled = stamp;
result = func.apply(thisArg, args);
}
else if (!maxTimeoutId) {
maxTimeoutId = setTimeout(maxDelayed, remaining);
}
}
if (isCalled && timeoutId) {
timeoutId = clearTimeout(timeoutId);
}
else if (!timeoutId && wait !== maxWait) {
timeoutId = setTimeout(delayed, wait);
}
if (leadingCall) {
isCalled = true;
result = func.apply(thisArg, args);
}
if (isCalled && !timeoutId && !maxTimeoutId) {
args = thisArg = null;
}
return result;
};
}
/**
* Defers executing the `func` function until the current call stack has cleared.
* Additional arguments will be provided to `func` when it is invoked.
*
* @static
* @memberOf _
* @category Functions
* @param {Function} func The function to defer.
* @param {...*} [arg] Arguments to invoke the function with.
* @returns {number} Returns the timer id.
* @example
*
* _.defer(function(text) { console.log(text); }, 'deferred');
* // logs 'deferred' after one or more milliseconds
*/
function defer(func) {
if (!isFunction(func)) {
throw new TypeError;
}
var args = slice(arguments, 1);
return setTimeout(function() { func.apply(undefined, args); }, 1);
}
/**
* Executes the `func` function after `wait` milliseconds. Additional arguments
* will be provided to `func` when it is invoked.
*
* @static
* @memberOf _
* @category Functions
* @param {Function} func The function to delay.
* @param {number} wait The number of milliseconds to delay execution.
* @param {...*} [arg] Arguments to invoke the function with.
* @returns {number} Returns the timer id.
* @example
*
* _.delay(function(text) { console.log(text); }, 1000, 'later');
* // => logs 'later' after one second
*/
function delay(func, wait) {
if (!isFunction(func)) {
throw new TypeError;
}
var args = slice(arguments, 2);
return setTimeout(function() { func.apply(undefined, args); }, wait);
}
/**
* Creates a function that memoizes the result of `func`. If `resolver` is
* provided it will be used to determine the cache key for storing the result
* based on the arguments provided to the memoized function. By default, the
* first argument provided to the memoized function is used as the cache key.
* The `func` is executed with the `this` binding of the memoized function.
* The result cache is exposed as the `cache` property on the memoized function.
*
* @static
* @memberOf _
* @category Functions
* @param {Function} func The function to have its output memoized.
* @param {Function} [resolver] A function used to resolve the cache key.
* @returns {Function} Returns the new memoizing function.
* @example
*
* var fibonacci = _.memoize(function(n) {
* return n < 2 ? n : fibonacci(n - 1) + fibonacci(n - 2);
* });
*
* fibonacci(9)
* // => 34
*
* var data = {
* 'fred': { 'name': 'fred', 'age': 40 },
* 'pebbles': { 'name': 'pebbles', 'age': 1 }
* };
*
* // modifying the result cache
* var get = _.memoize(function(name) { return data[name]; }, _.identity);
* get('pebbles');
* // => { 'name': 'pebbles', 'age': 1 }
*
* get.cache.pebbles.name = 'penelope';
* get('pebbles');
* // => { 'name': 'penelope', 'age': 1 }
*/
function memoize(func, resolver) {
if (!isFunction(func)) {
throw new TypeError;
}
var memoized = function() {
var cache = memoized.cache,
key = resolver ? resolver.apply(this, arguments) : keyPrefix + arguments[0];
return hasOwnProperty.call(cache, key)
? cache[key]
: (cache[key] = func.apply(this, arguments));
}
memoized.cache = {};
return memoized;
}
/**
* Creates a function that is restricted to execute `func` once. Repeat calls to
* the function will return the value of the first call. The `func` is executed
* with the `this` binding of the created function.
*
* @static
* @memberOf _
* @category Functions
* @param {Function} func The function to restrict.
* @returns {Function} Returns the new restricted function.
* @example
*
* var initialize = _.once(createApplication);
* initialize();
* initialize();
* // `initialize` executes `createApplication` once
*/
function once(func) {
var ran,
result;
if (!isFunction(func)) {
throw new TypeError;
}
return function() {
if (ran) {
return result;
}
ran = true;
result = func.apply(this, arguments);
// clear the `func` variable so the function may be garbage collected
func = null;
return result;
};
}
/**
* Creates a function that, when called, invokes `func` with any additional
* `partial` arguments prepended to those provided to the new function. This
* method is similar to `_.bind` except it does **not** alter the `this` binding.
*
* @static
* @memberOf _
* @category Functions
* @param {Function} func The function to partially apply arguments to.
* @param {...*} [arg] Arguments to be partially applied.
* @returns {Function} Returns the new partially applied function.
* @example
*
* var greet = function(greeting, name) { return greeting + ' ' + name; };
* var hi = _.partial(greet, 'hi');
* hi('fred');
* // => 'hi fred'
*/
function partial(func) {
return createWrapper(func, 16, slice(arguments, 1));
}
/**
* This method is like `_.partial` except that `partial` arguments are
* appended to those provided to the new function.
*
* @static
* @memberOf _
* @category Functions
* @param {Function} func The function to partially apply arguments to.
* @param {...*} [arg] Arguments to be partially applied.
* @returns {Function} Returns the new partially applied function.
* @example
*
* var defaultsDeep = _.partialRight(_.merge, _.defaults);
*
* var options = {
* 'variable': 'data',
* 'imports': { 'jq': $ }
* };
*
* defaultsDeep(options, _.templateSettings);
*
* options.variable
* // => 'data'
*
* options.imports
* // => { '_': _, 'jq': $ }
*/
function partialRight(func) {
return createWrapper(func, 32, null, slice(arguments, 1));
}
/**
* Creates a function that, when executed, will only call the `func` function
* at most once per every `wait` milliseconds. Provide an options object to
* indicate that `func` should be invoked on the leading and/or trailing edge
* of the `wait` timeout. Subsequent calls to the throttled function will
* return the result of the last `func` call.
*
* Note: If `leading` and `trailing` options are `true` `func` will be called
* on the trailing edge of the timeout only if the the throttled function is
* invoked more than once during the `wait` timeout.
*
* @static
* @memberOf _
* @category Functions
* @param {Function} func The function to throttle.
* @param {number} wait The number of milliseconds to throttle executions to.
* @param {Object} [options] The options object.
* @param {boolean} [options.leading=true] Specify execution on the leading edge of the timeout.
* @param {boolean} [options.trailing=true] Specify execution on the trailing edge of the timeout.
* @returns {Function} Returns the new throttled function.
* @example
*
* // avoid excessively updating the position while scrolling
* var throttled = _.throttle(updatePosition, 100);
* jQuery(window).on('scroll', throttled);
*
* // execute `renewToken` when the click event is fired, but not more than once every 5 minutes
* jQuery('.interactive').on('click', _.throttle(renewToken, 300000, {
* 'trailing': false
* }));
*/
function throttle(func, wait, options) {
var leading = true,
trailing = true;
if (!isFunction(func)) {
throw new TypeError;
}
if (options === false) {
leading = false;
} else if (isObject(options)) {
leading = 'leading' in options ? options.leading : leading;
trailing = 'trailing' in options ? options.trailing : trailing;
}
debounceOptions.leading = leading;
debounceOptions.maxWait = wait;
debounceOptions.trailing = trailing;
return debounce(func, wait, debounceOptions);
}
/**
* Creates a function that provides `value` to the wrapper function as its
* first argument. Additional arguments provided to the function are appended
* to those provided to the wrapper function. The wrapper is executed with
* the `this` binding of the created function.
*
* @static
* @memberOf _
* @category Functions
* @param {*} value The value to wrap.
* @param {Function} wrapper The wrapper function.
* @returns {Function} Returns the new function.
* @example
*
* var p = _.wrap(_.escape, function(func, text) {
* return '<p>' + func(text) + '</p>';
* });
*
* p('Fred, Wilma, & Pebbles');
* // => '<p>Fred, Wilma, &amp; Pebbles</p>'
*/
function wrap(value, wrapper) {
return createWrapper(wrapper, 16, [value]);
}
/*--------------------------------------------------------------------------*/
/**
* Creates a function that returns `value`.
*
* @static
* @memberOf _
* @category Utilities
* @param {*} value The value to return from the new function.
* @returns {Function} Returns the new function.
* @example
*
* var object = { 'name': 'fred' };
* var getter = _.constant(object);
* getter() === object;
* // => true
*/
function constant(value) {
return function() {
return value;
};
}
/**
* Produces a callback bound to an optional `thisArg`. If `func` is a property
* name the created callback will return the property value for a given element.
* If `func` is an object the created callback will return `true` for elements
* that contain the equivalent object properties, otherwise it will return `false`.
*
* @static
* @memberOf _
* @category Utilities
* @param {*} [func=identity] The value to convert to a callback.
* @param {*} [thisArg] The `this` binding of the created callback.
* @param {number} [argCount] The number of arguments the callback accepts.
* @returns {Function} Returns a callback function.
* @example
*
* var characters = [
* { 'name': 'barney', 'age': 36 },
* { 'name': 'fred', 'age': 40 }
* ];
*
* // wrap to create custom callback shorthands
* _.createCallback = _.wrap(_.createCallback, function(func, callback, thisArg) {
* var match = /^(.+?)__([gl]t)(.+)$/.exec(callback);
* return !match ? func(callback, thisArg) : function(object) {
* return match[2] == 'gt' ? object[match[1]] > match[3] : object[match[1]] < match[3];
* };
* });
*
* _.filter(characters, 'age__gt38');
* // => [{ 'name': 'fred', 'age': 40 }]
*/
function createCallback(func, thisArg, argCount) {
var type = typeof func;
if (func == null || type == 'function') {
return baseCreateCallback(func, thisArg, argCount);
}
// handle "_.pluck" style callback shorthands
if (type != 'object') {
return property(func);
}
var props = keys(func),
key = props[0],
a = func[key];
// handle "_.where" style callback shorthands
if (props.length == 1 && a === a && !isObject(a)) {
// fast path the common case of providing an object with a single
// property containing a primitive value
return function(object) {
var b = object[key];
return a === b && (a !== 0 || (1 / a == 1 / b));
};
}
return function(object) {
var length = props.length,
result = false;
while (length--) {
if (!(result = baseIsEqual(object[props[length]], func[props[length]], null, true))) {
break;
}
}
return result;
};
}
/**
* Converts the characters `&`, `<`, `>`, `"`, and `'` in `string` to their
* corresponding HTML entities.
*
* @static
* @memberOf _
* @category Utilities
* @param {string} string The string to escape.
* @returns {string} Returns the escaped string.
* @example
*
* _.escape('Fred, Wilma, & Pebbles');
* // => 'Fred, Wilma, &amp; Pebbles'
*/
function escape(string) {
return string == null ? '' : String(string).replace(reUnescapedHtml, escapeHtmlChar);
}
/**
* This method returns the first argument provided to it.
*
* @static
* @memberOf _
* @category Utilities
* @param {*} value Any value.
* @returns {*} Returns `value`.
* @example
*
* var object = { 'name': 'fred' };
* _.identity(object) === object;
* // => true
*/
function identity(value) {
return value;
}
/**
* Adds function properties of a source object to the destination object.
* If `object` is a function methods will be added to its prototype as well.
*
* @static
* @memberOf _
* @category Utilities
* @param {Function|Object} [object=lodash] object The destination object.
* @param {Object} source The object of functions to add.
* @param {Object} [options] The options object.
* @param {boolean} [options.chain=true] Specify whether the functions added are chainable.
* @example
*
* function capitalize(string) {
* return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase();
* }
*
* _.mixin({ 'capitalize': capitalize });
* _.capitalize('fred');
* // => 'Fred'
*
* _('fred').capitalize().value();
* // => 'Fred'
*
* _.mixin({ 'capitalize': capitalize }, { 'chain': false });
* _('fred').capitalize();
* // => 'Fred'
*/
function mixin(object, source, options) {
var chain = true,
methodNames = source && functions(source);
if (!source || (!options && !methodNames.length)) {
if (options == null) {
options = source;
}
ctor = lodashWrapper;
source = object;
object = lodash;
methodNames = functions(source);
}
if (options === false) {
chain = false;
} else if (isObject(options) && 'chain' in options) {
chain = options.chain;
}
var ctor = object,
isFunc = isFunction(ctor);
forEach(methodNames, function(methodName) {
var func = object[methodName] = source[methodName];
if (isFunc) {
ctor.prototype[methodName] = function() {
var chainAll = this.__chain__,
value = this.__wrapped__,
args = [value];
push.apply(args, arguments);
var result = func.apply(object, args);
if (chain || chainAll) {
if (value === result && isObject(result)) {
return this;
}
result = new ctor(result);
result.__chain__ = chainAll;
}
return result;
};
}
});
}
/**
* Reverts the '_' variable to its previous value and returns a reference to
* the `lodash` function.
*
* @static
* @memberOf _
* @category Utilities
* @returns {Function} Returns the `lodash` function.
* @example
*
* var lodash = _.noConflict();
*/
function noConflict() {
context._ = oldDash;
return this;
}
/**
* A no-operation function.
*
* @static
* @memberOf _
* @category Utilities
* @example
*
* var object = { 'name': 'fred' };
* _.noop(object) === undefined;
* // => true
*/
function noop() {
// no operation performed
}
/**
* Gets the number of milliseconds that have elapsed since the Unix epoch
* (1 January 1970 00:00:00 UTC).
*
* @static
* @memberOf _
* @category Utilities
* @example
*
* var stamp = _.now();
* _.defer(function() { console.log(_.now() - stamp); });
* // => logs the number of milliseconds it took for the deferred function to be called
*/
var now = isNative(now = Date.now) && now || function() {
return new Date().getTime();
};
/**
* Converts the given value into an integer of the specified radix.
* If `radix` is `undefined` or `0` a `radix` of `10` is used unless the
* `value` is a hexadecimal, in which case a `radix` of `16` is used.
*
* Note: This method avoids differences in native ES3 and ES5 `parseInt`
* implementations. See http://es5.github.io/#E.
*
* @static
* @memberOf _
* @category Utilities
* @param {string} value The value to parse.
* @param {number} [radix] The radix used to interpret the value to parse.
* @returns {number} Returns the new integer value.
* @example
*
* _.parseInt('08');
* // => 8
*/
var parseInt = nativeParseInt(whitespace + '08') == 8 ? nativeParseInt : function(value, radix) {
// Firefox < 21 and Opera < 15 follow the ES3 specified implementation of `parseInt`
return nativeParseInt(isString(value) ? value.replace(reLeadingSpacesAndZeros, '') : value, radix || 0);
};
/**
* Creates a "_.pluck" style function, which returns the `key` value of a
* given object.
*
* @static
* @memberOf _
* @category Utilities
* @param {string} key The name of the property to retrieve.
* @returns {Function} Returns the new function.
* @example
*
* var characters = [
* { 'name': 'fred', 'age': 40 },
* { 'name': 'barney', 'age': 36 }
* ];
*
* var getName = _.property('name');
*
* _.map(characters, getName);
* // => ['barney', 'fred']
*
* _.sortBy(characters, getName);
* // => [{ 'name': 'barney', 'age': 36 }, { 'name': 'fred', 'age': 40 }]
*/
function property(key) {
return function(object) {
return object[key];
};
}
/**
* Produces a random number between `min` and `max` (inclusive). If only one
* argument is provided a number between `0` and the given number will be
* returned. If `floating` is truey or either `min` or `max` are floats a
* floating-point number will be returned instead of an integer.
*
* @static
* @memberOf _
* @category Utilities
* @param {number} [min=0] The minimum possible value.
* @param {number} [max=1] The maximum possible value.
* @param {boolean} [floating=false] Specify returning a floating-point number.
* @returns {number} Returns a random number.
* @example
*
* _.random(0, 5);
* // => an integer between 0 and 5
*
* _.random(5);
* // => also an integer between 0 and 5
*
* _.random(5, true);
* // => a floating-point number between 0 and 5
*
* _.random(1.2, 5.2);
* // => a floating-point number between 1.2 and 5.2
*/
function random(min, max, floating) {
var noMin = min == null,
noMax = max == null;
if (floating == null) {
if (typeof min == 'boolean' && noMax) {
floating = min;
min = 1;
}
else if (!noMax && typeof max == 'boolean') {
floating = max;
noMax = true;
}
}
if (noMin && noMax) {
max = 1;
}
min = +min || 0;
if (noMax) {
max = min;
min = 0;
} else {
max = +max || 0;
}
if (floating || min % 1 || max % 1) {
var rand = nativeRandom();
return nativeMin(min + (rand * (max - min + parseFloat('1e-' + ((rand +'').length - 1)))), max);
}
return baseRandom(min, max);
}
/**
* Resolves the value of property `key` on `object`. If `key` is a function
* it will be invoked with the `this` binding of `object` and its result returned,
* else the property value is returned. If `object` is falsey then `undefined`
* is returned.
*
* @static
* @memberOf _
* @category Utilities
* @param {Object} object The object to inspect.
* @param {string} key The name of the property to resolve.
* @returns {*} Returns the resolved value.
* @example
*
* var object = {
* 'cheese': 'crumpets',
* 'stuff': function() {
* return 'nonsense';
* }
* };
*
* _.result(object, 'cheese');
* // => 'crumpets'
*
* _.result(object, 'stuff');
* // => 'nonsense'
*/
function result(object, key) {
if (object) {
var value = object[key];
return isFunction(value) ? object[key]() : value;
}
}
/**
* A micro-templating method that handles arbitrary delimiters, preserves
* whitespace, and correctly escapes quotes within interpolated code.
*
* Note: In the development build, `_.template` utilizes sourceURLs for easier
* debugging. See http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl
*
* For more information on precompiling templates see:
* http://lodash.com/custom-builds
*
* For more information on Chrome extension sandboxes see:
* http://developer.chrome.com/stable/extensions/sandboxingEval.html
*
* @static
* @memberOf _
* @category Utilities
* @param {string} text The template text.
* @param {Object} data The data object used to populate the text.
* @param {Object} [options] The options object.
* @param {RegExp} [options.escape] The "escape" delimiter.
* @param {RegExp} [options.evaluate] The "evaluate" delimiter.
* @param {Object} [options.imports] An object to import into the template as local variables.
* @param {RegExp} [options.interpolate] The "interpolate" delimiter.
* @param {string} [sourceURL] The sourceURL of the template's compiled source.
* @param {string} [variable] The data object variable name.
* @returns {Function|string} Returns a compiled function when no `data` object
* is given, else it returns the interpolated text.
* @example
*
* // using the "interpolate" delimiter to create a compiled template
* var compiled = _.template('hello <%= name %>');
* compiled({ 'name': 'fred' });
* // => 'hello fred'
*
* // using the "escape" delimiter to escape HTML in data property values
* _.template('<b><%- value %></b>', { 'value': '<script>' });
* // => '<b>&lt;script&gt;</b>'
*
* // using the "evaluate" delimiter to generate HTML
* var list = '<% _.forEach(people, function(name) { %><li><%- name %></li><% }); %>';
* _.template(list, { 'people': ['fred', 'barney'] });
* // => '<li>fred</li><li>barney</li>'
*
* // using the ES6 delimiter as an alternative to the default "interpolate" delimiter
* _.template('hello ${ name }', { 'name': 'pebbles' });
* // => 'hello pebbles'
*
* // using the internal `print` function in "evaluate" delimiters
* _.template('<% print("hello " + name); %>!', { 'name': 'barney' });
* // => 'hello barney!'
*
* // using a custom template delimiters
* _.templateSettings = {
* 'interpolate': /{{([\s\S]+?)}}/g
* };
*
* _.template('hello {{ name }}!', { 'name': 'mustache' });
* // => 'hello mustache!'
*
* // using the `imports` option to import jQuery
* var list = '<% jq.each(people, function(name) { %><li><%- name %></li><% }); %>';
* _.template(list, { 'people': ['fred', 'barney'] }, { 'imports': { 'jq': jQuery } });
* // => '<li>fred</li><li>barney</li>'
*
* // using the `sourceURL` option to specify a custom sourceURL for the template
* var compiled = _.template('hello <%= name %>', null, { 'sourceURL': '/basic/greeting.jst' });
* compiled(data);
* // => find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector
*
* // using the `variable` option to ensure a with-statement isn't used in the compiled template
* var compiled = _.template('hi <%= data.name %>!', null, { 'variable': 'data' });
* compiled.source;
* // => function(data) {
* var __t, __p = '', __e = _.escape;
* __p += 'hi ' + ((__t = ( data.name )) == null ? '' : __t) + '!';
* return __p;
* }
*
* // using the `source` property to inline compiled templates for meaningful
* // line numbers in error messages and a stack trace
* fs.writeFileSync(path.join(cwd, 'jst.js'), '\
* var JST = {\
* "main": ' + _.template(mainText).source + '\
* };\
* ');
*/
function template(text, data, options) {
// based on John Resig's `tmpl` implementation
// http://ejohn.org/blog/javascript-micro-templating/
// and Laura Doktorova's doT.js
// https://github.com/olado/doT
var settings = lodash.templateSettings;
text = String(text || '');
// avoid missing dependencies when `iteratorTemplate` is not defined
options = iteratorTemplate ? defaults({}, options, settings) : settings;
var imports = iteratorTemplate && defaults({}, options.imports, settings.imports),
importsKeys = iteratorTemplate ? keys(imports) : ['_'],
importsValues = iteratorTemplate ? values(imports) : [lodash];
var isEvaluating,
index = 0,
interpolate = options.interpolate || reNoMatch,
source = "__p += '";
// compile the regexp to match each delimiter
var reDelimiters = RegExp(
(options.escape || reNoMatch).source + '|' +
interpolate.source + '|' +
(interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' +
(options.evaluate || reNoMatch).source + '|$'
, 'g');
text.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
interpolateValue || (interpolateValue = esTemplateValue);
// escape characters that cannot be included in string literals
source += text.slice(index, offset).replace(reUnescapedString, escapeStringChar);
// replace delimiters with snippets
if (escapeValue) {
source += "' +\n__e(" + escapeValue + ") +\n'";
}
if (evaluateValue) {
isEvaluating = true;
source += "';\n" + evaluateValue + ";\n__p += '";
}
if (interpolateValue) {
source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
}
index = offset + match.length;
// the JS engine embedded in Adobe products requires returning the `match`
// string in order to produce the correct `offset` value
return match;
});
source += "';\n";
// if `variable` is not specified, wrap a with-statement around the generated
// code to add the data object to the top of the scope chain
var variable = options.variable,
hasVariable = variable;
if (!hasVariable) {
variable = 'obj';
source = 'with (' + variable + ') {\n' + source + '\n}\n';
}
// cleanup code by stripping empty strings
source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
.replace(reEmptyStringMiddle, '$1')
.replace(reEmptyStringTrailing, '$1;');
// frame code as the function body
source = 'function(' + variable + ') {\n' +
(hasVariable ? '' : variable + ' || (' + variable + ' = {});\n') +
"var __t, __p = '', __e = _.escape" +
(isEvaluating
? ', __j = Array.prototype.join;\n' +
"function print() { __p += __j.call(arguments, '') }\n"
: ';\n'
) +
source +
'return __p\n}';
// Use a sourceURL for easier debugging.
// http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl
var sourceURL = '\n/*\n//# sourceURL=' + (options.sourceURL || '/lodash/template/source[' + (templateCounter++) + ']') + '\n*/';
try {
var result = Function(importsKeys, 'return ' + source + sourceURL).apply(undefined, importsValues);
} catch(e) {
e.source = source;
throw e;
}
if (data) {
return result(data);
}
// provide the compiled function's source by its `toString` method, in
// supported environments, or the `source` property as a convenience for
// inlining compiled templates during the build process
result.source = source;
return result;
}
/**
* Executes the callback `n` times, returning an array of the results
* of each callback execution. The callback is bound to `thisArg` and invoked
* with one argument; (index).
*
* @static
* @memberOf _
* @category Utilities
* @param {number} n The number of times to execute the callback.
* @param {Function} callback The function called per iteration.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {Array} Returns an array of the results of each `callback` execution.
* @example
*
* var diceRolls = _.times(3, _.partial(_.random, 1, 6));
* // => [3, 6, 4]
*
* _.times(3, function(n) { mage.castSpell(n); });
* // => calls `mage.castSpell(n)` three times, passing `n` of `0`, `1`, and `2` respectively
*
* _.times(3, function(n) { this.cast(n); }, mage);
* // => also calls `mage.castSpell(n)` three times
*/
function times(n, callback, thisArg) {
n = (n = +n) > -1 ? n : 0;
var index = -1,
result = Array(n);
callback = baseCreateCallback(callback, thisArg, 1);
while (++index < n) {
result[index] = callback(index);
}
return result;
}
/**
* The inverse of `_.escape` this method converts the HTML entities
* `&amp;`, `&lt;`, `&gt;`, `&quot;`, and `&#39;` in `string` to their
* corresponding characters.
*
* @static
* @memberOf _
* @category Utilities
* @param {string} string The string to unescape.
* @returns {string} Returns the unescaped string.
* @example
*
* _.unescape('Fred, Barney &amp; Pebbles');
* // => 'Fred, Barney & Pebbles'
*/
function unescape(string) {
return string == null ? '' : String(string).replace(reEscapedHtml, unescapeHtmlChar);
}
/**
* Generates a unique ID. If `prefix` is provided the ID will be appended to it.
*
* @static
* @memberOf _
* @category Utilities
* @param {string} [prefix] The value to prefix the ID with.
* @returns {string} Returns the unique ID.
* @example
*
* _.uniqueId('contact_');
* // => 'contact_104'
*
* _.uniqueId();
* // => '105'
*/
function uniqueId(prefix) {
var id = ++idCounter;
return String(prefix == null ? '' : prefix) + id;
}
/*--------------------------------------------------------------------------*/
/**
* Creates a `lodash` object that wraps the given value with explicit
* method chaining enabled.
*
* @static
* @memberOf _
* @category Chaining
* @param {*} value The value to wrap.
* @returns {Object} Returns the wrapper object.
* @example
*
* var characters = [
* { 'name': 'barney', 'age': 36 },
* { 'name': 'fred', 'age': 40 },
* { 'name': 'pebbles', 'age': 1 }
* ];
*
* var youngest = _.chain(characters)
* .sortBy('age')
* .map(function(chr) { return chr.name + ' is ' + chr.age; })
* .first()
* .value();
* // => 'pebbles is 1'
*/
function chain(value) {
value = new lodashWrapper(value);
value.__chain__ = true;
return value;
}
/**
* Invokes `interceptor` with the `value` as the first argument and then
* returns `value`. The purpose of this method is to "tap into" a method
* chain in order to perform operations on intermediate results within
* the chain.
*
* @static
* @memberOf _
* @category Chaining
* @param {*} value The value to provide to `interceptor`.
* @param {Function} interceptor The function to invoke.
* @returns {*} Returns `value`.
* @example
*
* _([1, 2, 3, 4])
* .tap(function(array) { array.pop(); })
* .reverse()
* .value();
* // => [3, 2, 1]
*/
function tap(value, interceptor) {
interceptor(value);
return value;
}
/**
* Enables explicit method chaining on the wrapper object.
*
* @name chain
* @memberOf _
* @category Chaining
* @returns {*} Returns the wrapper object.
* @example
*
* var characters = [
* { 'name': 'barney', 'age': 36 },
* { 'name': 'fred', 'age': 40 }
* ];
*
* // without explicit chaining
* _(characters).first();
* // => { 'name': 'barney', 'age': 36 }
*
* // with explicit chaining
* _(characters).chain()
* .first()
* .pick('age')
* .value();
* // => { 'age': 36 }
*/
function wrapperChain() {
this.__chain__ = true;
return this;
}
/**
* Produces the `toString` result of the wrapped value.
*
* @name toString
* @memberOf _
* @category Chaining
* @returns {string} Returns the string result.
* @example
*
* _([1, 2, 3]).toString();
* // => '1,2,3'
*/
function wrapperToString() {
return String(this.__wrapped__);
}
/**
* Extracts the wrapped value.
*
* @name valueOf
* @memberOf _
* @alias value
* @category Chaining
* @returns {*} Returns the wrapped value.
* @example
*
* _([1, 2, 3]).valueOf();
* // => [1, 2, 3]
*/
function wrapperValueOf() {
return this.__wrapped__;
}
/*--------------------------------------------------------------------------*/
// add functions that return wrapped values when chaining
lodash.after = after;
lodash.assign = assign;
lodash.at = at;
lodash.bind = bind;
lodash.bindAll = bindAll;
lodash.bindKey = bindKey;
lodash.chain = chain;
lodash.compact = compact;
lodash.compose = compose;
lodash.constant = constant;
lodash.countBy = countBy;
lodash.create = create;
lodash.createCallback = createCallback;
lodash.curry = curry;
lodash.debounce = debounce;
lodash.defaults = defaults;
lodash.defer = defer;
lodash.delay = delay;
lodash.difference = difference;
lodash.filter = filter;
lodash.flatten = flatten;
lodash.forEach = forEach;
lodash.forEachRight = forEachRight;
lodash.forIn = forIn;
lodash.forInRight = forInRight;
lodash.forOwn = forOwn;
lodash.forOwnRight = forOwnRight;
lodash.functions = functions;
lodash.groupBy = groupBy;
lodash.indexBy = indexBy;
lodash.initial = initial;
lodash.intersection = intersection;
lodash.invert = invert;
lodash.invoke = invoke;
lodash.keys = keys;
lodash.map = map;
lodash.mapValues = mapValues;
lodash.max = max;
lodash.memoize = memoize;
lodash.merge = merge;
lodash.min = min;
lodash.omit = omit;
lodash.once = once;
lodash.pairs = pairs;
lodash.partial = partial;
lodash.partialRight = partialRight;
lodash.pick = pick;
lodash.pluck = pluck;
lodash.property = property;
lodash.pull = pull;
lodash.range = range;
lodash.reject = reject;
lodash.remove = remove;
lodash.rest = rest;
lodash.shuffle = shuffle;
lodash.sortBy = sortBy;
lodash.tap = tap;
lodash.throttle = throttle;
lodash.times = times;
lodash.toArray = toArray;
lodash.transform = transform;
lodash.union = union;
lodash.uniq = uniq;
lodash.values = values;
lodash.where = where;
lodash.without = without;
lodash.wrap = wrap;
lodash.xor = xor;
lodash.zip = zip;
lodash.zipObject = zipObject;
// add aliases
lodash.collect = map;
lodash.drop = rest;
lodash.each = forEach;
lodash.eachRight = forEachRight;
lodash.extend = assign;
lodash.methods = functions;
lodash.object = zipObject;
lodash.select = filter;
lodash.tail = rest;
lodash.unique = uniq;
lodash.unzip = zip;
// add functions to `lodash.prototype`
mixin(lodash);
/*--------------------------------------------------------------------------*/
// add functions that return unwrapped values when chaining
lodash.clone = clone;
lodash.cloneDeep = cloneDeep;
lodash.contains = contains;
lodash.escape = escape;
lodash.every = every;
lodash.find = find;
lodash.findIndex = findIndex;
lodash.findKey = findKey;
lodash.findLast = findLast;
lodash.findLastIndex = findLastIndex;
lodash.findLastKey = findLastKey;
lodash.has = has;
lodash.identity = identity;
lodash.indexOf = indexOf;
lodash.isArguments = isArguments;
lodash.isArray = isArray;
lodash.isBoolean = isBoolean;
lodash.isDate = isDate;
lodash.isElement = isElement;
lodash.isEmpty = isEmpty;
lodash.isEqual = isEqual;
lodash.isFinite = isFinite;
lodash.isFunction = isFunction;
lodash.isNaN = isNaN;
lodash.isNull = isNull;
lodash.isNumber = isNumber;
lodash.isObject = isObject;
lodash.isPlainObject = isPlainObject;
lodash.isRegExp = isRegExp;
lodash.isString = isString;
lodash.isUndefined = isUndefined;
lodash.lastIndexOf = lastIndexOf;
lodash.mixin = mixin;
lodash.noConflict = noConflict;
lodash.noop = noop;
lodash.now = now;
lodash.parseInt = parseInt;
lodash.random = random;
lodash.reduce = reduce;
lodash.reduceRight = reduceRight;
lodash.result = result;
lodash.runInContext = runInContext;
lodash.size = size;
lodash.some = some;
lodash.sortedIndex = sortedIndex;
lodash.template = template;
lodash.unescape = unescape;
lodash.uniqueId = uniqueId;
// add aliases
lodash.all = every;
lodash.any = some;
lodash.detect = find;
lodash.findWhere = find;
lodash.foldl = reduce;
lodash.foldr = reduceRight;
lodash.include = contains;
lodash.inject = reduce;
mixin(function() {
var source = {}
forOwn(lodash, function(func, methodName) {
if (!lodash.prototype[methodName]) {
source[methodName] = func;
}
});
return source;
}(), false);
/*--------------------------------------------------------------------------*/
// add functions capable of returning wrapped and unwrapped values when chaining
lodash.first = first;
lodash.last = last;
lodash.sample = sample;
// add aliases
lodash.take = first;
lodash.head = first;
forOwn(lodash, function(func, methodName) {
var callbackable = methodName !== 'sample';
if (!lodash.prototype[methodName]) {
lodash.prototype[methodName]= function(n, guard) {
var chainAll = this.__chain__,
result = func(this.__wrapped__, n, guard);
return !chainAll && (n == null || (guard && !(callbackable && typeof n == 'function')))
? result
: new lodashWrapper(result, chainAll);
};
}
});
/*--------------------------------------------------------------------------*/
/**
* The semantic version number.
*
* @static
* @memberOf _
* @type string
*/
lodash.VERSION = '2.4.1';
// add "Chaining" functions to the wrapper
lodash.prototype.chain = wrapperChain;
lodash.prototype.toString = wrapperToString;
lodash.prototype.value = wrapperValueOf;
lodash.prototype.valueOf = wrapperValueOf;
// add `Array` functions that return unwrapped values
baseEach(['join', 'pop', 'shift'], function(methodName) {
var func = arrayRef[methodName];
lodash.prototype[methodName] = function() {
var chainAll = this.__chain__,
result = func.apply(this.__wrapped__, arguments);
return chainAll
? new lodashWrapper(result, chainAll)
: result;
};
});
// add `Array` functions that return the existing wrapped value
baseEach(['push', 'reverse', 'sort', 'unshift'], function(methodName) {
var func = arrayRef[methodName];
lodash.prototype[methodName] = function() {
func.apply(this.__wrapped__, arguments);
return this;
};
});
// add `Array` functions that return new wrapped values
baseEach(['concat', 'slice', 'splice'], function(methodName) {
var func = arrayRef[methodName];
lodash.prototype[methodName] = function() {
return new lodashWrapper(func.apply(this.__wrapped__, arguments), this.__chain__);
};
});
// avoid array-like object bugs with `Array#shift` and `Array#splice`
// in IE < 9, Firefox < 10, Narwhal, and RingoJS
if (!support.spliceObjects) {
baseEach(['pop', 'shift', 'splice'], function(methodName) {
var func = arrayRef[methodName],
isSplice = methodName == 'splice';
lodash.prototype[methodName] = function() {
var chainAll = this.__chain__,
value = this.__wrapped__,
result = func.apply(value, arguments);
if (value.length === 0) {
delete value[0];
}
return (chainAll || isSplice)
? new lodashWrapper(result, chainAll)
: result;
};
});
}
// add pseudo private property to be used and removed during the build process
lodash._baseEach = baseEach;
lodash._iteratorTemplate = iteratorTemplate;
lodash._shimKeys = shimKeys;
return lodash;
}
/*--------------------------------------------------------------------------*/
// expose Lo-Dash
var _ = runInContext();
// some AMD build optimizers like r.js check for condition patterns like the following:
if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
// Expose Lo-Dash to the global object even when an AMD loader is present in
// case Lo-Dash is loaded with a RequireJS shim config.
// See http://requirejs.org/docs/api.html#config-shim
root._ = _;
// define as an anonymous module so, through path mapping, it can be
// referenced as the "underscore" module
define(function() {
return _;
});
}
// check for `exports` after `define` in case a build optimizer adds an `exports` object
else if (freeExports && freeModule) {
// in Node.js or RingoJS
if (moduleExports) {
(freeModule.exports = _)._ = _;
}
// in Narwhal or Rhino -require
else {
freeExports._ = _;
}
}
else {
// in a browser or Rhino
root._ = _;
}
}.call(this));
}).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{}],"lodash":[function(require,module,exports){
module.exports=require('4HJaAd');
},{}],"mori":[function(require,module,exports){
module.exports=require('ekOHxz');
},{}],"ekOHxz":[function(require,module,exports){
(function(definition){if(typeof exports==="object"){module.exports=definition();}else if(typeof define==="function"&&define.amd){define(definition);}else{mori=definition();}})(function(){return function(){
var g,aa=this;
function m(a){var b=typeof a;if("object"==b)if(a){if(a instanceof Array)return"array";if(a instanceof Object)return b;var c=Object.prototype.toString.call(a);if("[object Window]"==c)return"object";if("[object Array]"==c||"number"==typeof a.length&&"undefined"!=typeof a.splice&&"undefined"!=typeof a.propertyIsEnumerable&&!a.propertyIsEnumerable("splice"))return"array";if("[object Function]"==c||"undefined"!=typeof a.call&&"undefined"!=typeof a.propertyIsEnumerable&&!a.propertyIsEnumerable("call"))return"function"}else return"null";else if("function"==
b&&"undefined"==typeof a.call)return"object";return b}var ba="closure_uid_"+(1E9*Math.random()>>>0),ca=0;function p(a,b){var c=a.split("."),d=aa;c[0]in d||!d.execScript||d.execScript("var "+c[0]);for(var e;c.length&&(e=c.shift());)c.length||void 0===b?d=d[e]?d[e]:d[e]={}:d[e]=b};function da(a,b){for(var c in a)b.call(void 0,a[c],c,a)};function ea(a,b){null!=a&&this.append.apply(this,arguments)}ea.prototype.Va="";ea.prototype.append=function(a,b,c){this.Va+=a;if(null!=b)for(var d=1;d<arguments.length;d++)this.Va+=arguments[d];return this};ea.prototype.toString=function(){return this.Va};function fa(a,b){a.sort(b||ga)}function ha(a,b){for(var c=0;c<a.length;c++)a[c]={index:c,value:a[c]};var d=b||ga;fa(a,function(a,b){return d(a.value,b.value)||a.index-b.index});for(c=0;c<a.length;c++)a[c]=a[c].value}function ga(a,b){return a>b?1:a<b?-1:0};var ia=null,ja=null;function ka(){return new la(null,5,[ma,!0,oa,!0,pa,!1,qa,!1,ra,ia],null)}function r(a){return null!=a&&!1!==a}function sa(a){return r(a)?!1:!0}function s(a,b){return a[m(null==b?null:b)]?!0:a._?!0:u?!1:null}function ta(a){return null==a?null:a.constructor}function x(a,b){var c=ta(b),c=r(r(c)?c.Db:c)?c.Bb:m(b);return Error(["No protocol method ",a," defined for type ",c,": ",b].join(""))}function ua(a){var b=a.Bb;return r(b)?b:""+A.b(a)}
function va(a){for(var b=a.length,c=Array(b),d=0;;)if(d<b)c[d]=a[d],d+=1;else break;return c}function wa(a){return Array.prototype.slice.call(arguments)}
var xa=function(){function a(a,b){return C.c?C.c(function(a,b){a.push(b);return a},[],b):C.call(null,function(a,b){a.push(b);return a},[],b)}function b(a){return c.a(null,a)}var c=null,c=function(c,e){switch(arguments.length){case 1:return b.call(this,c);case 2:return a.call(this,0,e)}throw Error("Invalid arity: "+arguments.length);};c.b=b;c.a=a;return c}(),ya={},za={};
function Aa(a){if(a?a.L:a)return a.L(a);var b;b=Aa[m(null==a?null:a)];if(!b&&(b=Aa._,!b))throw x("ICounted.-count",a);return b.call(null,a)}function Ba(a){if(a?a.I:a)return a.I(a);var b;b=Ba[m(null==a?null:a)];if(!b&&(b=Ba._,!b))throw x("IEmptyableCollection.-empty",a);return b.call(null,a)}var Ca={};function Da(a,b){if(a?a.G:a)return a.G(a,b);var c;c=Da[m(null==a?null:a)];if(!c&&(c=Da._,!c))throw x("ICollection.-conj",a);return c.call(null,a,b)}
var Ea={},D=function(){function a(a,b,c){if(a?a.aa:a)return a.aa(a,b,c);var h;h=D[m(null==a?null:a)];if(!h&&(h=D._,!h))throw x("IIndexed.-nth",a);return h.call(null,a,b,c)}function b(a,b){if(a?a.J:a)return a.J(a,b);var c;c=D[m(null==a?null:a)];if(!c&&(c=D._,!c))throw x("IIndexed.-nth",a);return c.call(null,a,b)}var c=null,c=function(c,e,f){switch(arguments.length){case 2:return b.call(this,c,e);case 3:return a.call(this,c,e,f)}throw Error("Invalid arity: "+arguments.length);};c.a=b;c.c=a;return c}(),
Fa={};function Ha(a){if(a?a.Q:a)return a.Q(a);var b;b=Ha[m(null==a?null:a)];if(!b&&(b=Ha._,!b))throw x("ISeq.-first",a);return b.call(null,a)}function Ia(a){if(a?a.S:a)return a.S(a);var b;b=Ia[m(null==a?null:a)];if(!b&&(b=Ia._,!b))throw x("ISeq.-rest",a);return b.call(null,a)}
var Ja={},Ka={},La=function(){function a(a,b,c){if(a?a.C:a)return a.C(a,b,c);var h;h=La[m(null==a?null:a)];if(!h&&(h=La._,!h))throw x("ILookup.-lookup",a);return h.call(null,a,b,c)}function b(a,b){if(a?a.u:a)return a.u(a,b);var c;c=La[m(null==a?null:a)];if(!c&&(c=La._,!c))throw x("ILookup.-lookup",a);return c.call(null,a,b)}var c=null,c=function(c,e,f){switch(arguments.length){case 2:return b.call(this,c,e);case 3:return a.call(this,c,e,f)}throw Error("Invalid arity: "+arguments.length);};c.a=b;c.c=
a;return c}(),Ma={};function Na(a,b){if(a?a.kb:a)return a.kb(a,b);var c;c=Na[m(null==a?null:a)];if(!c&&(c=Na._,!c))throw x("IAssociative.-contains-key?",a);return c.call(null,a,b)}function Oa(a,b,c){if(a?a.ua:a)return a.ua(a,b,c);var d;d=Oa[m(null==a?null:a)];if(!d&&(d=Oa._,!d))throw x("IAssociative.-assoc",a);return d.call(null,a,b,c)}var Pa={};function Qa(a,b){if(a?a.nb:a)return a.nb(a,b);var c;c=Qa[m(null==a?null:a)];if(!c&&(c=Qa._,!c))throw x("IMap.-dissoc",a);return c.call(null,a,b)}var Sa={};
function Ta(a){if(a?a.$a:a)return a.$a(a);var b;b=Ta[m(null==a?null:a)];if(!b&&(b=Ta._,!b))throw x("IMapEntry.-key",a);return b.call(null,a)}function Ua(a){if(a?a.ab:a)return a.ab(a);var b;b=Ua[m(null==a?null:a)];if(!b&&(b=Ua._,!b))throw x("IMapEntry.-val",a);return b.call(null,a)}var Va={};function Wa(a,b){if(a?a.vb:a)return a.vb(a,b);var c;c=Wa[m(null==a?null:a)];if(!c&&(c=Wa._,!c))throw x("ISet.-disjoin",a);return c.call(null,a,b)}
function Xa(a){if(a?a.Ia:a)return a.Ia(a);var b;b=Xa[m(null==a?null:a)];if(!b&&(b=Xa._,!b))throw x("IStack.-peek",a);return b.call(null,a)}function Ya(a){if(a?a.Ja:a)return a.Ja(a);var b;b=Ya[m(null==a?null:a)];if(!b&&(b=Ya._,!b))throw x("IStack.-pop",a);return b.call(null,a)}var Za={};function $a(a,b,c){if(a?a.Pa:a)return a.Pa(a,b,c);var d;d=$a[m(null==a?null:a)];if(!d&&(d=$a._,!d))throw x("IVector.-assoc-n",a);return d.call(null,a,b,c)}
function ab(a){if(a?a.ub:a)return a.ub(a);var b;b=ab[m(null==a?null:a)];if(!b&&(b=ab._,!b))throw x("IDeref.-deref",a);return b.call(null,a)}var bb={};function cb(a){if(a?a.D:a)return a.D(a);var b;b=cb[m(null==a?null:a)];if(!b&&(b=cb._,!b))throw x("IMeta.-meta",a);return b.call(null,a)}var db={};function eb(a,b){if(a?a.F:a)return a.F(a,b);var c;c=eb[m(null==a?null:a)];if(!c&&(c=eb._,!c))throw x("IWithMeta.-with-meta",a);return c.call(null,a,b)}
var fb={},gb=function(){function a(a,b,c){if(a?a.M:a)return a.M(a,b,c);var h;h=gb[m(null==a?null:a)];if(!h&&(h=gb._,!h))throw x("IReduce.-reduce",a);return h.call(null,a,b,c)}function b(a,b){if(a?a.N:a)return a.N(a,b);var c;c=gb[m(null==a?null:a)];if(!c&&(c=gb._,!c))throw x("IReduce.-reduce",a);return c.call(null,a,b)}var c=null,c=function(c,e,f){switch(arguments.length){case 2:return b.call(this,c,e);case 3:return a.call(this,c,e,f)}throw Error("Invalid arity: "+arguments.length);};c.a=b;c.c=a;return c}();
function hb(a,b,c){if(a?a.Za:a)return a.Za(a,b,c);var d;d=hb[m(null==a?null:a)];if(!d&&(d=hb._,!d))throw x("IKVReduce.-kv-reduce",a);return d.call(null,a,b,c)}function ib(a,b){if(a?a.v:a)return a.v(a,b);var c;c=ib[m(null==a?null:a)];if(!c&&(c=ib._,!c))throw x("IEquiv.-equiv",a);return c.call(null,a,b)}function jb(a){if(a?a.B:a)return a.B(a);var b;b=jb[m(null==a?null:a)];if(!b&&(b=jb._,!b))throw x("IHash.-hash",a);return b.call(null,a)}var kb={};
function lb(a){if(a?a.H:a)return a.H(a);var b;b=lb[m(null==a?null:a)];if(!b&&(b=lb._,!b))throw x("ISeqable.-seq",a);return b.call(null,a)}var mb={},nb={},ob={};function pb(a){if(a?a.Xa:a)return a.Xa(a);var b;b=pb[m(null==a?null:a)];if(!b&&(b=pb._,!b))throw x("IReversible.-rseq",a);return b.call(null,a)}function qb(a,b){if(a?a.yb:a)return a.yb(a,b);var c;c=qb[m(null==a?null:a)];if(!c&&(c=qb._,!c))throw x("ISorted.-sorted-seq",a);return c.call(null,a,b)}
function rb(a,b,c){if(a?a.zb:a)return a.zb(a,b,c);var d;d=rb[m(null==a?null:a)];if(!d&&(d=rb._,!d))throw x("ISorted.-sorted-seq-from",a);return d.call(null,a,b,c)}function sb(a,b){if(a?a.xb:a)return a.xb(a,b);var c;c=sb[m(null==a?null:a)];if(!c&&(c=sb._,!c))throw x("ISorted.-entry-key",a);return c.call(null,a,b)}function tb(a){if(a?a.wb:a)return a.wb(a);var b;b=tb[m(null==a?null:a)];if(!b&&(b=tb._,!b))throw x("ISorted.-comparator",a);return b.call(null,a)}
function ub(a,b){if(a?a.Sb:a)return a.Sb(0,b);var c;c=ub[m(null==a?null:a)];if(!c&&(c=ub._,!c))throw x("IWriter.-write",a);return c.call(null,a,b)}var vb={};function wb(a,b,c){if(a?a.w:a)return a.w(a,b,c);var d;d=wb[m(null==a?null:a)];if(!d&&(d=wb._,!d))throw x("IPrintWithWriter.-pr-writer",a);return d.call(null,a,b,c)}function xb(a,b,c){if(a?a.Rb:a)return a.Rb(0,b,c);var d;d=xb[m(null==a?null:a)];if(!d&&(d=xb._,!d))throw x("IWatchable.-notify-watches",a);return d.call(null,a,b,c)}
function yb(a){if(a?a.Wa:a)return a.Wa(a);var b;b=yb[m(null==a?null:a)];if(!b&&(b=yb._,!b))throw x("IEditableCollection.-as-transient",a);return b.call(null,a)}function zb(a,b){if(a?a.Ka:a)return a.Ka(a,b);var c;c=zb[m(null==a?null:a)];if(!c&&(c=zb._,!c))throw x("ITransientCollection.-conj!",a);return c.call(null,a,b)}function Ab(a){if(a?a.Oa:a)return a.Oa(a);var b;b=Ab[m(null==a?null:a)];if(!b&&(b=Ab._,!b))throw x("ITransientCollection.-persistent!",a);return b.call(null,a)}
function Bb(a,b,c){if(a?a.cb:a)return a.cb(a,b,c);var d;d=Bb[m(null==a?null:a)];if(!d&&(d=Bb._,!d))throw x("ITransientAssociative.-assoc!",a);return d.call(null,a,b,c)}function Cb(a,b){if(a?a.Ab:a)return a.Ab(a,b);var c;c=Cb[m(null==a?null:a)];if(!c&&(c=Cb._,!c))throw x("ITransientMap.-dissoc!",a);return c.call(null,a,b)}function Db(a,b,c){if(a?a.Pb:a)return a.Pb(0,b,c);var d;d=Db[m(null==a?null:a)];if(!d&&(d=Db._,!d))throw x("ITransientVector.-assoc-n!",a);return d.call(null,a,b,c)}
function Eb(a){if(a?a.Qb:a)return a.Qb();var b;b=Eb[m(null==a?null:a)];if(!b&&(b=Eb._,!b))throw x("ITransientVector.-pop!",a);return b.call(null,a)}function Fb(a,b){if(a?a.Ob:a)return a.Ob(0,b);var c;c=Fb[m(null==a?null:a)];if(!c&&(c=Fb._,!c))throw x("ITransientSet.-disjoin!",a);return c.call(null,a,b)}function Gb(a){if(a?a.Kb:a)return a.Kb();var b;b=Gb[m(null==a?null:a)];if(!b&&(b=Gb._,!b))throw x("IChunk.-drop-first",a);return b.call(null,a)}
function Hb(a){if(a?a.sb:a)return a.sb(a);var b;b=Hb[m(null==a?null:a)];if(!b&&(b=Hb._,!b))throw x("IChunkedSeq.-chunked-first",a);return b.call(null,a)}function Ib(a){if(a?a.tb:a)return a.tb(a);var b;b=Ib[m(null==a?null:a)];if(!b&&(b=Ib._,!b))throw x("IChunkedSeq.-chunked-rest",a);return b.call(null,a)}function Jb(a){if(a?a.rb:a)return a.rb(a);var b;b=Jb[m(null==a?null:a)];if(!b&&(b=Jb._,!b))throw x("IChunkedNext.-chunked-next",a);return b.call(null,a)}
function Kb(a){this.vc=a;this.q=0;this.i=1073741824}Kb.prototype.Sb=function(a,b){return this.vc.append(b)};function Lb(a){var b=new ea;a.w(null,new Kb(b),ka());return""+A.b(b)}var Mb="undefined"!==typeof Math.imul&&0!==(Math.imul.a?Math.imul.a(4294967295,5):Math.imul.call(null,4294967295,5))?function(a,b){return Math.imul(a,b)}:function(a,b){var c=a&65535,d=b&65535;return c*d+((a>>>16&65535)*d+c*(b>>>16&65535)<<16>>>0)|0};function Nb(a){a=Mb(a,3432918353);return Mb(a<<15|a>>>-15,461845907)}
function Ob(a,b){var c=a^b;return Mb(c<<13|c>>>-13,5)+3864292196}function Pb(a,b){var c=a^b,c=Mb(c^c>>>16,2246822507),c=Mb(c^c>>>13,3266489909);return c^c>>>16}var Qb={},Rb=0;function Sb(a){255<Rb&&(Qb={},Rb=0);var b=Qb[a];if("number"!==typeof b){a:if(null!=a)if(b=a.length,0<b){for(var c=0,d=0;;)if(c<b)var e=c+1,d=Mb(31,d)+a.charCodeAt(c),c=e;else{b=d;break a}b=void 0}else b=0;else b=0;Qb[a]=b;Rb+=1}return a=b}
function Tb(a){a&&(a.i&4194304||a.Dc)?a=a.B(null):"number"===typeof a?a=Math.floor(a)%2147483647:!0===a?a=1:!1===a?a=0:"string"===typeof a?(a=Sb(a),0!==a&&(a=Nb(a),a=Ob(0,a),a=Pb(a,4))):a=null==a?0:u?jb(a):null;return a}
function Ub(a){var b;b=a.name;var c;a:{c=1;for(var d=0;;)if(c<b.length){var e=c+2,d=Ob(d,Nb(b.charCodeAt(c-1)|b.charCodeAt(c)<<16));c=e}else{c=d;break a}c=void 0}c=1===(b.length&1)?c^Nb(b.charCodeAt(b.length-1)):c;b=Pb(c,Mb(2,b.length));a=Sb(a.fa);return b^a+2654435769+(b<<6)+(b>>2)}
function Vb(a,b){if(r(Wb.a?Wb.a(a,b):Wb.call(null,a,b)))return 0;var c=sa(a.fa);if(r(c?b.fa:c))return-1;if(r(a.fa)){if(sa(b.fa))return 1;c=Xb.a?Xb.a(a.fa,b.fa):Xb.call(null,a.fa,b.fa);return 0===c?Xb.a?Xb.a(a.name,b.name):Xb.call(null,a.name,b.name):c}return Yb?Xb.a?Xb.a(a.name,b.name):Xb.call(null,a.name,b.name):null}function Zb(a,b,c,d,e){this.fa=a;this.name=b;this.Na=c;this.Ua=d;this.W=e;this.i=2154168321;this.q=4096}g=Zb.prototype;g.w=function(a,b){return ub(b,this.Na)};
g.B=function(){var a=this.Ua;return null!=a?a:this.Ua=a=Ub(this)};g.F=function(a,b){return new Zb(this.fa,this.name,this.Na,this.Ua,b)};g.D=function(){return this.W};g.call=function(){var a=null;return a=function(a,c,d){switch(arguments.length){case 2:return La.c(c,this,null);case 3:return La.c(c,this,d)}throw Error("Invalid arity: "+arguments.length);}}();g.apply=function(a,b){return this.call.apply(this,[this].concat(va(b)))};g.b=function(a){return La.c(a,this,null)};
g.a=function(a,b){return La.c(a,this,b)};g.v=function(a,b){return b instanceof Zb?this.Na===b.Na:!1};g.toString=function(){return this.Na};var $b=function(){function a(a,b){var c=null!=a?""+A.b(a)+"/"+A.b(b):b;return new Zb(a,b,c,null,null)}function b(a){return a instanceof Zb?a:c.a(null,a)}var c=null,c=function(c,e){switch(arguments.length){case 1:return b.call(this,c);case 2:return a.call(this,c,e)}throw Error("Invalid arity: "+arguments.length);};c.b=b;c.a=a;return c}();
function E(a){if(null==a)return null;if(a&&(a.i&8388608||a.hc))return a.H(null);if(a instanceof Array||"string"===typeof a)return 0===a.length?null:new ac(a,0);if(s(kb,a))return lb(a);if(u)throw Error(""+A.b(a)+" is not ISeqable");return null}function F(a){if(null==a)return null;if(a&&(a.i&64||a.bb))return a.Q(null);a=E(a);return null==a?null:Ha(a)}function G(a){return null!=a?a&&(a.i&64||a.bb)?a.S(null):(a=E(a))?Ia(a):H:H}function I(a){return null==a?null:a&&(a.i&128||a.ob)?a.U(null):E(G(a))}
var Wb=function(){function a(a,b){return null==a?null==b:a===b||ib(a,b)}var b=null,c=function(){function a(b,d,k){var l=null;2<arguments.length&&(l=J(Array.prototype.slice.call(arguments,2),0));return c.call(this,b,d,l)}function c(a,d,e){for(;;)if(b.a(a,d))if(I(e))a=d,d=F(e),e=I(e);else return b.a(d,F(e));else return!1}a.k=2;a.f=function(a){var b=F(a);a=I(a);var d=F(a);a=G(a);return c(b,d,a)};a.d=c;return a}(),b=function(b,e,f){switch(arguments.length){case 1:return!0;case 2:return a.call(this,b,
e);default:return c.d(b,e,J(arguments,2))}throw Error("Invalid arity: "+arguments.length);};b.k=2;b.f=c.f;b.b=function(){return!0};b.a=a;b.d=c.d;return b}();function bc(a,b){var c=Nb(a),c=Ob(0,c);return Pb(c,b)}function cc(a){var b=0,c=1;for(a=E(a);;)if(null!=a)b+=1,c=Mb(31,c)+Tb(F(a))|0,a=I(a);else return bc(c,b)}function dc(a){var b=0,c=0;for(a=E(a);;)if(null!=a)b+=1,c=c+Tb(F(a))|0,a=I(a);else return bc(c,b)}za["null"]=!0;Aa["null"]=function(){return 0};
Date.prototype.v=function(a,b){return b instanceof Date&&this.toString()===b.toString()};ib.number=function(a,b){return a===b};bb["function"]=!0;cb["function"]=function(){return null};ya["function"]=!0;jb._=function(a){return a[ba]||(a[ba]=++ca)};function ec(a){this.l=a;this.q=0;this.i=32768}ec.prototype.ub=function(){return this.l};function fc(a){return a instanceof ec}
var gc=function(){function a(a,b,c,d){for(var l=Aa(a);;)if(d<l){c=b.a?b.a(c,D.a(a,d)):b.call(null,c,D.a(a,d));if(fc(c))return K.b?K.b(c):K.call(null,c);d+=1}else return c}function b(a,b,c){for(var d=Aa(a),l=0;;)if(l<d){c=b.a?b.a(c,D.a(a,l)):b.call(null,c,D.a(a,l));if(fc(c))return K.b?K.b(c):K.call(null,c);l+=1}else return c}function c(a,b){var c=Aa(a);if(0===c)return b.o?b.o():b.call(null);for(var d=D.a(a,0),l=1;;)if(l<c){d=b.a?b.a(d,D.a(a,l)):b.call(null,d,D.a(a,l));if(fc(d))return K.b?K.b(d):K.call(null,
d);l+=1}else return d}var d=null,d=function(d,f,h,k){switch(arguments.length){case 2:return c.call(this,d,f);case 3:return b.call(this,d,f,h);case 4:return a.call(this,d,f,h,k)}throw Error("Invalid arity: "+arguments.length);};d.a=c;d.c=b;d.n=a;return d}(),hc=function(){function a(a,b,c,d){for(var l=a.length;;)if(d<l){c=b.a?b.a(c,a[d]):b.call(null,c,a[d]);if(fc(c))return K.b?K.b(c):K.call(null,c);d+=1}else return c}function b(a,b,c){for(var d=a.length,l=0;;)if(l<d){c=b.a?b.a(c,a[l]):b.call(null,c,
a[l]);if(fc(c))return K.b?K.b(c):K.call(null,c);l+=1}else return c}function c(a,b){var c=a.length;if(0===a.length)return b.o?b.o():b.call(null);for(var d=a[0],l=1;;)if(l<c){d=b.a?b.a(d,a[l]):b.call(null,d,a[l]);if(fc(d))return K.b?K.b(d):K.call(null,d);l+=1}else return d}var d=null,d=function(d,f,h,k){switch(arguments.length){case 2:return c.call(this,d,f);case 3:return b.call(this,d,f,h);case 4:return a.call(this,d,f,h,k)}throw Error("Invalid arity: "+arguments.length);};d.a=c;d.c=b;d.n=a;return d}();
function ic(a){return a?a.i&2||a.Yb?!0:a.i?!1:s(za,a):s(za,a)}function jc(a){return a?a.i&16||a.Lb?!0:a.i?!1:s(Ea,a):s(Ea,a)}function ac(a,b){this.e=a;this.p=b;this.i=166199550;this.q=8192}g=ac.prototype;g.toString=function(){return Lb(this)};g.J=function(a,b){var c=b+this.p;return c<this.e.length?this.e[c]:null};g.aa=function(a,b,c){a=b+this.p;return a<this.e.length?this.e[a]:c};g.U=function(){return this.p+1<this.e.length?new ac(this.e,this.p+1):null};g.L=function(){return this.e.length-this.p};
g.Xa=function(){var a=Aa(this);return 0<a?new kc(this,a-1,null):null};g.B=function(){return cc(this)};g.v=function(a,b){return lc.a?lc.a(this,b):lc.call(null,this,b)};g.I=function(){return H};g.N=function(a,b){return hc.n(this.e,b,this.e[this.p],this.p+1)};g.M=function(a,b,c){return hc.n(this.e,b,c,this.p)};g.Q=function(){return this.e[this.p]};g.S=function(){return this.p+1<this.e.length?new ac(this.e,this.p+1):H};g.H=function(){return this};
g.G=function(a,b){return M.a?M.a(b,this):M.call(null,b,this)};
var mc=function(){function a(a,b){return b<a.length?new ac(a,b):null}function b(a){return c.a(a,0)}var c=null,c=function(c,e){switch(arguments.length){case 1:return b.call(this,c);case 2:return a.call(this,c,e)}throw Error("Invalid arity: "+arguments.length);};c.b=b;c.a=a;return c}(),J=function(){function a(a,b){return mc.a(a,b)}function b(a){return mc.a(a,0)}var c=null,c=function(c,e){switch(arguments.length){case 1:return b.call(this,c);case 2:return a.call(this,c,e)}throw Error("Invalid arity: "+
arguments.length);};c.b=b;c.a=a;return c}();function kc(a,b,c){this.jb=a;this.p=b;this.j=c;this.i=32374990;this.q=8192}g=kc.prototype;g.toString=function(){return Lb(this)};g.D=function(){return this.j};g.U=function(){return 0<this.p?new kc(this.jb,this.p-1,null):null};g.L=function(){return this.p+1};g.B=function(){return cc(this)};g.v=function(a,b){return lc.a?lc.a(this,b):lc.call(null,this,b)};g.I=function(){return N.a?N.a(H,this.j):N.call(null,H,this.j)};
g.N=function(a,b){return nc.a?nc.a(b,this):nc.call(null,b,this)};g.M=function(a,b,c){return nc.c?nc.c(b,c,this):nc.call(null,b,c,this)};g.Q=function(){return D.a(this.jb,this.p)};g.S=function(){return 0<this.p?new kc(this.jb,this.p-1,null):H};g.H=function(){return this};g.F=function(a,b){return new kc(this.jb,this.p,b)};g.G=function(a,b){return M.a?M.a(b,this):M.call(null,b,this)};function oc(a){for(;;){var b=I(a);if(null!=b)a=b;else return F(a)}}ib._=function(a,b){return a===b};
var pc=function(){function a(a,b){return null!=a?Da(a,b):Da(H,b)}var b=null,c=function(){function a(b,d,k){var l=null;2<arguments.length&&(l=J(Array.prototype.slice.call(arguments,2),0));return c.call(this,b,d,l)}function c(a,d,e){for(;;)if(r(e))a=b.a(a,d),d=F(e),e=I(e);else return b.a(a,d)}a.k=2;a.f=function(a){var b=F(a);a=I(a);var d=F(a);a=G(a);return c(b,d,a)};a.d=c;return a}(),b=function(b,e,f){switch(arguments.length){case 2:return a.call(this,b,e);default:return c.d(b,e,J(arguments,2))}throw Error("Invalid arity: "+
arguments.length);};b.k=2;b.f=c.f;b.a=a;b.d=c.d;return b}();function qc(a){return null==a?null:Ba(a)}function O(a){if(null!=a)if(a&&(a.i&2||a.Yb))a=a.L(null);else if(a instanceof Array)a=a.length;else if("string"===typeof a)a=a.length;else if(s(za,a))a=Aa(a);else if(u)a:{a=E(a);for(var b=0;;){if(ic(a)){a=b+Aa(a);break a}a=I(a);b+=1}a=void 0}else a=null;else a=0;return a}
var rc=function(){function a(a,b,c){for(;;){if(null==a)return c;if(0===b)return E(a)?F(a):c;if(jc(a))return D.c(a,b,c);if(E(a))a=I(a),b-=1;else return u?c:null}}function b(a,b){for(;;){if(null==a)throw Error("Index out of bounds");if(0===b){if(E(a))return F(a);throw Error("Index out of bounds");}if(jc(a))return D.a(a,b);if(E(a)){var c=I(a),h=b-1;a=c;b=h}else{if(u)throw Error("Index out of bounds");return null}}}var c=null,c=function(c,e,f){switch(arguments.length){case 2:return b.call(this,c,e);case 3:return a.call(this,
c,e,f)}throw Error("Invalid arity: "+arguments.length);};c.a=b;c.c=a;return c}(),P=function(){function a(a,b,c){if("number"!==typeof b)throw Error("index argument to nth must be a number.");if(null==a)return c;if(a&&(a.i&16||a.Lb))return a.aa(null,b,c);if(a instanceof Array||"string"===typeof a)return b<a.length?a[b]:c;if(s(Ea,a))return D.a(a,b);if(a?a.i&64||a.bb||(a.i?0:s(Fa,a)):s(Fa,a))return rc.c(a,b,c);if(u)throw Error("nth not supported on this type "+A.b(ua(ta(a))));return null}function b(a,
b){if("number"!==typeof b)throw Error("index argument to nth must be a number");if(null==a)return a;if(a&&(a.i&16||a.Lb))return a.J(null,b);if(a instanceof Array||"string"===typeof a)return b<a.length?a[b]:null;if(s(Ea,a))return D.a(a,b);if(a?a.i&64||a.bb||(a.i?0:s(Fa,a)):s(Fa,a))return rc.a(a,b);if(u)throw Error("nth not supported on this type "+A.b(ua(ta(a))));return null}var c=null,c=function(c,e,f){switch(arguments.length){case 2:return b.call(this,c,e);case 3:return a.call(this,c,e,f)}throw Error("Invalid arity: "+
arguments.length);};c.a=b;c.c=a;return c}(),Q=function(){function a(a,b,c){return null!=a?a&&(a.i&256||a.Mb)?a.C(null,b,c):a instanceof Array?b<a.length?a[b]:c:"string"===typeof a?b<a.length?a[b]:c:s(Ka,a)?La.c(a,b,c):u?c:null:c}function b(a,b){return null==a?null:a&&(a.i&256||a.Mb)?a.u(null,b):a instanceof Array?b<a.length?a[b]:null:"string"===typeof a?b<a.length?a[b]:null:s(Ka,a)?La.a(a,b):null}var c=null,c=function(c,e,f){switch(arguments.length){case 2:return b.call(this,c,e);case 3:return a.call(this,
c,e,f)}throw Error("Invalid arity: "+arguments.length);};c.a=b;c.c=a;return c}(),R=function(){function a(a,b,c){return null!=a?Oa(a,b,c):sc.a?sc.a([b],[c]):sc.call(null,[b],[c])}var b=null,c=function(){function a(b,d,k,l){var n=null;3<arguments.length&&(n=J(Array.prototype.slice.call(arguments,3),0));return c.call(this,b,d,k,n)}function c(a,d,e,l){for(;;)if(a=b.c(a,d,e),r(l))d=F(l),e=F(I(l)),l=I(I(l));else return a}a.k=3;a.f=function(a){var b=F(a);a=I(a);var d=F(a);a=I(a);var l=F(a);a=G(a);return c(b,
d,l,a)};a.d=c;return a}(),b=function(b,e,f,h){switch(arguments.length){case 3:return a.call(this,b,e,f);default:return c.d(b,e,f,J(arguments,3))}throw Error("Invalid arity: "+arguments.length);};b.k=3;b.f=c.f;b.c=a;b.d=c.d;return b}(),tc=function(){function a(a,b){return null==a?null:Qa(a,b)}var b=null,c=function(){function a(b,d,k){var l=null;2<arguments.length&&(l=J(Array.prototype.slice.call(arguments,2),0));return c.call(this,b,d,l)}function c(a,d,e){for(;;){if(null==a)return null;a=b.a(a,d);
if(r(e))d=F(e),e=I(e);else return a}}a.k=2;a.f=function(a){var b=F(a);a=I(a);var d=F(a);a=G(a);return c(b,d,a)};a.d=c;return a}(),b=function(b,e,f){switch(arguments.length){case 1:return b;case 2:return a.call(this,b,e);default:return c.d(b,e,J(arguments,2))}throw Error("Invalid arity: "+arguments.length);};b.k=2;b.f=c.f;b.b=function(a){return a};b.a=a;b.d=c.d;return b}();function uc(a){var b="function"==m(a);return b?b:a?r(r(null)?null:a.Xb)?!0:a.Cb?!1:s(ya,a):s(ya,a)}
function vc(a,b){this.h=a;this.j=b;this.q=0;this.i=393217}g=vc.prototype;
g.call=function(){var a=null;return a=function(a,c,d,e,f,h,k,l,n,q,t,v,w,y,B,L,U,Z,na,Ga,Ra,wc){switch(arguments.length){case 1:var z=a,z=this;return z.h.o?z.h.o():z.h.call(null);case 2:return z=a,z=this,z.h.b?z.h.b(c):z.h.call(null,c);case 3:return z=a,z=this,z.h.a?z.h.a(c,d):z.h.call(null,c,d);case 4:return z=a,z=this,z.h.c?z.h.c(c,d,e):z.h.call(null,c,d,e);case 5:return z=a,z=this,z.h.n?z.h.n(c,d,e,f):z.h.call(null,c,d,e,f);case 6:return z=a,z=this,z.h.s?z.h.s(c,d,e,f,h):z.h.call(null,c,d,e,f,
h);case 7:return z=a,z=this,z.h.X?z.h.X(c,d,e,f,h,k):z.h.call(null,c,d,e,f,h,k);case 8:return z=a,z=this,z.h.ga?z.h.ga(c,d,e,f,h,k,l):z.h.call(null,c,d,e,f,h,k,l);case 9:return z=a,z=this,z.h.Ga?z.h.Ga(c,d,e,f,h,k,l,n):z.h.call(null,c,d,e,f,h,k,l,n);case 10:return z=a,z=this,z.h.Ha?z.h.Ha(c,d,e,f,h,k,l,n,q):z.h.call(null,c,d,e,f,h,k,l,n,q);case 11:return z=a,z=this,z.h.va?z.h.va(c,d,e,f,h,k,l,n,q,t):z.h.call(null,c,d,e,f,h,k,l,n,q,t);case 12:return z=a,z=this,z.h.wa?z.h.wa(c,d,e,f,h,k,l,n,q,t,v):
z.h.call(null,c,d,e,f,h,k,l,n,q,t,v);case 13:return z=a,z=this,z.h.xa?z.h.xa(c,d,e,f,h,k,l,n,q,t,v,w):z.h.call(null,c,d,e,f,h,k,l,n,q,t,v,w);case 14:return z=a,z=this,z.h.ya?z.h.ya(c,d,e,f,h,k,l,n,q,t,v,w,y):z.h.call(null,c,d,e,f,h,k,l,n,q,t,v,w,y);case 15:return z=a,z=this,z.h.za?z.h.za(c,d,e,f,h,k,l,n,q,t,v,w,y,B):z.h.call(null,c,d,e,f,h,k,l,n,q,t,v,w,y,B);case 16:return z=a,z=this,z.h.Aa?z.h.Aa(c,d,e,f,h,k,l,n,q,t,v,w,y,B,L):z.h.call(null,c,d,e,f,h,k,l,n,q,t,v,w,y,B,L);case 17:return z=a,z=this,
z.h.Ba?z.h.Ba(c,d,e,f,h,k,l,n,q,t,v,w,y,B,L,U):z.h.call(null,c,d,e,f,h,k,l,n,q,t,v,w,y,B,L,U);case 18:return z=a,z=this,z.h.Ca?z.h.Ca(c,d,e,f,h,k,l,n,q,t,v,w,y,B,L,U,Z):z.h.call(null,c,d,e,f,h,k,l,n,q,t,v,w,y,B,L,U,Z);case 19:return z=a,z=this,z.h.Da?z.h.Da(c,d,e,f,h,k,l,n,q,t,v,w,y,B,L,U,Z,na):z.h.call(null,c,d,e,f,h,k,l,n,q,t,v,w,y,B,L,U,Z,na);case 20:return z=a,z=this,z.h.Ea?z.h.Ea(c,d,e,f,h,k,l,n,q,t,v,w,y,B,L,U,Z,na,Ga):z.h.call(null,c,d,e,f,h,k,l,n,q,t,v,w,y,B,L,U,Z,na,Ga);case 21:return z=
a,z=this,z.h.Fa?z.h.Fa(c,d,e,f,h,k,l,n,q,t,v,w,y,B,L,U,Z,na,Ga,Ra):z.h.call(null,c,d,e,f,h,k,l,n,q,t,v,w,y,B,L,U,Z,na,Ga,Ra);case 22:return z=a,z=this,S.bc?S.bc(z.h,c,d,e,f,h,k,l,n,q,t,v,w,y,B,L,U,Z,na,Ga,Ra,wc):S.call(null,z.h,c,d,e,f,h,k,l,n,q,t,v,w,y,B,L,U,Z,na,Ga,Ra,wc)}throw Error("Invalid arity: "+arguments.length);}}();g.apply=function(a,b){return this.call.apply(this,[this].concat(va(b)))};g.o=function(){return this.h.o?this.h.o():this.h.call(null)};
g.b=function(a){return this.h.b?this.h.b(a):this.h.call(null,a)};g.a=function(a,b){return this.h.a?this.h.a(a,b):this.h.call(null,a,b)};g.c=function(a,b,c){return this.h.c?this.h.c(a,b,c):this.h.call(null,a,b,c)};g.n=function(a,b,c,d){return this.h.n?this.h.n(a,b,c,d):this.h.call(null,a,b,c,d)};g.s=function(a,b,c,d,e){return this.h.s?this.h.s(a,b,c,d,e):this.h.call(null,a,b,c,d,e)};g.X=function(a,b,c,d,e,f){return this.h.X?this.h.X(a,b,c,d,e,f):this.h.call(null,a,b,c,d,e,f)};
g.ga=function(a,b,c,d,e,f,h){return this.h.ga?this.h.ga(a,b,c,d,e,f,h):this.h.call(null,a,b,c,d,e,f,h)};g.Ga=function(a,b,c,d,e,f,h,k){return this.h.Ga?this.h.Ga(a,b,c,d,e,f,h,k):this.h.call(null,a,b,c,d,e,f,h,k)};g.Ha=function(a,b,c,d,e,f,h,k,l){return this.h.Ha?this.h.Ha(a,b,c,d,e,f,h,k,l):this.h.call(null,a,b,c,d,e,f,h,k,l)};g.va=function(a,b,c,d,e,f,h,k,l,n){return this.h.va?this.h.va(a,b,c,d,e,f,h,k,l,n):this.h.call(null,a,b,c,d,e,f,h,k,l,n)};
g.wa=function(a,b,c,d,e,f,h,k,l,n,q){return this.h.wa?this.h.wa(a,b,c,d,e,f,h,k,l,n,q):this.h.call(null,a,b,c,d,e,f,h,k,l,n,q)};g.xa=function(a,b,c,d,e,f,h,k,l,n,q,t){return this.h.xa?this.h.xa(a,b,c,d,e,f,h,k,l,n,q,t):this.h.call(null,a,b,c,d,e,f,h,k,l,n,q,t)};g.ya=function(a,b,c,d,e,f,h,k,l,n,q,t,v){return this.h.ya?this.h.ya(a,b,c,d,e,f,h,k,l,n,q,t,v):this.h.call(null,a,b,c,d,e,f,h,k,l,n,q,t,v)};
g.za=function(a,b,c,d,e,f,h,k,l,n,q,t,v,w){return this.h.za?this.h.za(a,b,c,d,e,f,h,k,l,n,q,t,v,w):this.h.call(null,a,b,c,d,e,f,h,k,l,n,q,t,v,w)};g.Aa=function(a,b,c,d,e,f,h,k,l,n,q,t,v,w,y){return this.h.Aa?this.h.Aa(a,b,c,d,e,f,h,k,l,n,q,t,v,w,y):this.h.call(null,a,b,c,d,e,f,h,k,l,n,q,t,v,w,y)};g.Ba=function(a,b,c,d,e,f,h,k,l,n,q,t,v,w,y,B){return this.h.Ba?this.h.Ba(a,b,c,d,e,f,h,k,l,n,q,t,v,w,y,B):this.h.call(null,a,b,c,d,e,f,h,k,l,n,q,t,v,w,y,B)};
g.Ca=function(a,b,c,d,e,f,h,k,l,n,q,t,v,w,y,B,L){return this.h.Ca?this.h.Ca(a,b,c,d,e,f,h,k,l,n,q,t,v,w,y,B,L):this.h.call(null,a,b,c,d,e,f,h,k,l,n,q,t,v,w,y,B,L)};g.Da=function(a,b,c,d,e,f,h,k,l,n,q,t,v,w,y,B,L,U){return this.h.Da?this.h.Da(a,b,c,d,e,f,h,k,l,n,q,t,v,w,y,B,L,U):this.h.call(null,a,b,c,d,e,f,h,k,l,n,q,t,v,w,y,B,L,U)};
g.Ea=function(a,b,c,d,e,f,h,k,l,n,q,t,v,w,y,B,L,U,Z){return this.h.Ea?this.h.Ea(a,b,c,d,e,f,h,k,l,n,q,t,v,w,y,B,L,U,Z):this.h.call(null,a,b,c,d,e,f,h,k,l,n,q,t,v,w,y,B,L,U,Z)};g.Fa=function(a,b,c,d,e,f,h,k,l,n,q,t,v,w,y,B,L,U,Z,na){return this.h.Fa?this.h.Fa(a,b,c,d,e,f,h,k,l,n,q,t,v,w,y,B,L,U,Z,na):this.h.call(null,a,b,c,d,e,f,h,k,l,n,q,t,v,w,y,B,L,U,Z,na)};g.Xb=!0;g.F=function(a,b){return new vc(this.h,b)};g.D=function(){return this.j};
function N(a,b){return uc(a)&&!(a?a.i&262144||a.oc||(a.i?0:s(db,a)):s(db,a))?new vc(a,b):null==a?null:eb(a,b)}function xc(a){var b=null!=a;return(b?a?a.i&131072||a.ec||(a.i?0:s(bb,a)):s(bb,a):b)?cb(a):null}function yc(a){return null==a?null:Xa(a)}function zc(a){return null==a?null:Ya(a)}
var Ac=function(){function a(a,b){return null==a?null:Wa(a,b)}var b=null,c=function(){function a(b,d,k){var l=null;2<arguments.length&&(l=J(Array.prototype.slice.call(arguments,2),0));return c.call(this,b,d,l)}function c(a,d,e){for(;;){if(null==a)return null;a=b.a(a,d);if(r(e))d=F(e),e=I(e);else return a}}a.k=2;a.f=function(a){var b=F(a);a=I(a);var d=F(a);a=G(a);return c(b,d,a)};a.d=c;return a}(),b=function(b,e,f){switch(arguments.length){case 1:return b;case 2:return a.call(this,b,e);default:return c.d(b,
e,J(arguments,2))}throw Error("Invalid arity: "+arguments.length);};b.k=2;b.f=c.f;b.b=function(a){return a};b.a=a;b.d=c.d;return b}();function Bc(a){return null==a||sa(E(a))}function Cc(a){return null==a?!1:a?a.i&8||a.Ac?!0:a.i?!1:s(Ca,a):s(Ca,a)}function Dc(a){return null==a?!1:a?a.i&4096||a.jc?!0:a.i?!1:s(Va,a):s(Va,a)}function Ec(a){return a?a.i&512||a.yc?!0:a.i?!1:s(Ma,a):s(Ma,a)}function Fc(a){return a?a.i&16777216||a.ic?!0:a.i?!1:s(mb,a):s(mb,a)}
function Gc(a){return null==a?!1:a?a.i&1024||a.cc?!0:a.i?!1:s(Pa,a):s(Pa,a)}function Hc(a){return a?a.i&16384||a.Gc?!0:a.i?!1:s(Za,a):s(Za,a)}function Ic(a){return a?a.q&512||a.zc?!0:!1:!1}function Jc(a){var b=[];da(a,function(a){return function(b,e){return a.push(e)}}(b));return b}function Kc(a,b,c,d,e){for(;0!==e;)c[d]=a[b],d+=1,e-=1,b+=1}var Lc={};function Mc(a){return null==a?!1:a?a.i&64||a.bb?!0:a.i?!1:s(Fa,a):s(Fa,a)}function Nc(a){return r(a)?!0:!1}
function Oc(a,b){return Q.c(a,b,Lc)===Lc?!1:!0}function Xb(a,b){if(a===b)return 0;if(null==a)return-1;if(null==b)return 1;if(ta(a)===ta(b))return a&&(a.q&2048||a.lb)?a.mb(null,b):ga(a,b);if(u)throw Error("compare on non-nil objects of different types");return null}
var Pc=function(){function a(a,b,c,h){for(;;){var k=Xb(P.a(a,h),P.a(b,h));if(0===k&&h+1<c)h+=1;else return k}}function b(a,b){var f=O(a),h=O(b);return f<h?-1:f>h?1:u?c.n(a,b,f,0):null}var c=null,c=function(c,e,f,h){switch(arguments.length){case 2:return b.call(this,c,e);case 4:return a.call(this,c,e,f,h)}throw Error("Invalid arity: "+arguments.length);};c.a=b;c.n=a;return c}();
function Qc(a){return Wb.a(a,Xb)?Xb:function(b,c){var d=a.a?a.a(b,c):a.call(null,b,c);return"number"===typeof d?d:r(d)?-1:r(a.a?a.a(c,b):a.call(null,c,b))?1:0}}
var Sc=function(){function a(a,b){if(E(b)){var c=Rc.b?Rc.b(b):Rc.call(null,b);ha(c,Qc(a));return E(c)}return H}function b(a){return c.a(Xb,a)}var c=null,c=function(c,e){switch(arguments.length){case 1:return b.call(this,c);case 2:return a.call(this,c,e)}throw Error("Invalid arity: "+arguments.length);};c.b=b;c.a=a;return c}(),Tc=function(){function a(a,b,c){return Sc.a(function(c,f){return Qc(b).call(null,a.b?a.b(c):a.call(null,c),a.b?a.b(f):a.call(null,f))},c)}function b(a,b){return c.c(a,Xb,b)}
var c=null,c=function(c,e,f){switch(arguments.length){case 2:return b.call(this,c,e);case 3:return a.call(this,c,e,f)}throw Error("Invalid arity: "+arguments.length);};c.a=b;c.c=a;return c}(),nc=function(){function a(a,b,c){for(c=E(c);;)if(c){b=a.a?a.a(b,F(c)):a.call(null,b,F(c));if(fc(b))return K.b?K.b(b):K.call(null,b);c=I(c)}else return b}function b(a,b){var c=E(b);return c?C.c?C.c(a,F(c),I(c)):C.call(null,a,F(c),I(c)):a.o?a.o():a.call(null)}var c=null,c=function(c,e,f){switch(arguments.length){case 2:return b.call(this,
c,e);case 3:return a.call(this,c,e,f)}throw Error("Invalid arity: "+arguments.length);};c.a=b;c.c=a;return c}(),C=function(){function a(a,b,c){return c&&(c.i&524288||c.Nb)?c.M(null,a,b):c instanceof Array?hc.c(c,a,b):"string"===typeof c?hc.c(c,a,b):s(fb,c)?gb.c(c,a,b):u?nc.c(a,b,c):null}function b(a,b){return b&&(b.i&524288||b.Nb)?b.N(null,a):b instanceof Array?hc.a(b,a):"string"===typeof b?hc.a(b,a):s(fb,b)?gb.a(b,a):u?nc.a(a,b):null}var c=null,c=function(c,e,f){switch(arguments.length){case 2:return b.call(this,
c,e);case 3:return a.call(this,c,e,f)}throw Error("Invalid arity: "+arguments.length);};c.a=b;c.c=a;return c}(),Uc=function(){var a=null,b=function(){function a(c,f,h){var k=null;2<arguments.length&&(k=J(Array.prototype.slice.call(arguments,2),0));return b.call(this,c,f,k)}function b(a,c,d){for(;;)if(a>c)if(I(d))a=c,c=F(d),d=I(d);else return c>F(d);else return!1}a.k=2;a.f=function(a){var c=F(a);a=I(a);var h=F(a);a=G(a);return b(c,h,a)};a.d=b;return a}(),a=function(a,d,e){switch(arguments.length){case 1:return!0;
case 2:return a>d;default:return b.d(a,d,J(arguments,2))}throw Error("Invalid arity: "+arguments.length);};a.k=2;a.f=b.f;a.b=function(){return!0};a.a=function(a,b){return a>b};a.d=b.d;return a}(),Vc=function(){var a=null,b=function(){function a(c,f,h){var k=null;2<arguments.length&&(k=J(Array.prototype.slice.call(arguments,2),0));return b.call(this,c,f,k)}function b(a,c,d){for(;;)if(a>=c)if(I(d))a=c,c=F(d),d=I(d);else return c>=F(d);else return!1}a.k=2;a.f=function(a){var c=F(a);a=I(a);var h=F(a);
a=G(a);return b(c,h,a)};a.d=b;return a}(),a=function(a,d,e){switch(arguments.length){case 1:return!0;case 2:return a>=d;default:return b.d(a,d,J(arguments,2))}throw Error("Invalid arity: "+arguments.length);};a.k=2;a.f=b.f;a.b=function(){return!0};a.a=function(a,b){return a>=b};a.d=b.d;return a}();function Wc(a){return a-1}
var Xc=function(){function a(a,b){return a>b?a:b}var b=null,c=function(){function a(b,d,k){var l=null;2<arguments.length&&(l=J(Array.prototype.slice.call(arguments,2),0));return c.call(this,b,d,l)}function c(a,d,e){return C.c(b,a>d?a:d,e)}a.k=2;a.f=function(a){var b=F(a);a=I(a);var d=F(a);a=G(a);return c(b,d,a)};a.d=c;return a}(),b=function(b,e,f){switch(arguments.length){case 1:return b;case 2:return a.call(this,b,e);default:return c.d(b,e,J(arguments,2))}throw Error("Invalid arity: "+arguments.length);
};b.k=2;b.f=c.f;b.b=function(a){return a};b.a=a;b.d=c.d;return b}();function Yc(a){a=(a-a%2)/2;return 0<=a?Math.floor.b?Math.floor.b(a):Math.floor.call(null,a):Math.ceil.b?Math.ceil.b(a):Math.ceil.call(null,a)}function Zc(a){a-=a>>1&1431655765;a=(a&858993459)+(a>>2&858993459);return 16843009*(a+(a>>4)&252645135)>>24}function $c(a){var b=1;for(a=E(a);;)if(a&&0<b)b-=1,a=I(a);else return a}
var A=function(){function a(a){return null==a?"":a.toString()}var b=null,c=function(){function a(b,d){var k=null;1<arguments.length&&(k=J(Array.prototype.slice.call(arguments,1),0));return c.call(this,b,k)}function c(a,d){for(var e=new ea(b.b(a)),l=d;;)if(r(l))e=e.append(b.b(F(l))),l=I(l);else return e.toString()}a.k=1;a.f=function(a){var b=F(a);a=G(a);return c(b,a)};a.d=c;return a}(),b=function(b,e){switch(arguments.length){case 0:return"";case 1:return a.call(this,b);default:return c.d(b,J(arguments,
1))}throw Error("Invalid arity: "+arguments.length);};b.k=1;b.f=c.f;b.o=function(){return""};b.b=a;b.d=c.d;return b}(),ad=function(){var a=null,a=function(a,c,d){switch(arguments.length){case 2:return a.substring(c);case 3:return a.substring(c,d)}throw Error("Invalid arity: "+arguments.length);};a.a=function(a,c){return a.substring(c)};a.c=function(a,c,d){return a.substring(c,d)};return a}();
function lc(a,b){return Nc(Fc(b)?function(){for(var c=E(a),d=E(b);;){if(null==c)return null==d;if(null==d)return!1;if(Wb.a(F(c),F(d)))c=I(c),d=I(d);else return u?!1:null}}():null)}function bd(a,b,c,d,e){this.j=a;this.first=b;this.ta=c;this.count=d;this.m=e;this.i=65937646;this.q=8192}g=bd.prototype;g.toString=function(){return Lb(this)};g.D=function(){return this.j};g.U=function(){return 1===this.count?null:this.ta};g.L=function(){return this.count};g.Ia=function(){return this.first};g.Ja=function(){return Ia(this)};
g.B=function(){var a=this.m;return null!=a?a:this.m=a=cc(this)};g.v=function(a,b){return lc(this,b)};g.I=function(){return H};g.N=function(a,b){return nc.a(b,this)};g.M=function(a,b,c){return nc.c(b,c,this)};g.Q=function(){return this.first};g.S=function(){return 1===this.count?H:this.ta};g.H=function(){return this};g.F=function(a,b){return new bd(b,this.first,this.ta,this.count,this.m)};g.G=function(a,b){return new bd(this.j,b,this,this.count+1,null)};
function cd(a){this.j=a;this.i=65937614;this.q=8192}g=cd.prototype;g.toString=function(){return Lb(this)};g.D=function(){return this.j};g.U=function(){return null};g.L=function(){return 0};g.Ia=function(){return null};g.Ja=function(){throw Error("Can't pop empty list");};g.B=function(){return 0};g.v=function(a,b){return lc(this,b)};g.I=function(){return this};g.N=function(a,b){return nc.a(b,this)};g.M=function(a,b,c){return nc.c(b,c,this)};g.Q=function(){return null};g.S=function(){return H};
g.H=function(){return null};g.F=function(a,b){return new cd(b)};g.G=function(a,b){return new bd(this.j,b,null,1,null)};var H=new cd(null);function dd(a){return a?a.i&134217728||a.Fc?!0:a.i?!1:s(ob,a):s(ob,a)}function ed(a){return dd(a)?pb(a):C.c(pc,H,a)}
var fd=function(){function a(a){var d=null;0<arguments.length&&(d=J(Array.prototype.slice.call(arguments,0),0));return b.call(this,d)}function b(a){var b;if(a instanceof ac&&0===a.p)b=a.e;else a:{for(b=[];;)if(null!=a)b.push(a.Q(null)),a=a.U(null);else break a;b=void 0}a=b.length;for(var e=H;;)if(0<a){var f=a-1,e=e.G(null,b[a-1]);a=f}else return e}a.k=0;a.f=function(a){a=E(a);return b(a)};a.d=b;return a}();function gd(a,b,c,d){this.j=a;this.first=b;this.ta=c;this.m=d;this.i=65929452;this.q=8192}
g=gd.prototype;g.toString=function(){return Lb(this)};g.D=function(){return this.j};g.U=function(){return null==this.ta?null:E(this.ta)};g.B=function(){var a=this.m;return null!=a?a:this.m=a=cc(this)};g.v=function(a,b){return lc(this,b)};g.I=function(){return N(H,this.j)};g.N=function(a,b){return nc.a(b,this)};g.M=function(a,b,c){return nc.c(b,c,this)};g.Q=function(){return this.first};g.S=function(){return null==this.ta?H:this.ta};g.H=function(){return this};
g.F=function(a,b){return new gd(b,this.first,this.ta,this.m)};g.G=function(a,b){return new gd(null,b,this,this.m)};function M(a,b){var c=null==b;return(c?c:b&&(b.i&64||b.bb))?new gd(null,a,b,null):new gd(null,a,E(b),null)}function T(a,b,c,d){this.fa=a;this.name=b;this.sa=c;this.Ua=d;this.i=2153775105;this.q=4096}g=T.prototype;g.w=function(a,b){return ub(b,":"+A.b(this.sa))};g.B=function(){var a=this.Ua;return null!=a?a:this.Ua=a=Ub(this)+2654435769};
g.call=function(){var a=null;return a=function(a,c,d){switch(arguments.length){case 2:return Q.a(c,this);case 3:return Q.c(c,this,d)}throw Error("Invalid arity: "+arguments.length);}}();g.apply=function(a,b){return this.call.apply(this,[this].concat(va(b)))};g.b=function(a){return Q.a(a,this)};g.a=function(a,b){return Q.c(a,this,b)};g.v=function(a,b){return b instanceof T?this.sa===b.sa:!1};g.toString=function(){return":"+A.b(this.sa)};
function hd(a,b){return a===b?!0:a instanceof T&&b instanceof T?a.sa===b.sa:!1}
var jd=function(){function a(a,b){return new T(a,b,""+A.b(r(a)?""+A.b(a)+"/":null)+A.b(b),null)}function b(a){if(a instanceof T)return a;if(a instanceof Zb){var b;if(a&&(a.q&4096||a.fc))b=a.fa;else throw Error("Doesn't support namespace: "+A.b(a));return new T(b,id.b?id.b(a):id.call(null,a),a.Na,null)}return"string"===typeof a?(b=a.split("/"),2===b.length?new T(b[0],b[1],a,null):new T(null,b[0],a,null)):null}var c=null,c=function(c,e){switch(arguments.length){case 1:return b.call(this,c);case 2:return a.call(this,
c,e)}throw Error("Invalid arity: "+arguments.length);};c.b=b;c.a=a;return c}();function V(a,b,c,d){this.j=a;this.Ya=b;this.r=c;this.m=d;this.q=0;this.i=32374988}g=V.prototype;g.toString=function(){return Lb(this)};function kd(a){null!=a.Ya&&(a.r=a.Ya.o?a.Ya.o():a.Ya.call(null),a.Ya=null);return a.r}g.D=function(){return this.j};g.U=function(){lb(this);return null==this.r?null:I(this.r)};g.B=function(){var a=this.m;return null!=a?a:this.m=a=cc(this)};g.v=function(a,b){return lc(this,b)};
g.I=function(){return N(H,this.j)};g.N=function(a,b){return nc.a(b,this)};g.M=function(a,b,c){return nc.c(b,c,this)};g.Q=function(){lb(this);return null==this.r?null:F(this.r)};g.S=function(){lb(this);return null!=this.r?G(this.r):H};g.H=function(){kd(this);if(null==this.r)return null;for(var a=this.r;;)if(a instanceof V)a=kd(a);else return this.r=a,E(this.r)};g.F=function(a,b){return new V(b,this.Ya,this.r,this.m)};g.G=function(a,b){return M(b,this)};
function ld(a,b){this.qb=a;this.end=b;this.q=0;this.i=2}ld.prototype.L=function(){return this.end};ld.prototype.add=function(a){this.qb[this.end]=a;return this.end+=1};ld.prototype.da=function(){var a=new md(this.qb,0,this.end);this.qb=null;return a};function md(a,b,c){this.e=a;this.O=b;this.end=c;this.q=0;this.i=524306}g=md.prototype;g.N=function(a,b){return hc.n(this.e,b,this.e[this.O],this.O+1)};g.M=function(a,b,c){return hc.n(this.e,b,c,this.O)};
g.Kb=function(){if(this.O===this.end)throw Error("-drop-first of empty chunk");return new md(this.e,this.O+1,this.end)};g.J=function(a,b){return this.e[this.O+b]};g.aa=function(a,b,c){return 0<=b&&b<this.end-this.O?this.e[this.O+b]:c};g.L=function(){return this.end-this.O};
var nd=function(){function a(a,b,c){return new md(a,b,c)}function b(a,b){return new md(a,b,a.length)}function c(a){return new md(a,0,a.length)}var d=null,d=function(d,f,h){switch(arguments.length){case 1:return c.call(this,d);case 2:return b.call(this,d,f);case 3:return a.call(this,d,f,h)}throw Error("Invalid arity: "+arguments.length);};d.b=c;d.a=b;d.c=a;return d}();function od(a,b,c,d){this.da=a;this.oa=b;this.j=c;this.m=d;this.i=31850732;this.q=1536}g=od.prototype;g.toString=function(){return Lb(this)};
g.D=function(){return this.j};g.U=function(){if(1<Aa(this.da))return new od(Gb(this.da),this.oa,this.j,null);var a=lb(this.oa);return null==a?null:a};g.B=function(){var a=this.m;return null!=a?a:this.m=a=cc(this)};g.v=function(a,b){return lc(this,b)};g.I=function(){return N(H,this.j)};g.Q=function(){return D.a(this.da,0)};g.S=function(){return 1<Aa(this.da)?new od(Gb(this.da),this.oa,this.j,null):null==this.oa?H:this.oa};g.H=function(){return this};g.sb=function(){return this.da};
g.tb=function(){return null==this.oa?H:this.oa};g.F=function(a,b){return new od(this.da,this.oa,b,this.m)};g.G=function(a,b){return M(b,this)};g.rb=function(){return null==this.oa?null:this.oa};function pd(a,b){return 0===Aa(a)?b:new od(a,b,null,null)}function Rc(a){for(var b=[];;)if(E(a))b.push(F(a)),a=I(a);else return b}function qd(a,b){if(ic(a))return O(a);for(var c=a,d=b,e=0;;)if(0<d&&E(c))c=I(c),d-=1,e+=1;else return e}
var sd=function rd(b){return null==b?null:null==I(b)?E(F(b)):u?M(F(b),rd(I(b))):null},td=function(){function a(a,b){return new V(null,function(){var c=E(a);return c?Ic(c)?pd(Hb(c),d.a(Ib(c),b)):M(F(c),d.a(G(c),b)):b},null,null)}function b(a){return new V(null,function(){return a},null,null)}function c(){return new V(null,function(){return null},null,null)}var d=null,e=function(){function a(c,d,e){var f=null;2<arguments.length&&(f=J(Array.prototype.slice.call(arguments,2),0));return b.call(this,c,
d,f)}function b(a,c,e){return function t(a,b){return new V(null,function(){var c=E(a);return c?Ic(c)?pd(Hb(c),t(Ib(c),b)):M(F(c),t(G(c),b)):r(b)?t(F(b),I(b)):null},null,null)}(d.a(a,c),e)}a.k=2;a.f=function(a){var c=F(a);a=I(a);var d=F(a);a=G(a);return b(c,d,a)};a.d=b;return a}(),d=function(d,h,k){switch(arguments.length){case 0:return c.call(this);case 1:return b.call(this,d);case 2:return a.call(this,d,h);default:return e.d(d,h,J(arguments,2))}throw Error("Invalid arity: "+arguments.length);};d.k=
2;d.f=e.f;d.o=c;d.b=b;d.a=a;d.d=e.d;return d}(),ud=function(){function a(a,b,c,d){return M(a,M(b,M(c,d)))}function b(a,b,c){return M(a,M(b,c))}var c=null,d=function(){function a(c,d,e,n,q){var t=null;4<arguments.length&&(t=J(Array.prototype.slice.call(arguments,4),0));return b.call(this,c,d,e,n,t)}function b(a,c,d,e,f){return M(a,M(c,M(d,M(e,sd(f)))))}a.k=4;a.f=function(a){var c=F(a);a=I(a);var d=F(a);a=I(a);var e=F(a);a=I(a);var q=F(a);a=G(a);return b(c,d,e,q,a)};a.d=b;return a}(),c=function(c,f,
h,k,l){switch(arguments.length){case 1:return E(c);case 2:return M(c,f);case 3:return b.call(this,c,f,h);case 4:return a.call(this,c,f,h,k);default:return d.d(c,f,h,k,J(arguments,4))}throw Error("Invalid arity: "+arguments.length);};c.k=4;c.f=d.f;c.b=function(a){return E(a)};c.a=function(a,b){return M(a,b)};c.c=b;c.n=a;c.d=d.d;return c}();function vd(a){return Ab(a)}
var wd=function(){var a=null,b=function(){function a(c,f,h){var k=null;2<arguments.length&&(k=J(Array.prototype.slice.call(arguments,2),0));return b.call(this,c,f,k)}function b(a,c,d){for(;;)if(a=zb(a,c),r(d))c=F(d),d=I(d);else return a}a.k=2;a.f=function(a){var c=F(a);a=I(a);var h=F(a);a=G(a);return b(c,h,a)};a.d=b;return a}(),a=function(a,d,e){switch(arguments.length){case 2:return zb(a,d);default:return b.d(a,d,J(arguments,2))}throw Error("Invalid arity: "+arguments.length);};a.k=2;a.f=b.f;a.a=
function(a,b){return zb(a,b)};a.d=b.d;return a}(),xd=function(){var a=null,b=function(){function a(c,f,h,k){var l=null;3<arguments.length&&(l=J(Array.prototype.slice.call(arguments,3),0));return b.call(this,c,f,h,l)}function b(a,c,d,k){for(;;)if(a=Bb(a,c,d),r(k))c=F(k),d=F(I(k)),k=I(I(k));else return a}a.k=3;a.f=function(a){var c=F(a);a=I(a);var h=F(a);a=I(a);var k=F(a);a=G(a);return b(c,h,k,a)};a.d=b;return a}(),a=function(a,d,e,f){switch(arguments.length){case 3:return Bb(a,d,e);default:return b.d(a,
d,e,J(arguments,3))}throw Error("Invalid arity: "+arguments.length);};a.k=3;a.f=b.f;a.c=function(a,b,e){return Bb(a,b,e)};a.d=b.d;return a}(),yd=function(){var a=null,b=function(){function a(c,f,h){var k=null;2<arguments.length&&(k=J(Array.prototype.slice.call(arguments,2),0));return b.call(this,c,f,k)}function b(a,c,d){for(;;)if(a=Cb(a,c),r(d))c=F(d),d=I(d);else return a}a.k=2;a.f=function(a){var c=F(a);a=I(a);var h=F(a);a=G(a);return b(c,h,a)};a.d=b;return a}(),a=function(a,d,e){switch(arguments.length){case 2:return Cb(a,
d);default:return b.d(a,d,J(arguments,2))}throw Error("Invalid arity: "+arguments.length);};a.k=2;a.f=b.f;a.a=function(a,b){return Cb(a,b)};a.d=b.d;return a}(),zd=function(){var a=null,b=function(){function a(c,f,h){var k=null;2<arguments.length&&(k=J(Array.prototype.slice.call(arguments,2),0));return b.call(this,c,f,k)}function b(a,c,d){for(;;)if(a=Fb(a,c),r(d))c=F(d),d=I(d);else return a}a.k=2;a.f=function(a){var c=F(a);a=I(a);var h=F(a);a=G(a);return b(c,h,a)};a.d=b;return a}(),a=function(a,d,
e){switch(arguments.length){case 2:return Fb(a,d);default:return b.d(a,d,J(arguments,2))}throw Error("Invalid arity: "+arguments.length);};a.k=2;a.f=b.f;a.a=function(a,b){return Fb(a,b)};a.d=b.d;return a}();
function Ad(a,b,c){var d=E(c);if(0===b)return a.o?a.o():a.call(null);c=Ha(d);var e=Ia(d);if(1===b)return a.b?a.b(c):a.b?a.b(c):a.call(null,c);var d=Ha(e),f=Ia(e);if(2===b)return a.a?a.a(c,d):a.a?a.a(c,d):a.call(null,c,d);var e=Ha(f),h=Ia(f);if(3===b)return a.c?a.c(c,d,e):a.c?a.c(c,d,e):a.call(null,c,d,e);var f=Ha(h),k=Ia(h);if(4===b)return a.n?a.n(c,d,e,f):a.n?a.n(c,d,e,f):a.call(null,c,d,e,f);var h=Ha(k),l=Ia(k);if(5===b)return a.s?a.s(c,d,e,f,h):a.s?a.s(c,d,e,f,h):a.call(null,c,d,e,f,h);var k=Ha(l),
n=Ia(l);if(6===b)return a.X?a.X(c,d,e,f,h,k):a.X?a.X(c,d,e,f,h,k):a.call(null,c,d,e,f,h,k);var l=Ha(n),q=Ia(n);if(7===b)return a.ga?a.ga(c,d,e,f,h,k,l):a.ga?a.ga(c,d,e,f,h,k,l):a.call(null,c,d,e,f,h,k,l);var n=Ha(q),t=Ia(q);if(8===b)return a.Ga?a.Ga(c,d,e,f,h,k,l,n):a.Ga?a.Ga(c,d,e,f,h,k,l,n):a.call(null,c,d,e,f,h,k,l,n);var q=Ha(t),v=Ia(t);if(9===b)return a.Ha?a.Ha(c,d,e,f,h,k,l,n,q):a.Ha?a.Ha(c,d,e,f,h,k,l,n,q):a.call(null,c,d,e,f,h,k,l,n,q);var t=Ha(v),w=Ia(v);if(10===b)return a.va?a.va(c,d,e,
f,h,k,l,n,q,t):a.va?a.va(c,d,e,f,h,k,l,n,q,t):a.call(null,c,d,e,f,h,k,l,n,q,t);var v=Ha(w),y=Ia(w);if(11===b)return a.wa?a.wa(c,d,e,f,h,k,l,n,q,t,v):a.wa?a.wa(c,d,e,f,h,k,l,n,q,t,v):a.call(null,c,d,e,f,h,k,l,n,q,t,v);var w=Ha(y),B=Ia(y);if(12===b)return a.xa?a.xa(c,d,e,f,h,k,l,n,q,t,v,w):a.xa?a.xa(c,d,e,f,h,k,l,n,q,t,v,w):a.call(null,c,d,e,f,h,k,l,n,q,t,v,w);var y=Ha(B),L=Ia(B);if(13===b)return a.ya?a.ya(c,d,e,f,h,k,l,n,q,t,v,w,y):a.ya?a.ya(c,d,e,f,h,k,l,n,q,t,v,w,y):a.call(null,c,d,e,f,h,k,l,n,q,
t,v,w,y);var B=Ha(L),U=Ia(L);if(14===b)return a.za?a.za(c,d,e,f,h,k,l,n,q,t,v,w,y,B):a.za?a.za(c,d,e,f,h,k,l,n,q,t,v,w,y,B):a.call(null,c,d,e,f,h,k,l,n,q,t,v,w,y,B);var L=Ha(U),Z=Ia(U);if(15===b)return a.Aa?a.Aa(c,d,e,f,h,k,l,n,q,t,v,w,y,B,L):a.Aa?a.Aa(c,d,e,f,h,k,l,n,q,t,v,w,y,B,L):a.call(null,c,d,e,f,h,k,l,n,q,t,v,w,y,B,L);var U=Ha(Z),na=Ia(Z);if(16===b)return a.Ba?a.Ba(c,d,e,f,h,k,l,n,q,t,v,w,y,B,L,U):a.Ba?a.Ba(c,d,e,f,h,k,l,n,q,t,v,w,y,B,L,U):a.call(null,c,d,e,f,h,k,l,n,q,t,v,w,y,B,L,U);var Z=
Ha(na),Ga=Ia(na);if(17===b)return a.Ca?a.Ca(c,d,e,f,h,k,l,n,q,t,v,w,y,B,L,U,Z):a.Ca?a.Ca(c,d,e,f,h,k,l,n,q,t,v,w,y,B,L,U,Z):a.call(null,c,d,e,f,h,k,l,n,q,t,v,w,y,B,L,U,Z);var na=Ha(Ga),Ra=Ia(Ga);if(18===b)return a.Da?a.Da(c,d,e,f,h,k,l,n,q,t,v,w,y,B,L,U,Z,na):a.Da?a.Da(c,d,e,f,h,k,l,n,q,t,v,w,y,B,L,U,Z,na):a.call(null,c,d,e,f,h,k,l,n,q,t,v,w,y,B,L,U,Z,na);Ga=Ha(Ra);Ra=Ia(Ra);if(19===b)return a.Ea?a.Ea(c,d,e,f,h,k,l,n,q,t,v,w,y,B,L,U,Z,na,Ga):a.Ea?a.Ea(c,d,e,f,h,k,l,n,q,t,v,w,y,B,L,U,Z,na,Ga):a.call(null,
c,d,e,f,h,k,l,n,q,t,v,w,y,B,L,U,Z,na,Ga);var wc=Ha(Ra);Ia(Ra);if(20===b)return a.Fa?a.Fa(c,d,e,f,h,k,l,n,q,t,v,w,y,B,L,U,Z,na,Ga,wc):a.Fa?a.Fa(c,d,e,f,h,k,l,n,q,t,v,w,y,B,L,U,Z,na,Ga,wc):a.call(null,c,d,e,f,h,k,l,n,q,t,v,w,y,B,L,U,Z,na,Ga,wc);throw Error("Only up to 20 arguments supported on functions");}
var S=function(){function a(a,b,c,d,e){b=ud.n(b,c,d,e);c=a.k;return a.f?(d=qd(b,c+1),d<=c?Ad(a,d,b):a.f(b)):a.apply(a,Rc(b))}function b(a,b,c,d){b=ud.c(b,c,d);c=a.k;return a.f?(d=qd(b,c+1),d<=c?Ad(a,d,b):a.f(b)):a.apply(a,Rc(b))}function c(a,b,c){b=ud.a(b,c);c=a.k;if(a.f){var d=qd(b,c+1);return d<=c?Ad(a,d,b):a.f(b)}return a.apply(a,Rc(b))}function d(a,b){var c=a.k;if(a.f){var d=qd(b,c+1);return d<=c?Ad(a,d,b):a.f(b)}return a.apply(a,Rc(b))}var e=null,f=function(){function a(c,d,e,f,h,w){var y=null;
5<arguments.length&&(y=J(Array.prototype.slice.call(arguments,5),0));return b.call(this,c,d,e,f,h,y)}function b(a,c,d,e,f,h){c=M(c,M(d,M(e,M(f,sd(h)))));d=a.k;return a.f?(e=qd(c,d+1),e<=d?Ad(a,e,c):a.f(c)):a.apply(a,Rc(c))}a.k=5;a.f=function(a){var c=F(a);a=I(a);var d=F(a);a=I(a);var e=F(a);a=I(a);var f=F(a);a=I(a);var h=F(a);a=G(a);return b(c,d,e,f,h,a)};a.d=b;return a}(),e=function(e,k,l,n,q,t){switch(arguments.length){case 2:return d.call(this,e,k);case 3:return c.call(this,e,k,l);case 4:return b.call(this,
e,k,l,n);case 5:return a.call(this,e,k,l,n,q);default:return f.d(e,k,l,n,q,J(arguments,5))}throw Error("Invalid arity: "+arguments.length);};e.k=5;e.f=f.f;e.a=d;e.c=c;e.n=b;e.s=a;e.d=f.d;return e}(),Bd=function(){function a(a,b){return!Wb.a(a,b)}var b=null,c=function(){function a(c,d,k){var l=null;2<arguments.length&&(l=J(Array.prototype.slice.call(arguments,2),0));return b.call(this,c,d,l)}function b(a,c,d){return sa(S.n(Wb,a,c,d))}a.k=2;a.f=function(a){var c=F(a);a=I(a);var d=F(a);a=G(a);return b(c,
d,a)};a.d=b;return a}(),b=function(b,e,f){switch(arguments.length){case 1:return!1;case 2:return a.call(this,b,e);default:return c.d(b,e,J(arguments,2))}throw Error("Invalid arity: "+arguments.length);};b.k=2;b.f=c.f;b.b=function(){return!1};b.a=a;b.d=c.d;return b}();function Cd(a){return E(a)?a:null}function Dd(a,b){for(;;){if(null==E(b))return!0;if(r(a.b?a.b(F(b)):a.call(null,F(b)))){var c=a,d=I(b);a=c;b=d}else return u?!1:null}}
function Ed(a,b){for(;;)if(E(b)){var c=a.b?a.b(F(b)):a.call(null,F(b));if(r(c))return c;var c=a,d=I(b);a=c;b=d}else return null}function Fd(a){return a}
function Gd(a){return function(){var b=null,c=function(){function b(a,d,k){var l=null;2<arguments.length&&(l=J(Array.prototype.slice.call(arguments,2),0));return c.call(this,a,d,l)}function c(b,d,e){return sa(S.n(a,b,d,e))}b.k=2;b.f=function(a){var b=F(a);a=I(a);var d=F(a);a=G(a);return c(b,d,a)};b.d=c;return b}(),b=function(b,e,f){switch(arguments.length){case 0:return sa(a.o?a.o():a.call(null));case 1:var h=b;return sa(a.b?a.b(h):a.call(null,h));case 2:var h=b,k=e;return sa(a.a?a.a(h,k):a.call(null,
h,k));default:return c.d(b,e,J(arguments,2))}throw Error("Invalid arity: "+arguments.length);};b.k=2;b.f=c.f;return b}()}
var Hd=function(){function a(a,b,c){return function(){var d=null,l=function(){function d(a,b,c,e){var f=null;3<arguments.length&&(f=J(Array.prototype.slice.call(arguments,3),0));return k.call(this,a,b,c,f)}function k(d,l,n,q){return a.b?a.b(b.b?b.b(S.s(c,d,l,n,q)):b.call(null,S.s(c,d,l,n,q))):a.call(null,b.b?b.b(S.s(c,d,l,n,q)):b.call(null,S.s(c,d,l,n,q)))}d.k=3;d.f=function(a){var b=F(a);a=I(a);var c=F(a);a=I(a);var d=F(a);a=G(a);return k(b,c,d,a)};d.d=k;return d}(),d=function(d,k,t,v){switch(arguments.length){case 0:return a.b?
a.b(b.b?b.b(c.o?c.o():c.call(null)):b.call(null,c.o?c.o():c.call(null))):a.call(null,b.b?b.b(c.o?c.o():c.call(null)):b.call(null,c.o?c.o():c.call(null)));case 1:var w=d;return a.b?a.b(b.b?b.b(c.b?c.b(w):c.call(null,w)):b.call(null,c.b?c.b(w):c.call(null,w))):a.call(null,b.b?b.b(c.b?c.b(w):c.call(null,w)):b.call(null,c.b?c.b(w):c.call(null,w)));case 2:var w=d,y=k;return a.b?a.b(b.b?b.b(c.a?c.a(w,y):c.call(null,w,y)):b.call(null,c.a?c.a(w,y):c.call(null,w,y))):a.call(null,b.b?b.b(c.a?c.a(w,y):c.call(null,
w,y)):b.call(null,c.a?c.a(w,y):c.call(null,w,y)));case 3:var w=d,y=k,B=t;return a.b?a.b(b.b?b.b(c.c?c.c(w,y,B):c.call(null,w,y,B)):b.call(null,c.c?c.c(w,y,B):c.call(null,w,y,B))):a.call(null,b.b?b.b(c.c?c.c(w,y,B):c.call(null,w,y,B)):b.call(null,c.c?c.c(w,y,B):c.call(null,w,y,B)));default:return l.d(d,k,t,J(arguments,3))}throw Error("Invalid arity: "+arguments.length);};d.k=3;d.f=l.f;return d}()}function b(a,b){return function(){var c=null,d=function(){function c(a,b,e,f){var h=null;3<arguments.length&&
(h=J(Array.prototype.slice.call(arguments,3),0));return d.call(this,a,b,e,h)}function d(c,h,k,l){return a.b?a.b(S.s(b,c,h,k,l)):a.call(null,S.s(b,c,h,k,l))}c.k=3;c.f=function(a){var b=F(a);a=I(a);var c=F(a);a=I(a);var e=F(a);a=G(a);return d(b,c,e,a)};c.d=d;return c}(),c=function(c,h,q,t){switch(arguments.length){case 0:return a.b?a.b(b.o?b.o():b.call(null)):a.call(null,b.o?b.o():b.call(null));case 1:var v=c;return a.b?a.b(b.b?b.b(v):b.call(null,v)):a.call(null,b.b?b.b(v):b.call(null,v));case 2:var v=
c,w=h;return a.b?a.b(b.a?b.a(v,w):b.call(null,v,w)):a.call(null,b.a?b.a(v,w):b.call(null,v,w));case 3:var v=c,w=h,y=q;return a.b?a.b(b.c?b.c(v,w,y):b.call(null,v,w,y)):a.call(null,b.c?b.c(v,w,y):b.call(null,v,w,y));default:return d.d(c,h,q,J(arguments,3))}throw Error("Invalid arity: "+arguments.length);};c.k=3;c.f=d.f;return c}()}var c=null,d=function(){function a(c,d,e,n){var q=null;3<arguments.length&&(q=J(Array.prototype.slice.call(arguments,3),0));return b.call(this,c,d,e,q)}function b(a,c,d,
e){return function(a){return function(){function b(a){var d=null;0<arguments.length&&(d=J(Array.prototype.slice.call(arguments,0),0));return c.call(this,d)}function c(b){b=S.a(F(a),b);for(var d=I(a);;)if(d)b=F(d).call(null,b),d=I(d);else return b}b.k=0;b.f=function(a){a=E(a);return c(a)};b.d=c;return b}()}(ed(ud.n(a,c,d,e)))}a.k=3;a.f=function(a){var c=F(a);a=I(a);var d=F(a);a=I(a);var e=F(a);a=G(a);return b(c,d,e,a)};a.d=b;return a}(),c=function(c,f,h,k){switch(arguments.length){case 0:return Fd;
case 1:return c;case 2:return b.call(this,c,f);case 3:return a.call(this,c,f,h);default:return d.d(c,f,h,J(arguments,3))}throw Error("Invalid arity: "+arguments.length);};c.k=3;c.f=d.f;c.o=function(){return Fd};c.b=function(a){return a};c.a=b;c.c=a;c.d=d.d;return c}(),Id=function(){function a(a,b,c,d){return function(){function e(a){var b=null;0<arguments.length&&(b=J(Array.prototype.slice.call(arguments,0),0));return q.call(this,b)}function q(e){return S.s(a,b,c,d,e)}e.k=0;e.f=function(a){a=E(a);
return q(a)};e.d=q;return e}()}function b(a,b,c){return function(){function d(a){var b=null;0<arguments.length&&(b=J(Array.prototype.slice.call(arguments,0),0));return e.call(this,b)}function e(d){return S.n(a,b,c,d)}d.k=0;d.f=function(a){a=E(a);return e(a)};d.d=e;return d}()}function c(a,b){return function(){function c(a){var b=null;0<arguments.length&&(b=J(Array.prototype.slice.call(arguments,0),0));return d.call(this,b)}function d(c){return S.c(a,b,c)}c.k=0;c.f=function(a){a=E(a);return d(a)};
c.d=d;return c}()}var d=null,e=function(){function a(c,d,e,f,t){var v=null;4<arguments.length&&(v=J(Array.prototype.slice.call(arguments,4),0));return b.call(this,c,d,e,f,v)}function b(a,c,d,e,f){return function(){function b(a){var c=null;0<arguments.length&&(c=J(Array.prototype.slice.call(arguments,0),0));return h.call(this,c)}function h(b){return S.s(a,c,d,e,td.a(f,b))}b.k=0;b.f=function(a){a=E(a);return h(a)};b.d=h;return b}()}a.k=4;a.f=function(a){var c=F(a);a=I(a);var d=F(a);a=I(a);var e=F(a);
a=I(a);var f=F(a);a=G(a);return b(c,d,e,f,a)};a.d=b;return a}(),d=function(d,h,k,l,n){switch(arguments.length){case 1:return d;case 2:return c.call(this,d,h);case 3:return b.call(this,d,h,k);case 4:return a.call(this,d,h,k,l);default:return e.d(d,h,k,l,J(arguments,4))}throw Error("Invalid arity: "+arguments.length);};d.k=4;d.f=e.f;d.b=function(a){return a};d.a=c;d.c=b;d.n=a;d.d=e.d;return d}(),Jd=function(){function a(a,b,c,d){return function(){var l=null,n=function(){function l(a,b,c,d){var e=null;
3<arguments.length&&(e=J(Array.prototype.slice.call(arguments,3),0));return n.call(this,a,b,c,e)}function n(l,q,t,B){return S.s(a,null==l?b:l,null==q?c:q,null==t?d:t,B)}l.k=3;l.f=function(a){var b=F(a);a=I(a);var c=F(a);a=I(a);var d=F(a);a=G(a);return n(b,c,d,a)};l.d=n;return l}(),l=function(l,t,v,w){switch(arguments.length){case 2:var y=l,B=t;return a.a?a.a(null==y?b:y,null==B?c:B):a.call(null,null==y?b:y,null==B?c:B);case 3:var y=l,B=t,L=v;return a.c?a.c(null==y?b:y,null==B?c:B,null==L?d:L):a.call(null,
null==y?b:y,null==B?c:B,null==L?d:L);default:return n.d(l,t,v,J(arguments,3))}throw Error("Invalid arity: "+arguments.length);};l.k=3;l.f=n.f;return l}()}function b(a,b,c){return function(){var d=null,l=function(){function d(a,b,c,e){var f=null;3<arguments.length&&(f=J(Array.prototype.slice.call(arguments,3),0));return k.call(this,a,b,c,f)}function k(d,l,n,q){return S.s(a,null==d?b:d,null==l?c:l,n,q)}d.k=3;d.f=function(a){var b=F(a);a=I(a);var c=F(a);a=I(a);var d=F(a);a=G(a);return k(b,c,d,a)};d.d=
k;return d}(),d=function(d,k,t,v){switch(arguments.length){case 2:var w=d,y=k;return a.a?a.a(null==w?b:w,null==y?c:y):a.call(null,null==w?b:w,null==y?c:y);case 3:var w=d,y=k,B=t;return a.c?a.c(null==w?b:w,null==y?c:y,B):a.call(null,null==w?b:w,null==y?c:y,B);default:return l.d(d,k,t,J(arguments,3))}throw Error("Invalid arity: "+arguments.length);};d.k=3;d.f=l.f;return d}()}function c(a,b){return function(){var c=null,d=function(){function c(a,b,e,f){var h=null;3<arguments.length&&(h=J(Array.prototype.slice.call(arguments,
3),0));return d.call(this,a,b,e,h)}function d(c,h,k,l){return S.s(a,null==c?b:c,h,k,l)}c.k=3;c.f=function(a){var b=F(a);a=I(a);var c=F(a);a=I(a);var e=F(a);a=G(a);return d(b,c,e,a)};c.d=d;return c}(),c=function(c,h,q,t){switch(arguments.length){case 1:var v=c;return a.b?a.b(null==v?b:v):a.call(null,null==v?b:v);case 2:var v=c,w=h;return a.a?a.a(null==v?b:v,w):a.call(null,null==v?b:v,w);case 3:var v=c,w=h,y=q;return a.c?a.c(null==v?b:v,w,y):a.call(null,null==v?b:v,w,y);default:return d.d(c,h,q,J(arguments,
3))}throw Error("Invalid arity: "+arguments.length);};c.k=3;c.f=d.f;return c}()}var d=null,d=function(d,f,h,k){switch(arguments.length){case 2:return c.call(this,d,f);case 3:return b.call(this,d,f,h);case 4:return a.call(this,d,f,h,k)}throw Error("Invalid arity: "+arguments.length);};d.a=c;d.c=b;d.n=a;return d}(),Kd=function(){function a(a,b,c,e){return new V(null,function(){var n=E(b),q=E(c),t=E(e);return n&&q&&t?M(a.c?a.c(F(n),F(q),F(t)):a.call(null,F(n),F(q),F(t)),d.n(a,G(n),G(q),G(t))):null},
null,null)}function b(a,b,c){return new V(null,function(){var e=E(b),n=E(c);return e&&n?M(a.a?a.a(F(e),F(n)):a.call(null,F(e),F(n)),d.c(a,G(e),G(n))):null},null,null)}function c(a,b){return new V(null,function(){var c=E(b);if(c){if(Ic(c)){for(var e=Hb(c),n=O(e),q=new ld(Array(n),0),t=0;;)if(t<n){var v=a.b?a.b(D.a(e,t)):a.call(null,D.a(e,t));q.add(v);t+=1}else break;return pd(q.da(),d.a(a,Ib(c)))}return M(a.b?a.b(F(c)):a.call(null,F(c)),d.a(a,G(c)))}return null},null,null)}var d=null,e=function(){function a(c,
d,e,f,t){var v=null;4<arguments.length&&(v=J(Array.prototype.slice.call(arguments,4),0));return b.call(this,c,d,e,f,v)}function b(a,c,e,f,h){var v=function y(a){return new V(null,function(){var b=d.a(E,a);return Dd(Fd,b)?M(d.a(F,b),y(d.a(G,b))):null},null,null)};return d.a(function(){return function(b){return S.a(a,b)}}(v),v(pc.d(h,f,J([e,c],0))))}a.k=4;a.f=function(a){var c=F(a);a=I(a);var d=F(a);a=I(a);var e=F(a);a=I(a);var f=F(a);a=G(a);return b(c,d,e,f,a)};a.d=b;return a}(),d=function(d,h,k,l,
n){switch(arguments.length){case 2:return c.call(this,d,h);case 3:return b.call(this,d,h,k);case 4:return a.call(this,d,h,k,l);default:return e.d(d,h,k,l,J(arguments,4))}throw Error("Invalid arity: "+arguments.length);};d.k=4;d.f=e.f;d.a=c;d.c=b;d.n=a;d.d=e.d;return d}(),Md=function Ld(b,c){return new V(null,function(){if(0<b){var d=E(c);return d?M(F(d),Ld(b-1,G(d))):null}return null},null,null)};
function Nd(a,b){return new V(null,function(c){return function(){return c(a,b)}}(function(a,b){for(;;){var e=E(b);if(0<a&&e){var f=a-1,e=G(e);a=f;b=e}else return e}}),null,null)}
var Od=function(){function a(a,b){return Md(a,c.b(b))}function b(a){return new V(null,function(){return M(a,c.b(a))},null,null)}var c=null,c=function(c,e){switch(arguments.length){case 1:return b.call(this,c);case 2:return a.call(this,c,e)}throw Error("Invalid arity: "+arguments.length);};c.b=b;c.a=a;return c}(),Pd=function(){function a(a,b){return Md(a,c.b(b))}function b(a){return new V(null,function(){return M(a.o?a.o():a.call(null),c.b(a))},null,null)}var c=null,c=function(c,e){switch(arguments.length){case 1:return b.call(this,
c);case 2:return a.call(this,c,e)}throw Error("Invalid arity: "+arguments.length);};c.b=b;c.a=a;return c}(),Qd=function(){function a(a,c){return new V(null,function(){var f=E(a),h=E(c);return f&&h?M(F(f),M(F(h),b.a(G(f),G(h)))):null},null,null)}var b=null,c=function(){function a(b,d,k){var l=null;2<arguments.length&&(l=J(Array.prototype.slice.call(arguments,2),0));return c.call(this,b,d,l)}function c(a,d,e){return new V(null,function(){var c=Kd.a(E,pc.d(e,d,J([a],0)));return Dd(Fd,c)?td.a(Kd.a(F,
c),S.a(b,Kd.a(G,c))):null},null,null)}a.k=2;a.f=function(a){var b=F(a);a=I(a);var d=F(a);a=G(a);return c(b,d,a)};a.d=c;return a}(),b=function(b,e,f){switch(arguments.length){case 2:return a.call(this,b,e);default:return c.d(b,e,J(arguments,2))}throw Error("Invalid arity: "+arguments.length);};b.k=2;b.f=c.f;b.a=a;b.d=c.d;return b}();function Rd(a){return function c(a,e){return new V(null,function(){var f=E(a);return f?M(F(f),c(G(f),e)):E(e)?c(F(e),G(e)):null},null,null)}(null,a)}
var Sd=function(){function a(a,b){return Rd(Kd.a(a,b))}var b=null,c=function(){function a(c,d,k){var l=null;2<arguments.length&&(l=J(Array.prototype.slice.call(arguments,2),0));return b.call(this,c,d,l)}function b(a,c,d){return Rd(S.n(Kd,a,c,d))}a.k=2;a.f=function(a){var c=F(a);a=I(a);var d=F(a);a=G(a);return b(c,d,a)};a.d=b;return a}(),b=function(b,e,f){switch(arguments.length){case 2:return a.call(this,b,e);default:return c.d(b,e,J(arguments,2))}throw Error("Invalid arity: "+arguments.length);};
b.k=2;b.f=c.f;b.a=a;b.d=c.d;return b}(),Ud=function Td(b,c){return new V(null,function(){var d=E(c);if(d){if(Ic(d)){for(var e=Hb(d),f=O(e),h=new ld(Array(f),0),k=0;;)if(k<f){if(r(b.b?b.b(D.a(e,k)):b.call(null,D.a(e,k)))){var l=D.a(e,k);h.add(l)}k+=1}else break;return pd(h.da(),Td(b,Ib(d)))}e=F(d);d=G(d);return r(b.b?b.b(e):b.call(null,e))?M(e,Td(b,d)):Td(b,d)}return null},null,null)};function Vd(a,b){return Ud(Gd(a),b)}
function Wd(a){var b=Xd;return function d(a){return new V(null,function(){return M(a,r(b.b?b.b(a):b.call(null,a))?Sd.a(d,E.b?E.b(a):E.call(null,a)):null)},null,null)}(a)}function Yd(a,b){return null!=a?a&&(a.q&4||a.Bc)?vd(C.c(zb,yb(a),b)):C.c(Da,a,b):C.c(pc,H,b)}
var Zd=function(){function a(a,b,c,k){return new V(null,function(){var l=E(k);if(l){var n=Md(a,l);return a===O(n)?M(n,d.n(a,b,c,Nd(b,l))):Da(H,Md(a,td.a(n,c)))}return null},null,null)}function b(a,b,c){return new V(null,function(){var k=E(c);if(k){var l=Md(a,k);return a===O(l)?M(l,d.c(a,b,Nd(b,k))):null}return null},null,null)}function c(a,b){return d.c(a,a,b)}var d=null,d=function(d,f,h,k){switch(arguments.length){case 2:return c.call(this,d,f);case 3:return b.call(this,d,f,h);case 4:return a.call(this,
d,f,h,k)}throw Error("Invalid arity: "+arguments.length);};d.a=c;d.c=b;d.n=a;return d}(),$d=function(){function a(a,b,c){var h=Lc;for(b=E(b);;)if(b){var k=a;if(k?k.i&256||k.Mb||(k.i?0:s(Ka,k)):s(Ka,k)){a=Q.c(a,F(b),h);if(h===a)return c;b=I(b)}else return c}else return a}function b(a,b){return c.c(a,b,null)}var c=null,c=function(c,e,f){switch(arguments.length){case 2:return b.call(this,c,e);case 3:return a.call(this,c,e,f)}throw Error("Invalid arity: "+arguments.length);};c.a=b;c.c=a;return c}(),ae=
function(){function a(a,b,c,d,f,t){var v=P.c(b,0,null);return(b=$c(b))?R.c(a,v,e.X(Q.a(a,v),b,c,d,f,t)):R.c(a,v,c.n?c.n(Q.a(a,v),d,f,t):c.call(null,Q.a(a,v),d,f,t))}function b(a,b,c,d,f){var t=P.c(b,0,null);return(b=$c(b))?R.c(a,t,e.s(Q.a(a,t),b,c,d,f)):R.c(a,t,c.c?c.c(Q.a(a,t),d,f):c.call(null,Q.a(a,t),d,f))}function c(a,b,c,d){var f=P.c(b,0,null);return(b=$c(b))?R.c(a,f,e.n(Q.a(a,f),b,c,d)):R.c(a,f,c.a?c.a(Q.a(a,f),d):c.call(null,Q.a(a,f),d))}function d(a,b,c){var d=P.c(b,0,null);return(b=$c(b))?
R.c(a,d,e.c(Q.a(a,d),b,c)):R.c(a,d,c.b?c.b(Q.a(a,d)):c.call(null,Q.a(a,d)))}var e=null,f=function(){function a(c,d,e,f,h,w,y){var B=null;6<arguments.length&&(B=J(Array.prototype.slice.call(arguments,6),0));return b.call(this,c,d,e,f,h,w,B)}function b(a,c,d,f,h,k,y){var B=P.c(c,0,null);return(c=$c(c))?R.c(a,B,S.d(e,Q.a(a,B),c,d,f,J([h,k,y],0))):R.c(a,B,S.d(d,Q.a(a,B),f,h,k,J([y],0)))}a.k=6;a.f=function(a){var c=F(a);a=I(a);var d=F(a);a=I(a);var e=F(a);a=I(a);var f=F(a);a=I(a);var h=F(a);a=I(a);var y=
F(a);a=G(a);return b(c,d,e,f,h,y,a)};a.d=b;return a}(),e=function(e,k,l,n,q,t,v){switch(arguments.length){case 3:return d.call(this,e,k,l);case 4:return c.call(this,e,k,l,n);case 5:return b.call(this,e,k,l,n,q);case 6:return a.call(this,e,k,l,n,q,t);default:return f.d(e,k,l,n,q,t,J(arguments,6))}throw Error("Invalid arity: "+arguments.length);};e.k=6;e.f=f.f;e.c=d;e.n=c;e.s=b;e.X=a;e.d=f.d;return e}();function be(a,b){this.t=a;this.e=b}
function ce(a){return new be(a,[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null])}function de(a){return new be(a.t,va(a.e))}function ee(a){a=a.g;return 32>a?0:a-1>>>5<<5}function fe(a,b,c){for(;;){if(0===b)return c;var d=ce(a);d.e[0]=c;c=d;b-=5}}var he=function ge(b,c,d,e){var f=de(d),h=b.g-1>>>c&31;5===c?f.e[h]=e:(d=d.e[h],b=null!=d?ge(b,c-5,d,e):fe(null,c-5,e),f.e[h]=b);return f};
function ie(a,b){throw Error("No item "+A.b(a)+" in vector of length "+A.b(b));}function je(a){var b=a.root;for(a=a.shift;;)if(0<a)a-=5,b=b.e[0];else return b.e}function ke(a,b){if(b>=ee(a))return a.R;for(var c=a.root,d=a.shift;;)if(0<d)var e=d-5,c=c.e[b>>>d&31],d=e;else return c.e}function le(a,b){return 0<=b&&b<a.g?ke(a,b):ie(b,a.g)}
var ne=function me(b,c,d,e,f){var h=de(d);if(0===c)h.e[e&31]=f;else{var k=e>>>c&31;b=me(b,c-5,d.e[k],e,f);h.e[k]=b}return h},pe=function oe(b,c,d){var e=b.g-2>>>c&31;if(5<c){b=oe(b,c-5,d.e[e]);if(null==b&&0===e)return null;d=de(d);d.e[e]=b;return d}return 0===e?null:u?(d=de(d),d.e[e]=null,d):null};function W(a,b,c,d,e,f){this.j=a;this.g=b;this.shift=c;this.root=d;this.R=e;this.m=f;this.i=167668511;this.q=8196}g=W.prototype;g.toString=function(){return Lb(this)};
g.u=function(a,b){return La.c(this,b,null)};g.C=function(a,b,c){return"number"===typeof b?D.c(this,b,c):c};g.Za=function(a,b,c){a=[0,c];for(c=0;;)if(c<this.g){var d=ke(this,c),e=d.length;a:{for(var f=0,h=a[1];;)if(f<e){h=b.c?b.c(h,f+c,d[f]):b.call(null,h,f+c,d[f]);if(fc(h)){d=h;break a}f+=1}else{a[0]=e;d=a[1]=h;break a}d=void 0}if(fc(d))return K.b?K.b(d):K.call(null,d);c+=a[0]}else return a[1]};g.J=function(a,b){return le(this,b)[b&31]};
g.aa=function(a,b,c){return 0<=b&&b<this.g?ke(this,b)[b&31]:c};g.Pa=function(a,b,c){if(0<=b&&b<this.g)return ee(this)<=b?(a=va(this.R),a[b&31]=c,new W(this.j,this.g,this.shift,this.root,a,null)):new W(this.j,this.g,this.shift,ne(this,this.shift,this.root,b,c),this.R,null);if(b===this.g)return Da(this,c);if(u)throw Error("Index "+A.b(b)+" out of bounds [0,"+A.b(this.g)+"]");return null};g.D=function(){return this.j};g.L=function(){return this.g};g.$a=function(){return D.a(this,0)};
g.ab=function(){return D.a(this,1)};g.Ia=function(){return 0<this.g?D.a(this,this.g-1):null};g.Ja=function(){if(0===this.g)throw Error("Can't pop empty vector");if(1===this.g)return eb(qe,this.j);if(1<this.g-ee(this))return new W(this.j,this.g-1,this.shift,this.root,this.R.slice(0,-1),null);if(u){var a=ke(this,this.g-2),b=pe(this,this.shift,this.root),b=null==b?X:b,c=this.g-1;return 5<this.shift&&null==b.e[1]?new W(this.j,c,this.shift-5,b.e[0],a,null):new W(this.j,c,this.shift,b,a,null)}return null};
g.Xa=function(){return 0<this.g?new kc(this,this.g-1,null):null};g.B=function(){var a=this.m;return null!=a?a:this.m=a=cc(this)};g.v=function(a,b){return lc(this,b)};g.Wa=function(){return new re(this.g,this.shift,se.b?se.b(this.root):se.call(null,this.root),te.b?te.b(this.R):te.call(null,this.R))};g.I=function(){return N(qe,this.j)};g.N=function(a,b){return gc.a(this,b)};g.M=function(a,b,c){return gc.c(this,b,c)};
g.ua=function(a,b,c){if("number"===typeof b)return $a(this,b,c);throw Error("Vector's key for assoc must be a number.");};g.H=function(){return 0===this.g?null:32>=this.g?new ac(this.R,0):u?ue.n?ue.n(this,je(this),0,0):ue.call(null,this,je(this),0,0):null};g.F=function(a,b){return new W(b,this.g,this.shift,this.root,this.R,this.m)};
g.G=function(a,b){if(32>this.g-ee(this)){for(var c=this.R.length,d=Array(c+1),e=0;;)if(e<c)d[e]=this.R[e],e+=1;else break;d[c]=b;return new W(this.j,this.g+1,this.shift,this.root,d,null)}c=(d=this.g>>>5>1<<this.shift)?this.shift+5:this.shift;d?(d=ce(null),d.e[0]=this.root,e=fe(null,this.shift,new be(null,this.R)),d.e[1]=e):d=he(this,this.shift,this.root,new be(null,this.R));return new W(this.j,this.g+1,c,d,[b],null)};
g.call=function(){var a=null;return a=function(a,c,d){switch(arguments.length){case 2:return this.J(null,c);case 3:return this.aa(null,c,d)}throw Error("Invalid arity: "+arguments.length);}}();g.apply=function(a,b){return this.call.apply(this,[this].concat(va(b)))};g.b=function(a){return this.J(null,a)};g.a=function(a,b){return this.aa(null,a,b)};
var X=new be(null,[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null]),qe=new W(null,0,5,X,[],0);function ve(a,b){var c=a.length,d=b?a:va(a);if(32>c)return new W(null,c,5,X,d,null);for(var e=32,f=(new W(null,32,5,X,d.slice(0,32),null)).Wa(null);;)if(e<c)var h=e+1,f=wd.a(f,d[e]),e=h;else return Ab(f)}function we(a){return Ab(C.c(zb,yb(qe),a))}
var xe=function(){function a(a){var d=null;0<arguments.length&&(d=J(Array.prototype.slice.call(arguments,0),0));return b.call(this,d)}function b(a){return a instanceof ac&&0===a.p?ve.a?ve.a(a.e,!0):ve.call(null,a.e,!0):we(a)}a.k=0;a.f=function(a){a=E(a);return b(a)};a.d=b;return a}();function ye(a,b,c,d,e,f){this.P=a;this.ea=b;this.p=c;this.O=d;this.j=e;this.m=f;this.i=32243948;this.q=1536}g=ye.prototype;g.toString=function(){return Lb(this)};
g.U=function(){if(this.O+1<this.ea.length){var a=ue.n?ue.n(this.P,this.ea,this.p,this.O+1):ue.call(null,this.P,this.ea,this.p,this.O+1);return null==a?null:a}return Jb(this)};g.B=function(){var a=this.m;return null!=a?a:this.m=a=cc(this)};g.v=function(a,b){return lc(this,b)};g.I=function(){return N(qe,this.j)};g.N=function(a,b){return gc.a(ze.c?ze.c(this.P,this.p+this.O,O(this.P)):ze.call(null,this.P,this.p+this.O,O(this.P)),b)};
g.M=function(a,b,c){return gc.c(ze.c?ze.c(this.P,this.p+this.O,O(this.P)):ze.call(null,this.P,this.p+this.O,O(this.P)),b,c)};g.Q=function(){return this.ea[this.O]};g.S=function(){if(this.O+1<this.ea.length){var a=ue.n?ue.n(this.P,this.ea,this.p,this.O+1):ue.call(null,this.P,this.ea,this.p,this.O+1);return null==a?H:a}return Ib(this)};g.H=function(){return this};g.sb=function(){return nd.a(this.ea,this.O)};
g.tb=function(){var a=this.p+this.ea.length;return a<Aa(this.P)?ue.n?ue.n(this.P,ke(this.P,a),a,0):ue.call(null,this.P,ke(this.P,a),a,0):H};g.F=function(a,b){return ue.s?ue.s(this.P,this.ea,this.p,this.O,b):ue.call(null,this.P,this.ea,this.p,this.O,b)};g.G=function(a,b){return M(b,this)};g.rb=function(){var a=this.p+this.ea.length;return a<Aa(this.P)?ue.n?ue.n(this.P,ke(this.P,a),a,0):ue.call(null,this.P,ke(this.P,a),a,0):null};
var ue=function(){function a(a,b,c,d,l){return new ye(a,b,c,d,l,null)}function b(a,b,c,d){return new ye(a,b,c,d,null,null)}function c(a,b,c){return new ye(a,le(a,b),b,c,null,null)}var d=null,d=function(d,f,h,k,l){switch(arguments.length){case 3:return c.call(this,d,f,h);case 4:return b.call(this,d,f,h,k);case 5:return a.call(this,d,f,h,k,l)}throw Error("Invalid arity: "+arguments.length);};d.c=c;d.n=b;d.s=a;return d}();
function Ae(a,b,c,d,e){this.j=a;this.ca=b;this.start=c;this.end=d;this.m=e;this.i=166617887;this.q=8192}g=Ae.prototype;g.toString=function(){return Lb(this)};g.u=function(a,b){return La.c(this,b,null)};g.C=function(a,b,c){return"number"===typeof b?D.c(this,b,c):c};g.J=function(a,b){return 0>b||this.end<=this.start+b?ie(b,this.end-this.start):D.a(this.ca,this.start+b)};g.aa=function(a,b,c){return 0>b||this.end<=this.start+b?c:D.c(this.ca,this.start+b,c)};
g.Pa=function(a,b,c){var d=this,e=d.start+b;return Be.s?Be.s(d.j,R.c(d.ca,e,c),d.start,function(){var a=d.end,b=e+1;return a>b?a:b}(),null):Be.call(null,d.j,R.c(d.ca,e,c),d.start,function(){var a=d.end,b=e+1;return a>b?a:b}(),null)};g.D=function(){return this.j};g.L=function(){return this.end-this.start};g.Ia=function(){return D.a(this.ca,this.end-1)};
g.Ja=function(){if(this.start===this.end)throw Error("Can't pop empty vector");return Be.s?Be.s(this.j,this.ca,this.start,this.end-1,null):Be.call(null,this.j,this.ca,this.start,this.end-1,null)};g.Xa=function(){return this.start!==this.end?new kc(this,this.end-this.start-1,null):null};g.B=function(){var a=this.m;return null!=a?a:this.m=a=cc(this)};g.v=function(a,b){return lc(this,b)};g.I=function(){return N(qe,this.j)};g.N=function(a,b){return gc.a(this,b)};
g.M=function(a,b,c){return gc.c(this,b,c)};g.ua=function(a,b,c){if("number"===typeof b)return $a(this,b,c);throw Error("Subvec's key for assoc must be a number.");};g.H=function(){var a=this;return function(b){return function d(e){return e===a.end?null:M(D.a(a.ca,e),new V(null,function(){return function(){return d(e+1)}}(b),null,null))}}(this)(a.start)};g.F=function(a,b){return Be.s?Be.s(b,this.ca,this.start,this.end,this.m):Be.call(null,b,this.ca,this.start,this.end,this.m)};
g.G=function(a,b){return Be.s?Be.s(this.j,$a(this.ca,this.end,b),this.start,this.end+1,null):Be.call(null,this.j,$a(this.ca,this.end,b),this.start,this.end+1,null)};g.call=function(){var a=null;return a=function(a,c,d){switch(arguments.length){case 2:return this.J(null,c);case 3:return this.aa(null,c,d)}throw Error("Invalid arity: "+arguments.length);}}();g.apply=function(a,b){return this.call.apply(this,[this].concat(va(b)))};g.b=function(a){return this.J(null,a)};
g.a=function(a,b){return this.aa(null,a,b)};function Be(a,b,c,d,e){for(;;)if(b instanceof Ae)c=b.start+c,d=b.start+d,b=b.ca;else{var f=O(b);if(0>c||0>d||c>f||d>f)throw Error("Index out of bounds");return new Ae(a,b,c,d,e)}}
var ze=function(){function a(a,b,c){return Be(null,a,b,c,null)}function b(a,b){return c.c(a,b,O(a))}var c=null,c=function(c,e,f){switch(arguments.length){case 2:return b.call(this,c,e);case 3:return a.call(this,c,e,f)}throw Error("Invalid arity: "+arguments.length);};c.a=b;c.c=a;return c}();function Ce(a,b){return a===b.t?b:new be(a,va(b.e))}function se(a){return new be({},va(a.e))}
function te(a){var b=[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null];Kc(a,0,b,0,a.length);return b}
var Ee=function De(b,c,d,e){d=Ce(b.root.t,d);var f=b.g-1>>>c&31;if(5===c)b=e;else{var h=d.e[f];b=null!=h?De(b,c-5,h,e):fe(b.root.t,c-5,e)}d.e[f]=b;return d},Ge=function Fe(b,c,d){d=Ce(b.root.t,d);var e=b.g-2>>>c&31;if(5<c){b=Fe(b,c-5,d.e[e]);if(null==b&&0===e)return null;d.e[e]=b;return d}return 0===e?null:u?(d.e[e]=null,d):null};function re(a,b,c,d){this.g=a;this.shift=b;this.root=c;this.R=d;this.i=275;this.q=88}g=re.prototype;
g.call=function(){var a=null;return a=function(a,c,d){switch(arguments.length){case 2:return this.u(null,c);case 3:return this.C(null,c,d)}throw Error("Invalid arity: "+arguments.length);}}();g.apply=function(a,b){return this.call.apply(this,[this].concat(va(b)))};g.b=function(a){return this.u(null,a)};g.a=function(a,b){return this.C(null,a,b)};g.u=function(a,b){return La.c(this,b,null)};g.C=function(a,b,c){return"number"===typeof b?D.c(this,b,c):c};
g.J=function(a,b){if(this.root.t)return le(this,b)[b&31];throw Error("nth after persistent!");};g.aa=function(a,b,c){return 0<=b&&b<this.g?D.a(this,b):c};g.L=function(){if(this.root.t)return this.g;throw Error("count after persistent!");};
g.Pb=function(a,b,c){var d=this;if(d.root.t){if(0<=b&&b<d.g)return ee(this)<=b?d.R[b&31]=c:(a=function(){return function f(a,k){var l=Ce(d.root.t,k);if(0===a)l.e[b&31]=c;else{var n=b>>>a&31,q=f(a-5,l.e[n]);l.e[n]=q}return l}}(this).call(null,d.shift,d.root),d.root=a),this;if(b===d.g)return zb(this,c);if(u)throw Error("Index "+A.b(b)+" out of bounds for TransientVector of length"+A.b(d.g));return null}throw Error("assoc! after persistent!");};
g.Qb=function(){if(this.root.t){if(0===this.g)throw Error("Can't pop empty vector");if(1===this.g)return this.g=0,this;if(0<(this.g-1&31))return this.g-=1,this;if(u){var a;a:if(a=this.g-2,a>=ee(this))a=this.R;else{for(var b=this.root,c=b,d=this.shift;;)if(0<d)c=Ce(b.t,c.e[a>>>d&31]),d-=5;else{a=c.e;break a}a=void 0}b=Ge(this,this.shift,this.root);b=null!=b?b:new be(this.root.t,[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null]);5<this.shift&&null==b.e[1]?(this.root=Ce(this.root.t,b.e[0]),this.shift-=5):this.root=b;this.g-=1;this.R=a;return this}return null}throw Error("pop! after persistent!");};g.cb=function(a,b,c){if("number"===typeof b)return Db(this,b,c);throw Error("TransientVector's key for assoc! must be a number.");};
g.Ka=function(a,b){if(this.root.t){if(32>this.g-ee(this))this.R[this.g&31]=b;else{var c=new be(this.root.t,this.R),d=[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null];d[0]=b;this.R=d;if(this.g>>>5>1<<this.shift){var d=[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],e=this.shift+
5;d[0]=this.root;d[1]=fe(this.root.t,this.shift,c);this.root=new be(this.root.t,d);this.shift=e}else this.root=Ee(this,this.shift,this.root,c)}this.g+=1;return this}throw Error("conj! after persistent!");};g.Oa=function(){if(this.root.t){this.root.t=null;var a=this.g-ee(this),b=Array(a);Kc(this.R,0,b,0,a);return new W(null,this.g,this.shift,this.root,b,null)}throw Error("persistent! called twice");};function He(a,b,c,d){this.j=a;this.ba=b;this.pa=c;this.m=d;this.q=0;this.i=31850572}g=He.prototype;
g.toString=function(){return Lb(this)};g.D=function(){return this.j};g.B=function(){var a=this.m;return null!=a?a:this.m=a=cc(this)};g.v=function(a,b){return lc(this,b)};g.I=function(){return N(H,this.j)};g.Q=function(){return F(this.ba)};g.S=function(){var a=I(this.ba);return a?new He(this.j,a,this.pa,null):null==this.pa?Ba(this):new He(this.j,this.pa,null,null)};g.H=function(){return this};g.F=function(a,b){return new He(b,this.ba,this.pa,this.m)};g.G=function(a,b){return M(b,this)};
function Ie(a,b,c,d,e){this.j=a;this.count=b;this.ba=c;this.pa=d;this.m=e;this.i=31858766;this.q=8192}g=Ie.prototype;g.toString=function(){return Lb(this)};g.D=function(){return this.j};g.L=function(){return this.count};g.Ia=function(){return F(this.ba)};g.Ja=function(){if(r(this.ba)){var a=I(this.ba);return a?new Ie(this.j,this.count-1,a,this.pa,null):new Ie(this.j,this.count-1,E(this.pa),qe,null)}return this};g.B=function(){var a=this.m;return null!=a?a:this.m=a=cc(this)};
g.v=function(a,b){return lc(this,b)};g.I=function(){return Je};g.Q=function(){return F(this.ba)};g.S=function(){return G(E(this))};g.H=function(){var a=E(this.pa),b=this.ba;return r(r(b)?b:a)?new He(null,this.ba,E(a),null):null};g.F=function(a,b){return new Ie(b,this.count,this.ba,this.pa,this.m)};g.G=function(a,b){var c;r(this.ba)?(c=this.pa,c=new Ie(this.j,this.count+1,this.ba,pc.a(r(c)?c:qe,b),null)):c=new Ie(this.j,this.count+1,pc.a(this.ba,b),qe,null);return c};var Je=new Ie(null,0,null,qe,0);
function Ke(){this.q=0;this.i=2097152}Ke.prototype.v=function(){return!1};var Le=new Ke;function Me(a,b){return Nc(Gc(b)?O(a)===O(b)?Dd(Fd,Kd.a(function(a){return Wb.a(Q.c(b,F(a),Le),F(I(a)))},a)):null:null)}function Ne(a){this.r=a}Ne.prototype.next=function(){if(null!=this.r){var a=F(this.r);this.r=I(this.r);return{done:!1,value:a}}return{done:!0,value:null}};function Oe(a){return new Ne(E(a))}function Pe(a){this.r=a}
Pe.prototype.next=function(){if(null!=this.r){var a=F(this.r),b=P.c(a,0,null),a=P.c(a,1,null);this.r=I(this.r);return{done:!1,value:[b,a]}}return{done:!0,value:null}};function Qe(a){return new Pe(E(a))}function Re(a){this.r=a}Re.prototype.next=function(){if(null!=this.r){var a=F(this.r);this.r=I(this.r);return{done:!1,value:[a,a]}}return{done:!0,value:null}};function Se(a){return new Re(E(a))}
function Te(a,b){var c=a.e;if(b instanceof T)a:{for(var d=c.length,e=b.sa,f=0;;){if(d<=f){c=-1;break a}var h=c[f];if(h instanceof T&&e===h.sa){c=f;break a}if(u)f+=2;else{c=null;break a}}c=void 0}else if("string"==typeof b||"number"===typeof b)a:{d=c.length;for(e=0;;){if(d<=e){c=-1;break a}if(b===c[e]){c=e;break a}if(u)e+=2;else{c=null;break a}}c=void 0}else if(b instanceof Zb)a:{d=c.length;e=b.Na;for(f=0;;){if(d<=f){c=-1;break a}h=c[f];if(h instanceof Zb&&e===h.Na){c=f;break a}if(u)f+=2;else{c=null;
break a}}c=void 0}else if(null==b)a:{d=c.length;for(e=0;;){if(d<=e){c=-1;break a}if(null==c[e]){c=e;break a}if(u)e+=2;else{c=null;break a}}c=void 0}else if(u)a:{d=c.length;for(e=0;;){if(d<=e){c=-1;break a}if(Wb.a(b,c[e])){c=e;break a}if(u)e+=2;else{c=null;break a}}c=void 0}else c=null;return c}function Ue(a,b,c){this.e=a;this.p=b;this.W=c;this.q=0;this.i=32374990}g=Ue.prototype;g.toString=function(){return Lb(this)};g.D=function(){return this.W};
g.U=function(){return this.p<this.e.length-2?new Ue(this.e,this.p+2,this.W):null};g.L=function(){return(this.e.length-this.p)/2};g.B=function(){return cc(this)};g.v=function(a,b){return lc(this,b)};g.I=function(){return N(H,this.W)};g.N=function(a,b){return nc.a(b,this)};g.M=function(a,b,c){return nc.c(b,c,this)};g.Q=function(){return new W(null,2,5,X,[this.e[this.p],this.e[this.p+1]],null)};g.S=function(){return this.p<this.e.length-2?new Ue(this.e,this.p+2,this.W):H};g.H=function(){return this};
g.F=function(a,b){return new Ue(this.e,this.p,b)};g.G=function(a,b){return M(b,this)};function la(a,b,c,d){this.j=a;this.g=b;this.e=c;this.m=d;this.i=16647951;this.q=8196}g=la.prototype;g.toString=function(){return Lb(this)};g.keys=function(){return Oe(Ve.b?Ve.b(this):Ve.call(null,this))};g.entries=function(){return Qe(E(this))};g.values=function(){return Oe(We.b?We.b(this):We.call(null,this))};g.has=function(a){return Oc(this,a)};g.get=function(a){return this.u(null,a)};
g.forEach=function(a){for(var b=E(this),c=null,d=0,e=0;;)if(e<d){var f=c.J(null,e),h=P.c(f,0,null),f=P.c(f,1,null);a.a?a.a(f,h):a.call(null,f,h);e+=1}else if(b=E(b))Ic(b)?(c=Hb(b),b=Ib(b),h=c,d=O(c),c=h):(c=F(b),h=P.c(c,0,null),f=P.c(c,1,null),a.a?a.a(f,h):a.call(null,f,h),b=I(b),c=null,d=0),e=0;else return null};g.u=function(a,b){return La.c(this,b,null)};g.C=function(a,b,c){a=Te(this,b);return-1===a?c:this.e[a+1]};
g.Za=function(a,b,c){a=this.e.length;for(var d=0;;)if(d<a){c=b.c?b.c(c,this.e[d],this.e[d+1]):b.call(null,c,this.e[d],this.e[d+1]);if(fc(c))return K.b?K.b(c):K.call(null,c);d+=2}else return c};g.D=function(){return this.j};g.L=function(){return this.g};g.B=function(){var a=this.m;return null!=a?a:this.m=a=dc(this)};g.v=function(a,b){return Me(this,b)};g.Wa=function(){return new Xe({},this.e.length,va(this.e))};g.I=function(){return eb(Ye,this.j)};g.N=function(a,b){return nc.a(b,this)};
g.M=function(a,b,c){return nc.c(b,c,this)};g.nb=function(a,b){if(0<=Te(this,b)){var c=this.e.length,d=c-2;if(0===d)return Ba(this);for(var d=Array(d),e=0,f=0;;){if(e>=c)return new la(this.j,this.g-1,d,null);if(Wb.a(b,this.e[e]))e+=2;else if(u)d[f]=this.e[e],d[f+1]=this.e[e+1],f+=2,e+=2;else return null}}else return this};
g.ua=function(a,b,c){a=Te(this,b);if(-1===a){if(this.g<Ze){a=this.e;for(var d=a.length,e=Array(d+2),f=0;;)if(f<d)e[f]=a[f],f+=1;else break;e[d]=b;e[d+1]=c;return new la(this.j,this.g+1,e,null)}return eb(Oa(Yd($e,this),b,c),this.j)}return c===this.e[a+1]?this:u?(b=va(this.e),b[a+1]=c,new la(this.j,this.g,b,null)):null};g.kb=function(a,b){return-1!==Te(this,b)};g.H=function(){var a=this.e;return 0<=a.length-2?new Ue(a,0,null):null};g.F=function(a,b){return new la(b,this.g,this.e,this.m)};
g.G=function(a,b){if(Hc(b))return Oa(this,D.a(b,0),D.a(b,1));for(var c=this,d=E(b);;){if(null==d)return c;var e=F(d);if(Hc(e))c=Oa(c,D.a(e,0),D.a(e,1)),d=I(d);else throw Error("conj on a map takes map entries or seqables of map entries");}};g.call=function(){var a=null;return a=function(a,c,d){switch(arguments.length){case 2:return this.u(null,c);case 3:return this.C(null,c,d)}throw Error("Invalid arity: "+arguments.length);}}();g.apply=function(a,b){return this.call.apply(this,[this].concat(va(b)))};
g.b=function(a){return this.u(null,a)};g.a=function(a,b){return this.C(null,a,b)};var Ye=new la(null,0,[],null),Ze=8;function af(a){for(var b=a.length,c=0,d=yb(Ye);;)if(c<b)var e=c+2,d=Bb(d,a[c],a[c+1]),c=e;else return Ab(d)}function Xe(a,b,c){this.Ra=a;this.ja=b;this.e=c;this.q=56;this.i=258}g=Xe.prototype;
g.Ab=function(a,b){if(r(this.Ra)){var c=Te(this,b);0<=c&&(this.e[c]=this.e[this.ja-2],this.e[c+1]=this.e[this.ja-1],c=this.e,c.pop(),c.pop(),this.ja-=2);return this}throw Error("dissoc! after persistent!");};g.cb=function(a,b,c){if(r(this.Ra)){a=Te(this,b);if(-1===a)return this.ja+2<=2*Ze?(this.ja+=2,this.e.push(b),this.e.push(c),this):xd.c(bf.a?bf.a(this.ja,this.e):bf.call(null,this.ja,this.e),b,c);c!==this.e[a+1]&&(this.e[a+1]=c);return this}throw Error("assoc! after persistent!");};
g.Ka=function(a,b){if(r(this.Ra)){if(b?b.i&2048||b.dc||(b.i?0:s(Sa,b)):s(Sa,b))return Bb(this,cf.b?cf.b(b):cf.call(null,b),df.b?df.b(b):df.call(null,b));for(var c=E(b),d=this;;){var e=F(c);if(r(e))c=I(c),d=Bb(d,cf.b?cf.b(e):cf.call(null,e),df.b?df.b(e):df.call(null,e));else return d}}else throw Error("conj! after persistent!");};g.Oa=function(){if(r(this.Ra))return this.Ra=!1,new la(null,Yc(this.ja),this.e,null);throw Error("persistent! called twice");};g.u=function(a,b){return La.c(this,b,null)};
g.C=function(a,b,c){if(r(this.Ra))return a=Te(this,b),-1===a?c:this.e[a+1];throw Error("lookup after persistent!");};g.L=function(){if(r(this.Ra))return Yc(this.ja);throw Error("count after persistent!");};function bf(a,b){for(var c=yb($e),d=0;;)if(d<a)c=xd.c(c,b[d],b[d+1]),d+=2;else return c}function ef(){this.l=!1}function ff(a,b){return a===b?!0:hd(a,b)?!0:u?Wb.a(a,b):null}
var gf=function(){function a(a,b,c,h,k){a=va(a);a[b]=c;a[h]=k;return a}function b(a,b,c){a=va(a);a[b]=c;return a}var c=null,c=function(c,e,f,h,k){switch(arguments.length){case 3:return b.call(this,c,e,f);case 5:return a.call(this,c,e,f,h,k)}throw Error("Invalid arity: "+arguments.length);};c.c=b;c.s=a;return c}();function hf(a,b){var c=Array(a.length-2);Kc(a,0,c,0,2*b);Kc(a,2*(b+1),c,2*b,c.length-2*b);return c}
var jf=function(){function a(a,b,c,h,k,l){a=a.La(b);a.e[c]=h;a.e[k]=l;return a}function b(a,b,c,h){a=a.La(b);a.e[c]=h;return a}var c=null,c=function(c,e,f,h,k,l){switch(arguments.length){case 4:return b.call(this,c,e,f,h);case 6:return a.call(this,c,e,f,h,k,l)}throw Error("Invalid arity: "+arguments.length);};c.n=b;c.X=a;return c}();
function kf(a,b,c){for(var d=a.length,e=0;;)if(e<d){var f=a[e];null!=f?c=b.c?b.c(c,f,a[e+1]):b.call(null,c,f,a[e+1]):(f=a[e+1],c=null!=f?f.Ta(b,c):c);if(fc(c))return K.b?K.b(c):K.call(null,c);e+=2}else return c}function lf(a,b,c){this.t=a;this.A=b;this.e=c}g=lf.prototype;g.La=function(a){if(a===this.t)return this;var b=Zc(this.A),c=Array(0>b?4:2*(b+1));Kc(this.e,0,c,0,2*b);return new lf(a,this.A,c)};
g.gb=function(a,b,c,d,e){var f=1<<(c>>>b&31);if(0===(this.A&f))return this;var h=Zc(this.A&f-1),k=this.e[2*h],l=this.e[2*h+1];return null==k?(b=l.gb(a,b+5,c,d,e),b===l?this:null!=b?jf.n(this,a,2*h+1,b):this.A===f?null:u?mf(this,a,f,h):null):ff(d,k)?(e[0]=!0,mf(this,a,f,h)):u?this:null};function mf(a,b,c,d){if(a.A===c)return null;a=a.La(b);b=a.e;var e=b.length;a.A^=c;Kc(b,2*(d+1),b,2*d,e-2*(d+1));b[e-2]=null;b[e-1]=null;return a}g.eb=function(){return nf.b?nf.b(this.e):nf.call(null,this.e)};
g.Ta=function(a,b){return kf(this.e,a,b)};g.Ma=function(a,b,c,d){var e=1<<(b>>>a&31);if(0===(this.A&e))return d;var f=Zc(this.A&e-1),e=this.e[2*f],f=this.e[2*f+1];return null==e?f.Ma(a+5,b,c,d):ff(c,e)?f:u?d:null};
g.ia=function(a,b,c,d,e,f){var h=1<<(c>>>b&31),k=Zc(this.A&h-1);if(0===(this.A&h)){var l=Zc(this.A);if(2*l<this.e.length){a=this.La(a);b=a.e;f.l=!0;a:for(c=2*(l-k),f=2*k+(c-1),l=2*(k+1)+(c-1);;){if(0===c)break a;b[l]=b[f];l-=1;c-=1;f-=1}b[2*k]=d;b[2*k+1]=e;a.A|=h;return a}if(16<=l){k=[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null];k[c>>>b&31]=of.ia(a,b+5,c,d,e,f);for(e=d=0;;)if(32>d)0!==
(this.A>>>d&1)&&(k[d]=null!=this.e[e]?of.ia(a,b+5,Tb(this.e[e]),this.e[e],this.e[e+1],f):this.e[e+1],e+=2),d+=1;else break;return new pf(a,l+1,k)}return u?(b=Array(2*(l+4)),Kc(this.e,0,b,0,2*k),b[2*k]=d,b[2*k+1]=e,Kc(this.e,2*k,b,2*(k+1),2*(l-k)),f.l=!0,a=this.La(a),a.e=b,a.A|=h,a):null}l=this.e[2*k];h=this.e[2*k+1];return null==l?(l=h.ia(a,b+5,c,d,e,f),l===h?this:jf.n(this,a,2*k+1,l)):ff(d,l)?e===h?this:jf.n(this,a,2*k+1,e):u?(f.l=!0,jf.X(this,a,2*k,null,2*k+1,qf.ga?qf.ga(a,b+5,l,h,c,d,e):qf.call(null,
a,b+5,l,h,c,d,e))):null};
g.ha=function(a,b,c,d,e){var f=1<<(b>>>a&31),h=Zc(this.A&f-1);if(0===(this.A&f)){var k=Zc(this.A);if(16<=k){h=[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null];h[b>>>a&31]=of.ha(a+5,b,c,d,e);for(d=c=0;;)if(32>c)0!==(this.A>>>c&1)&&(h[c]=null!=this.e[d]?of.ha(a+5,Tb(this.e[d]),this.e[d],this.e[d+1],e):this.e[d+1],d+=2),c+=1;else break;return new pf(null,k+1,h)}a=Array(2*(k+1));Kc(this.e,
0,a,0,2*h);a[2*h]=c;a[2*h+1]=d;Kc(this.e,2*h,a,2*(h+1),2*(k-h));e.l=!0;return new lf(null,this.A|f,a)}k=this.e[2*h];f=this.e[2*h+1];return null==k?(k=f.ha(a+5,b,c,d,e),k===f?this:new lf(null,this.A,gf.c(this.e,2*h+1,k))):ff(c,k)?d===f?this:new lf(null,this.A,gf.c(this.e,2*h+1,d)):u?(e.l=!0,new lf(null,this.A,gf.s(this.e,2*h,null,2*h+1,qf.X?qf.X(a+5,k,f,b,c,d):qf.call(null,a+5,k,f,b,c,d)))):null};
g.fb=function(a,b,c){var d=1<<(b>>>a&31);if(0===(this.A&d))return this;var e=Zc(this.A&d-1),f=this.e[2*e],h=this.e[2*e+1];return null==f?(a=h.fb(a+5,b,c),a===h?this:null!=a?new lf(null,this.A,gf.c(this.e,2*e+1,a)):this.A===d?null:u?new lf(null,this.A^d,hf(this.e,e)):null):ff(c,f)?new lf(null,this.A^d,hf(this.e,e)):u?this:null};var of=new lf(null,0,[]);
function rf(a,b,c){var d=a.e;a=2*(a.g-1);for(var e=Array(a),f=0,h=1,k=0;;)if(f<a)f!==c&&null!=d[f]&&(e[h]=d[f],h+=2,k|=1<<f),f+=1;else return new lf(b,k,e)}function pf(a,b,c){this.t=a;this.g=b;this.e=c}g=pf.prototype;g.La=function(a){return a===this.t?this:new pf(a,this.g,va(this.e))};
g.gb=function(a,b,c,d,e){var f=c>>>b&31,h=this.e[f];if(null==h)return this;b=h.gb(a,b+5,c,d,e);if(b===h)return this;if(null==b){if(8>=this.g)return rf(this,a,f);a=jf.n(this,a,f,b);a.g-=1;return a}return u?jf.n(this,a,f,b):null};g.eb=function(){return sf.b?sf.b(this.e):sf.call(null,this.e)};g.Ta=function(a,b){for(var c=this.e.length,d=0,e=b;;)if(d<c){var f=this.e[d];if(null!=f&&(e=f.Ta(a,e),fc(e)))return K.b?K.b(e):K.call(null,e);d+=1}else return e};
g.Ma=function(a,b,c,d){var e=this.e[b>>>a&31];return null!=e?e.Ma(a+5,b,c,d):d};g.ia=function(a,b,c,d,e,f){var h=c>>>b&31,k=this.e[h];if(null==k)return a=jf.n(this,a,h,of.ia(a,b+5,c,d,e,f)),a.g+=1,a;b=k.ia(a,b+5,c,d,e,f);return b===k?this:jf.n(this,a,h,b)};g.ha=function(a,b,c,d,e){var f=b>>>a&31,h=this.e[f];if(null==h)return new pf(null,this.g+1,gf.c(this.e,f,of.ha(a+5,b,c,d,e)));a=h.ha(a+5,b,c,d,e);return a===h?this:new pf(null,this.g,gf.c(this.e,f,a))};
g.fb=function(a,b,c){var d=b>>>a&31,e=this.e[d];return null!=e?(a=e.fb(a+5,b,c),a===e?this:null==a?8>=this.g?rf(this,null,d):new pf(null,this.g-1,gf.c(this.e,d,a)):u?new pf(null,this.g,gf.c(this.e,d,a)):null):this};function tf(a,b,c){b*=2;for(var d=0;;)if(d<b){if(ff(c,a[d]))return d;d+=2}else return-1}function uf(a,b,c,d){this.t=a;this.ra=b;this.g=c;this.e=d}g=uf.prototype;
g.La=function(a){if(a===this.t)return this;var b=Array(2*(this.g+1));Kc(this.e,0,b,0,2*this.g);return new uf(a,this.ra,this.g,b)};g.gb=function(a,b,c,d,e){b=tf(this.e,this.g,d);if(-1===b)return this;e[0]=!0;if(1===this.g)return null;a=this.La(a);e=a.e;e[b]=e[2*this.g-2];e[b+1]=e[2*this.g-1];e[2*this.g-1]=null;e[2*this.g-2]=null;a.g-=1;return a};g.eb=function(){return nf.b?nf.b(this.e):nf.call(null,this.e)};g.Ta=function(a,b){return kf(this.e,a,b)};
g.Ma=function(a,b,c,d){a=tf(this.e,this.g,c);return 0>a?d:ff(c,this.e[a])?this.e[a+1]:u?d:null};
g.ia=function(a,b,c,d,e,f){if(c===this.ra){b=tf(this.e,this.g,d);if(-1===b){if(this.e.length>2*this.g)return a=jf.X(this,a,2*this.g,d,2*this.g+1,e),f.l=!0,a.g+=1,a;c=this.e.length;b=Array(c+2);Kc(this.e,0,b,0,c);b[c]=d;b[c+1]=e;f.l=!0;f=this.g+1;a===this.t?(this.e=b,this.g=f,a=this):a=new uf(this.t,this.ra,f,b);return a}return this.e[b+1]===e?this:jf.n(this,a,b+1,e)}return(new lf(a,1<<(this.ra>>>b&31),[null,this,null,null])).ia(a,b,c,d,e,f)};
g.ha=function(a,b,c,d,e){return b===this.ra?(a=tf(this.e,this.g,c),-1===a?(a=2*this.g,b=Array(a+2),Kc(this.e,0,b,0,a),b[a]=c,b[a+1]=d,e.l=!0,new uf(null,this.ra,this.g+1,b)):Wb.a(this.e[a],d)?this:new uf(null,this.ra,this.g,gf.c(this.e,a+1,d))):(new lf(null,1<<(this.ra>>>a&31),[null,this])).ha(a,b,c,d,e)};g.fb=function(a,b,c){a=tf(this.e,this.g,c);return-1===a?this:1===this.g?null:u?new uf(null,this.ra,this.g-1,hf(this.e,Yc(a))):null};
var qf=function(){function a(a,b,c,h,k,l,n){var q=Tb(c);if(q===k)return new uf(null,q,2,[c,h,l,n]);var t=new ef;return of.ia(a,b,q,c,h,t).ia(a,b,k,l,n,t)}function b(a,b,c,h,k,l){var n=Tb(b);if(n===h)return new uf(null,n,2,[b,c,k,l]);var q=new ef;return of.ha(a,n,b,c,q).ha(a,h,k,l,q)}var c=null,c=function(c,e,f,h,k,l,n){switch(arguments.length){case 6:return b.call(this,c,e,f,h,k,l);case 7:return a.call(this,c,e,f,h,k,l,n)}throw Error("Invalid arity: "+arguments.length);};c.X=b;c.ga=a;return c}();
function vf(a,b,c,d,e){this.j=a;this.ka=b;this.p=c;this.r=d;this.m=e;this.q=0;this.i=32374860}g=vf.prototype;g.toString=function(){return Lb(this)};g.D=function(){return this.j};g.B=function(){var a=this.m;return null!=a?a:this.m=a=cc(this)};g.v=function(a,b){return lc(this,b)};g.I=function(){return N(H,this.j)};g.N=function(a,b){return nc.a(b,this)};g.M=function(a,b,c){return nc.c(b,c,this)};g.Q=function(){return null==this.r?new W(null,2,5,X,[this.ka[this.p],this.ka[this.p+1]],null):F(this.r)};
g.S=function(){return null==this.r?nf.c?nf.c(this.ka,this.p+2,null):nf.call(null,this.ka,this.p+2,null):nf.c?nf.c(this.ka,this.p,I(this.r)):nf.call(null,this.ka,this.p,I(this.r))};g.H=function(){return this};g.F=function(a,b){return new vf(b,this.ka,this.p,this.r,this.m)};g.G=function(a,b){return M(b,this)};
var nf=function(){function a(a,b,c){if(null==c)for(c=a.length;;)if(b<c){if(null!=a[b])return new vf(null,a,b,null,null);var h=a[b+1];if(r(h)&&(h=h.eb(),r(h)))return new vf(null,a,b+2,h,null);b+=2}else return null;else return new vf(null,a,b,c,null)}function b(a){return c.c(a,0,null)}var c=null,c=function(c,e,f){switch(arguments.length){case 1:return b.call(this,c);case 3:return a.call(this,c,e,f)}throw Error("Invalid arity: "+arguments.length);};c.b=b;c.c=a;return c}();
function wf(a,b,c,d,e){this.j=a;this.ka=b;this.p=c;this.r=d;this.m=e;this.q=0;this.i=32374860}g=wf.prototype;g.toString=function(){return Lb(this)};g.D=function(){return this.j};g.B=function(){var a=this.m;return null!=a?a:this.m=a=cc(this)};g.v=function(a,b){return lc(this,b)};g.I=function(){return N(H,this.j)};g.N=function(a,b){return nc.a(b,this)};g.M=function(a,b,c){return nc.c(b,c,this)};g.Q=function(){return F(this.r)};
g.S=function(){return sf.n?sf.n(null,this.ka,this.p,I(this.r)):sf.call(null,null,this.ka,this.p,I(this.r))};g.H=function(){return this};g.F=function(a,b){return new wf(b,this.ka,this.p,this.r,this.m)};g.G=function(a,b){return M(b,this)};
var sf=function(){function a(a,b,c,h){if(null==h)for(h=b.length;;)if(c<h){var k=b[c];if(r(k)&&(k=k.eb(),r(k)))return new wf(a,b,c+1,k,null);c+=1}else return null;else return new wf(a,b,c,h,null)}function b(a){return c.n(null,a,0,null)}var c=null,c=function(c,e,f,h){switch(arguments.length){case 1:return b.call(this,c);case 4:return a.call(this,c,e,f,h)}throw Error("Invalid arity: "+arguments.length);};c.b=b;c.n=a;return c}();
function xf(a,b,c,d,e,f){this.j=a;this.g=b;this.root=c;this.T=d;this.Y=e;this.m=f;this.i=16123663;this.q=8196}g=xf.prototype;g.toString=function(){return Lb(this)};g.keys=function(){return Oe(Ve.b?Ve.b(this):Ve.call(null,this))};g.entries=function(){return Qe(E(this))};g.values=function(){return Oe(We.b?We.b(this):We.call(null,this))};g.has=function(a){return Oc(this,a)};g.get=function(a){return this.u(null,a)};
g.forEach=function(a){for(var b=E(this),c=null,d=0,e=0;;)if(e<d){var f=c.J(null,e),h=P.c(f,0,null),f=P.c(f,1,null);a.a?a.a(f,h):a.call(null,f,h);e+=1}else if(b=E(b))Ic(b)?(c=Hb(b),b=Ib(b),h=c,d=O(c),c=h):(c=F(b),h=P.c(c,0,null),f=P.c(c,1,null),a.a?a.a(f,h):a.call(null,f,h),b=I(b),c=null,d=0),e=0;else return null};g.u=function(a,b){return La.c(this,b,null)};g.C=function(a,b,c){return null==b?this.T?this.Y:c:null==this.root?c:u?this.root.Ma(0,Tb(b),b,c):null};
g.Za=function(a,b,c){a=this.T?b.c?b.c(c,null,this.Y):b.call(null,c,null,this.Y):c;return fc(a)?K.b?K.b(a):K.call(null,a):null!=this.root?this.root.Ta(b,a):u?a:null};g.D=function(){return this.j};g.L=function(){return this.g};g.B=function(){var a=this.m;return null!=a?a:this.m=a=dc(this)};g.v=function(a,b){return Me(this,b)};g.Wa=function(){return new yf({},this.root,this.g,this.T,this.Y)};g.I=function(){return eb($e,this.j)};
g.nb=function(a,b){if(null==b)return this.T?new xf(this.j,this.g-1,this.root,!1,null,null):this;if(null==this.root)return this;if(u){var c=this.root.fb(0,Tb(b),b);return c===this.root?this:new xf(this.j,this.g-1,c,this.T,this.Y,null)}return null};
g.ua=function(a,b,c){if(null==b)return this.T&&c===this.Y?this:new xf(this.j,this.T?this.g:this.g+1,this.root,!0,c,null);a=new ef;b=(null==this.root?of:this.root).ha(0,Tb(b),b,c,a);return b===this.root?this:new xf(this.j,a.l?this.g+1:this.g,b,this.T,this.Y,null)};g.kb=function(a,b){return null==b?this.T:null==this.root?!1:u?this.root.Ma(0,Tb(b),b,Lc)!==Lc:null};g.H=function(){if(0<this.g){var a=null!=this.root?this.root.eb():null;return this.T?M(new W(null,2,5,X,[null,this.Y],null),a):a}return null};
g.F=function(a,b){return new xf(b,this.g,this.root,this.T,this.Y,this.m)};g.G=function(a,b){if(Hc(b))return Oa(this,D.a(b,0),D.a(b,1));for(var c=this,d=E(b);;){if(null==d)return c;var e=F(d);if(Hc(e))c=Oa(c,D.a(e,0),D.a(e,1)),d=I(d);else throw Error("conj on a map takes map entries or seqables of map entries");}};
g.call=function(){var a=null;return a=function(a,c,d){switch(arguments.length){case 2:return this.u(null,c);case 3:return this.C(null,c,d)}throw Error("Invalid arity: "+arguments.length);}}();g.apply=function(a,b){return this.call.apply(this,[this].concat(va(b)))};g.b=function(a){return this.u(null,a)};g.a=function(a,b){return this.C(null,a,b)};var $e=new xf(null,0,null,!1,null,0);function sc(a,b){for(var c=a.length,d=0,e=yb($e);;)if(d<c)var f=d+1,e=e.cb(null,a[d],b[d]),d=f;else return Ab(e)}
function yf(a,b,c,d,e){this.t=a;this.root=b;this.count=c;this.T=d;this.Y=e;this.q=56;this.i=258}g=yf.prototype;g.Ab=function(a,b){if(this.t)if(null==b)this.T&&(this.T=!1,this.Y=null,this.count-=1);else{if(null!=this.root){var c=new ef,d=this.root.gb(this.t,0,Tb(b),b,c);d!==this.root&&(this.root=d);r(c[0])&&(this.count-=1)}}else throw Error("dissoc! after persistent!");return this};g.cb=function(a,b,c){return zf(this,b,c)};
g.Ka=function(a,b){var c;a:{if(this.t){if(b?b.i&2048||b.dc||(b.i?0:s(Sa,b)):s(Sa,b)){c=zf(this,cf.b?cf.b(b):cf.call(null,b),df.b?df.b(b):df.call(null,b));break a}c=E(b);for(var d=this;;){var e=F(c);if(r(e))c=I(c),d=zf(d,cf.b?cf.b(e):cf.call(null,e),df.b?df.b(e):df.call(null,e));else{c=d;break a}}}else throw Error("conj! after persistent");c=void 0}return c};
g.Oa=function(){var a;if(this.t)this.t=null,a=new xf(null,this.count,this.root,this.T,this.Y,null);else throw Error("persistent! called twice");return a};g.u=function(a,b){return null==b?this.T?this.Y:null:null==this.root?null:this.root.Ma(0,Tb(b),b)};g.C=function(a,b,c){return null==b?this.T?this.Y:c:null==this.root?c:this.root.Ma(0,Tb(b),b,c)};g.L=function(){if(this.t)return this.count;throw Error("count after persistent!");};
function zf(a,b,c){if(a.t){if(null==b)a.Y!==c&&(a.Y=c),a.T||(a.count+=1,a.T=!0);else{var d=new ef;b=(null==a.root?of:a.root).ia(a.t,0,Tb(b),b,c,d);b!==a.root&&(a.root=b);d.l&&(a.count+=1)}return a}throw Error("assoc! after persistent!");}function Af(a,b,c){for(var d=b;;)if(null!=a)b=c?a.left:a.right,d=pc.a(d,a),a=b;else return d}function Bf(a,b,c,d,e){this.j=a;this.stack=b;this.ib=c;this.g=d;this.m=e;this.q=0;this.i=32374862}g=Bf.prototype;g.toString=function(){return Lb(this)};g.D=function(){return this.j};
g.L=function(){return 0>this.g?O(I(this))+1:this.g};g.B=function(){var a=this.m;return null!=a?a:this.m=a=cc(this)};g.v=function(a,b){return lc(this,b)};g.I=function(){return N(H,this.j)};g.N=function(a,b){return nc.a(b,this)};g.M=function(a,b,c){return nc.c(b,c,this)};g.Q=function(){return yc(this.stack)};g.S=function(){var a=F(this.stack),a=Af(this.ib?a.right:a.left,I(this.stack),this.ib);return null!=a?new Bf(null,a,this.ib,this.g-1,null):H};g.H=function(){return this};
g.F=function(a,b){return new Bf(b,this.stack,this.ib,this.g,this.m)};g.G=function(a,b){return M(b,this)};function Cf(a,b,c){return new Bf(null,Af(a,null,b),b,c,null)}function Df(a,b,c,d){return c instanceof Y?c.left instanceof Y?new Y(c.key,c.l,c.left.qa(),new $(a,b,c.right,d,null),null):c.right instanceof Y?new Y(c.right.key,c.right.l,new $(c.key,c.l,c.left,c.right.left,null),new $(a,b,c.right.right,d,null),null):u?new $(a,b,c,d,null):null:new $(a,b,c,d,null)}
function Ef(a,b,c,d){return d instanceof Y?d.right instanceof Y?new Y(d.key,d.l,new $(a,b,c,d.left,null),d.right.qa(),null):d.left instanceof Y?new Y(d.left.key,d.left.l,new $(a,b,c,d.left.left,null),new $(d.key,d.l,d.left.right,d.right,null),null):u?new $(a,b,c,d,null):null:new $(a,b,c,d,null)}
function Ff(a,b,c,d){if(c instanceof Y)return new Y(a,b,c.qa(),d,null);if(d instanceof $)return Ef(a,b,c,d.hb());if(d instanceof Y&&d.left instanceof $)return new Y(d.left.key,d.left.l,new $(a,b,c,d.left.left,null),Ef(d.key,d.l,d.left.right,d.right.hb()),null);if(u)throw Error("red-black tree invariant violation");return null}
var Hf=function Gf(b,c,d){d=null!=b.left?Gf(b.left,c,d):d;if(fc(d))return K.b?K.b(d):K.call(null,d);d=c.c?c.c(d,b.key,b.l):c.call(null,d,b.key,b.l);if(fc(d))return K.b?K.b(d):K.call(null,d);b=null!=b.right?Gf(b.right,c,d):d;return fc(b)?K.b?K.b(b):K.call(null,b):b};function $(a,b,c,d,e){this.key=a;this.l=b;this.left=c;this.right=d;this.m=e;this.q=0;this.i=32402207}g=$.prototype;g.Hb=function(a){return a.Jb(this)};g.hb=function(){return new Y(this.key,this.l,this.left,this.right,null)};g.qa=function(){return this};
g.Gb=function(a){return a.Ib(this)};g.replace=function(a,b,c,d){return new $(a,b,c,d,null)};g.Ib=function(a){return new $(a.key,a.l,this,a.right,null)};g.Jb=function(a){return new $(a.key,a.l,a.left,this,null)};g.Ta=function(a,b){return Hf(this,a,b)};g.u=function(a,b){return D.c(this,b,null)};g.C=function(a,b,c){return D.c(this,b,c)};g.J=function(a,b){return 0===b?this.key:1===b?this.l:null};g.aa=function(a,b,c){return 0===b?this.key:1===b?this.l:u?c:null};
g.Pa=function(a,b,c){return(new W(null,2,5,X,[this.key,this.l],null)).Pa(null,b,c)};g.D=function(){return null};g.L=function(){return 2};g.$a=function(){return this.key};g.ab=function(){return this.l};g.Ia=function(){return this.l};g.Ja=function(){return new W(null,1,5,X,[this.key],null)};g.B=function(){var a=this.m;return null!=a?a:this.m=a=cc(this)};g.v=function(a,b){return lc(this,b)};g.I=function(){return qe};g.N=function(a,b){return gc.a(this,b)};g.M=function(a,b,c){return gc.c(this,b,c)};
g.ua=function(a,b,c){return R.c(new W(null,2,5,X,[this.key,this.l],null),b,c)};g.H=function(){return Da(Da(H,this.l),this.key)};g.F=function(a,b){return N(new W(null,2,5,X,[this.key,this.l],null),b)};g.G=function(a,b){return new W(null,3,5,X,[this.key,this.l,b],null)};g.call=function(){var a=null;return a=function(a,c,d){switch(arguments.length){case 2:return this.u(null,c);case 3:return this.C(null,c,d)}throw Error("Invalid arity: "+arguments.length);}}();
g.apply=function(a,b){return this.call.apply(this,[this].concat(va(b)))};g.b=function(a){return this.u(null,a)};g.a=function(a,b){return this.C(null,a,b)};function Y(a,b,c,d,e){this.key=a;this.l=b;this.left=c;this.right=d;this.m=e;this.q=0;this.i=32402207}g=Y.prototype;g.Hb=function(a){return new Y(this.key,this.l,this.left,a,null)};g.hb=function(){throw Error("red-black tree invariant violation");};g.qa=function(){return new $(this.key,this.l,this.left,this.right,null)};
g.Gb=function(a){return new Y(this.key,this.l,a,this.right,null)};g.replace=function(a,b,c,d){return new Y(a,b,c,d,null)};g.Ib=function(a){return this.left instanceof Y?new Y(this.key,this.l,this.left.qa(),new $(a.key,a.l,this.right,a.right,null),null):this.right instanceof Y?new Y(this.right.key,this.right.l,new $(this.key,this.l,this.left,this.right.left,null),new $(a.key,a.l,this.right.right,a.right,null),null):u?new $(a.key,a.l,this,a.right,null):null};
g.Jb=function(a){return this.right instanceof Y?new Y(this.key,this.l,new $(a.key,a.l,a.left,this.left,null),this.right.qa(),null):this.left instanceof Y?new Y(this.left.key,this.left.l,new $(a.key,a.l,a.left,this.left.left,null),new $(this.key,this.l,this.left.right,this.right,null),null):u?new $(a.key,a.l,a.left,this,null):null};g.Ta=function(a,b){return Hf(this,a,b)};g.u=function(a,b){return D.c(this,b,null)};g.C=function(a,b,c){return D.c(this,b,c)};
g.J=function(a,b){return 0===b?this.key:1===b?this.l:null};g.aa=function(a,b,c){return 0===b?this.key:1===b?this.l:u?c:null};g.Pa=function(a,b,c){return(new W(null,2,5,X,[this.key,this.l],null)).Pa(null,b,c)};g.D=function(){return null};g.L=function(){return 2};g.$a=function(){return this.key};g.ab=function(){return this.l};g.Ia=function(){return this.l};g.Ja=function(){return new W(null,1,5,X,[this.key],null)};g.B=function(){var a=this.m;return null!=a?a:this.m=a=cc(this)};
g.v=function(a,b){return lc(this,b)};g.I=function(){return qe};g.N=function(a,b){return gc.a(this,b)};g.M=function(a,b,c){return gc.c(this,b,c)};g.ua=function(a,b,c){return R.c(new W(null,2,5,X,[this.key,this.l],null),b,c)};g.H=function(){return Da(Da(H,this.l),this.key)};g.F=function(a,b){return N(new W(null,2,5,X,[this.key,this.l],null),b)};g.G=function(a,b){return new W(null,3,5,X,[this.key,this.l,b],null)};
g.call=function(){var a=null;return a=function(a,c,d){switch(arguments.length){case 2:return this.u(null,c);case 3:return this.C(null,c,d)}throw Error("Invalid arity: "+arguments.length);}}();g.apply=function(a,b){return this.call.apply(this,[this].concat(va(b)))};g.b=function(a){return this.u(null,a)};g.a=function(a,b){return this.C(null,a,b)};
var Jf=function If(b,c,d,e,f){if(null==c)return new Y(d,e,null,null,null);var h=b.a?b.a(d,c.key):b.call(null,d,c.key);return 0===h?(f[0]=c,null):0>h?(b=If(b,c.left,d,e,f),null!=b?c.Gb(b):null):u?(b=If(b,c.right,d,e,f),null!=b?c.Hb(b):null):null},Lf=function Kf(b,c){if(null==b)return c;if(null==c)return b;if(b instanceof Y){if(c instanceof Y){var d=Kf(b.right,c.left);return d instanceof Y?new Y(d.key,d.l,new Y(b.key,b.l,b.left,d.left,null),new Y(c.key,c.l,d.right,c.right,null),null):new Y(b.key,b.l,
b.left,new Y(c.key,c.l,d,c.right,null),null)}return new Y(b.key,b.l,b.left,Kf(b.right,c),null)}return c instanceof Y?new Y(c.key,c.l,Kf(b,c.left),c.right,null):u?(d=Kf(b.right,c.left),d instanceof Y?new Y(d.key,d.l,new $(b.key,b.l,b.left,d.left,null),new $(c.key,c.l,d.right,c.right,null),null):Ff(b.key,b.l,b.left,new $(c.key,c.l,d,c.right,null))):null},Nf=function Mf(b,c,d,e){if(null!=c){var f=b.a?b.a(d,c.key):b.call(null,d,c.key);if(0===f)return e[0]=c,Lf(c.left,c.right);if(0>f)return b=Mf(b,c.left,
d,e),null!=b||null!=e[0]?c.left instanceof $?Ff(c.key,c.l,b,c.right):new Y(c.key,c.l,b,c.right,null):null;if(u){b=Mf(b,c.right,d,e);if(null!=b||null!=e[0])if(c.right instanceof $)if(e=c.key,d=c.l,c=c.left,b instanceof Y)c=new Y(e,d,c,b.qa(),null);else if(c instanceof $)c=Df(e,d,c.hb(),b);else if(c instanceof Y&&c.right instanceof $)c=new Y(c.right.key,c.right.l,Df(c.key,c.l,c.left.hb(),c.right.left),new $(e,d,c.right.right,b,null),null);else{if(u)throw Error("red-black tree invariant violation");
c=null}else c=new Y(c.key,c.l,c.left,b,null);else c=null;return c}}return null},Pf=function Of(b,c,d,e){var f=c.key,h=b.a?b.a(d,f):b.call(null,d,f);return 0===h?c.replace(f,e,c.left,c.right):0>h?c.replace(f,c.l,Of(b,c.left,d,e),c.right):u?c.replace(f,c.l,c.left,Of(b,c.right,d,e)):null};function Qf(a,b,c,d,e){this.Z=a;this.ma=b;this.g=c;this.j=d;this.m=e;this.i=418776847;this.q=8192}g=Qf.prototype;g.toString=function(){return Lb(this)};g.keys=function(){return Oe(Ve.b?Ve.b(this):Ve.call(null,this))};
g.entries=function(){return Qe(E(this))};g.values=function(){return Oe(We.b?We.b(this):We.call(null,this))};g.has=function(a){return Oc(this,a)};g.get=function(a){return this.u(null,a)};g.forEach=function(a){for(var b=E(this),c=null,d=0,e=0;;)if(e<d){var f=c.J(null,e),h=P.c(f,0,null),f=P.c(f,1,null);a.a?a.a(f,h):a.call(null,f,h);e+=1}else if(b=E(b))Ic(b)?(c=Hb(b),b=Ib(b),h=c,d=O(c),c=h):(c=F(b),h=P.c(c,0,null),f=P.c(c,1,null),a.a?a.a(f,h):a.call(null,f,h),b=I(b),c=null,d=0),e=0;else return null};
function Rf(a,b){for(var c=a.ma;;)if(null!=c){var d=a.Z.a?a.Z.a(b,c.key):a.Z.call(null,b,c.key);if(0===d)return c;if(0>d)c=c.left;else if(u)c=c.right;else return null}else return null}g.u=function(a,b){return La.c(this,b,null)};g.C=function(a,b,c){a=Rf(this,b);return null!=a?a.l:c};g.Za=function(a,b,c){return null!=this.ma?Hf(this.ma,b,c):c};g.D=function(){return this.j};g.L=function(){return this.g};g.Xa=function(){return 0<this.g?Cf(this.ma,!1,this.g):null};
g.B=function(){var a=this.m;return null!=a?a:this.m=a=dc(this)};g.v=function(a,b){return Me(this,b)};g.I=function(){return N(Sf,this.j)};g.nb=function(a,b){var c=[null],d=Nf(this.Z,this.ma,b,c);return null==d?null==P.a(c,0)?this:new Qf(this.Z,null,0,this.j,null):new Qf(this.Z,d.qa(),this.g-1,this.j,null)};
g.ua=function(a,b,c){a=[null];var d=Jf(this.Z,this.ma,b,c,a);return null==d?(a=P.a(a,0),Wb.a(c,a.l)?this:new Qf(this.Z,Pf(this.Z,this.ma,b,c),this.g,this.j,null)):new Qf(this.Z,d.qa(),this.g+1,this.j,null)};g.kb=function(a,b){return null!=Rf(this,b)};g.H=function(){return 0<this.g?Cf(this.ma,!0,this.g):null};g.F=function(a,b){return new Qf(this.Z,this.ma,this.g,b,this.m)};
g.G=function(a,b){if(Hc(b))return Oa(this,D.a(b,0),D.a(b,1));for(var c=this,d=E(b);;){if(null==d)return c;var e=F(d);if(Hc(e))c=Oa(c,D.a(e,0),D.a(e,1)),d=I(d);else throw Error("conj on a map takes map entries or seqables of map entries");}};g.call=function(){var a=null;return a=function(a,c,d){switch(arguments.length){case 2:return this.u(null,c);case 3:return this.C(null,c,d)}throw Error("Invalid arity: "+arguments.length);}}();g.apply=function(a,b){return this.call.apply(this,[this].concat(va(b)))};
g.b=function(a){return this.u(null,a)};g.a=function(a,b){return this.C(null,a,b)};g.yb=function(a,b){return 0<this.g?Cf(this.ma,b,this.g):null};g.zb=function(a,b,c){if(0<this.g){a=null;for(var d=this.ma;;)if(null!=d){var e=this.Z.a?this.Z.a(b,d.key):this.Z.call(null,b,d.key);if(0===e)return new Bf(null,pc.a(a,d),c,-1,null);if(r(c))0>e?(a=pc.a(a,d),d=d.left):d=d.right;else if(u)0<e?(a=pc.a(a,d),d=d.right):d=d.left;else return null}else return null==a?null:new Bf(null,a,c,-1,null)}else return null};
g.xb=function(a,b){return cf.b?cf.b(b):cf.call(null,b)};g.wb=function(){return this.Z};
var Sf=new Qf(Xb,null,0,null,0),Tf=function(){function a(a){var d=null;0<arguments.length&&(d=J(Array.prototype.slice.call(arguments,0),0));return b.call(this,d)}function b(a){a=E(a);for(var b=yb($e);;)if(a){var e=I(I(a)),b=xd.c(b,F(a),F(I(a)));a=e}else return Ab(b)}a.k=0;a.f=function(a){a=E(a);return b(a)};a.d=b;return a}(),Uf=function(){function a(a){var d=null;0<arguments.length&&(d=J(Array.prototype.slice.call(arguments,0),0));return b.call(this,d)}function b(a){return new la(null,Yc(O(a)),S.a(wa,
a),null)}a.k=0;a.f=function(a){a=E(a);return b(a)};a.d=b;return a}(),Vf=function(){function a(a){var d=null;0<arguments.length&&(d=J(Array.prototype.slice.call(arguments,0),0));return b.call(this,d)}function b(a){a=E(a);for(var b=Sf;;)if(a){var e=I(I(a)),b=R.c(b,F(a),F(I(a)));a=e}else return b}a.k=0;a.f=function(a){a=E(a);return b(a)};a.d=b;return a}(),Wf=function(){function a(a,d){var e=null;1<arguments.length&&(e=J(Array.prototype.slice.call(arguments,1),0));return b.call(this,a,e)}function b(a,
b){for(var e=E(b),f=new Qf(Qc(a),null,0,null,0);;)if(e)var h=I(I(e)),f=R.c(f,F(e),F(I(e))),e=h;else return f}a.k=1;a.f=function(a){var d=F(a);a=G(a);return b(d,a)};a.d=b;return a}();function Xf(a,b){this.V=a;this.W=b;this.q=0;this.i=32374988}g=Xf.prototype;g.toString=function(){return Lb(this)};g.D=function(){return this.W};g.U=function(){var a=this.V,a=(a?a.i&128||a.ob||(a.i?0:s(Ja,a)):s(Ja,a))?this.V.U(null):I(this.V);return null==a?null:new Xf(a,this.W)};g.B=function(){return cc(this)};
g.v=function(a,b){return lc(this,b)};g.I=function(){return N(H,this.W)};g.N=function(a,b){return nc.a(b,this)};g.M=function(a,b,c){return nc.c(b,c,this)};g.Q=function(){return this.V.Q(null).$a(null)};g.S=function(){var a=this.V,a=(a?a.i&128||a.ob||(a.i?0:s(Ja,a)):s(Ja,a))?this.V.U(null):I(this.V);return null!=a?new Xf(a,this.W):H};g.H=function(){return this};g.F=function(a,b){return new Xf(this.V,b)};g.G=function(a,b){return M(b,this)};function Ve(a){return(a=E(a))?new Xf(a,null):null}
function cf(a){return Ta(a)}function Yf(a,b){this.V=a;this.W=b;this.q=0;this.i=32374988}g=Yf.prototype;g.toString=function(){return Lb(this)};g.D=function(){return this.W};g.U=function(){var a=this.V,a=(a?a.i&128||a.ob||(a.i?0:s(Ja,a)):s(Ja,a))?this.V.U(null):I(this.V);return null==a?null:new Yf(a,this.W)};g.B=function(){return cc(this)};g.v=function(a,b){return lc(this,b)};g.I=function(){return N(H,this.W)};g.N=function(a,b){return nc.a(b,this)};g.M=function(a,b,c){return nc.c(b,c,this)};g.Q=function(){return this.V.Q(null).ab(null)};
g.S=function(){var a=this.V,a=(a?a.i&128||a.ob||(a.i?0:s(Ja,a)):s(Ja,a))?this.V.U(null):I(this.V);return null!=a?new Yf(a,this.W):H};g.H=function(){return this};g.F=function(a,b){return new Yf(this.V,b)};g.G=function(a,b){return M(b,this)};function We(a){return(a=E(a))?new Yf(a,null):null}function df(a){return Ua(a)}
var Zf=function(){function a(a){var d=null;0<arguments.length&&(d=J(Array.prototype.slice.call(arguments,0),0));return b.call(this,d)}function b(a){return r(Ed(Fd,a))?C.a(function(a,b){return pc.a(r(a)?a:Ye,b)},a):null}a.k=0;a.f=function(a){a=E(a);return b(a)};a.d=b;return a}();function $f(a,b,c){this.j=a;this.Sa=b;this.m=c;this.i=15077647;this.q=8196}g=$f.prototype;g.toString=function(){return Lb(this)};g.keys=function(){return Oe(E(this))};g.entries=function(){return Se(E(this))};g.values=function(){return Oe(E(this))};
g.has=function(a){return Oc(this,a)};g.forEach=function(a){for(var b=E(this),c=null,d=0,e=0;;)if(e<d){var f=c.J(null,e),h=P.c(f,0,null),f=P.c(f,1,null);a.a?a.a(f,h):a.call(null,f,h);e+=1}else if(b=E(b))Ic(b)?(c=Hb(b),b=Ib(b),h=c,d=O(c),c=h):(c=F(b),h=P.c(c,0,null),f=P.c(c,1,null),a.a?a.a(f,h):a.call(null,f,h),b=I(b),c=null,d=0),e=0;else return null};g.u=function(a,b){return La.c(this,b,null)};g.C=function(a,b,c){return Na(this.Sa,b)?b:c};g.D=function(){return this.j};g.L=function(){return Aa(this.Sa)};
g.B=function(){var a=this.m;return null!=a?a:this.m=a=dc(this)};g.v=function(a,b){return Dc(b)&&O(this)===O(b)&&Dd(function(a){return function(b){return Oc(a,b)}}(this),b)};g.Wa=function(){return new ag(yb(this.Sa))};g.I=function(){return N(bg,this.j)};g.vb=function(a,b){return new $f(this.j,Qa(this.Sa,b),null)};g.H=function(){return Ve(this.Sa)};g.F=function(a,b){return new $f(b,this.Sa,this.m)};g.G=function(a,b){return new $f(this.j,R.c(this.Sa,b,null),null)};
g.call=function(){var a=null;return a=function(a,c,d){switch(arguments.length){case 2:return this.u(null,c);case 3:return this.C(null,c,d)}throw Error("Invalid arity: "+arguments.length);}}();g.apply=function(a,b){return this.call.apply(this,[this].concat(va(b)))};g.b=function(a){return this.u(null,a)};g.a=function(a,b){return this.C(null,a,b)};var bg=new $f(null,Ye,0);function ag(a){this.la=a;this.i=259;this.q=136}g=ag.prototype;
g.call=function(){var a=null;return a=function(a,c,d){switch(arguments.length){case 2:return La.c(this.la,c,Lc)===Lc?null:c;case 3:return La.c(this.la,c,Lc)===Lc?d:c}throw Error("Invalid arity: "+arguments.length);}}();g.apply=function(a,b){return this.call.apply(this,[this].concat(va(b)))};g.b=function(a){return La.c(this.la,a,Lc)===Lc?null:a};g.a=function(a,b){return La.c(this.la,a,Lc)===Lc?b:a};g.u=function(a,b){return La.c(this,b,null)};g.C=function(a,b,c){return La.c(this.la,b,Lc)===Lc?c:b};
g.L=function(){return O(this.la)};g.Ob=function(a,b){this.la=yd.a(this.la,b);return this};g.Ka=function(a,b){this.la=xd.c(this.la,b,null);return this};g.Oa=function(){return new $f(null,Ab(this.la),null)};function cg(a,b,c){this.j=a;this.na=b;this.m=c;this.i=417730831;this.q=8192}g=cg.prototype;g.toString=function(){return Lb(this)};g.keys=function(){return Oe(E(this))};g.entries=function(){return Se(E(this))};g.values=function(){return Oe(E(this))};g.has=function(a){return Oc(this,a)};
g.forEach=function(a){for(var b=E(this),c=null,d=0,e=0;;)if(e<d){var f=c.J(null,e),h=P.c(f,0,null),f=P.c(f,1,null);a.a?a.a(f,h):a.call(null,f,h);e+=1}else if(b=E(b))Ic(b)?(c=Hb(b),b=Ib(b),h=c,d=O(c),c=h):(c=F(b),h=P.c(c,0,null),f=P.c(c,1,null),a.a?a.a(f,h):a.call(null,f,h),b=I(b),c=null,d=0),e=0;else return null};g.u=function(a,b){return La.c(this,b,null)};g.C=function(a,b,c){a=Rf(this.na,b);return null!=a?a.key:c};g.D=function(){return this.j};g.L=function(){return O(this.na)};
g.Xa=function(){return 0<O(this.na)?Kd.a(cf,pb(this.na)):null};g.B=function(){var a=this.m;return null!=a?a:this.m=a=dc(this)};g.v=function(a,b){return Dc(b)&&O(this)===O(b)&&Dd(function(a){return function(b){return Oc(a,b)}}(this),b)};g.I=function(){return N(dg,this.j)};g.vb=function(a,b){return new cg(this.j,tc.a(this.na,b),null)};g.H=function(){return Ve(this.na)};g.F=function(a,b){return new cg(b,this.na,this.m)};g.G=function(a,b){return new cg(this.j,R.c(this.na,b,null),null)};
g.call=function(){var a=null;return a=function(a,c,d){switch(arguments.length){case 2:return this.u(null,c);case 3:return this.C(null,c,d)}throw Error("Invalid arity: "+arguments.length);}}();g.apply=function(a,b){return this.call.apply(this,[this].concat(va(b)))};g.b=function(a){return this.u(null,a)};g.a=function(a,b){return this.C(null,a,b)};g.yb=function(a,b){return Kd.a(cf,qb(this.na,b))};g.zb=function(a,b,c){return Kd.a(cf,rb(this.na,b,c))};g.xb=function(a,b){return b};g.wb=function(){return tb(this.na)};
var dg=new cg(null,Sf,0);function eg(a){a=E(a);if(null==a)return bg;if(a instanceof ac&&0===a.p){a=a.e;a:{for(var b=0,c=yb(bg);;)if(b<a.length)var d=b+1,c=c.Ka(null,a[b]),b=d;else{a=c;break a}a=void 0}return a.Oa(null)}if(u)for(d=yb(bg);;)if(null!=a)b=a.U(null),d=d.Ka(null,a.Q(null)),a=b;else return d.Oa(null);else return null}
var fg=function(){function a(a){var d=null;0<arguments.length&&(d=J(Array.prototype.slice.call(arguments,0),0));return b.call(this,d)}function b(a){return C.c(Da,dg,a)}a.k=0;a.f=function(a){a=E(a);return b(a)};a.d=b;return a}(),gg=function(){function a(a,d){var e=null;1<arguments.length&&(e=J(Array.prototype.slice.call(arguments,1),0));return b.call(this,a,e)}function b(a,b){return C.c(Da,new cg(null,Wf(a),0),b)}a.k=1;a.f=function(a){var d=F(a);a=G(a);return b(d,a)};a.d=b;return a}();
function hg(a){for(var b=qe;;)if(I(a))b=pc.a(b,F(a)),a=I(a);else return E(b)}function id(a){if(a&&(a.q&4096||a.fc))return a.name;if("string"===typeof a)return a;throw Error("Doesn't support name: "+A.b(a));}
var ig=function(){function a(a,b,c){return(a.b?a.b(b):a.call(null,b))>(a.b?a.b(c):a.call(null,c))?b:c}var b=null,c=function(){function a(b,d,k,l){var n=null;3<arguments.length&&(n=J(Array.prototype.slice.call(arguments,3),0));return c.call(this,b,d,k,n)}function c(a,d,e,l){return C.c(function(c,d){return b.c(a,c,d)},b.c(a,d,e),l)}a.k=3;a.f=function(a){var b=F(a);a=I(a);var d=F(a);a=I(a);var l=F(a);a=G(a);return c(b,d,l,a)};a.d=c;return a}(),b=function(b,e,f,h){switch(arguments.length){case 2:return e;
case 3:return a.call(this,b,e,f);default:return c.d(b,e,f,J(arguments,3))}throw Error("Invalid arity: "+arguments.length);};b.k=3;b.f=c.f;b.a=function(a,b){return b};b.c=a;b.d=c.d;return b}(),jg=function(){function a(a,b,f){return new V(null,function(){var h=E(f);return h?M(Md(a,h),c.c(a,b,Nd(b,h))):null},null,null)}function b(a,b){return c.c(a,a,b)}var c=null,c=function(c,e,f){switch(arguments.length){case 2:return b.call(this,c,e);case 3:return a.call(this,c,e,f)}throw Error("Invalid arity: "+arguments.length);
};c.a=b;c.c=a;return c}(),lg=function kg(b,c){return new V(null,function(){var d=E(c);return d?r(b.b?b.b(F(d)):b.call(null,F(d)))?M(F(d),kg(b,G(d))):null:null},null,null)};function mg(a,b,c){return function(d){var e=tb(a);return b.a?b.a(e.a?e.a(sb(a,d),c):e.call(null,sb(a,d),c),0):b.call(null,e.a?e.a(sb(a,d),c):e.call(null,sb(a,d),c),0)}}
var ng=function(){function a(a,b,c,h,k){var l=rb(a,c,!0);if(r(l)){var n=P.c(l,0,null);return lg(mg(a,h,k),r(mg(a,b,c).call(null,n))?l:I(l))}return null}function b(a,b,c){var h=mg(a,b,c),k;a:{k=[Uc,Vc];var l=k.length;if(l<=Ze)for(var n=0,q=yb(Ye);;)if(n<l)var t=n+1,q=Bb(q,k[n],null),n=t;else{k=new $f(null,Ab(q),null);break a}else for(n=0,q=yb(bg);;)if(n<l)t=n+1,q=zb(q,k[n]),n=t;else{k=Ab(q);break a}k=void 0}return r(k.call(null,b))?(a=rb(a,c,!0),r(a)?(b=P.c(a,0,null),r(h.b?h.b(b):h.call(null,b))?a:
I(a)):null):lg(h,qb(a,!0))}var c=null,c=function(c,e,f,h,k){switch(arguments.length){case 3:return b.call(this,c,e,f);case 5:return a.call(this,c,e,f,h,k)}throw Error("Invalid arity: "+arguments.length);};c.c=b;c.s=a;return c}();function og(a,b,c,d,e){this.j=a;this.start=b;this.end=c;this.step=d;this.m=e;this.i=32375006;this.q=8192}g=og.prototype;g.toString=function(){return Lb(this)};
g.J=function(a,b){if(b<Aa(this))return this.start+b*this.step;if(this.start>this.end&&0===this.step)return this.start;throw Error("Index out of bounds");};g.aa=function(a,b,c){return b<Aa(this)?this.start+b*this.step:this.start>this.end&&0===this.step?this.start:c};g.D=function(){return this.j};
g.U=function(){return 0<this.step?this.start+this.step<this.end?new og(this.j,this.start+this.step,this.end,this.step,null):null:this.start+this.step>this.end?new og(this.j,this.start+this.step,this.end,this.step,null):null};g.L=function(){return sa(lb(this))?0:Math.ceil((this.end-this.start)/this.step)};g.B=function(){var a=this.m;return null!=a?a:this.m=a=cc(this)};g.v=function(a,b){return lc(this,b)};g.I=function(){return N(H,this.j)};g.N=function(a,b){return gc.a(this,b)};
g.M=function(a,b,c){return gc.c(this,b,c)};g.Q=function(){return null==lb(this)?null:this.start};g.S=function(){return null!=lb(this)?new og(this.j,this.start+this.step,this.end,this.step,null):H};g.H=function(){return 0<this.step?this.start<this.end?this:null:this.start>this.end?this:null};g.F=function(a,b){return new og(b,this.start,this.end,this.step,this.m)};g.G=function(a,b){return M(b,this)};
var pg=function(){function a(a,b,c){return new og(null,a,b,c,null)}function b(a,b){return e.c(a,b,1)}function c(a){return e.c(0,a,1)}function d(){return e.c(0,Number.MAX_VALUE,1)}var e=null,e=function(e,h,k){switch(arguments.length){case 0:return d.call(this);case 1:return c.call(this,e);case 2:return b.call(this,e,h);case 3:return a.call(this,e,h,k)}throw Error("Invalid arity: "+arguments.length);};e.o=d;e.b=c;e.a=b;e.c=a;return e}(),qg=function(){function a(a,b){for(;;)if(E(b)&&0<a){var c=a-1,h=
I(b);a=c;b=h}else return null}function b(a){for(;;)if(E(a))a=I(a);else return null}var c=null,c=function(c,e){switch(arguments.length){case 1:return b.call(this,c);case 2:return a.call(this,c,e)}throw Error("Invalid arity: "+arguments.length);};c.b=b;c.a=a;return c}(),rg=function(){function a(a,b){qg.a(a,b);return b}function b(a){qg.b(a);return a}var c=null,c=function(c,e){switch(arguments.length){case 1:return b.call(this,c);case 2:return a.call(this,c,e)}throw Error("Invalid arity: "+arguments.length);
};c.b=b;c.a=a;return c}();function sg(a,b){if("string"===typeof b){var c=a.exec(b);return Wb.a(F(c),b)?1===O(c)?F(c):we(c):null}throw new TypeError("re-matches must match against a string.");}function tg(a){var b;b=/^(?:\(\?([idmsux]*)\))?(.*)/;if("string"===typeof a)a=b.exec(a),b=null==a?null:1===O(a)?F(a):we(a);else throw new TypeError("re-find must match against a string.");P.c(b,0,null);a=P.c(b,1,null);b=P.c(b,2,null);return new RegExp(b,a)}
function ug(a,b,c,d,e,f,h){var k=ja;try{ja=null==ja?null:ja-1;if(null!=ja&&0>ja)return ub(a,"#");ub(a,c);E(h)&&(b.c?b.c(F(h),a,f):b.call(null,F(h),a,f));for(var l=I(h),n=ra.b(f)-1;;)if(!l||null!=n&&0===n){E(l)&&0===n&&(ub(a,d),ub(a,"..."));break}else{ub(a,d);b.c?b.c(F(l),a,f):b.call(null,F(l),a,f);var q=I(l);c=n-1;l=q;n=c}return ub(a,e)}finally{ja=k}}
var vg=function(){function a(a,d){var e=null;1<arguments.length&&(e=J(Array.prototype.slice.call(arguments,1),0));return b.call(this,a,e)}function b(a,b){for(var e=E(b),f=null,h=0,k=0;;)if(k<h){var l=f.J(null,k);ub(a,l);k+=1}else if(e=E(e))f=e,Ic(f)?(e=Hb(f),h=Ib(f),f=e,l=O(e),e=h,h=l):(l=F(f),ub(a,l),e=I(f),f=null,h=0),k=0;else return null}a.k=1;a.f=function(a){var d=F(a);a=G(a);return b(d,a)};a.d=b;return a}(),wg={'"':'\\"',"\\":"\\\\","\b":"\\b","\f":"\\f","\n":"\\n","\r":"\\r","\t":"\\t"};
function xg(a){return'"'+A.b(a.replace(RegExp('[\\\\"\b\f\n\r\t]',"g"),function(a){return wg[a]}))+'"'}
var Ag=function yg(b,c,d){if(null==b)return ub(c,"nil");if(void 0===b)return ub(c,"#\x3cundefined\x3e");if(u){r(function(){var c=Q.a(d,pa);return r(c)?(c=b?b.i&131072||b.ec?!0:b.i?!1:s(bb,b):s(bb,b))?xc(b):c:c}())&&(ub(c,"^"),yg(xc(b),c,d),ub(c," "));if(null==b)return ub(c,"nil");if(b.Db)return b.Tb(b,c,d);if(b&&(b.i&2147483648||b.K))return b.w(null,c,d);if(ta(b)===Boolean||"number"===typeof b)return ub(c,""+A.b(b));if(null!=b&&b.constructor===Object)return ub(c,"#js "),zg.n?zg.n(Kd.a(function(c){return new W(null,
2,5,X,[jd.b(c),b[c]],null)},Jc(b)),yg,c,d):zg.call(null,Kd.a(function(c){return new W(null,2,5,X,[jd.b(c),b[c]],null)},Jc(b)),yg,c,d);if(b instanceof Array)return ug(c,yg,"#js ["," ","]",d,b);if("string"==typeof b)return r(oa.b(d))?ub(c,xg(b)):ub(c,b);if(uc(b))return vg.d(c,J(["#\x3c",""+A.b(b),"\x3e"],0));if(b instanceof Date){var e=function(b,c){for(var d=""+A.b(b);;)if(O(d)<c)d="0"+A.b(d);else return d};return vg.d(c,J(['#inst "',""+A.b(b.getUTCFullYear()),"-",e(b.getUTCMonth()+1,2),"-",e(b.getUTCDate(),
2),"T",e(b.getUTCHours(),2),":",e(b.getUTCMinutes(),2),":",e(b.getUTCSeconds(),2),".",e(b.getUTCMilliseconds(),3),"-",'00:00"'],0))}return b instanceof RegExp?vg.d(c,J(['#"',b.source,'"'],0)):(b?b.i&2147483648||b.K||(b.i?0:s(vb,b)):s(vb,b))?wb(b,c,d):u?vg.d(c,J(["#\x3c",""+A.b(b),"\x3e"],0)):null}return null};
function Bg(a,b){var c=new ea;a:{var d=new Kb(c);Ag(F(a),d,b);for(var e=E(I(a)),f=null,h=0,k=0;;)if(k<h){var l=f.J(null,k);ub(d," ");Ag(l,d,b);k+=1}else if(e=E(e))f=e,Ic(f)?(e=Hb(f),h=Ib(f),f=e,l=O(e),e=h,h=l):(l=F(f),ub(d," "),Ag(l,d,b),e=I(f),f=null,h=0),k=0;else break a}return c}
var Cg=function(){function a(a){var d=null;0<arguments.length&&(d=J(Array.prototype.slice.call(arguments,0),0));return b.call(this,d)}function b(a){var b=ka();return Bc(a)?"":""+A.b(Bg(a,b))}a.k=0;a.f=function(a){a=E(a);return b(a)};a.d=b;return a}();function zg(a,b,c,d){return ug(c,function(a,c,d){b.c?b.c(Ta(a),c,d):b.call(null,Ta(a),c,d);ub(c," ");return b.c?b.c(Ua(a),c,d):b.call(null,Ua(a),c,d)},"{",", ","}",d,E(a))}ac.prototype.K=!0;
ac.prototype.w=function(a,b,c){return ug(b,Ag,"("," ",")",c,this)};V.prototype.K=!0;V.prototype.w=function(a,b,c){return ug(b,Ag,"("," ",")",c,this)};Bf.prototype.K=!0;Bf.prototype.w=function(a,b,c){return ug(b,Ag,"("," ",")",c,this)};vf.prototype.K=!0;vf.prototype.w=function(a,b,c){return ug(b,Ag,"("," ",")",c,this)};$.prototype.K=!0;$.prototype.w=function(a,b,c){return ug(b,Ag,"["," ","]",c,this)};Ue.prototype.K=!0;Ue.prototype.w=function(a,b,c){return ug(b,Ag,"("," ",")",c,this)};
cg.prototype.K=!0;cg.prototype.w=function(a,b,c){return ug(b,Ag,"#{"," ","}",c,this)};ye.prototype.K=!0;ye.prototype.w=function(a,b,c){return ug(b,Ag,"("," ",")",c,this)};gd.prototype.K=!0;gd.prototype.w=function(a,b,c){return ug(b,Ag,"("," ",")",c,this)};kc.prototype.K=!0;kc.prototype.w=function(a,b,c){return ug(b,Ag,"("," ",")",c,this)};xf.prototype.K=!0;xf.prototype.w=function(a,b,c){return zg(this,Ag,b,c)};wf.prototype.K=!0;wf.prototype.w=function(a,b,c){return ug(b,Ag,"("," ",")",c,this)};
Ae.prototype.K=!0;Ae.prototype.w=function(a,b,c){return ug(b,Ag,"["," ","]",c,this)};Qf.prototype.K=!0;Qf.prototype.w=function(a,b,c){return zg(this,Ag,b,c)};$f.prototype.K=!0;$f.prototype.w=function(a,b,c){return ug(b,Ag,"#{"," ","}",c,this)};od.prototype.K=!0;od.prototype.w=function(a,b,c){return ug(b,Ag,"("," ",")",c,this)};Yf.prototype.K=!0;Yf.prototype.w=function(a,b,c){return ug(b,Ag,"("," ",")",c,this)};Y.prototype.K=!0;Y.prototype.w=function(a,b,c){return ug(b,Ag,"["," ","]",c,this)};
W.prototype.K=!0;W.prototype.w=function(a,b,c){return ug(b,Ag,"["," ","]",c,this)};He.prototype.K=!0;He.prototype.w=function(a,b,c){return ug(b,Ag,"("," ",")",c,this)};cd.prototype.K=!0;cd.prototype.w=function(a,b){return ub(b,"()")};Ie.prototype.K=!0;Ie.prototype.w=function(a,b,c){return ug(b,Ag,"#queue ["," ","]",c,E(this))};la.prototype.K=!0;la.prototype.w=function(a,b,c){return zg(this,Ag,b,c)};og.prototype.K=!0;og.prototype.w=function(a,b,c){return ug(b,Ag,"("," ",")",c,this)};
Xf.prototype.K=!0;Xf.prototype.w=function(a,b,c){return ug(b,Ag,"("," ",")",c,this)};bd.prototype.K=!0;bd.prototype.w=function(a,b,c){return ug(b,Ag,"("," ",")",c,this)};W.prototype.lb=!0;W.prototype.mb=function(a,b){return Pc.a(this,b)};Ae.prototype.lb=!0;Ae.prototype.mb=function(a,b){return Pc.a(this,b)};T.prototype.lb=!0;T.prototype.mb=function(a,b){return Vb(this,b)};Zb.prototype.lb=!0;Zb.prototype.mb=function(a,b){return Vb(this,b)};
function Dg(a,b){if(a?a.gc:a)return a.gc(a,b);var c;c=Dg[m(null==a?null:a)];if(!c&&(c=Dg._,!c))throw x("IReset.-reset!",a);return c.call(null,a,b)}
var Eg=function(){function a(a,b,c,d,e){if(a?a.nc:a)return a.nc(a,b,c,d,e);var q;q=Eg[m(null==a?null:a)];if(!q&&(q=Eg._,!q))throw x("ISwap.-swap!",a);return q.call(null,a,b,c,d,e)}function b(a,b,c,d){if(a?a.mc:a)return a.mc(a,b,c,d);var e;e=Eg[m(null==a?null:a)];if(!e&&(e=Eg._,!e))throw x("ISwap.-swap!",a);return e.call(null,a,b,c,d)}function c(a,b,c){if(a?a.lc:a)return a.lc(a,b,c);var d;d=Eg[m(null==a?null:a)];if(!d&&(d=Eg._,!d))throw x("ISwap.-swap!",a);return d.call(null,a,b,c)}function d(a,b){if(a?
a.kc:a)return a.kc(a,b);var c;c=Eg[m(null==a?null:a)];if(!c&&(c=Eg._,!c))throw x("ISwap.-swap!",a);return c.call(null,a,b)}var e=null,e=function(e,h,k,l,n){switch(arguments.length){case 2:return d.call(this,e,h);case 3:return c.call(this,e,h,k);case 4:return b.call(this,e,h,k,l);case 5:return a.call(this,e,h,k,l,n)}throw Error("Invalid arity: "+arguments.length);};e.a=d;e.c=c;e.n=b;e.s=a;return e}();function Fg(a,b,c,d){this.state=a;this.j=b;this.wc=c;this.Wb=d;this.i=2153938944;this.q=16386}g=Fg.prototype;
g.B=function(){return this[ba]||(this[ba]=++ca)};g.Rb=function(a,b,c){a=E(this.Wb);for(var d=null,e=0,f=0;;)if(f<e){var h=d.J(null,f),k=P.c(h,0,null),h=P.c(h,1,null);h.n?h.n(k,this,b,c):h.call(null,k,this,b,c);f+=1}else if(a=E(a))Ic(a)?(d=Hb(a),a=Ib(a),k=d,e=O(d),d=k):(d=F(a),k=P.c(d,0,null),h=P.c(d,1,null),h.n?h.n(k,this,b,c):h.call(null,k,this,b,c),a=I(a),d=null,e=0),f=0;else return null};g.w=function(a,b,c){ub(b,"#\x3cAtom: ");Ag(this.state,b,c);return ub(b,"\x3e")};g.D=function(){return this.j};
g.ub=function(){return this.state};g.v=function(a,b){return this===b};
var Hg=function(){function a(a){return new Fg(a,null,null,null)}var b=null,c=function(){function a(c,d){var k=null;1<arguments.length&&(k=J(Array.prototype.slice.call(arguments,1),0));return b.call(this,c,k)}function b(a,c){var d=Mc(c)?S.a(Tf,c):c,e=Q.a(d,Gg),d=Q.a(d,pa);return new Fg(a,d,e,null)}a.k=1;a.f=function(a){var c=F(a);a=G(a);return b(c,a)};a.d=b;return a}(),b=function(b,e){switch(arguments.length){case 1:return a.call(this,b);default:return c.d(b,J(arguments,1))}throw Error("Invalid arity: "+
arguments.length);};b.k=1;b.f=c.f;b.b=a;b.d=c.d;return b}();function Ig(a,b){if(a instanceof Fg){var c=a.wc;if(null!=c&&!r(c.b?c.b(b):c.call(null,b)))throw Error("Assert failed: Validator rejected reference state\n"+A.b(Cg.d(J([fd(new Zb(null,"validate","validate",1439230700,null),new Zb(null,"new-value","new-value",-1567397401,null))],0))));c=a.state;a.state=b;null!=a.Wb&&xb(a,c,b);return b}return Dg(a,b)}function K(a){return ab(a)}
var Jg=function(){function a(a,b,c,d){return a instanceof Fg?Ig(a,b.c?b.c(a.state,c,d):b.call(null,a.state,c,d)):Eg.n(a,b,c,d)}function b(a,b,c){return a instanceof Fg?Ig(a,b.a?b.a(a.state,c):b.call(null,a.state,c)):Eg.c(a,b,c)}function c(a,b){return a instanceof Fg?Ig(a,b.b?b.b(a.state):b.call(null,a.state)):Eg.a(a,b)}var d=null,e=function(){function a(c,d,e,f,t){var v=null;4<arguments.length&&(v=J(Array.prototype.slice.call(arguments,4),0));return b.call(this,c,d,e,f,v)}function b(a,c,d,e,f){return a instanceof
Fg?Ig(a,S.s(c,a.state,d,e,f)):Eg.s(a,c,d,e,f)}a.k=4;a.f=function(a){var c=F(a);a=I(a);var d=F(a);a=I(a);var e=F(a);a=I(a);var f=F(a);a=G(a);return b(c,d,e,f,a)};a.d=b;return a}(),d=function(d,h,k,l,n){switch(arguments.length){case 2:return c.call(this,d,h);case 3:return b.call(this,d,h,k);case 4:return a.call(this,d,h,k,l);default:return e.d(d,h,k,l,J(arguments,4))}throw Error("Invalid arity: "+arguments.length);};d.k=4;d.f=e.f;d.a=c;d.c=b;d.n=a;d.d=e.d;return d}(),Kg={};
function Lg(a){if(a?a.ac:a)return a.ac(a);var b;b=Lg[m(null==a?null:a)];if(!b&&(b=Lg._,!b))throw x("IEncodeJS.-clj-\x3ejs",a);return b.call(null,a)}function Mg(a){return(a?r(r(null)?null:a.$b)||(a.Cb?0:s(Kg,a)):s(Kg,a))?Lg(a):"string"===typeof a||"number"===typeof a||a instanceof T||a instanceof Zb?Ng.b?Ng.b(a):Ng.call(null,a):Cg.d(J([a],0))}
var Ng=function Og(b){if(null==b)return null;if(b?r(r(null)?null:b.$b)||(b.Cb?0:s(Kg,b)):s(Kg,b))return Lg(b);if(b instanceof T)return id(b);if(b instanceof Zb)return""+A.b(b);if(Gc(b)){var c={};b=E(b);for(var d=null,e=0,f=0;;)if(f<e){var h=d.J(null,f),k=P.c(h,0,null),h=P.c(h,1,null);c[Mg(k)]=Og(h);f+=1}else if(b=E(b))Ic(b)?(e=Hb(b),b=Ib(b),d=e,e=O(e)):(e=F(b),d=P.c(e,0,null),e=P.c(e,1,null),c[Mg(d)]=Og(e),b=I(b),d=null,e=0),f=0;else break;return c}if(Cc(b)){c=[];b=E(Kd.a(Og,b));d=null;for(f=e=0;;)if(f<
e)k=d.J(null,f),c.push(k),f+=1;else if(b=E(b))d=b,Ic(d)?(b=Hb(d),f=Ib(d),d=b,e=O(b),b=f):(b=F(d),c.push(b),b=I(d),d=null,e=0),f=0;else break;return c}return u?b:null},Pg={};function Qg(a,b){if(a?a.Zb:a)return a.Zb(a,b);var c;c=Qg[m(null==a?null:a)];if(!c&&(c=Qg._,!c))throw x("IEncodeClojure.-js-\x3eclj",a);return c.call(null,a,b)}
var Sg=function(){function a(a){return b.d(a,J([new la(null,1,[Rg,!1],null)],0))}var b=null,c=function(){function a(c,d){var k=null;1<arguments.length&&(k=J(Array.prototype.slice.call(arguments,1),0));return b.call(this,c,k)}function b(a,c){if(a?r(r(null)?null:a.Cc)||(a.Cb?0:s(Pg,a)):s(Pg,a))return Qg(a,S.a(Uf,c));if(E(c)){var d=Mc(c)?S.a(Tf,c):c,e=Q.a(d,Rg);return function(a,b,c,d){return function y(e){return Mc(e)?rg.b(Kd.a(y,e)):Cc(e)?Yd(qc(e),Kd.a(y,e)):e instanceof Array?we(Kd.a(y,e)):ta(e)===
Object?Yd(Ye,function(){return function(a,b,c,d){return function Ra(f){return new V(null,function(a,b,c,d){return function(){for(;;){var a=E(f);if(a){if(Ic(a)){var b=Hb(a),c=O(b),h=new ld(Array(c),0);a:{for(var k=0;;)if(k<c){var l=D.a(b,k),l=new W(null,2,5,X,[d.b?d.b(l):d.call(null,l),y(e[l])],null);h.add(l);k+=1}else{b=!0;break a}b=void 0}return b?pd(h.da(),Ra(Ib(a))):pd(h.da(),null)}h=F(a);return M(new W(null,2,5,X,[d.b?d.b(h):d.call(null,h),y(e[h])],null),Ra(G(a)))}return null}}}(a,b,c,d),null,
null)}}(a,b,c,d)(Jc(e))}()):u?e:null}}(c,d,e,r(e)?jd:A)(a)}return null}a.k=1;a.f=function(a){var c=F(a);a=G(a);return b(c,a)};a.d=b;return a}(),b=function(b,e){switch(arguments.length){case 1:return a.call(this,b);default:return c.d(b,J(arguments,1))}throw Error("Invalid arity: "+arguments.length);};b.k=1;b.f=c.f;b.b=a;b.d=c.d;return b}();function Tg(a){this.pb=a;this.q=0;this.i=2153775104}
Tg.prototype.B=function(){for(var a=Cg.d(J([this],0)),b=0,c=0;c<a.length;++c)b=31*b+a.charCodeAt(c),b%=4294967296;return b};Tg.prototype.w=function(a,b){return ub(b,'#uuid "'+A.b(this.pb)+'"')};Tg.prototype.v=function(a,b){return b instanceof Tg&&this.pb===b.pb};Tg.prototype.toString=function(){return this.pb};var Ug=new T(null,"ppath","ppath"),Vg=new T("zip","branch?","zip/branch?"),Wg=new T(null,"r","r"),Xg=new T("zip","children","zip/children"),pa=new T(null,"meta","meta"),qa=new T(null,"dup","dup"),u=new T(null,"else","else"),Gg=new T(null,"validator","validator"),Yb=new T(null,"default","default"),Yg=new T(null,"sequential","sequential"),ma=new T(null,"flush-on-newline","flush-on-newline"),Zg=new T(null,"l","l"),$g=new T("zip","make-node","zip/make-node"),oa=new T(null,"readably","readably"),ra=new T(null,
"print-length","print-length"),ah=new T(null,"pnodes","pnodes"),bh=new T(null,"changed?","changed?"),ch=new T(null,"tag","tag"),dh=new T(null,"set","set"),eh=new T(null,"end","end"),fh=new T(null,"atom","atom"),Rg=new T(null,"keywordize-keys","keywordize-keys"),gh=new T(null,"map","map"),hh=new T("mori","not-found","mori/not-found"),ih=new T("cljs.core","not-found","cljs.core/not-found");var jh,kh;function lh(a){return a.o?a.o():a.call(null)}function mh(a){return a.o?a.o():a.call(null)}var nh=function(){function a(a,b,c){return Gc(c)?hb(c,a,b):null==c?b:c instanceof Array?hc.c(c,a,b):u?gb.c(c,a,b):null}function b(a,b){return c.c(a,a.o?a.o():a.call(null),b)}var c=null,c=function(c,e,f){switch(arguments.length){case 2:return b.call(this,c,e);case 3:return a.call(this,c,e,f)}throw Error("Invalid arity: "+arguments.length);};c.a=b;c.c=a;return c}();
function oh(a,b,c,d){if(a?a.Eb:a)return a.Eb(a,b,c,d);var e;e=oh[m(null==a?null:a)];if(!e&&(e=oh._,!e))throw x("CollFold.coll-fold",a);return e.call(null,a,b,c,d)}
var qh=function ph(b,c){"undefined"===typeof jh&&(jh=function(b,c,f,h){this.$=b;this.Qa=c;this.uc=f;this.sc=h;this.q=0;this.i=917504},jh.Db=!0,jh.Bb="clojure.core.reducers/t6322",jh.Tb=function(b,c){return ub(c,"clojure.core.reducers/t6322")},jh.prototype.N=function(b,c){return gb.c(this,c,c.o?c.o():c.call(null))},jh.prototype.M=function(b,c,f){return gb.c(this.Qa,this.$.b?this.$.b(c):this.$.call(null,c),f)},jh.prototype.D=function(){return this.sc},jh.prototype.F=function(b,c){return new jh(this.$,
this.Qa,this.uc,c)});return new jh(c,b,ph,null)},sh=function rh(b,c){"undefined"===typeof kh&&(kh=function(b,c,f,h){this.$=b;this.Qa=c;this.rc=f;this.tc=h;this.q=0;this.i=917504},kh.Db=!0,kh.Bb="clojure.core.reducers/t6328",kh.Tb=function(b,c){return ub(c,"clojure.core.reducers/t6328")},kh.prototype.Eb=function(b,c,f,h){return oh(this.Qa,c,f,this.$.b?this.$.b(h):this.$.call(null,h))},kh.prototype.N=function(b,c){return gb.c(this.Qa,this.$.b?this.$.b(c):this.$.call(null,c),c.o?c.o():c.call(null))},
kh.prototype.M=function(b,c,f){return gb.c(this.Qa,this.$.b?this.$.b(c):this.$.call(null,c),f)},kh.prototype.D=function(){return this.tc},kh.prototype.F=function(b,c){return new kh(this.$,this.Qa,this.rc,c)});return new kh(c,b,rh,null)},th=function(){function a(a,b){return sh(b,function(b){return function(){var c=null;return c=function(c,e,h){switch(arguments.length){case 0:return b.o?b.o():b.call(null);case 2:return b.a?b.a(c,a.b?a.b(e):a.call(null,e)):b.call(null,c,a.b?a.b(e):a.call(null,e));case 3:return b.a?
b.a(c,a.a?a.a(e,h):a.call(null,e,h)):b.call(null,c,a.a?a.a(e,h):a.call(null,e,h))}throw Error("Invalid arity: "+arguments.length);}}()})}function b(a){return function(b){return c.a(a,b)}}var c=null,c=function(c,e){switch(arguments.length){case 1:return b.call(this,c);case 2:return a.call(this,c,e)}throw Error("Invalid arity: "+arguments.length);};c.b=b;c.a=a;return c}(),uh=function(){function a(a,b){return sh(b,function(b){return function(){var c=null;return c=function(c,e,h){switch(arguments.length){case 0:return b.o?
b.o():b.call(null);case 2:return r(a.b?a.b(e):a.call(null,e))?b.a?b.a(c,e):b.call(null,c,e):c;case 3:return r(a.a?a.a(e,h):a.call(null,e,h))?b.c?b.c(c,e,h):b.call(null,c,e,h):c}throw Error("Invalid arity: "+arguments.length);}}()})}function b(a){return function(b){return c.a(a,b)}}var c=null,c=function(c,e){switch(arguments.length){case 1:return b.call(this,c);case 2:return a.call(this,c,e)}throw Error("Invalid arity: "+arguments.length);};c.b=b;c.a=a;return c}(),vh=function(){function a(a){return sh(a,
function(a){return function(){var b=null;return b=function(b,d){switch(arguments.length){case 0:return a.o?a.o():a.call(null);case 2:return Fc(d)?c.b(d).M(null,a,b):a.a?a.a(b,d):a.call(null,b,d)}throw Error("Invalid arity: "+arguments.length);}}()})}function b(){return function(a){return c.b(a)}}var c=null,c=function(c){switch(arguments.length){case 0:return b.call(this);case 1:return a.call(this,c)}throw Error("Invalid arity: "+arguments.length);};c.o=b;c.b=a;return c}(),wh=function(){function a(a,
b){return uh.a(Gd(a),b)}function b(a){return function(b){return c.a(a,b)}}var c=null,c=function(c,e){switch(arguments.length){case 1:return b.call(this,c);case 2:return a.call(this,c,e)}throw Error("Invalid arity: "+arguments.length);};c.b=b;c.a=a;return c}(),xh=function(){function a(a,b){return qh(b,function(b){return function(){var c=null;return c=function(c,e,h){switch(arguments.length){case 0:return b.o?b.o():b.call(null);case 2:return r(a.b?a.b(e):a.call(null,e))?b.a?b.a(c,e):b.call(null,c,e):
new ec(c);case 3:return r(a.a?a.a(e,h):a.call(null,e,h))?b.c?b.c(c,e,h):b.call(null,c,e,h):new ec(c)}throw Error("Invalid arity: "+arguments.length);}}()})}function b(a){return function(b){return c.a(a,b)}}var c=null,c=function(c,e){switch(arguments.length){case 1:return b.call(this,c);case 2:return a.call(this,c,e)}throw Error("Invalid arity: "+arguments.length);};c.b=b;c.a=a;return c}(),yh=function(){function a(a,b){return qh(b,function(b){return function(a){return function(){var c=null;return c=
function(c,d,e){switch(arguments.length){case 0:return b.o?b.o():b.call(null);case 2:return Jg.a(a,Wc),0>ab(a)?new ec(c):b.a?b.a(c,d):b.call(null,c,d);case 3:return Jg.a(a,Wc),0>ab(a)?new ec(c):b.c?b.c(c,d,e):b.call(null,c,d,e)}throw Error("Invalid arity: "+arguments.length);}}()}(Hg.b(a))})}function b(a){return function(b){return c.a(a,b)}}var c=null,c=function(c,e){switch(arguments.length){case 1:return b.call(this,c);case 2:return a.call(this,c,e)}throw Error("Invalid arity: "+arguments.length);
};c.b=b;c.a=a;return c}(),zh=function(){function a(a,b){return qh(b,function(b){return function(a){return function(){var c=null;return c=function(c,d,e){switch(arguments.length){case 0:return b.o?b.o():b.call(null);case 2:return Jg.a(a,Wc),0>ab(a)?b.a?b.a(c,d):b.call(null,c,d):c;case 3:return Jg.a(a,Wc),0>ab(a)?b.c?b.c(c,d,e):b.call(null,c,d,e):c}throw Error("Invalid arity: "+arguments.length);}}()}(Hg.b(a))})}function b(a){return function(b){return c.a(a,b)}}var c=null,c=function(c,e){switch(arguments.length){case 1:return b.call(this,
c);case 2:return a.call(this,c,e)}throw Error("Invalid arity: "+arguments.length);};c.b=b;c.a=a;return c}(),Bh=function Ah(b,c,d,e){if(Bc(b))return d.o?d.o():d.call(null);if(O(b)<=c)return nh.c(e,d.o?d.o():d.call(null),b);if(u){var f=Yc(O(b)),h=ze.c(b,0,f);b=ze.c(b,f,O(b));return lh(function(b,c,e,f){return function(){var b=f(c),h;h=f(e);return d.a?d.a(b.o?b.o():b.call(null),mh(h)):d.call(null,b.o?b.o():b.call(null),mh(h))}}(f,h,b,function(b,f,h){return function(q){return function(){return function(){return Ah(q,
c,d,e)}}(b,f,h)}}(f,h,b)))}return null};W.prototype.Eb=function(a,b,c,d){return Bh(this,b,c,d)};oh.object=function(a,b,c,d){return nh.c(d,c.o?c.o():c.call(null),a)};oh["null"]=function(a,b,c){return c.o?c.o():c.call(null)};function Ch(a,b){var c=S.c(ig,a,b);return M(c,Vd(function(a){return function(b){return a===b}}(c),b))}
var Dh=function(){function a(a,b){return O(a)<O(b)?C.c(pc,b,a):C.c(pc,a,b)}var b=null,c=function(){function a(c,d,k){var l=null;2<arguments.length&&(l=J(Array.prototype.slice.call(arguments,2),0));return b.call(this,c,d,l)}function b(a,c,d){a=Ch(O,pc.d(d,c,J([a],0)));return C.c(Yd,F(a),G(a))}a.k=2;a.f=function(a){var c=F(a);a=I(a);var d=F(a);a=G(a);return b(c,d,a)};a.d=b;return a}(),b=function(b,e,f){switch(arguments.length){case 0:return bg;case 1:return b;case 2:return a.call(this,b,e);default:return c.d(b,
e,J(arguments,2))}throw Error("Invalid arity: "+arguments.length);};b.k=2;b.f=c.f;b.o=function(){return bg};b.b=function(a){return a};b.a=a;b.d=c.d;return b}(),Eh=function(){function a(a,b){for(;;)if(O(b)<O(a)){var c=a;a=b;b=c}else return C.c(function(a,b){return function(a,c){return Oc(b,c)?a:Ac.a(a,c)}}(a,b),a,a)}var b=null,c=function(){function a(b,d,k){var l=null;2<arguments.length&&(l=J(Array.prototype.slice.call(arguments,2),0));return c.call(this,b,d,l)}function c(a,d,e){a=Ch(function(a){return-O(a)},
pc.d(e,d,J([a],0)));return C.c(b,F(a),G(a))}a.k=2;a.f=function(a){var b=F(a);a=I(a);var d=F(a);a=G(a);return c(b,d,a)};a.d=c;return a}(),b=function(b,e,f){switch(arguments.length){case 1:return b;case 2:return a.call(this,b,e);default:return c.d(b,e,J(arguments,2))}throw Error("Invalid arity: "+arguments.length);};b.k=2;b.f=c.f;b.b=function(a){return a};b.a=a;b.d=c.d;return b}(),Fh=function(){function a(a,b){return O(a)<O(b)?C.c(function(a,c){return Oc(b,c)?Ac.a(a,c):a},a,a):C.c(Ac,a,b)}var b=null,
c=function(){function a(b,d,k){var l=null;2<arguments.length&&(l=J(Array.prototype.slice.call(arguments,2),0));return c.call(this,b,d,l)}function c(a,d,e){return C.c(b,a,pc.a(e,d))}a.k=2;a.f=function(a){var b=F(a);a=I(a);var d=F(a);a=G(a);return c(b,d,a)};a.d=c;return a}(),b=function(b,e,f){switch(arguments.length){case 1:return b;case 2:return a.call(this,b,e);default:return c.d(b,e,J(arguments,2))}throw Error("Invalid arity: "+arguments.length);};b.k=2;b.f=c.f;b.b=function(a){return a};b.a=a;b.d=
c.d;return b}();function Gh(a,b){return Wb.a(a,b)?new W(null,3,5,X,[null,null,a],null):new W(null,3,5,X,[a,b,null],null)}function Hh(a){return E(a)?C.c(function(a,c){var d=P.c(c,0,null),e=P.c(c,1,null);return R.c(a,d,e)},we(Od.a(S.a(Xc,Ve(a)),null)),a):null}
function Ih(a,b,c){var d=Q.a(a,c),e=Q.a(b,c),f=Jh.a?Jh.a(d,e):Jh.call(null,d,e),h=P.c(f,0,null),k=P.c(f,1,null),f=P.c(f,2,null);a=Oc(a,c);b=Oc(b,c);d=a&&b&&(null!=f||null==d&&null==e);return new W(null,3,5,X,[!a||null==h&&d?null:new af([c,h]),!b||null==k&&d?null:new af([c,k]),d?new af([c,f]):null],null)}
var Kh=function(){function a(a,b,c){return C.c(function(a,b){return rg.b(Kd.c(Zf,a,b))},new W(null,3,5,X,[null,null,null],null),Kd.a(Id.c(Ih,a,b),c))}function b(a,b){return c.c(a,b,Dh.a(Ve(a),Ve(b)))}var c=null,c=function(c,e,f){switch(arguments.length){case 2:return b.call(this,c,e);case 3:return a.call(this,c,e,f)}throw Error("Invalid arity: "+arguments.length);};c.a=b;c.c=a;return c}();
function Lh(a,b){return we(Kd.a(Hh,Kh.c(Hc(a)?a:we(a),Hc(b)?b:we(b),pg.b(function(){var c=O(a),d=O(b);return c>d?c:d}()))))}function Mh(a,b){return new W(null,3,5,X,[Cd(Fh.a(a,b)),Cd(Fh.a(b,a)),Cd(Eh.a(a,b))],null)}function Nh(a){if(a?a.qc:a)return a.qc(a);var b;b=Nh[m(null==a?null:a)];if(!b&&(b=Nh._,!b))throw x("EqualityPartition.equality-partition",a);return b.call(null,a)}
function Oh(a,b){if(a?a.pc:a)return a.pc(a,b);var c;c=Oh[m(null==a?null:a)];if(!c&&(c=Oh._,!c))throw x("Diff.diff-similar",a);return c.call(null,a,b)}Nh._=function(a){return(a?a.i&1024||a.cc||(a.i?0:s(Pa,a)):s(Pa,a))?gh:(a?a.i&4096||a.jc||(a.i?0:s(Va,a)):s(Va,a))?dh:(a?a.i&16777216||a.ic||(a.i?0:s(mb,a)):s(mb,a))?Yg:Yb?fh:null};Nh["boolean"]=function(){return fh};Nh["function"]=function(){return fh};Nh.array=function(){return Yg};Nh.number=function(){return fh};Nh.string=function(){return fh};
Nh["null"]=function(){return fh};Oh._=function(a,b){return function(){switch(Nh(a)instanceof T?Nh(a).sa:null){case "map":return Kh;case "sequential":return Lh;case "set":return Mh;case "atom":return Gh;default:throw Error("No matching clause: "+A.b(Nh(a)));}}().call(null,a,b)};Oh["boolean"]=function(a,b){return Gh(a,b)};Oh["function"]=function(a,b){return Gh(a,b)};Oh.array=function(a,b){return Lh(a,b)};Oh.number=function(a,b){return Gh(a,b)};Oh.string=function(a,b){return Gh(a,b)};
Oh["null"]=function(a,b){return Gh(a,b)};function Jh(a,b){return Wb.a(a,b)?new W(null,3,5,X,[null,null,a],null):Wb.a(Nh(a),Nh(b))?Oh(a,b):Gh(a,b)};function Ph(a){if(a?a.Ub:a)return a.Ub();var b;b=Ph[m(null==a?null:a)];if(!b&&(b=Ph._,!b))throw x("PushbackReader.read-char",a);return b.call(null,a)}function Qh(a,b){if(a?a.Vb:a)return a.Vb(0,b);var c;c=Qh[m(null==a?null:a)];if(!c&&(c=Qh._,!c))throw x("PushbackReader.unread",a);return c.call(null,a,b)}function Rh(a,b,c){this.r=a;this.buffer=b;this.Fb=c}Rh.prototype.Ub=function(){return 0===this.buffer.length?(this.Fb+=1,this.r[this.Fb]):this.buffer.pop()};Rh.prototype.Vb=function(a,b){return this.buffer.push(b)};
function Sh(a){var b=!/[^\t\n\r ]/.test(a);return r(b)?b:","===a}var Th=function(){function a(a,d){var e=null;1<arguments.length&&(e=J(Array.prototype.slice.call(arguments,1),0));return b.call(this,0,e)}function b(a,b){throw Error(S.a(A,b));}a.k=1;a.f=function(a){F(a);a=G(a);return b(0,a)};a.d=b;return a}();
function Uh(a,b){for(var c=new ea(b),d=Ph(a);;){var e;if(!(e=null==d||Sh(d))){e=d;var f="#"!==e;e=f?(f="'"!==e)?(f=":"!==e)?Vh.b?Vh.b(e):Vh.call(null,e):f:f:f}if(e)return Qh(a,d),c.toString();c.append(d);d=Ph(a)}}function Wh(a){for(;;){var b=Ph(a);if("\n"===b||"\r"===b||null==b)return a}}var Xh=tg("^([-+]?)(?:(0)|([1-9][0-9]*)|0[xX]([0-9A-Fa-f]+)|0([0-7]+)|([1-9][0-9]?)[rR]([0-9A-Za-z]+))(N)?$"),Yh=tg("^([-+]?[0-9]+)/([0-9]+)$"),Zh=tg("^([-+]?[0-9]+(\\.[0-9]*)?([eE][-+]?[0-9]+)?)(M)?$"),$h=tg("^[:]?([^0-9/].*/)?([^0-9/][^/]*)$");
function ai(a,b){var c=a.exec(b);return null!=c&&c[0]===b?1===c.length?c[0]:c:null}var bi=tg("^[0-9A-Fa-f]{2}$"),ci=tg("^[0-9A-Fa-f]{4}$");function di(a,b,c,d){return r(sg(a,d))?d:Th.d(b,J(["Unexpected unicode escape \\",c,d],0))}function ei(a){return String.fromCharCode(parseInt(a,16))}
function fi(a){var b=Ph(a),c="t"===b?"\t":"r"===b?"\r":"n"===b?"\n":"\\"===b?"\\":'"'===b?'"':"b"===b?"\b":"f"===b?"\f":null;r(c)?a=c:"x"===b?(c=(new ea(Ph(a),Ph(a))).toString(),a=ei(di(bi,a,b,c))):"u"===b?(c=(new ea(Ph(a),Ph(a),Ph(a),Ph(a))).toString(),a=ei(di(ci,a,b,c))):a=/[^0-9]/.test(b)?u?Th.d(a,J(["Unexpected unicode escape \\",b],0)):null:String.fromCharCode(b);return a}
function gi(a,b){for(var c=yb(qe);;){var d;a:{d=Sh;for(var e=b,f=Ph(e);;)if(r(d.b?d.b(f):d.call(null,f)))f=Ph(e);else{d=f;break a}d=void 0}r(d)||Th.d(b,J(["EOF while reading"],0));if(a===d)return Ab(c);e=Vh.b?Vh.b(d):Vh.call(null,d);r(e)?d=e.a?e.a(b,d):e.call(null,b,d):(Qh(b,d),d=hi.n?hi.n(b,!0,null,!0):hi.call(null,b,!0,null));c=d===b?c:wd.a(c,d)}}function ii(a,b){return Th.d(a,J(["Reader for ",b," not implemented yet"],0))}
function ji(a,b){var c=Ph(a),d=ki.b?ki.b(c):ki.call(null,c);if(r(d))return d.a?d.a(a,b):d.call(null,a,b);d=li.a?li.a(a,c):li.call(null,a,c);return r(d)?d:Th.d(a,J(["No dispatch macro for ",c],0))}function mi(a,b){return Th.d(a,J(["Unmached delimiter ",b],0))}function ni(a){return S.a(fd,gi(")",a))}function oi(a){return gi("]",a)}
function pi(a){var b=gi("}",a),c=O(b);if("number"!==typeof c||isNaN(c)||Infinity===c||parseFloat(c)!==parseInt(c,10))throw Error("Argument must be an integer: "+A.b(c));0!==(c&1)&&Th.d(a,J(["Map literal must contain an even number of forms"],0));return S.a(Tf,b)}function qi(a){for(var b=new ea,c=Ph(a);;){if(null==c)return Th.d(a,J(["EOF while reading"],0));if("\\"===c)b.append(fi(a)),c=Ph(a);else{if('"'===c)return b.toString();if(Yb)b.append(c),c=Ph(a);else return null}}}
function ri(a){for(var b=new ea,c=Ph(a);;){if(null==c)return Th.d(a,J(["EOF while reading"],0));if("\\"===c){b.append(c);var d=Ph(a);if(null==d)return Th.d(a,J(["EOF while reading"],0));var e=function(){var a=b;a.append(d);return a}(),f=Ph(a),b=e,c=f}else{if('"'===c)return b.toString();if(u)e=function(){var a=b;a.append(c);return a}(),f=Ph(a),b=e,c=f;else return null}}}
function si(a,b){var c=Uh(a,b);if(r(-1!=c.indexOf("/")))c=$b.a(ad.c(c,0,c.indexOf("/")),ad.c(c,c.indexOf("/")+1,c.length));else var d=$b.b(c),c="nil"===c?null:"true"===c?!0:"false"===c?!1:u?d:null;return c}function ti(a){var b=Uh(a,Ph(a)),c=ai($h,b),b=c[0],d=c[1],c=c[2];return void 0!==d&&":/"===d.substring(d.length-2,d.length)||":"===c[c.length-1]||-1!==b.indexOf("::",1)?Th.d(a,J(["Invalid token: ",b],0)):null!=d&&0<d.length?jd.a(d.substring(0,d.indexOf("/")),c):jd.b(b)}
function ui(a){return function(b){return Da(Da(H,hi.n?hi.n(b,!0,null,!0):hi.call(null,b,!0,null)),a)}}function vi(){return function(a){return Th.d(a,J(["Unreadable form"],0))}}
function wi(a){var b;b=hi.n?hi.n(a,!0,null,!0):hi.call(null,a,!0,null);b=b instanceof Zb?new la(null,1,[ch,b],null):"string"===typeof b?new la(null,1,[ch,b],null):b instanceof T?new af([b,!0]):u?b:null;Gc(b)||Th.d(a,J(["Metadata must be Symbol,Keyword,String or Map"],0));var c=hi.n?hi.n(a,!0,null,!0):hi.call(null,a,!0,null);return(c?c.i&262144||c.oc||(c.i?0:s(db,c)):s(db,c))?N(c,Zf.d(J([xc(c),b],0))):Th.d(a,J(["Metadata can only be applied to IWithMetas"],0))}function xi(a){return eg(gi("}",a))}
function yi(a){return tg(ri(a))}function zi(a){hi.n?hi.n(a,!0,null,!0):hi.call(null,a,!0,null);return a}function Vh(a){return'"'===a?qi:":"===a?ti:";"===a?Wh:"'"===a?ui(new Zb(null,"quote","quote",1377916282,null)):"@"===a?ui(new Zb(null,"deref","deref",1494944732,null)):"^"===a?wi:"`"===a?ii:"~"===a?ii:"("===a?ni:")"===a?mi:"["===a?oi:"]"===a?mi:"{"===a?pi:"}"===a?mi:"\\"===a?Ph:"#"===a?ji:null}function ki(a){return"{"===a?xi:"\x3c"===a?vi():'"'===a?yi:"!"===a?Wh:"_"===a?zi:null}
function hi(a,b,c){for(;;){var d=Ph(a);if(null==d)return r(b)?Th.d(a,J(["EOF while reading"],0)):c;if(!Sh(d))if(";"===d)a=Wh.a?Wh.a(a,d):Wh.call(null,a);else if(u){var e=Vh(d);if(r(e))e=e.a?e.a(a,d):e.call(null,a,d);else{var e=a,f=void 0;!(f=!/[^0-9]/.test(d))&&(f=void 0,f="+"===d||"-"===d)&&(f=Ph(e),Qh(e,f),f=!/[^0-9]/.test(f));if(f)a:{e=a;d=new ea(d);for(f=Ph(e);;){var h;h=null==f;h||(h=(h=Sh(f))?h:Vh.b?Vh.b(f):Vh.call(null,f));if(r(h)){Qh(e,f);f=d=d.toString();h=void 0;if(r(ai(Xh,f)))if(f=ai(Xh,
f),null!=f[2])h=0;else{h=r(f[3])?[f[3],10]:r(f[4])?[f[4],16]:r(f[5])?[f[5],8]:r(f[6])?[f[7],parseInt(f[6],10)]:u?[null,null]:null;var k=h[0];null==k?h=null:(h=parseInt(k,h[1]),h="-"===f[1]?-h:h)}else h=void 0,r(ai(Yh,f))?(f=ai(Yh,f),h=parseInt(f[1],10)/parseInt(f[2],10)):h=r(ai(Zh,f))?parseFloat(f):null;f=h;e=r(f)?f:Th.d(e,J(["Invalid number format [",d,"]"],0));break a}d.append(f);f=Ph(e)}e=void 0}else e=u?si(a,d):null}if(e!==a)return e}else return null}}
function Ai(a){if(Wb.a(3,O(a)))return a;if(3<O(a))return ad.c(a,0,3);if(u)for(a=new ea(a);;)if(3>a.Va.length)a=a.append("0");else return a.toString();else return null}var Bi=function(a,b){return function(c,d){return Q.a(r(d)?b:a,c)}}(new W(null,13,5,X,[null,31,28,31,30,31,30,31,31,30,31,30,31],null),new W(null,13,5,X,[null,31,29,31,30,31,30,31,31,30,31,30,31],null)),Ci=/(\d\d\d\d)(?:-(\d\d)(?:-(\d\d)(?:[T](\d\d)(?::(\d\d)(?::(\d\d)(?:[.](\d+))?)?)?)?)?)?(?:[Z]|([-+])(\d\d):(\d\d))?/;
function Di(a){a=parseInt(a,10);return sa(isNaN(a))?a:null}function Ei(a,b,c,d){a<=b&&b<=c||Th.d(null,J([""+A.b(d)+" Failed: "+A.b(a)+"\x3c\x3d"+A.b(b)+"\x3c\x3d"+A.b(c)],0));return b}
function Fi(a){var b=sg(Ci,a);P.c(b,0,null);var c=P.c(b,1,null),d=P.c(b,2,null),e=P.c(b,3,null),f=P.c(b,4,null),h=P.c(b,5,null),k=P.c(b,6,null),l=P.c(b,7,null),n=P.c(b,8,null),q=P.c(b,9,null),t=P.c(b,10,null);if(sa(b))return Th.d(null,J(["Unrecognized date/time syntax: "+A.b(a)],0));a=Di(c);var b=function(){var a=Di(d);return r(a)?a:1}(),c=function(){var a=Di(e);return r(a)?a:1}(),v=function(){var a=Di(f);return r(a)?a:0}(),w=function(){var a=Di(h);return r(a)?a:0}(),y=function(){var a=Di(k);return r(a)?
a:0}(),B=function(){var a=Di(Ai(l));return r(a)?a:0}(),n=(Wb.a(n,"-")?-1:1)*(60*function(){var a=Di(q);return r(a)?a:0}()+function(){var a=Di(t);return r(a)?a:0}());return new W(null,8,5,X,[a,Ei(1,b,12,"timestamp month field must be in range 1..12"),Ei(1,c,Bi.a?Bi.a(b,0===(a%4+4)%4&&(0!==(a%100+100)%100||0===(a%400+400)%400)):Bi.call(null,b,0===(a%4+4)%4&&(0!==(a%100+100)%100||0===(a%400+400)%400)),"timestamp day field must be in range 1..last day in month"),Ei(0,v,23,"timestamp hour field must be in range 0..23"),
Ei(0,w,59,"timestamp minute field must be in range 0..59"),Ei(0,y,Wb.a(w,59)?60:59,"timestamp second field must be in range 0..60"),Ei(0,B,999,"timestamp millisecond field must be in range 0..999"),n],null)}
var Gi=Hg.b(new la(null,4,["inst",function(a){var b;if("string"===typeof a)if(b=Fi(a),r(b)){a=P.c(b,0,null);var c=P.c(b,1,null),d=P.c(b,2,null),e=P.c(b,3,null),f=P.c(b,4,null),h=P.c(b,5,null),k=P.c(b,6,null);b=P.c(b,7,null);b=new Date(Date.UTC(a,c-1,d,e,f,h,k)-6E4*b)}else b=Th.d(null,J(["Unrecognized date/time syntax: "+A.b(a)],0));else b=Th.d(null,J(["Instance literal expects a string for its timestamp."],0));return b},"uuid",function(a){return"string"===typeof a?new Tg(a):Th.d(null,J(["UUID literal expects a string as its representation."],
0))},"queue",function(a){return Hc(a)?Yd(Je,a):Th.d(null,J(["Queue literal expects a vector for its elements."],0))},"js",function(a){if(Hc(a)){var b=[];a=E(a);for(var c=null,d=0,e=0;;)if(e<d){var f=c.J(null,e);b.push(f);e+=1}else if(a=E(a))c=a,Ic(c)?(a=Hb(c),e=Ib(c),c=a,d=O(a),a=e):(a=F(c),b.push(a),a=I(c),c=null,d=0),e=0;else break;return b}if(Gc(a)){b={};a=E(a);c=null;for(e=d=0;;)if(e<d){var h=c.J(null,e),f=P.c(h,0,null),h=P.c(h,1,null);b[id(f)]=h;e+=1}else if(a=E(a))Ic(a)?(d=Hb(a),a=Ib(a),c=d,
d=O(d)):(d=F(a),c=P.c(d,0,null),d=P.c(d,1,null),b[id(c)]=d,a=I(a),c=null,d=0),e=0;else break;return b}return u?Th.d(null,J(["JS literal expects a vector or map containing only string or unqualified keyword keys"],0)):null}],null)),Hi=Hg.b(null);
function li(a,b){var c=si(a,b),d=Q.a(ab(Gi),""+A.b(c)),e=ab(Hi);return r(d)?d.b?d.b(hi(a,!0,null)):d.call(null,hi(a,!0,null)):r(e)?e.a?e.a(c,hi(a,!0,null)):e.call(null,c,hi(a,!0,null)):u?Th.d(a,J(["Could not find tag parser for ",""+A.b(c)," in ",Cg.d(J([Ve(ab(Gi))],0))],0)):null};p("mori.apply",S);p("mori.count",O);p("mori.distinct",function(a){return function c(a,e){return new V(null,function(){return function(a,d){for(;;){var e=a,l=P.c(e,0,null);if(e=E(e))if(Oc(d,l))l=G(e),e=d,a=l,d=e;else return M(l,c(G(e),pc.a(d,l)));else return null}}.call(null,a,e)},null,null)}(a,bg)});p("mori.empty",qc);p("mori.first",F);p("mori.rest",G);p("mori.seq",E);p("mori.conj",pc);p("mori.cons",M);
p("mori.find",function(a,b){return null!=a&&Ec(a)&&Oc(a,b)?new W(null,2,5,X,[b,Q.a(a,b)],null):null});p("mori.nth",P);p("mori.last",oc);p("mori.assoc",R);p("mori.dissoc",tc);p("mori.get_in",$d);p("mori.update_in",ae);p("mori.assoc_in",function Ii(b,c,d){var e=P.c(c,0,null);return(c=$c(c))?R.c(b,e,Ii(Q.a(b,e),c,d)):R.c(b,e,d)});p("mori.fnil",Jd);p("mori.disj",Ac);p("mori.pop",zc);p("mori.peek",yc);p("mori.hash",Tb);p("mori.get",Q);p("mori.has_key",Oc);p("mori.is_empty",Bc);p("mori.reverse",ed);
p("mori.take",Md);p("mori.drop",Nd);p("mori.take_nth",function Ji(b,c){return new V(null,function(){var d=E(c);return d?M(F(d),Ji(b,Nd(b,d))):null},null,null)});p("mori.partition",Zd);p("mori.partition_all",jg);p("mori.partition_by",function Ki(b,c){return new V(null,function(){var d=E(c);if(d){var e=F(d),f=b.b?b.b(e):b.call(null,e),e=M(e,lg(function(c,d){return function(c){return Wb.a(d,b.b?b.b(c):b.call(null,c))}}(e,f,d,d),I(d)));return M(e,Ki(b,E(Nd(O(e),d))))}return null},null,null)});
p("mori.iterate",function Li(b,c){return M(c,new V(null,function(){return Li(b,b.b?b.b(c):b.call(null,c))},null,null))});p("mori.into",Yd);p("mori.merge",Zf);p("mori.subvec",ze);p("mori.take_while",lg);p("mori.drop_while",function(a,b){return new V(null,function(c){return function(){return c(a,b)}}(function(a,b){for(;;){var e=E(b),f;f=(f=e)?a.b?a.b(F(e)):a.call(null,F(e)):f;if(r(f))f=a,e=G(e),a=f,b=e;else return e}}),null,null)});
p("mori.group_by",function(a,b){return C.c(function(b,d){var e=a.b?a.b(d):a.call(null,d);return R.c(b,e,pc.a(Q.c(b,e,qe),d))},Ye,b)});p("mori.interpose",function(a,b){return Nd(1,Qd.a(Od.b(a),b))});p("mori.interleave",Qd);p("mori.concat",td);p("mori.conj1",function(a,b){return a.G(null,b)});function Xd(a){return a instanceof Array||Fc(a)}p("mori.flatten",function(a){return Ud(function(a){return!Xd(a)},G(Wd(a)))});p("mori.lazy_seq",function(a){return new V(null,a,null,null)});p("mori.keys",Ve);
p("mori.select_keys",function(a,b){for(var c=Ye,d=E(b);;)if(d)var e=F(d),f=Q.c(a,e,ih),c=Bd.a(f,ih)?R.c(c,e,f):c,d=I(d);else return c});p("mori.vals",We);p("mori.prim_seq",mc);p("mori.map",Kd);p("mori.mapcat",Sd);p("mori.reduce",C);p("mori.reduce_kv",function(a,b,c){return null!=c?hb(c,a,b):b});p("mori.filter",Ud);p("mori.remove",Vd);p("mori.some",Ed);p("mori.every",Dd);p("mori.equals",Wb);p("mori.range",pg);p("mori.repeat",Od);p("mori.repeatedly",Pd);p("mori.sort",Sc);p("mori.sort_by",Tc);
p("mori.into_array",xa);p("mori.subseq",ng);p("mori.rmap",th);p("mori.rfilter",uh);p("mori.rremove",wh);p("mori.rtake",yh);p("mori.rtake_while",xh);p("mori.rdrop",zh);p("mori.rflatten",vh);p("mori.list",fd);p("mori.vector",xe);p("mori.array_map",Uf);p("mori.hash_map",Tf);p("mori.set",eg);p("mori.sorted_set",fg);p("mori.sorted_set_by",gg);p("mori.sorted_map",Vf);p("mori.sorted_map_by",Wf);
p("mori.queue",function(){function a(a){var d=null;0<arguments.length&&(d=J(Array.prototype.slice.call(arguments,0),0));return b.call(this,d)}function b(a){return Yd.a?Yd.a(Je,a):Yd.call(null,Je,a)}a.k=0;a.f=function(a){a=E(a);return b(a)};a.d=b;return a}());p("mori.keyword",jd);p("mori.symbol",$b);p("mori.zipmap",function(a,b){for(var c=yb(Ye),d=E(a),e=E(b);;)if(d&&e)c=xd.c(c,F(d),F(e)),d=I(d),e=I(e);else return Ab(c)});
p("mori.is_list",function(a){return a?a.i&33554432||a.Ec?!0:a.i?!1:s(nb,a):s(nb,a)});p("mori.is_seq",Mc);p("mori.is_vector",Hc);p("mori.is_map",Gc);p("mori.is_set",Dc);p("mori.is_keyword",function(a){return a instanceof T});p("mori.is_symbol",function(a){return a instanceof Zb});p("mori.is_collection",Cc);p("mori.is_sequential",Fc);p("mori.is_associative",Ec);p("mori.is_counted",ic);p("mori.is_indexed",jc);p("mori.is_reduceable",function(a){return a?a.i&524288||a.Nb?!0:a.i?!1:s(fb,a):s(fb,a)});
p("mori.is_seqable",function(a){return a?a.i&8388608||a.hc?!0:a.i?!1:s(kb,a):s(kb,a)});p("mori.is_reversible",dd);p("mori.union",Dh);p("mori.intersection",Eh);p("mori.difference",Fh);p("mori.is_subset",function(a,b){return O(a)<=O(b)&&Dd(function(a){return Oc(b,a)},a)});p("mori.is_superset",function(a,b){return O(a)>=O(b)&&Dd(function(b){return Oc(a,b)},b)});p("mori.partial",Id);p("mori.comp",Hd);
p("mori.pipeline",function(){function a(a){var d=null;0<arguments.length&&(d=J(Array.prototype.slice.call(arguments,0),0));return b.call(this,d)}function b(a){return C.a?C.a(function(a,b){return b.b?b.b(a):b.call(null,a)},a):C.call(null,function(a,b){return b.b?b.b(a):b.call(null,a)},a)}a.k=0;a.f=function(a){a=E(a);return b(a)};a.d=b;return a}());
p("mori.curry",function(){function a(a,d){var e=null;1<arguments.length&&(e=J(Array.prototype.slice.call(arguments,1),0));return b.call(this,a,e)}function b(a,b){return function(e){return S.a(a,M.a?M.a(e,b):M.call(null,e,b))}}a.k=1;a.f=function(a){var d=F(a);a=G(a);return b(d,a)};a.d=b;return a}());
p("mori.juxt",function(){function a(a){var d=null;0<arguments.length&&(d=J(Array.prototype.slice.call(arguments,0),0));return b.call(this,d)}function b(a){return function(){function b(a){var c=null;0<arguments.length&&(c=J(Array.prototype.slice.call(arguments,0),0));return e.call(this,c)}function e(b){return xa.b?xa.b(Kd.a?Kd.a(function(a){return S.a(a,b)},a):Kd.call(null,function(a){return S.a(a,b)},a)):xa.call(null,Kd.a?Kd.a(function(a){return S.a(a,b)},a):Kd.call(null,function(a){return S.a(a,
b)},a))}b.k=0;b.f=function(a){a=E(a);return e(a)};b.d=e;return b}()}a.k=0;a.f=function(a){a=E(a);return b(a)};a.d=b;return a}());
p("mori.knit",function(){function a(a){var d=null;0<arguments.length&&(d=J(Array.prototype.slice.call(arguments,0),0));return b.call(this,d)}function b(a){return function(b){return xa.b?xa.b(Kd.c?Kd.c(function(a,b){return a.b?a.b(b):a.call(null,b)},a,b):Kd.call(null,function(a,b){return a.b?a.b(b):a.call(null,b)},a,b)):xa.call(null,Kd.c?Kd.c(function(a,b){return a.b?a.b(b):a.call(null,b)},a,b):Kd.call(null,function(a,b){return a.b?a.b(b):a.call(null,b)},a,b))}}a.k=0;a.f=function(a){a=E(a);return b(a)};
a.d=b;return a}());p("mori.diff",Jh);p("mori.sum",function(a,b){return a+b});p("mori.inc",function(a){return a+1});p("mori.dec",function(a){return a-1});p("mori.is_even",function(a){return 0===(a%2+2)%2});p("mori.is_odd",function(a){return 1===(a%2+2)%2});p("mori.each",function(a,b){for(var c=E(a),d=null,e=0,f=0;;)if(f<e){var h=d.J(null,f);b.b?b.b(h):b.call(null,h);f+=1}else if(c=E(c))d=c,Ic(d)?(c=Hb(d),e=Ib(d),d=c,h=O(c),c=e,e=h):(h=F(d),b.b?b.b(h):b.call(null,h),c=I(d),d=null,e=0),f=0;else return null});
p("mori.identity",Fd);p("mori.constantly",function(a){return function(){function b(b){0<arguments.length&&J(Array.prototype.slice.call(arguments,0),0);return a}b.k=0;b.f=function(b){E(b);return a};b.d=function(){return a};return b}()});p("mori.clj_to_js",Ng);
p("mori.js_to_clj",function(){function a(a,b){return Sg.d(a,J([Rg,b],0))}function b(a){return Sg.b(a)}var c=null,c=function(c,e){switch(arguments.length){case 1:return b.call(this,c);case 2:return a.call(this,c,e)}throw Error("Invalid arity: "+arguments.length);};c.b=b;c.a=a;return c}());p("mori.parse",function(a){return hi(new Rh(a,[],-1),!1,null)});
p("mori.configure",function(a,b){switch(a){case "print-length":return ia=b;case "print-level":return ja=b;default:throw Error("No matching clause: "+A.b(a));}});
p("mori.proxy",function(a){if("undefined"!==typeof Proxy)return Proxy.create(function(){return{has:function(b){return Oc(a,b)},hasOwn:function(b){return Oc(a,b)},get:function(b,c){var d=Q.c?Q.c(a,c,hh):Q.call(null,a,c,hh);return hd(d,hh)?ic(a)&&"length"===c?O.b?O.b(a):O.call(null,a):null:u?d:null},set:function(){return null},enumerate:function(){return xa.b?xa.b(Ve.b?Ve.b(a):Ve.call(null,a)):xa.call(null,Ve.b?Ve.b(a):Ve.call(null,a))},keys:function(){return Gc(a)?xa.b?xa.b(Ve.b?Ve.b(a):Ve.call(null,
a)):xa.call(null,Ve.b?Ve.b(a):Ve.call(null,a)):Hc(a)?xa.b?xa.b(pg.b?pg.b(O.b?O.b(a):O.call(null,a)):pg.call(null,O.b?O.b(a):O.call(null,a))):xa.call(null,pg.b?pg.b(O.b?O.b(a):O.call(null,a)):pg.call(null,O.b?O.b(a):O.call(null,a))):null}}}());throw Error("ES6 Proxy not supported!");});V.prototype.inspect=function(){return this.toString()};ac.prototype.inspect=function(){return this.toString()};kc.prototype.inspect=function(){return this.toString()};Bf.prototype.inspect=function(){return this.toString()};
vf.prototype.inspect=function(){return this.toString()};wf.prototype.inspect=function(){return this.toString()};bd.prototype.inspect=function(){return this.toString()};gd.prototype.inspect=function(){return this.toString()};cd.prototype.inspect=function(){return this.toString()};W.prototype.inspect=function(){return this.toString()};od.prototype.inspect=function(){return this.toString()};ye.prototype.inspect=function(){return this.toString()};Ae.prototype.inspect=function(){return this.toString()};
$.prototype.inspect=function(){return this.toString()};Y.prototype.inspect=function(){return this.toString()};la.prototype.inspect=function(){return this.toString()};xf.prototype.inspect=function(){return this.toString()};Qf.prototype.inspect=function(){return this.toString()};$f.prototype.inspect=function(){return this.toString()};cg.prototype.inspect=function(){return this.toString()};og.prototype.inspect=function(){return this.toString()};T.prototype.inspect=function(){return this.toString()};
Zb.prototype.inspect=function(){return this.toString()};Ie.prototype.inspect=function(){return this.toString()};He.prototype.inspect=function(){return this.toString()};p("mori._equiv",function(a,b){return a.Hc(b)});p("mori._keys",function(a){return a.keys()});p("mori._values",function(a){return a.values()});p("mori._entries",function(a){return a.entries()});p("mori._has",function(a){return a.has()});p("mori._get",function(a){return a.get()});p("mori._forEach",function(a){return a.forEach()});
p("mori._next",function(a){return a.next()});p("mori.mutable.thaw",function(a){return yb(a)});p("mori.mutable.freeze",vd);p("mori.mutable.conj1",function(a,b){return a.Ka(null,b)});p("mori.mutable.conj",wd);p("mori.mutable.assoc",xd);p("mori.mutable.dissoc",yd);p("mori.mutable.pop",function(a){return Eb(a)});p("mori.mutable.disj",zd);function Mi(a,b,c,d){return N(new W(null,2,5,X,[d,null],null),new la(null,3,[$g,c,Xg,b,Vg,a],null))}function Ni(a){return a.b?a.b(0):a.call(null,0)}function Oi(a){return Vg.b(xc(a)).call(null,Ni(a))}function Pi(a){if(r(Oi(a)))return Xg.b(xc(a)).call(null,Ni(a));throw"called children on a leaf node";}function Qi(a,b,c){return $g.b(xc(a)).call(null,b,c)}
function Ri(a){if(r(Oi(a))){var b=P.c(a,0,null),c=P.c(a,1,null),d=Pi(a),e=P.c(d,0,null),f=$c(d);return r(d)?N(new W(null,2,5,X,[e,new la(null,4,[Zg,qe,ah,r(c)?pc.a(ah.b(c),b):new W(null,1,5,X,[b],null),Ug,c,Wg,f],null)],null),xc(a)):null}return null}
function Si(a){var b=P.c(a,0,null),c=P.c(a,1,null),d=Mc(c)?S.a(Tf,c):c,c=Q.a(d,Zg),e=Q.a(d,Ug),f=Q.a(d,ah),h=Q.a(d,Wg),d=Q.a(d,bh);return r(f)?(f=yc(f),N(r(d)?new W(null,2,5,X,[Qi(a,f,td.a(c,M(b,h))),r(e)?R.c(e,bh,!0):e],null):new W(null,2,5,X,[f,e],null),xc(a))):null}function Ti(a){var b=P.c(a,0,null),c=P.c(a,1,null),c=Mc(c)?S.a(Tf,c):c,d=Q.a(c,Zg),e=Q.a(c,Wg),f=P.c(e,0,null),h=$c(e);return r(r(c)?e:c)?N(new W(null,2,5,X,[f,R.d(c,Zg,pc.a(d,b),J([Wg,h],0))],null),xc(a)):null}
function Ui(a){var b=P.c(a,0,null),c=P.c(a,1,null),c=Mc(c)?S.a(Tf,c):c,d=Q.a(c,Zg),e=Q.a(c,Wg);return r(r(c)?e:c)?N(new W(null,2,5,X,[oc(e),R.d(c,Zg,S.n(pc,d,b,hg(e)),J([Wg,null],0))],null),xc(a)):a}function Vi(a){var b=P.c(a,0,null),c=P.c(a,1,null),c=Mc(c)?S.a(Tf,c):c,d=Q.a(c,Zg),e=Q.a(c,Wg);return r(r(c)?E(d):c)?N(new W(null,2,5,X,[yc(d),R.d(c,Zg,zc(d),J([Wg,M(b,e)],0))],null),xc(a)):null}
function Wi(a,b){P.c(a,0,null);var c=P.c(a,1,null);return N(new W(null,2,5,X,[b,R.c(c,bh,!0)],null),xc(a))}var Xi=function(){function a(a,d,e){var f=null;2<arguments.length&&(f=J(Array.prototype.slice.call(arguments,2),0));return b.call(this,a,d,f)}function b(a,b,e){return Wi(a,S.c(b,Ni(a),e))}a.k=2;a.f=function(a){var d=F(a);a=I(a);var e=F(a);a=G(a);return b(d,e,a)};a.d=b;return a}();p("mori.zip.zipper",Mi);p("mori.zip.seq_zip",function(a){return Mi(Mc,Fd,function(a,c){return N(c,xc(a))},a)});p("mori.zip.vector_zip",function(a){return Mi(Hc,E,function(a,c){return N(we(c),xc(a))},a)});p("mori.zip.node",Ni);p("mori.zip.is_branch",{}.xc);p("mori.zip.children",Pi);p("mori.zip.make_node",Qi);p("mori.zip.path",function(a){return ah.b(a.b?a.b(1):a.call(null,1))});p("mori.zip.lefts",function(a){return E(Zg.b(a.b?a.b(1):a.call(null,1)))});
p("mori.zip.rights",function(a){return Wg.b(a.b?a.b(1):a.call(null,1))});p("mori.zip.down",Ri);p("mori.zip.up",Si);p("mori.zip.root",function(a){for(;;){if(Wb.a(eh,a.b?a.b(1):a.call(null,1)))return Ni(a);var b=Si(a);if(r(b))a=b;else return Ni(a)}});p("mori.zip.right",Ti);p("mori.zip.rightmost",Ui);p("mori.zip.left",Vi);
p("mori.zip.leftmost",function(a){var b=P.c(a,0,null),c=P.c(a,1,null),c=Mc(c)?S.a(Tf,c):c,d=Q.a(c,Zg),e=Q.a(c,Wg);return r(r(c)?E(d):c)?N(new W(null,2,5,X,[F(d),R.d(c,Zg,qe,J([Wg,td.d(G(d),new W(null,1,5,X,[b],null),J([e],0))],0))],null),xc(a)):a});p("mori.zip.insert_left",function(a,b){var c=P.c(a,0,null),d=P.c(a,1,null),d=Mc(d)?S.a(Tf,d):d,e=Q.a(d,Zg);if(null==d)throw"Insert at top";return N(new W(null,2,5,X,[c,R.d(d,Zg,pc.a(e,b),J([bh,!0],0))],null),xc(a))});
p("mori.zip.insert_right",function(a,b){var c=P.c(a,0,null),d=P.c(a,1,null),d=Mc(d)?S.a(Tf,d):d,e=Q.a(d,Wg);if(null==d)throw"Insert at top";return N(new W(null,2,5,X,[c,R.d(d,Wg,M(b,e),J([bh,!0],0))],null),xc(a))});p("mori.zip.replace",Wi);p("mori.zip.edit",Xi);p("mori.zip.insert_child",function(a,b){return Wi(a,Qi(a,Ni(a),M(b,Pi(a))))});p("mori.zip.append_child",function(a,b){return Wi(a,Qi(a,Ni(a),td.a(Pi(a),new W(null,1,5,X,[b],null))))});
p("mori.zip.next",function(a){if(Wb.a(eh,a.b?a.b(1):a.call(null,1)))return a;var b;b=Oi(a);b=r(b)?Ri(a):b;if(r(b))return b;b=Ti(a);if(r(b))return b;for(;;)if(r(Si(a))){b=Ti(Si(a));if(r(b))return b;a=Si(a)}else return new W(null,2,5,X,[Ni(a),eh],null)});p("mori.zip.prev",function(a){var b=Vi(a);if(r(b))for(a=b;;)if(b=Oi(a),b=r(b)?Ri(a):b,r(b))a=Ui(b);else return a;else return Si(a)});p("mori.zip.is_end",function(a){return Wb.a(eh,a.b?a.b(1):a.call(null,1))});
p("mori.zip.remove",function(a){P.c(a,0,null);var b=P.c(a,1,null),b=Mc(b)?S.a(Tf,b):b,c=Q.a(b,Zg),d=Q.a(b,Ug),e=Q.a(b,ah),f=Q.a(b,Wg);if(null==b)throw"Remove at top";if(0<O(c))for(a=N(new W(null,2,5,X,[yc(c),R.d(b,Zg,zc(c),J([bh,!0],0))],null),xc(a));;)if(b=Oi(a),b=r(b)?Ri(a):b,r(b))a=Ui(b);else return a;else return N(new W(null,2,5,X,[Qi(a,yc(e),f),r(d)?R.c(d,bh,!0):d],null),xc(a))});;return this.mori;}.call({});});
},{}],5:[function(require,module,exports){
(function() {
var cloneFunc, _;
_ = require('lodash');
cloneFunc = function(obj) {
var basicClone, entryCopyFunc, properties;
if (_(obj).isObject() && !_(obj).isFunction()) {
properties = Object.getOwnPropertyNames(obj);
entryCopyFunc = function(acc, x) {
acc[x] = cloneFunc(obj[x]);
return acc;
};
basicClone = new obj.constructor();
return _(properties).reduce(entryCopyFunc, basicClone);
} else {
return obj;
}
};
module.exports = cloneFunc;
}).call(this);
},{"lodash":"4HJaAd"}],6:[function(require,module,exports){
(function() {
module.exports = typeof console !== "undefined" && console !== null ? console.log.bind(console) : typeof println !== "undefined" && println !== null ? println : typeof print !== "undefined" && print !== null ? print : function() {
return void 0;
};
}).call(this);
},{}],7:[function(require,module,exports){
/*
on Nashorn, we provide this via MersenneTwisterFast. in the browser,
we delegate to Math.random(), for speed. we could swap in a JS
implementation of the Mersenne Twister (code for it is googlable),
but I fear (though have not measured) the performance impact --ST
*/
(function() {
module.exports = typeof Random !== "undefined" && Random !== null ? Random : {
nextInt: function(limit) {
return Math.floor(Math.random() * limit);
},
nextLong: function(limit) {
return this.nextInt(limit);
},
nextDouble: function() {
return Math.random();
},
setSeed: function(seed) {}
};
}).call(this);
},{}],8:[function(require,module,exports){
(function() {
var Cloner, obj;
Cloner = require('./cloner');
module.exports = typeof StrictMath !== "undefined" && StrictMath !== null ? StrictMath : (obj = Cloner(Math), obj.toRadians = function(degrees) {
return degrees * Math.PI / 180;
}, obj.toDegrees = function(radians) {
return radians * 180 / Math.PI;
}, obj);
}).call(this);
},{"./cloner":5}],9:[function(require,module,exports){
(function() {
module.exports = function(msg) {
throw new Error("Illegal method call: `" + msg + "` is abstract");
};
}).call(this);
},{}],10:[function(require,module,exports){
(function() {
var BaseColors, ColorMax, Random, _;
_ = require('lodash');
Random = require('../shim/random');
ColorMax = 140;
BaseColors = _(0).range(ColorMax / 10).map(function(n) {
return (n * 10) + 5;
}).value();
module.exports = {
COLOR_MAX: ColorMax,
BASE_COLORS: BaseColors,
nthColor: function(n) {
var index;
index = n % BaseColors.length;
return BaseColors[index];
},
randomColor: function() {
var index;
index = Random.nextInt(BaseColors.length);
return BaseColors[index];
},
wrapColor: function(color) {
var modColor;
if (_(color).isArray()) {
return color;
} else {
modColor = color % ColorMax;
if (modColor >= 0) {
return modColor;
} else {
return ColorMax + modColor;
}
}
},
areRelatedByShade: function(color1, color2) {
return this._colorIntegral(color1) === this._colorIntegral(color2);
},
scaleColor: function(color, number, min, max) {
var finalPercent, percent, percent10, tempmax, tempval;
percent = min > max ? number < max ? 1.0 : number > min ? 0.0 : (tempval = min - number, tempmax = min - max, tempval / tempmax) : number > max ? 1.0 : number < min ? 0.0 : (tempval = number - min, tempmax = max - min, tempval / tempmax);
percent10 = percent * 10;
finalPercent = percent10 >= 9.9999 ? 9.9999 : percent10 < 0 ? 0 : percent10;
return this._colorIntegral(color) * 10 + finalPercent;
},
_colorIntegral: function(color) {
return Math.floor(color / 10);
}
};
}).call(this);
},{"../shim/random":7,"lodash":"4HJaAd"}],11:[function(require,module,exports){
(function() {
module.exports = {
NOT_EQUALS: {},
EQUALS: {
toInt: 0
},
GREATER_THAN: {
toInt: 1
},
LESS_THAN: {
toInt: -1
},
numericCompare: function(x, y) {
if (x < y) {
return this.LESS_THAN;
} else if (x > y) {
return this.GREATER_THAN;
} else {
return this.EQUALS;
}
}
};
}).call(this);
},{}],12:[function(require,module,exports){
(function() {
var DeathInterrupt, NetLogoException, StopInterrupt, TopologyInterrupt,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
NetLogoException = (function() {
function NetLogoException(message) {
this.message = message;
}
return NetLogoException;
})();
DeathInterrupt = (function(_super) {
__extends(DeathInterrupt, _super);
function DeathInterrupt() {
return DeathInterrupt.__super__.constructor.apply(this, arguments);
}
return DeathInterrupt;
})(NetLogoException);
TopologyInterrupt = (function(_super) {
__extends(TopologyInterrupt, _super);
function TopologyInterrupt() {
return TopologyInterrupt.__super__.constructor.apply(this, arguments);
}
return TopologyInterrupt;
})(NetLogoException);
StopInterrupt = (function(_super) {
__extends(StopInterrupt, _super);
function StopInterrupt() {
return StopInterrupt.__super__.constructor.apply(this, arguments);
}
return StopInterrupt;
})(NetLogoException);
module.exports = {
NetLogoException: NetLogoException,
DeathInterrupt: DeathInterrupt,
TopologyInterrupt: TopologyInterrupt,
StopInterrupt: StopInterrupt
};
}).call(this);
},{}],13:[function(require,module,exports){
(function() {
var Iterator;
module.exports = Iterator = (function() {
Iterator.prototype._items = void 0;
function Iterator(items) {
this._items = items.slice(0);
}
Iterator.prototype.map = function(f) {
return this._items.map(f);
};
Iterator.prototype.forEach = function(f) {
this._items.forEach(f);
};
Iterator.prototype.toArray = function() {
return this._items;
};
return Iterator;
})();
}).call(this);
},{}],14:[function(require,module,exports){
(function() {
var Iterator, Seq, _;
_ = require('lodash');
Iterator = require('./iterator');
module.exports = Seq = (function() {
function Seq(_items) {
this._items = _items;
}
Seq.prototype.size = function() {
return this.toArray().length;
};
Seq.prototype.length = function() {
return this.size();
};
Seq.prototype.isEmpty = function() {
return this.size() === 0;
};
Seq.prototype.nonEmpty = function() {
return this.size() !== 0;
};
Seq.prototype.contains = function(item) {
return _(this.toArray()).contains(item);
};
Seq.prototype.exists = function(pred) {
return _(this.toArray()).some(pred);
};
Seq.prototype.every = function(pred) {
return _(this.toArray()).every(pred);
};
Seq.prototype.filter = function(pred) {
return this._generateFrom(_(this.toArray()).filter(pred).value(), this);
};
Seq.prototype.find = function(pred) {
return _(this.toArray()).find(pred);
};
Seq.prototype.forEach = function(f) {
_(this.toArray()).forEach(f);
};
Seq.prototype.foldl = function(f, initial) {
return _(this.toArray()).foldl(f, initial);
};
Seq.prototype.iterator = function() {
return new Iterator(this._items);
};
Seq.prototype.toArray = function() {
return this._items.slice(0);
};
Seq.prototype.toString = function() {
return "Seq(" + (this.toArray().toString()) + ")";
};
Seq.prototype._generateFrom = function(newItems, oldSeq) {
return new Seq(newItems);
};
return Seq;
})();
}).call(this);
},{"./iterator":13,"lodash":"4HJaAd"}],15:[function(require,module,exports){
(function() {
var Iterator, Random, Shufflerator,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
Iterator = require('./iterator');
Random = require('../shim/random');
module.exports = Shufflerator = (function(_super) {
__extends(Shufflerator, _super);
Shufflerator.prototype._i = void 0;
Shufflerator.prototype._nextOne = void 0;
function Shufflerator(items) {
Shufflerator.__super__.constructor.call(this, items);
this._i = 0;
this._nextOne = null;
this._fetch();
}
Shufflerator.prototype.map = function(f) {
var acc;
acc = [];
while (this._hasNext()) {
acc.push(f(this._next()));
}
return acc;
};
Shufflerator.prototype.forEach = function(f) {
while (this._hasNext()) {
f(this._next());
}
};
Shufflerator.prototype.toArray = function() {
var acc;
acc = [];
while (this._hasNext()) {
acc.push(this._next());
}
return acc;
};
Shufflerator.prototype._hasNext = function() {
return this._i <= this._items.length;
};
Shufflerator.prototype._next = function() {
var result;
result = this._nextOne;
this._fetch();
return result;
};
/*
I dislike this. The fact that the items are prepolled annoys me. But there are two problems with trying to "fix"
that. First, fixing it involves changing JVM NetLogo/Headless. To me, that requires a disproportionate amount of
effort to do, relative to how likely--that is, not very likely--that this code is to be heavily worked on in the
future. The second problem is that it's not apparent to me how to you can make this code substantially cleaner
without significantly hurting performance. The very idea of a structure that statefully iterates a collection in
a random order is difficult to put into clear computational terms. When it needs to be done _efficiently_, that
becomes even more of a problem. As far as I can tell, the only efficient way to do it is like how we're doing it
(one variable tracking the current index/offset, and an array where consumed items are thrown into the front).
Whatever. The whole point is that this code isn't really worth worrying myself over, since it's pretty stable.
--JAB (7/25/14)
*/
Shufflerator.prototype._fetch = function() {
var randNum;
if (this._hasNext()) {
if (this._i < this._items.length - 1) {
randNum = this._i + Random.nextInt(this._items.length - this._i);
this._nextOne = this._items[randNum];
this._items[randNum] = this._items[this._i];
} else {
this._nextOne = this._items[this._i];
}
this._i++;
} else {
this._nextOne = null;
}
};
return Shufflerator;
})(Iterator);
}).call(this);
},{"../shim/random":7,"./iterator":13}],16:[function(require,module,exports){
(function() {
var _;
_ = require('lodash');
module.exports = function(arr) {
return function(f) {
var sortFunc;
sortFunc = function(x, y) {
var result;
result = f(x[1], y[1]);
if (result !== 0) {
return result;
} else if (x[0] < y[0]) {
return -1;
} else {
return 1;
}
};
return _(0).range(arr.length).zip(arr).value().sort(sortFunc).map(function(pair) {
return pair[1];
});
};
};
}).call(this);
},{"lodash":"4HJaAd"}],17:[function(require,module,exports){
(function() {
var Timer;
module.exports = Timer = (function() {
Timer.prototype._startTime = void 0;
function Timer() {
this.reset();
}
Timer.prototype.elapsed = function() {
return (Date.now() - this._startTime) / 1000;
};
Timer.prototype.reset = function() {
this._startTime = Date.now();
};
return Timer;
})();
}).call(this);
},{}],18:[function(require,module,exports){
(function() {
var Exception, StrictMath;
StrictMath = require('../shim/strictmath');
Exception = require('./exception');
module.exports = {
sin: function(degrees) {
return this._squash(this.unsquashedSin(degrees));
},
cos: function(degrees) {
return this._squash(this.unsquashedCos(degrees));
},
unsquashedSin: function(degrees) {
return StrictMath.sin(StrictMath.toRadians(degrees));
},
unsquashedCos: function(degrees) {
return StrictMath.cos(StrictMath.toRadians(degrees));
},
atan: function(d1, d2) {
if (d1 === 0 && d2 === 0) {
throw new Error("Runtime error: atan is undefined when both inputs are zero.");
} else if (d1 === 0) {
if (d2 > 0) {
return 0;
} else {
return 180;
}
} else if (d2 === 0) {
if (d1 > 0) {
return 90;
} else {
return 270;
}
} else {
return (StrictMath.toDegrees(StrictMath.atan2(d1, d2)) + 360) % 360;
}
},
_squash: function(x) {
if (StrictMath.abs(x) < 3.2e-15) {
return 0;
} else {
return x;
}
}
};
}).call(this);
},{"../shim/strictmath":8,"./exception":12}],19:[function(require,module,exports){
/*
This class should be favored over Lodash when you want quick typechecking that need not be thorough.
This was made specifically to compensate for the fact that Lodash's typechecking was swapped
into the sorting code and caused a 25% performance hit in BZ Benchmark. --JAB (4/30/14)
*/
(function() {
var Type;
Type = (function() {
function Type(_x) {
this._x = _x;
}
Type.prototype.isArray = function() {
return Array.isArray(this._x);
};
Type.prototype.isBoolean = function() {
return typeof this._x === "boolean";
};
Type.prototype.isFunction = function() {
return typeof this._x === "function";
};
Type.prototype.isNumber = function() {
return typeof this._x === "number";
};
Type.prototype.isObject = function() {
return typeof this._x === "object";
};
Type.prototype.isString = function() {
return typeof this._x === "string";
};
return Type;
})();
module.exports = function(x) {
return new Type(x);
};
}).call(this);
},{}],"agentmodel":[function(require,module,exports){
module.exports=require('S4CBE1');
},{}],"S4CBE1":[function(require,module,exports){
(function() {
var AgentModel;
module.exports = AgentModel = (function() {
var mergeObjectInto;
function AgentModel() {
this.turtles = {};
this.patches = {};
this.links = {};
this.observer = {};
this.world = {};
}
AgentModel.prototype.updates = function(modelUpdates) {
var u, _i, _len;
for (_i = 0, _len = modelUpdates.length; _i < _len; _i++) {
u = modelUpdates[_i];
this.update(u);
}
};
AgentModel.prototype.update = function(modelUpdate) {
var anyUpdates, bundle, id, linkBundle, patchBundle, turtleBundle, varUpdates, _i, _len, _ref, _ref1;
anyUpdates = false;
turtleBundle = {
updates: modelUpdate.turtles,
coll: this.turtles,
typeCanDie: true
};
patchBundle = {
updates: modelUpdate.patches,
coll: this.patches,
typeCanDie: false
};
linkBundle = {
updates: modelUpdate.links,
coll: this.links,
typeCanDie: true
};
_ref = [turtleBundle, patchBundle, linkBundle];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
bundle = _ref[_i];
_ref1 = bundle.updates;
for (id in _ref1) {
varUpdates = _ref1[id];
if (!(varUpdates != null)) {
continue;
}
anyUpdates = true;
if (bundle.typeCanDie && varUpdates.WHO === -1) {
delete bundle.coll[id];
} else {
mergeObjectInto(varUpdates, this._itemById(bundle.coll, id));
}
}
}
if ((modelUpdate.observer != null) && (modelUpdate.observer[0] != null)) {
mergeObjectInto(modelUpdate.observer[0], this.observer);
}
if ((modelUpdate.world != null) && (modelUpdate.world[0] != null)) {
mergeObjectInto(modelUpdate.world[0], this.world);
}
return anyUpdates;
};
AgentModel.prototype._itemById = function(coll, id) {
if (coll[id] == null) {
coll[id] = {};
}
return coll[id];
};
mergeObjectInto = function(updatedObject, targetObject) {
var value, variable;
for (variable in updatedObject) {
value = updatedObject[variable];
targetObject[variable.toLowerCase()] = value;
}
};
return AgentModel;
})();
}).call(this);
},{}],"9MEHHl":[function(require,module,exports){
/*
`Workspace` is needed to do anything. If you want the core of Tortoise, do `require('engine/workspace')`.
If you want the peripheral stuff (i.e. because you're a compiler or test infrastructure),
the other things you might want ought to get initialized by RequireJS here. --JAB (5/7/14)
*/
(function() {
require('./agentmodel');
require('./engine/workspace');
require('./engine/prim/prims');
require('./engine/prim/tasks');
require('./nashorn/denuller');
require('./shim/printer');
require('./util/call');
require('./util/notimplemented');
module.exports = function() {};
}).call(this);
},{"./agentmodel":"S4CBE1","./engine/prim/prims":"F1Ty61","./engine/prim/tasks":"RGwRBX","./engine/workspace":"ySLy9z","./nashorn/denuller":"ifYDNE","./shim/printer":"7dPD1G","./util/call":"FYTAuy","./util/notimplemented":"mdoUix"}],"bootstrap":[function(require,module,exports){
module.exports=require('9MEHHl');
},{}],"H2TUw+":[function(require,module,exports){
(function() {
var AbstractAgentSet, Exception, Nobody, Random, Seq, Shufflerator, stableSort,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
Nobody = require('./nobody');
Random = require('tortoise/shim/random');
Exception = require('tortoise/util/exception');
Seq = require('tortoise/util/seq');
Shufflerator = require('tortoise/util/shufflerator');
stableSort = require('tortoise/util/stablesort');
module.exports = AbstractAgentSet = (function(_super) {
__extends(AbstractAgentSet, _super);
AbstractAgentSet._selfManager = void 0;
function AbstractAgentSet(agents) {
AbstractAgentSet.__super__.constructor.call(this, agents);
this._selfManager = agents[0] != null ? agents[0].world.selfManager : {
askAgent: function() {
return function() {
return void 0;
};
},
self: function() {
return {
id: void 0
};
}
};
}
AbstractAgentSet.prototype.agentFilter = function(f) {
return this.filter(this._selfManager.askAgent(f));
};
AbstractAgentSet.prototype.agentAll = function(f) {
return this.every(this._selfManager.askAgent(f));
};
AbstractAgentSet.prototype.ask = function(f, shouldShuffle) {
var iter;
iter = shouldShuffle ? this.shufflerator() : this.iterator();
iter.forEach(this._selfManager.askAgent(f));
if (this._selfManager.self().id === -1) {
throw new Exception.DeathInterrupt;
}
};
AbstractAgentSet.prototype.projectionBy = function(f) {
return this.shufflerator().map(this._selfManager.askAgent(f));
};
AbstractAgentSet.prototype.maxOneOf = function(f) {
return this._findBestOf(-Number.MAX_VALUE, (function(result, currentBest) {
return result > currentBest;
}), f);
};
AbstractAgentSet.prototype.minOneOf = function(f) {
return this._findBestOf(Number.MAX_VALUE, (function(result, currentBest) {
return result < currentBest;
}), f);
};
AbstractAgentSet.prototype.shuffled = function() {
return this.copyWithNewAgents(this.shufflerator().toArray());
};
AbstractAgentSet.prototype.shufflerator = function() {
return new Shufflerator(this.toArray());
};
AbstractAgentSet.prototype.sort = function() {
if (this.isEmpty()) {
return this.toArray();
} else {
return stableSort(this.toArray())(function(x, y) {
return x.compare(y).toInt;
});
}
};
AbstractAgentSet.prototype.toArray = function() {
this._items = this.iterator().toArray();
return this._items.slice(0);
};
AbstractAgentSet.prototype.copyWithNewAgents = function(agents) {
return this._generateFrom(agents, this);
};
AbstractAgentSet.prototype._findBestOf = function(worstPossible, findIsBetter, f) {
var foldFunc, winners, _ref;
foldFunc = (function(_this) {
return function(_arg, agent) {
var currentBest, currentWinners, result;
currentBest = _arg[0], currentWinners = _arg[1];
result = _this._selfManager.askAgent(f)(agent);
if (result === currentBest) {
currentWinners.push(agent);
return [currentBest, currentWinners];
} else if (findIsBetter(result, currentBest)) {
return [result, [agent]];
} else {
return [currentBest, currentWinners];
}
};
})(this);
_ref = this.foldl(foldFunc, [worstPossible, []]), _ref[0], winners = _ref[1];
if (winners.length === 0) {
return Nobody;
} else {
return winners[Random.nextInt(winners.length)];
}
};
return AbstractAgentSet;
})(Seq);
}).call(this);
},{"./nobody":"xMfcne","tortoise/shim/random":7,"tortoise/util/exception":12,"tortoise/util/seq":14,"tortoise/util/shufflerator":15,"tortoise/util/stablesort":16}],"engine/core/abstractagentset":[function(require,module,exports){
module.exports=require('H2TUw+');
},{}],"0Rj2PA":[function(require,module,exports){
(function() {
var Link, Patch, Turtle;
Link = require('./link');
Patch = require('./patch');
Turtle = require('./turtle');
module.exports = function(agent) {
if (agent instanceof Turtle) {
return 1;
} else if (agent instanceof Patch) {
return 2;
} else if (agent instanceof Link) {
return 3;
} else {
return 0;
}
};
}).call(this);
},{"./link":"r3RBLf","./patch":"t5DuqE","./turtle":"d1H0D2"}],"engine/core/agenttoint":[function(require,module,exports){
module.exports=require('0Rj2PA');
},{}],"GRdTwj":[function(require,module,exports){
(function() {
var Breed, BreedManager, count, getNextOrdinal, _;
_ = require('lodash');
count = 0;
getNextOrdinal = function() {
return count++;
};
Breed = (function() {
Breed.prototype.ordinal = void 0;
function Breed(name, singular, _manager, varNames, _isDirectedLinkBreed, _shape, members) {
this.name = name;
this.singular = singular;
this._manager = _manager;
this.varNames = varNames != null ? varNames : [];
this._isDirectedLinkBreed = _isDirectedLinkBreed;
this._shape = _shape != null ? _shape : void 0;
this.members = members != null ? members : [];
this.ordinal = getNextOrdinal();
}
Breed.prototype.getShape = function() {
var _ref;
return (_ref = this._shape) != null ? _ref : (this.isLinky() ? this._manager.links()._shape : this._manager.turtles()._shape);
};
Breed.prototype.setShape = function(newShape) {
this._shape = newShape;
};
Breed.prototype.add = function(newAgent) {
var howManyToThrowOut, index, indexToSplitAt, whatToInsert;
index = _(this.members).findIndex(function(agent) {
return agent.id > newAgent.id;
});
indexToSplitAt = index >= 0 ? index : this.members.length;
howManyToThrowOut = 0;
whatToInsert = newAgent;
this.members.splice(indexToSplitAt, howManyToThrowOut, whatToInsert);
};
Breed.prototype.remove = function(agent) {
var howManyToThrowOut, indexToSplitAt;
indexToSplitAt = this.members.indexOf(agent);
howManyToThrowOut = 1;
this.members.splice(indexToSplitAt, howManyToThrowOut);
};
Breed.prototype.isLinky = function() {
return this._isDirectedLinkBreed != null;
};
Breed.prototype.isUndirected = function() {
return this._isDirectedLinkBreed === false;
};
Breed.prototype.isDirected = function() {
return this._isDirectedLinkBreed === true;
};
return Breed;
})();
module.exports = BreedManager = (function() {
BreedManager.prototype._breeds = void 0;
function BreedManager(breedObjs) {
var defaultBreeds;
defaultBreeds = {
TURTLES: new Breed("TURTLES", "turtle", this, [], void 0, "default"),
LINKS: new Breed("LINKS", "link", this, [], false, "default")
};
this._breeds = _(breedObjs).foldl((function(_this) {
return function(acc, breedObj) {
var trueName, trueSingular, trueVarNames;
trueName = breedObj.name.toUpperCase();
trueSingular = breedObj.singular.toLowerCase();
trueVarNames = breedObj.varNames || [];
acc[trueName] = new Breed(trueName, trueSingular, _this, trueVarNames, breedObj.isDirected);
return acc;
};
})(this), defaultBreeds);
}
BreedManager.prototype.get = function(name) {
return this._breeds[name.toUpperCase()];
};
BreedManager.prototype.setDefaultShape = function(breedName, shape) {
this.get(breedName).setShape(shape.toLowerCase());
};
BreedManager.prototype.setUnbreededLinksUndirected = function() {
this.links()._isDirectedLinkBreed = false;
};
BreedManager.prototype.setUnbreededLinksDirected = function() {
this.links()._isDirectedLinkBreed = true;
};
BreedManager.prototype.turtles = function() {
return this.get("TURTLES");
};
BreedManager.prototype.links = function() {
return this.get("LINKS");
};
return BreedManager;
})();
}).call(this);
},{"lodash":"4HJaAd"}],"engine/core/breedmanager":[function(require,module,exports){
module.exports=require('GRdTwj');
},{}],"engine/core/link":[function(require,module,exports){
module.exports=require('r3RBLf');
},{}],"r3RBLf":[function(require,module,exports){
(function() {
var AbstractAgentSet, ColorModel, Comparator, Exception, Link, TurtleSet, VariableManager, linkCompare, _;
_ = require('lodash');
AbstractAgentSet = require('./abstractagentset');
linkCompare = require('./structure/linkcompare');
VariableManager = require('./structure/variablemanager');
TurtleSet = require('./turtleset');
ColorModel = require('tortoise/util/colormodel');
Comparator = require('tortoise/util/comparator');
Exception = require('tortoise/util/exception');
module.exports = Link = (function() {
Link.prototype._breed = void 0;
Link.prototype._updateVarsByName = void 0;
Link.prototype._varManager = void 0;
function Link(id, isDirected, end1, end2, world, genUpdate, _registerDeath, _registerRemoval, getLinksByBreedName, breed, _color, _isHidden, _label, _labelcolor, _shape, _thickness, tiemode) {
var varNames;
this.id = id;
this.isDirected = isDirected;
this.end1 = end1;
this.end2 = end2;
this.world = world;
this._registerDeath = _registerDeath;
this._registerRemoval = _registerRemoval;
if (breed == null) {
breed = this.world.breedManager.links();
}
this._color = _color != null ? _color : 5;
this._isHidden = _isHidden != null ? _isHidden : false;
this._label = _label != null ? _label : "";
this._labelcolor = _labelcolor != null ? _labelcolor : 9.9;
this._shape = _shape != null ? _shape : "default";
this._thickness = _thickness != null ? _thickness : 0;
this.tiemode = tiemode != null ? tiemode : "none";
this._updateVarsByName = genUpdate(this);
varNames = this.world.linksOwnNames.concat(breed.varNames);
this._varManager = this._genVarManager(varNames, getLinksByBreedName);
this._setBreed(breed);
this.end1.addLink(this);
this.end2.addLink(this);
this.updateEndRelatedVars();
}
Link.prototype.getBreedName = function() {
return this._breed.name;
};
Link.prototype.getBreedOrdinal = function() {
return this._breed.ordinal;
};
Link.prototype.getVariable = function(varName) {
return this._varManager[varName];
};
Link.prototype.setVariable = function(varName, value) {
this._varManager[varName] = value;
};
Link.prototype.die = function() {
this._breed.remove(this);
if (this.id !== -1) {
this.end1.removeLink(this);
this.end2.removeLink(this);
this._registerRemoval(this);
this._seppuku();
this.id = -1;
}
throw new Exception.DeathInterrupt("Call only from inside an askAgent block");
};
Link.prototype.bothEnds = function() {
return new TurtleSet([this.end1, this.end2]);
};
Link.prototype.otherEnd = function() {
if (this.end1 === this.world.selfManager.myself()) {
return this.end2;
} else {
return this.end1;
}
};
Link.prototype.tie = function() {
this._setTieMode("fixed");
};
Link.prototype.untie = function() {
this._setTieMode("none");
};
Link.prototype.updateEndRelatedVars = function() {
this._updateVarsByName("heading", "size", "midpointx", "midpointy");
};
Link.prototype.toString = function() {
if (!this._isDead()) {
return "(" + this._breed.singular + " " + this.end1.id + " " + this.end2.id + ")";
} else {
return "nobody";
}
};
Link.prototype.getHeading = function() {
return this.world.topology.towards(this.end1.xcor, this.end1.ycor, this.end2.xcor, this.end2.ycor);
};
Link.prototype.getMidpointX = function() {
return this.world.topology.midpointx(this.end1.xcor, this.end2.xcor);
};
Link.prototype.getMidpointY = function() {
return this.world.topology.midpointy(this.end1.ycor, this.end2.ycor);
};
Link.prototype.getSize = function() {
return this.world.topology.distanceXY(this.end1.xcor, this.end1.ycor, this.end2.xcor, this.end2.ycor);
};
Link.prototype.ask = function(f) {
this.world.selfManager.askAgent(f)(this);
if (this.world.selfManager.self().id === -1) {
throw new Exception.DeathInterrupt;
}
};
Link.prototype.projectionBy = function(f) {
if (!this._isDead()) {
return this.world.selfManager.askAgent(f)(this);
} else {
throw new Error("That " + this._breed.singular + " is dead.");
}
};
Link.prototype.compare = function(x) {
switch (linkCompare(this, x)) {
case -1:
return Comparator.LESS_THAN;
case 0:
return Comparator.EQUALS;
case 1:
return Comparator.GREATER_THAN;
default:
throw new Error("Comparison should only yield an integer within the interval [-1,1]");
}
};
Link.prototype._seppuku = function() {
this._registerDeath(this.id);
};
Link.prototype._genVarManager = function(extraVarNames, getLinksByBreedName) {
var varBundles;
varBundles = [
{
name: 'breed',
get: ((function(_this) {
return function() {
return getLinksByBreedName(_this._breed.name);
};
})(this)),
set: ((function(_this) {
return function(x) {
return _this._setBreed(x);
};
})(this))
}, {
name: 'color',
get: ((function(_this) {
return function() {
return _this._color;
};
})(this)),
set: ((function(_this) {
return function(x) {
return _this._setColor(x);
};
})(this))
}, {
name: 'end1',
get: ((function(_this) {
return function() {
return _this.end1;
};
})(this)),
set: ((function(_this) {
return function(x) {
return _this._setEnd1(x);
};
})(this))
}, {
name: 'end2',
get: ((function(_this) {
return function() {
return _this.end2;
};
})(this)),
set: ((function(_this) {
return function(x) {
return _this._setEnd2(x);
};
})(this))
}, {
name: 'hidden?',
get: ((function(_this) {
return function() {
return _this._isHidden;
};
})(this)),
set: ((function(_this) {
return function(x) {
return _this._setIsHidden(x);
};
})(this))
}, {
name: 'label',
get: ((function(_this) {
return function() {
return _this._label;
};
})(this)),
set: ((function(_this) {
return function(x) {
return _this._setLabel(x);
};
})(this))
}, {
name: 'label-color',
get: ((function(_this) {
return function() {
return _this._labelcolor;
};
})(this)),
set: ((function(_this) {
return function(x) {
return _this._setLabelColor(x);
};
})(this))
}, {
name: 'shape',
get: ((function(_this) {
return function() {
return _this._shape;
};
})(this)),
set: ((function(_this) {
return function(x) {
return _this._setShape(x);
};
})(this))
}, {
name: 'thickness',
get: ((function(_this) {
return function() {
return _this._thickness;
};
})(this)),
set: ((function(_this) {
return function(x) {
return _this._setThickness(x);
};
})(this))
}, {
name: 'tie-mode',
get: ((function(_this) {
return function() {
return _this.tiemode;
};
})(this)),
set: ((function(_this) {
return function(x) {
return _this._setTieMode(x);
};
})(this))
}
];
return new VariableManager(extraVarNames, varBundles);
};
Link.prototype._genVarUpdate = function(varName) {
this._updateVarsByName(varName);
};
Link.prototype._setBreed = function(breed) {
var freshNames, newNames, obsoletedNames, oldNames, trueBreed;
trueBreed = (function() {
if (_(breed).isString()) {
return this.world.breedManager.get(breed);
} else if (breed instanceof AbstractAgentSet) {
if (breed.getBreedName != null) {
return this.world.breedManager.get(breed.getBreedName());
} else {
throw new Error("You can't set BREED to a non-breed agentset.");
}
} else {
return breed;
}
}).call(this);
if (this._breed !== trueBreed) {
trueBreed.add(this);
newNames = trueBreed.varNames;
oldNames = this._breed != null ? (this._breed.remove(this), this._breed.varNames) : [];
obsoletedNames = _(oldNames).difference(newNames).value();
freshNames = _(newNames).difference(oldNames).value();
this._varManager.refineBy(obsoletedNames)(freshNames);
}
this._breed = trueBreed;
this._genVarUpdate("breed");
this._setShape(trueBreed.getShape());
if (trueBreed !== this.world.breedManager.links()) {
this.world.breedManager.links().add(this);
}
};
Link.prototype._isDead = function() {
return this.id === -1;
};
Link.prototype._setColor = function(color) {
this._color = ColorModel.wrapColor(color);
this._genVarUpdate("color");
};
Link.prototype._setEnd1 = function(turtle) {
this.end1 = turtle;
this._genVarUpdate("end1");
};
Link.prototype._setEnd2 = function(turtle) {
this.end2 = turtle;
this._genVarUpdate("end2");
};
Link.prototype._setIsHidden = function(isHidden) {
this._isHidden = isHidden;
this._genVarUpdate("hidden?");
};
Link.prototype._setLabel = function(label) {
this._label = label;
this._genVarUpdate("label");
};
Link.prototype._setLabelColor = function(color) {
this._labelcolor = ColorModel.wrapColor(color);
this._genVarUpdate("label-color");
};
Link.prototype._setShape = function(shape) {
this._shape = shape.toLowerCase();
this._genVarUpdate("shape");
};
Link.prototype._setThickness = function(thickness) {
this._thickness = thickness;
this._genVarUpdate("thickness");
};
Link.prototype._setTieMode = function(mode) {
this.tiemode = mode;
this._genVarUpdate("tie-mode");
};
return Link;
})();
}).call(this);
},{"./abstractagentset":"H2TUw+","./structure/linkcompare":"2uDRqE","./structure/variablemanager":"OHTrEx","./turtleset":"4S23fo","lodash":"4HJaAd","tortoise/util/colormodel":10,"tortoise/util/comparator":11,"tortoise/util/exception":12}],"I7p8+g":[function(require,module,exports){
(function() {
var AbstractAgentSet, DeadSkippingIterator, LinkSet,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
AbstractAgentSet = require('./abstractagentset');
DeadSkippingIterator = require('./structure/deadskippingiterator');
module.exports = LinkSet = (function(_super) {
__extends(LinkSet, _super);
function LinkSet(_agents, _breedName, _specialName) {
this._agents = _agents;
this._breedName = _breedName != null ? _breedName : "LINKS";
this._specialName = _specialName;
LinkSet.__super__.constructor.call(this, this._unwrap(this._agents));
}
LinkSet.prototype.getBreedName = function() {
return this._breedName;
};
LinkSet.prototype.iterator = function() {
return new DeadSkippingIterator(this._unwrap(this._agents));
};
LinkSet.prototype.toString = function() {
var _ref;
return (_ref = this._specialName.toLowerCase()) != null ? _ref : "(agentset, " + (this.size()) + " " + (this.getBreedName().toLowerCase()) + ")";
};
LinkSet.prototype._generateFrom = function(newAgentArr, agents) {
return new LinkSet(newAgentArr, agents.getBreedName());
};
LinkSet.prototype._unwrap = function(agents) {
if (Type(agents).isFunction()) {
return agents();
} else {
return agents.slice(0);
}
};
return LinkSet;
})(AbstractAgentSet);
}).call(this);
},{"./abstractagentset":"H2TUw+","./structure/deadskippingiterator":"6ZdcXg"}],"engine/core/linkset":[function(require,module,exports){
module.exports=require('I7p8+g');
},{}],"xMfcne":[function(require,module,exports){
/*
Inclusion of `ask` is inspired by the fact that, since a primitive like `create-link-with` can
return `nobody`, and it can also take an initialization block for the to-be-created thing, either
the init block must be branched against or `nobody` must ignore it --JAB (7/18/14)
*/
(function() {
module.exports = {
ask: function() {},
id: -1,
toString: function() {
return "nobody";
}
};
}).call(this);
},{}],"engine/core/nobody":[function(require,module,exports){
module.exports=require('xMfcne');
},{}],"engine/core/observer":[function(require,module,exports){
module.exports=require('2IE8Rg');
},{}],"2IE8Rg":[function(require,module,exports){
(function() {
var Follow, Nobody, Observe, Observer, Patch, Ride, Turtle, VariableManager, Watch, agentToInt, _;
Observe = {
toInt: 0
};
Ride = {
toInt: 1
};
Follow = {
toInt: 2
};
Watch = {
toInt: 3
};
_ = require('lodash');
agentToInt = require('./agenttoint');
Nobody = require('./nobody');
Patch = require('./patch');
Turtle = require('./turtle');
VariableManager = require('./structure/variablemanager');
module.exports = Observer = (function() {
Observer.prototype.id = 0;
Observer.prototype._varManager = void 0;
Observer.prototype._perspective = void 0;
Observer.prototype._targetAgent = void 0;
Observer.prototype._codeGlobalNames = void 0;
Observer.prototype._updateVarsByName = void 0;
function Observer(genUpdate, _globalNames, _interfaceGlobalNames) {
this._globalNames = _globalNames;
this._interfaceGlobalNames = _interfaceGlobalNames;
this._updateVarsByName = genUpdate(this);
this.resetPerspective();
this._varManager = new VariableManager(this._globalNames);
this._codeGlobalNames = _(this._globalNames).difference(this._interfaceGlobalNames);
}
Observer.prototype.clearCodeGlobals = function() {
_(this._codeGlobalNames).forEach((function(_this) {
return function(name) {
_this._varManager[name] = 0;
};
})(this));
};
Observer.prototype.follow = function(turtle) {
this._perspective = Follow;
this._targetAgent = turtle;
this._updatePerspective();
};
Observer.prototype.getGlobal = function(varName) {
return this._varManager[varName];
};
Observer.prototype.resetPerspective = function() {
this._perspective = Observe;
this._targetAgent = null;
this._updatePerspective();
};
Observer.prototype.ride = function(turtle) {
this._perspective = Ride;
this._targetAgent = turtle;
this._updatePerspective();
};
Observer.prototype.setGlobal = function(varName, value) {
this._varManager[varName] = value;
};
Observer.prototype.subject = function() {
return this._targetAgent || Nobody;
};
Observer.prototype.unfocus = function(turtle) {
if (this._targetAgent === turtle) {
this.resetPerspective();
}
};
Observer.prototype.watch = function(agent) {
this._perspective = Watch;
this._targetAgent = agent instanceof Turtle || agent instanceof Patch ? agent : Nobody;
this._updatePerspective();
};
Observer.prototype._updatePerspective = function() {
this._updateVarsByName("perspective", "targetAgent");
};
Observer.prototype._getTargetAgentUpdate = function() {
if (this._targetAgent != null) {
return [agentToInt(this._targetAgent), this._targetAgent.id];
} else {
return null;
}
};
return Observer;
})();
}).call(this);
},{"./agenttoint":"0Rj2PA","./nobody":"xMfcne","./patch":"t5DuqE","./structure/variablemanager":"OHTrEx","./turtle":"d1H0D2","lodash":"4HJaAd"}],"engine/core/patch":[function(require,module,exports){
module.exports=require('t5DuqE');
},{}],"t5DuqE":[function(require,module,exports){
(function() {
var ColorModel, Comparator, Exception, Nobody, Patch, Random, Turtle, TurtleSet, VariableManager, _;
_ = require('lodash');
Nobody = require('./nobody');
Turtle = require('./turtle');
TurtleSet = require('./turtleset');
VariableManager = require('./structure/variablemanager');
Random = require('tortoise/shim/random');
ColorModel = require('tortoise/util/colormodel');
Comparator = require('tortoise/util/comparator');
Exception = require('tortoise/util/exception');
module.exports = Patch = (function() {
Patch.prototype._updateVarsByName = void 0;
Patch.prototype._varManager = void 0;
Patch.prototype.turtles = void 0;
function Patch(id, pxcor, pycor, world, genUpdate, _declareNonBlackPatch, _decrementPatchLabelCount, _incrementPatchLabelCount, _pcolor, _plabel, _plabelcolor) {
this.id = id;
this.pxcor = pxcor;
this.pycor = pycor;
this.world = world;
this._declareNonBlackPatch = _declareNonBlackPatch;
this._decrementPatchLabelCount = _decrementPatchLabelCount;
this._incrementPatchLabelCount = _incrementPatchLabelCount;
this._pcolor = _pcolor != null ? _pcolor : 0.0;
this._plabel = _plabel != null ? _plabel : "";
this._plabelcolor = _plabelcolor != null ? _plabelcolor : 9.9;
this._updateVarsByName = genUpdate(this);
this.turtles = [];
this._varManager = this._genVarManager(this.world.patchesOwnNames);
}
Patch.prototype.getVariable = function(varName) {
return this._varManager[varName];
};
Patch.prototype.setVariable = function(varName, value) {
this._varManager[varName] = value;
};
Patch.prototype.getPatchVariable = function(varName) {
return this._varManager[varName];
};
Patch.prototype.setPatchVariable = function(varName, value) {
this._varManager[varName] = value;
};
Patch.prototype.untrackTurtle = function(turtle) {
this.turtles.splice(this.turtles.indexOf(turtle, 0), 1);
};
Patch.prototype.trackTurtle = function(turtle) {
this.turtles.push(turtle);
};
Patch.prototype.getCoords = function() {
return [this.pxcor, this.pycor];
};
Patch.prototype.distance = function(agent) {
return this.world.topology.distance(this.pxcor, this.pycor, agent);
};
Patch.prototype.distanceXY = function(x, y) {
return this.world.topology.distanceXY(this.pxcor, this.pycor, x, y);
};
Patch.prototype.towardsXY = function(x, y) {
return this.world.topology.towards(this.pxcor, this.pycor, x, y);
};
Patch.prototype.turtlesHere = function() {
return new TurtleSet(this.turtles.slice(0));
};
Patch.prototype.ask = function(f) {
this.world.selfManager.askAgent(f)(this);
if (this.world.selfManager.self().id === -1) {
throw new Exception.DeathInterrupt;
}
};
Patch.prototype.projectionBy = function(f) {
return this.world.selfManager.askAgent(f)(this);
};
Patch.prototype.getNeighbors = function() {
return this.world.getNeighbors(this.pxcor, this.pycor);
};
Patch.prototype.getNeighbors4 = function() {
return this.world.getNeighbors4(this.pxcor, this.pycor);
};
Patch.prototype.sprout = function(n, breedName) {
return this.world.turtleManager.createTurtles(n, breedName, this.pxcor, this.pycor);
};
Patch.prototype.breedHere = function(breedName) {
var turtles;
turtles = _(this.turtles).filter(function(turtle) {
return turtle.getBreedName() === breedName;
}).value();
return new TurtleSet(turtles, breedName);
};
Patch.prototype.turtlesAt = function(dx, dy) {
return this.patchAt(dx, dy).turtlesHere();
};
Patch.prototype.patchAt = function(dx, dy) {
var error, newX, newY;
try {
newX = this.world.topology.wrapX(this.pxcor + dx);
newY = this.world.topology.wrapY(this.pycor + dy);
return this.world.getPatchAt(newX, newY);
} catch (_error) {
error = _error;
if (error instanceof Exception.TopologyInterrupt) {
return Nobody;
} else {
throw error;
}
}
};
Patch.prototype.watchMe = function() {
this.world.observer.watch(this);
};
Patch.prototype.inRadius = function(agents, radius) {
return this.world.topology.inRadius(this.pxcor, this.pycor, agents, radius);
};
Patch.prototype.compare = function(x) {
return Comparator.numericCompare(this.id, x.id);
};
Patch.prototype.toString = function() {
return "(patch " + this.pxcor + " " + this.pycor + ")";
};
Patch.prototype.reset = function() {
this._varManager = this._genVarManager(this.world.patchesOwnNames);
this._setPcolor(0);
this._setPlabel('');
this._setPlabelColor(9.9);
};
Patch.prototype._genVarManager = function(extraVarNames) {
var varBundles;
varBundles = [
{
name: 'id',
get: ((function(_this) {
return function() {
return _this.id;
};
})(this)),
set: (function() {})
}, {
name: 'pcolor',
get: ((function(_this) {
return function() {
return _this._pcolor;
};
})(this)),
set: ((function(_this) {
return function(x) {
return _this._setPcolor(x);
};
})(this))
}, {
name: 'plabel',
get: ((function(_this) {
return function() {
return _this._plabel;
};
})(this)),
set: ((function(_this) {
return function(x) {
return _this._setPlabel(x);
};
})(this))
}, {
name: 'plabel-color',
get: ((function(_this) {
return function() {
return _this._plabelcolor;
};
})(this)),
set: ((function(_this) {
return function(x) {
return _this._setPlabelColor(x);
};
})(this))
}, {
name: 'pxcor',
get: ((function(_this) {
return function() {
return _this.pxcor;
};
})(this)),
set: (function() {})
}, {
name: 'pycor',
get: ((function(_this) {
return function() {
return _this.pycor;
};
})(this)),
set: (function() {})
}
];
return new VariableManager(extraVarNames, varBundles);
};
Patch.prototype._genVarUpdate = function(varName) {
this._updateVarsByName(varName);
};
Patch.prototype._setPcolor = function(color) {
var wrappedColor;
wrappedColor = ColorModel.wrapColor(color);
if (this._pcolor !== wrappedColor) {
this._pcolor = wrappedColor;
this._genVarUpdate("pcolor");
if (wrappedColor !== 0) {
this._declareNonBlackPatch();
}
}
};
Patch.prototype._setPlabel = function(label) {
var isEmpty, wasEmpty;
wasEmpty = this._plabel === "";
isEmpty = label === "";
this._plabel = label;
this._genVarUpdate("plabel");
if (isEmpty && !wasEmpty) {
this._decrementPatchLabelCount();
} else if (!isEmpty && wasEmpty) {
this._incrementPatchLabelCount();
}
};
Patch.prototype._setPlabelColor = function(color) {
this._plabelcolor = ColorModel.wrapColor(color);
this._genVarUpdate("plabel-color");
};
return Patch;
})();
}).call(this);
},{"./nobody":"xMfcne","./structure/variablemanager":"OHTrEx","./turtle":"d1H0D2","./turtleset":"4S23fo","lodash":"4HJaAd","tortoise/shim/random":7,"tortoise/util/colormodel":10,"tortoise/util/comparator":11,"tortoise/util/exception":12}],"yG3HYq":[function(require,module,exports){
(function() {
var AbstractAgentSet, Iterator, PatchSet,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
AbstractAgentSet = require('./abstractagentset');
Iterator = require('tortoise/util/iterator');
module.exports = PatchSet = (function(_super) {
__extends(PatchSet, _super);
function PatchSet(agents, _specialName) {
this._specialName = _specialName;
PatchSet.__super__.constructor.call(this, agents);
}
PatchSet.prototype.toString = function() {
var _ref;
return (_ref = this._specialName.toLowerCase()) != null ? _ref : "(agentset, " + (this.size()) + " patches)";
};
PatchSet.prototype._generateFrom = function(newAgentArr, agents) {
return new PatchSet(newAgentArr);
};
return PatchSet;
})(AbstractAgentSet);
}).call(this);
},{"./abstractagentset":"H2TUw+","tortoise/util/iterator":13}],"engine/core/patchset":[function(require,module,exports){
module.exports=require('yG3HYq');
},{}],"B6cYv5":[function(require,module,exports){
(function() {
module.exports = {
turtleBuiltins: ["id", "color", "heading", "xcor", "ycor", "shape", "label", "label-color", "breed", "hidden?", "size", "pen-size", "pen-mode"],
patchBuiltins: ["pxcor", "pycor", "pcolor", "plabel", "plabel-color"],
linkBuiltins: ["end1", "end2", "lcolor", "llabel", "llabelcolor", "lhidden", "lbreed", "thickness", "lshape", "tie-mode"],
linkExtras: ["color", "heading", "shape", "label", "label-color", "breed", "hidden?", "size", "midpointx", "midpointy"]
};
}).call(this);
},{}],"engine/core/structure/builtins":[function(require,module,exports){
module.exports=require('B6cYv5');
},{}],"engine/core/structure/deadskippingiterator":[function(require,module,exports){
module.exports=require('6ZdcXg');
},{}],"6ZdcXg":[function(require,module,exports){
(function() {
var DeadSkippingIterator, Iterator,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
Iterator = require('tortoise/util/iterator');
module.exports = DeadSkippingIterator = (function(_super) {
__extends(DeadSkippingIterator, _super);
DeadSkippingIterator.prototype._i = void 0;
function DeadSkippingIterator(items) {
DeadSkippingIterator.__super__.constructor.call(this, items);
this._i = 0;
}
DeadSkippingIterator.prototype.map = function(f) {
var acc;
acc = [];
while (this._hasNext()) {
acc.push(f(this._next()));
}
return acc;
};
DeadSkippingIterator.prototype.forEach = function(f) {
while (this._hasNext()) {
f(this._next());
}
};
DeadSkippingIterator.prototype.toArray = function() {
var acc;
acc = [];
while (this._hasNext()) {
acc.push(this._next());
}
return acc;
};
DeadSkippingIterator.prototype._hasNext = function() {
this._skipToNext();
return this._isntEmpty();
};
DeadSkippingIterator.prototype._next = function() {
this._skipToNext();
return this._items[this._i++];
};
DeadSkippingIterator.prototype._skipToNext = function() {
while (this._isntEmpty() && this._items[this._i].id === -1) {
this._i++;
}
};
DeadSkippingIterator.prototype._isntEmpty = function() {
return this._i < this._items.length;
};
return DeadSkippingIterator;
})(Iterator);
}).call(this);
},{"tortoise/util/iterator":13}],"2uDRqE":[function(require,module,exports){
(function() {
module.exports = function(a, b) {
if (a === b) {
return 0;
} else if (a.id === -1 && b.id === -1) {
return 0;
} else if (a.end1.id < b.end1.id) {
return -1;
} else if (a.end1.id > b.end1.id) {
return 1;
} else if (a.end2.id < b.end2.id) {
return -1;
} else if (a.end2.id > b.end2.id) {
return 1;
} else if (a.getBreedName() === b.getBreedName()) {
return 0;
} else if (a.getBreedName() === "LINKS") {
return -1;
} else if (b.getBreedName() === "LINKS") {
return 1;
} else if (a.getBreedOrdinal() < b.getBreedOrdinal()) {
return -1;
} else if (a.getBreedOrdinal() > b.getBreedOrdinal()) {
return 1;
} else {
return 0;
}
};
}).call(this);
},{}],"engine/core/structure/linkcompare":[function(require,module,exports){
module.exports=require('2uDRqE');
},{}],"engine/core/structure/penmanager":[function(require,module,exports){
module.exports=require('KmqHcj');
},{}],"KmqHcj":[function(require,module,exports){
(function() {
var Down, PenManager, PenStatus, Up;
PenStatus = (function() {
function PenStatus(_name) {
this._name = _name;
}
PenStatus.prototype.toString = function() {
return this._name;
};
return PenStatus;
})();
Up = new PenStatus("up");
Down = new PenStatus("down");
module.exports = PenManager = (function() {
function PenManager(_updateFunc, _size, _status) {
this._updateFunc = _updateFunc;
this._size = _size != null ? _size : 1.0;
this._status = _status != null ? _status : Up;
}
PenManager.prototype.getSize = function() {
return this._size;
};
PenManager.prototype.getMode = function() {
return this._status;
};
PenManager.prototype.setPenMode = function(position) {
if (position === "up") {
this.raisePen();
} else {
this.lowerPen();
}
};
PenManager.prototype.raisePen = function() {
this._updateStatus(Up);
};
PenManager.prototype.lowerPen = function() {
this._updateStatus(Down);
};
PenManager.prototype.setSize = function(size) {
this._updateSize(size);
};
PenManager.prototype.clone = function() {
return new PenManager(this._updateFunc, this._size, this._status);
};
PenManager.prototype._updateSize = function(newSize) {
this._size = newSize;
this._updateFunc("pen-size");
};
PenManager.prototype._updateStatus = function(newStatus) {
this._status = newStatus;
this._updateFunc("pen-mode");
};
return PenManager;
})();
}).call(this);
},{}],"engine/core/structure/selfmanager":[function(require,module,exports){
module.exports=require('UzkpAA');
},{}],"UzkpAA":[function(require,module,exports){
(function() {
var Exception, SelfManager,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
Exception = require('tortoise/util/exception');
module.exports = SelfManager = (function() {
SelfManager.prototype._self = void 0;
SelfManager.prototype._myself = void 0;
function SelfManager() {
this.askAgent = __bind(this.askAgent, this);
this.self = __bind(this.self, this);
this._self = 0;
this._myself = 0;
}
SelfManager.prototype.self = function() {
return this._self;
};
SelfManager.prototype.myself = function() {
if (this._myself !== 0) {
return this._myself;
} else {
throw new Error("There is no agent for MYSELF to refer to.");
}
};
SelfManager.prototype.askAgent = function(f) {
return (function(_this) {
return function(agent) {
var error, oldAgent, oldMyself, res;
oldMyself = _this._myself;
oldAgent = _this._self;
_this._myself = _this._self;
_this._self = agent;
res = (function() {
try {
return f();
} catch (_error) {
error = _error;
if (!(error instanceof Exception.DeathInterrupt || error instanceof Exception.StopInterrupt)) {
throw error;
}
}
})();
_this._self = oldAgent;
_this._myself = oldMyself;
return res;
};
})(this);
};
return SelfManager;
})();
}).call(this);
},{"tortoise/util/exception":12}],"OHTrEx":[function(require,module,exports){
(function() {
var VariableManager,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
module.exports = VariableManager = (function() {
function VariableManager(_varNames, _getAndSetFuncs) {
this._varNames = _varNames != null ? _varNames : [];
this._getAndSetFuncs = _getAndSetFuncs != null ? _getAndSetFuncs : [];
this.refineBy = __bind(this.refineBy, this);
this._addVarsByName(this._varNames);
this._addVarsByBundle(this._getAndSetFuncs);
}
VariableManager.prototype.refineBy = function(obsoleteVarNames) {
if (obsoleteVarNames == null) {
obsoleteVarNames = [];
}
return (function(_this) {
return function(varNames, getAndSetFuncs) {
var invalidatedSetter, name, _i, _len;
if (varNames == null) {
varNames = [];
}
if (getAndSetFuncs == null) {
getAndSetFuncs = [];
}
invalidatedSetter = function() {
throw new Error("" + name + " is no longer a valid variable.");
};
for (_i = 0, _len = obsoleteVarNames.length; _i < _len; _i++) {
name = obsoleteVarNames[_i];
_this._defineProperty(name, {
get: void 0,
set: invalidatedSetter,
configurable: true
});
}
_this._addVarsByName(varNames);
_this._addVarsByBundle(getAndSetFuncs);
};
})(this);
};
VariableManager.prototype._addVarsByName = function(varNames) {
var name, _i, _len;
for (_i = 0, _len = varNames.length; _i < _len; _i++) {
name = varNames[_i];
this._defineProperty(name, {
value: 0,
writable: true,
configurable: true
});
}
};
VariableManager.prototype._addVarsByBundle = function(bundles) {
var obj, _i, _len;
for (_i = 0, _len = bundles.length; _i < _len; _i++) {
obj = bundles[_i];
this._defineProperty(obj.name, {
get: obj.get,
set: obj.set,
configurable: true
});
}
};
VariableManager.prototype._defineProperty = function(propName, config) {
Object.defineProperty(this, propName, config);
};
return VariableManager;
})();
}).call(this);
},{}],"engine/core/structure/variablemanager":[function(require,module,exports){
module.exports=require('OHTrEx');
},{}],"engine/core/topology/box":[function(require,module,exports){
module.exports=require('5rYtfT');
},{}],"5rYtfT":[function(require,module,exports){
(function() {
var Box, Topology,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
Topology = require('./topology');
module.exports = Box = (function(_super) {
__extends(Box, _super);
function Box() {
return Box.__super__.constructor.apply(this, arguments);
}
Box.prototype._wrapInX = false;
Box.prototype._wrapInY = false;
Box.prototype.wrapX = function(pos) {
return this._wrapXCautiously(pos);
};
Box.prototype.wrapY = function(pos) {
return this._wrapYCautiously(pos);
};
Box.prototype._getPatchNorth = function(pxcor, pycor) {
return (pycor !== this.maxPycor) && this._getPatchAt(pxcor, pycor + 1);
};
Box.prototype._getPatchSouth = function(pxcor, pycor) {
return (pycor !== this.minPycor) && this._getPatchAt(pxcor, pycor - 1);
};
Box.prototype._getPatchEast = function(pxcor, pycor) {
return (pxcor !== this.maxPxcor) && this._getPatchAt(pxcor + 1, pycor);
};
Box.prototype._getPatchWest = function(pxcor, pycor) {
return (pxcor !== this.minPxcor) && this._getPatchAt(pxcor - 1, pycor);
};
Box.prototype._getPatchNorthWest = function(pxcor, pycor) {
return (pycor !== this.maxPycor) && (pxcor !== this.minPxcor) && this._getPatchAt(pxcor - 1, pycor + 1);
};
Box.prototype._getPatchSouthWest = function(pxcor, pycor) {
return (pycor !== this.minPycor) && (pxcor !== this.minPxcor) && this._getPatchAt(pxcor - 1, pycor - 1);
};
Box.prototype._getPatchSouthEast = function(pxcor, pycor) {
return (pycor !== this.minPycor) && (pxcor !== this.maxPxcor) && this._getPatchAt(pxcor + 1, pycor - 1);
};
Box.prototype._getPatchNorthEast = function(pxcor, pycor) {
return (pycor !== this.maxPycor) && (pxcor !== this.maxPxcor) && this._getPatchAt(pxcor + 1, pycor + 1);
};
Box.prototype._refineScratchPads = function(yy, xx, scratch, scratch2, coefficient) {
var diffuseVal, x, y, _i, _j;
for (y = _i = 0; 0 <= yy ? _i < yy : _i > yy; y = 0 <= yy ? ++_i : --_i) {
for (x = _j = 0; 0 <= xx ? _j < xx : _j > xx; x = 0 <= xx ? ++_j : --_j) {
diffuseVal = (scratch[x][y] / 8) * coefficient;
if ((0 < y && y < yy - 1) && (0 < x && x < xx - 1)) {
scratch2[x][y] += scratch[x][y] - (8 * diffuseVal);
scratch2[x - 1][y - 1] += diffuseVal;
scratch2[x - 1][y] += diffuseVal;
scratch2[x - 1][y + 1] += diffuseVal;
scratch2[x][y + 1] += diffuseVal;
scratch2[x][y - 1] += diffuseVal;
scratch2[x + 1][y - 1] += diffuseVal;
scratch2[x + 1][y] += diffuseVal;
scratch2[x + 1][y + 1] += diffuseVal;
} else if ((0 < y && y < yy - 1)) {
if (x === 0) {
scratch2[x][y] += scratch[x][y] - (5 * diffuseVal);
scratch2[x][y + 1] += diffuseVal;
scratch2[x][y - 1] += diffuseVal;
scratch2[x + 1][y - 1] += diffuseVal;
scratch2[x + 1][y] += diffuseVal;
scratch2[x + 1][y + 1] += diffuseVal;
} else {
scratch2[x][y] += scratch[x][y] - (5 * diffuseVal);
scratch2[x][y + 1] += diffuseVal;
scratch2[x][y - 1] += diffuseVal;
scratch2[x - 1][y - 1] += diffuseVal;
scratch2[x - 1][y] += diffuseVal;
scratch2[x - 1][y + 1] += diffuseVal;
}
} else if ((0 < x && x < xx - 1)) {
if (y === 0) {
scratch2[x][y] += scratch[x][y] - (5 * diffuseVal);
scratch2[x - 1][y] += diffuseVal;
scratch2[x - 1][y + 1] += diffuseVal;
scratch2[x][y + 1] += diffuseVal;
scratch2[x + 1][y] += diffuseVal;
scratch2[x + 1][y + 1] += diffuseVal;
} else {
scratch2[x][y] += scratch[x][y] - (5 * diffuseVal);
scratch2[x - 1][y] += diffuseVal;
scratch2[x - 1][y - 1] += diffuseVal;
scratch2[x][y - 1] += diffuseVal;
scratch2[x + 1][y] += diffuseVal;
scratch2[x + 1][y - 1] += diffuseVal;
}
} else if (x === 0) {
if (y === 0) {
scratch2[x][y] += scratch[x][y] - (3 * diffuseVal);
scratch2[x][y + 1] += diffuseVal;
scratch2[x + 1][y] += diffuseVal;
scratch2[x + 1][y + 1] += diffuseVal;
} else {
scratch2[x][y] += scratch[x][y] - (3 * diffuseVal);
scratch2[x][y - 1] += diffuseVal;
scratch2[x + 1][y] += diffuseVal;
scratch2[x + 1][y - 1] += diffuseVal;
}
} else if (y === 0) {
scratch2[x][y] += scratch[x][y] - (3 * diffuseVal);
scratch2[x][y + 1] += diffuseVal;
scratch2[x - 1][y] += diffuseVal;
scratch2[x - 1][y + 1] += diffuseVal;
} else {
scratch2[x][y] += scratch[x][y] - (3 * diffuseVal);
scratch2[x][y - 1] += diffuseVal;
scratch2[x - 1][y] += diffuseVal;
scratch2[x - 1][y - 1] += diffuseVal;
}
}
}
};
Box.prototype._shortestX = function(x1, x2) {
return this._shortestNotWrapped(x1, x2);
};
Box.prototype._shortestY = function(y1, y2) {
return this._shortestNotWrapped(y1, y2);
};
return Box;
})(Topology);
}).call(this);
},{"./topology":"67eG/c"}],"tkIP+/":[function(require,module,exports){
(function() {
var Box, HorizCylinder, Torus, VertCylinder;
Box = require('./box');
HorizCylinder = require('./horizcylinder');
Torus = require('./torus');
VertCylinder = require('./vertcylinder');
module.exports = function(wrapsInX, wrapsInY, minX, maxX, minY, maxY, getPatchesFunc, getPatchAtFunc) {
var TopoClass;
TopoClass = wrapsInX && wrapsInY ? Torus : wrapsInX ? VertCylinder : wrapsInY ? HorizCylinder : Box;
return new TopoClass(minX, maxX, minY, maxY, getPatchesFunc, getPatchAtFunc);
};
}).call(this);
},{"./box":"5rYtfT","./horizcylinder":"nvL/xB","./torus":"5YpOai","./vertcylinder":"qudk3y"}],"engine/core/topology/factory":[function(require,module,exports){
module.exports=require('tkIP+/');
},{}],"nvL/xB":[function(require,module,exports){
(function() {
var HorizCylinder, Topology,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
Topology = require('./topology');
module.exports = HorizCylinder = (function(_super) {
__extends(HorizCylinder, _super);
function HorizCylinder() {
return HorizCylinder.__super__.constructor.apply(this, arguments);
}
HorizCylinder.prototype._wrapInX = false;
HorizCylinder.prototype._wrapInY = true;
HorizCylinder.prototype.wrapX = function(pos) {
return this._wrapXCautiously(pos);
};
HorizCylinder.prototype.wrapY = function(pos) {
return this._wrapYLeniently(pos);
};
HorizCylinder.prototype._getPatchEast = function(pxcor, pycor) {
return (pxcor !== this.maxPxcor) && this._getPatchAt(pxcor + 1, pycor);
};
HorizCylinder.prototype._getPatchWest = function(pxcor, pycor) {
return (pxcor !== this.minPxcor) && this._getPatchAt(pxcor - 1, pycor);
};
HorizCylinder.prototype._getPatchNorth = function(pxcor, pycor) {
if (pycor === this.maxPycor) {
return this._getPatchAt(pxcor, this.minPycor);
} else {
return this._getPatchAt(pxcor, pycor + 1);
}
};
HorizCylinder.prototype._getPatchSouth = function(pxcor, pycor) {
if (pycor === this.minPycor) {
return this._getPatchAt(pxcor, this.maxPycor);
} else {
return this._getPatchAt(pxcor, pycor - 1);
}
};
HorizCylinder.prototype._getPatchNorthWest = function(pxcor, pycor) {
if (pxcor === this.minPxcor) {
return false;
} else if (pycor === this.maxPycor) {
return this._getPatchAt(pxcor - 1, this.minPycor);
} else {
return this._getPatchAt(pxcor - 1, pycor + 1);
}
};
HorizCylinder.prototype._getPatchSouthWest = function(pxcor, pycor) {
if (pxcor === this.minPxcor) {
return false;
} else if (pycor === this.minPycor) {
return this._getPatchAt(pxcor - 1, this.maxPycor);
} else {
return this._getPatchAt(pxcor - 1, pycor - 1);
}
};
HorizCylinder.prototype._getPatchSouthEast = function(pxcor, pycor) {
if (pxcor === this.maxPxcor) {
return false;
} else if (pycor === this.minPycor) {
return this._getPatchAt(pxcor + 1, this.maxPycor);
} else {
return this._getPatchAt(pxcor + 1, pycor - 1);
}
};
HorizCylinder.prototype._getPatchNorthEast = function(pxcor, pycor) {
if (pxcor === this.maxPxcor) {
return false;
} else if (pycor === this.maxPycor) {
return this._getPatchAt(pxcor + 1, this.minPycor);
} else {
return this._getPatchAt(pxcor + 1, pycor + 1);
}
};
HorizCylinder.prototype._refineScratchPads = function(yy, xx, scratch, scratch2, coefficient) {
var diffuseVal, x, y, _i, _j, _ref, _ref1;
for (y = _i = yy, _ref = yy * 2; yy <= _ref ? _i < _ref : _i > _ref; y = yy <= _ref ? ++_i : --_i) {
for (x = _j = xx, _ref1 = xx * 2; xx <= _ref1 ? _j < _ref1 : _j > _ref1; x = xx <= _ref1 ? ++_j : --_j) {
diffuseVal = (scratch[x - xx][y - yy] / 8) * coefficient;
if ((xx < x && x < (xx * 2) - 1)) {
scratch2[x - xx][y - yy] += scratch[x - xx][y - yy] - (8 * diffuseVal);
scratch2[(x - 1) % xx][(y - 1) % yy] += diffuseVal;
scratch2[(x - 1) % xx][y % yy] += diffuseVal;
scratch2[(x - 1) % xx][(y + 1) % yy] += diffuseVal;
scratch2[x % xx][(y + 1) % yy] += diffuseVal;
scratch2[x % xx][(y - 1) % yy] += diffuseVal;
scratch2[(x + 1) % xx][(y - 1) % yy] += diffuseVal;
scratch2[(x + 1) % xx][y % yy] += diffuseVal;
scratch2[(x + 1) % xx][(y + 1) % yy] += diffuseVal;
} else if (x === xx) {
scratch2[x - xx][y - yy] += scratch[x - xx][y - yy] - (5 * diffuseVal);
scratch2[x % xx][(y + 1) % yy] += diffuseVal;
scratch2[x % xx][(y - 1) % yy] += diffuseVal;
scratch2[(x + 1) % xx][(y - 1) % yy] += diffuseVal;
scratch2[(x + 1) % xx][y % yy] += diffuseVal;
scratch2[(x + 1) % xx][(y + 1) % yy] += diffuseVal;
} else {
scratch2[x - xx][y - yy] += scratch[x - xx][y - yy] - (5 * diffuseVal);
scratch2[x % xx][(y + 1) % yy] += diffuseVal;
scratch2[x % xx][(y - 1) % yy] += diffuseVal;
scratch2[(x - 1) % xx][(y - 1) % yy] += diffuseVal;
scratch2[(x - 1) % xx][y % yy] += diffuseVal;
scratch2[(x - 1) % xx][(y + 1) % yy] += diffuseVal;
}
}
}
};
HorizCylinder.prototype._shortestX = function(x1, x2) {
return this._shortestNotWrapped(x1, x2);
};
HorizCylinder.prototype._shortestY = function(y1, y2) {
return this._shortestYWrapped(y1, y2);
};
return HorizCylinder;
})(Topology);
}).call(this);
},{"./topology":"67eG/c"}],"engine/core/topology/horizcylinder":[function(require,module,exports){
module.exports=require('nvL/xB');
},{}],"engine/core/topology/topology":[function(require,module,exports){
module.exports=require('67eG/c');
},{}],"67eG/c":[function(require,module,exports){
(function() {
var Exception, Random, StrictMath, Topology, abstractMethod, _;
_ = require('lodash');
Topology = require('./topology');
Random = require('tortoise/shim/random');
StrictMath = require('tortoise/shim/strictmath');
abstractMethod = require('tortoise/util/abstractmethoderror');
Exception = require('tortoise/util/exception');
module.exports = Topology = (function() {
Topology.prototype._wrapInX = void 0;
Topology.prototype._wrapInY = void 0;
Topology.prototype.height = void 0;
Topology.prototype.width = void 0;
Topology.prototype._neighborCache = void 0;
Topology.prototype._neighbor4Cache = void 0;
function Topology(minPxcor, maxPxcor, minPycor, maxPycor, _getPatches, _getPatchAt) {
this.minPxcor = minPxcor;
this.maxPxcor = maxPxcor;
this.minPycor = minPycor;
this.maxPycor = maxPycor;
this._getPatches = _getPatches;
this._getPatchAt = _getPatchAt;
this.height = 1 + this.maxPycor - this.minPycor;
this.width = 1 + this.maxPxcor - this.minPxcor;
this._neighborCache = {};
this._neighbor4Cache = {};
}
Topology.prototype.diffuse = function(varName, coefficient) {
this._sloppyDiffuse(varName, coefficient);
};
Topology.prototype.getNeighbors = function(pxcor, pycor) {
var key;
key = "(" + pxcor + ", " + pycor + ")";
if (this._neighborCache.hasOwnProperty(key)) {
return this._neighborCache[key];
} else {
return this._neighborCache[key] = this._filterNeighbors(this._getNeighbors(pxcor, pycor));
}
};
Topology.prototype.getNeighbors4 = function(pxcor, pycor) {
var key;
key = "(" + pxcor + ", " + pycor + ")";
if (this._neighbor4Cache.hasOwnProperty(key)) {
return this._neighbor4Cache[key];
} else {
return this._neighbor4Cache[key] = this._filterNeighbors(this._getNeighbors4(pxcor, pycor));
}
};
Topology.prototype._filterNeighbors = function(neighbors) {
return _(neighbors).filter(function(patch) {
return patch !== false;
}).uniq().value();
};
Topology.prototype.distanceXY = function(x1, y1, x2, y2) {
var a2, b2;
a2 = StrictMath.pow(this._shortestX(x1, x2), 2);
b2 = StrictMath.pow(this._shortestY(y1, y2), 2);
return StrictMath.sqrt(a2 + b2);
};
Topology.prototype.distance = function(x1, y1, agent) {
var x2, y2, _ref;
_ref = agent.getCoords(), x2 = _ref[0], y2 = _ref[1];
return this.distanceXY(x1, y1, x2, y2);
};
Topology.prototype.towards = function(x1, y1, x2, y2) {
var dx, dy;
dx = this._shortestX(x1, x2);
dy = this._shortestY(y1, y2);
if (dx === 0) {
if (dy >= 0) {
return 0;
} else {
return 180;
}
} else if (dy === 0) {
if (dx >= 0) {
return 90;
} else {
return 270;
}
} else {
return (270 + StrictMath.toDegrees(Math.PI + StrictMath.atan2(-dy, dx))) % 360;
}
};
Topology.prototype.midpointx = function(x1, x2) {
var pos;
pos = (x1 + (x1 + this._shortestX(x1, x2))) / 2;
return this._wrap(pos, this.minPxcor - 0.5, this.maxPxcor + 0.5);
};
Topology.prototype.midpointy = function(y1, y2) {
var pos;
pos = (y1 + (y1 + this._shortestY(y1, y2))) / 2;
return this._wrap(pos, this.minPycor - 0.5, this.maxPycor + 0.5);
};
Topology.prototype.inRadius = function(x, y, agents, radius) {
return agents.filter((function(_this) {
return function(agent) {
var xcor, ycor, _ref;
_ref = agent.getCoords(), xcor = _ref[0], ycor = _ref[1];
return _this.distanceXY(xcor, ycor, x, y) <= radius;
};
})(this));
};
Topology.prototype.randomXcor = function() {
return this._randomCor(this.minPxcor, this.maxPxcor);
};
Topology.prototype.randomYcor = function() {
return this._randomCor(this.minPycor, this.maxPycor);
};
Topology.prototype._randomCor = function(min, max) {
return min - 0.5 + Random.nextDouble() * (max - min + 1);
};
Topology.prototype._getNeighbors = function(pxcor, pycor) {
if (pxcor === this.maxPxcor && pxcor === this.minPxcor) {
if (pycor === this.maxPycor && pycor === this.minPycor) {
return [];
} else {
return [this._getPatchNorth(pxcor, pycor), this._getPatchSouth(pxcor, pycor)];
}
} else if (pycor === this.maxPycor && pycor === this.minPycor) {
return [this._getPatchEast(pxcor, pycor), this._getPatchWest(pxcor, pycor)];
} else {
return [this._getPatchNorth(pxcor, pycor), this._getPatchEast(pxcor, pycor), this._getPatchSouth(pxcor, pycor), this._getPatchWest(pxcor, pycor), this._getPatchNorthEast(pxcor, pycor), this._getPatchSouthEast(pxcor, pycor), this._getPatchSouthWest(pxcor, pycor), this._getPatchNorthWest(pxcor, pycor)];
}
};
Topology.prototype._getNeighbors4 = function(pxcor, pycor) {
if (pxcor === this.maxPxcor && pxcor === this.minPxcor) {
if (pycor === this.maxPycor && pycor === this.minPycor) {
return [];
} else {
return [this._getPatchNorth(pxcor, pycor), this._getPatchSouth(pxcor, pycor)];
}
} else if (pycor === this.maxPycor && pycor === this.minPycor) {
return [this._getPatchEast(pxcor, pycor), this._getPatchWest(pxcor, pycor)];
} else {
return [this._getPatchNorth(pxcor, pycor), this._getPatchEast(pxcor, pycor), this._getPatchSouth(pxcor, pycor), this._getPatchWest(pxcor, pycor)];
}
};
Topology.prototype._refineScratchPads = function(yy, xx, scratch, scratch2, coefficient) {};
Topology.prototype._shortestNotWrapped = function(cor1, cor2) {
return Math.abs(cor1 - cor2) * (cor1 > cor2 ? -1 : 1);
};
Topology.prototype._shortestWrapped = function(cor1, cor2, limit) {
var absDist;
absDist = StrictMath.abs(cor1 - cor2);
if (absDist > limit / 2) {
return (limit - absDist) * (cor2 > cor1 ? -1 : 1);
} else {
return this._shortestNotWrapped(cor1, cor2);
}
};
Topology.prototype._shortestXWrapped = function(cor1, cor2) {
return this._shortestWrapped(cor1, cor2, this.width);
};
Topology.prototype._shortestYWrapped = function(cor1, cor2) {
return this._shortestWrapped(cor1, cor2, this.height);
};
Topology.prototype._sloppyDiffuse = function(varName, coefficient) {
var mapAll, scratch, scratch2, xx, yy;
yy = this.height;
xx = this.width;
mapAll = function(f) {
var x, y, _i, _results;
_results = [];
for (x = _i = 0; 0 <= xx ? _i < xx : _i > xx; x = 0 <= xx ? ++_i : --_i) {
_results.push((function() {
var _j, _results1;
_results1 = [];
for (y = _j = 0; 0 <= yy ? _j < yy : _j > yy; y = 0 <= yy ? ++_j : --_j) {
_results1.push(f(x, y));
}
return _results1;
})());
}
return _results;
};
scratch = mapAll((function(_this) {
return function(x, y) {
return _this._getPatchAt(x + _this.minPxcor, y + _this.minPycor).getVariable(varName);
};
})(this));
scratch2 = mapAll(function() {
return 0;
});
this._refineScratchPads(yy, xx, scratch, scratch2, coefficient);
mapAll((function(_this) {
return function(x, y) {
return _this._getPatchAt(x + _this.minPxcor, y + _this.minPycor).setVariable(varName, scratch2[x][y]);
};
})(this));
};
Topology.prototype._wrap = function(pos, min, max) {
var result;
if (pos >= max) {
return min + ((pos - max) % (max - min));
} else if (pos < min) {
result = max - ((min - pos) % (max - min));
if (result < max) {
return result;
} else {
return min;
}
} else {
return pos;
}
};
Topology.prototype._wrapXCautiously = function(pos) {
return this._wrapCautiously(this.minPxcor, this.maxPxcor, pos);
};
Topology.prototype._wrapXLeniently = function(pos) {
return this._wrapLeniently(this.minPxcor, this.maxPxcor, pos);
};
Topology.prototype._wrapYCautiously = function(pos) {
return this._wrapCautiously(this.minPycor, this.maxPycor, pos);
};
Topology.prototype._wrapYLeniently = function(pos) {
return this._wrapLeniently(this.minPycor, this.maxPycor, pos);
};
Topology.prototype._wrapCautiously = function(minCor, maxCor, pos) {
var max, min;
min = minCor - 0.5;
max = maxCor + 0.5;
if ((min <= pos && pos < max)) {
return pos;
} else {
throw new Exception.TopologyInterrupt("Cannot move turtle beyond the world's edge.");
}
};
Topology.prototype._wrapLeniently = function(minCor, maxCor, pos) {
return this._wrap(pos, minCor - 0.5, maxCor + 0.5);
};
Topology.prototype.wrapX = function(pos) {
return abstractMethod('Topology.wrapX');
};
Topology.prototype.wrapY = function(pos) {
return abstractMethod('Topology.wrapY');
};
Topology.prototype._shortestX = function(x1, x2) {
return abstractMethod('Topology._shortestX');
};
Topology.prototype._shortestY = function(y1, y2) {
return abstractMethod('Topology._shortestY');
};
Topology.prototype._getPatchNorth = function(x, y) {
return abstractMethod('Topology._getPatchNorth');
};
Topology.prototype._getPatchEast = function(x, y) {
return abstractMethod('Topology._getPatchEast');
};
Topology.prototype._getPatchSouth = function(x, y) {
return abstractMethod('Topology._getPatchSouth');
};
Topology.prototype._getPatchWest = function(x, y) {
return abstractMethod('Topology._getPatchWest');
};
Topology.prototype._getPatchNorthEast = function(x, y) {
return abstractMethod('Topology._getPatchNorthEast');
};
Topology.prototype._getPatchSouthEast = function(x, y) {
return abstractMethod('Topology._getPatchSouthEast');
};
Topology.prototype._getPatchSouthWest = function(x, y) {
return abstractMethod('Topology._getPatchSouthWest');
};
Topology.prototype._getPatchNorthWest = function(x, y) {
return abstractMethod('Topology._getPatchNorthWest');
};
return Topology;
})();
}).call(this);
},{"./topology":"67eG/c","lodash":"4HJaAd","tortoise/shim/random":7,"tortoise/shim/strictmath":8,"tortoise/util/abstractmethoderror":9,"tortoise/util/exception":12}],"engine/core/topology/torus":[function(require,module,exports){
module.exports=require('5YpOai');
},{}],"5YpOai":[function(require,module,exports){
(function() {
var Topology, Torus, _,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
_ = require('lodash');
Topology = require('./topology');
module.exports = Torus = (function(_super) {
__extends(Torus, _super);
function Torus() {
return Torus.__super__.constructor.apply(this, arguments);
}
Torus.prototype._wrapInX = true;
Torus.prototype._wrapInY = true;
Torus.prototype.wrapX = function(pos) {
return this._wrapXLeniently(pos);
};
Torus.prototype.wrapY = function(pos) {
return this._wrapYLeniently(pos);
};
Torus.prototype.diffuse = function(varName, coefficient) {
var scratch;
scratch = _(0).range(this.width).map(function() {
return [];
}).value();
this._getPatches().forEach((function(_this) {
return function(patch) {
scratch[patch.pxcor - _this.minPxcor][patch.pycor - _this.minPycor] = patch.getVariable(varName);
};
})(this));
this._getPatches().forEach((function(_this) {
return function(patch) {
var diffusalSum, orderedNeighbors, pxcor, pycor;
pxcor = patch.pxcor;
pycor = patch.pycor;
orderedNeighbors = [_this._getPatchSouthWest(pxcor, pycor), _this._getPatchWest(pxcor, pycor), _this._getPatchNorthWest(pxcor, pycor), _this._getPatchSouth(pxcor, pycor), _this._getPatchNorth(pxcor, pycor), _this._getPatchSouthEast(pxcor, pycor), _this._getPatchEast(pxcor, pycor), _this._getPatchNorthEast(pxcor, pycor)];
diffusalSum = _(orderedNeighbors).map(function(nb) {
return scratch[nb.pxcor - _this.minPxcor][nb.pycor - _this.minPycor];
}).reduce(function(acc, x) {
return acc + x;
});
patch.setVariable(varName, patch.getVariable(varName) * (1.0 - coefficient) + (diffusalSum / 8) * coefficient);
};
})(this));
};
Torus.prototype._getPatchNorth = function(pxcor, pycor) {
if (pycor === this.maxPycor) {
return this._getPatchAt(pxcor, this.minPycor);
} else {
return this._getPatchAt(pxcor, pycor + 1);
}
};
Torus.prototype._getPatchSouth = function(pxcor, pycor) {
if (pycor === this.minPycor) {
return this._getPatchAt(pxcor, this.maxPycor);
} else {
return this._getPatchAt(pxcor, pycor - 1);
}
};
Torus.prototype._getPatchEast = function(pxcor, pycor) {
if (pxcor === this.maxPxcor) {
return this._getPatchAt(this.minPxcor, pycor);
} else {
return this._getPatchAt(pxcor + 1, pycor);
}
};
Torus.prototype._getPatchWest = function(pxcor, pycor) {
if (pxcor === this.minPxcor) {
return this._getPatchAt(this.maxPxcor, pycor);
} else {
return this._getPatchAt(pxcor - 1, pycor);
}
};
Torus.prototype._getPatchNorthWest = function(pxcor, pycor) {
if (pycor === this.maxPycor) {
if (pxcor === this.minPxcor) {
return this._getPatchAt(this.maxPxcor, this.minPycor);
} else {
return this._getPatchAt(pxcor - 1, this.minPycor);
}
} else if (pxcor === this.minPxcor) {
return this._getPatchAt(this.maxPxcor, pycor + 1);
} else {
return this._getPatchAt(pxcor - 1, pycor + 1);
}
};
Torus.prototype._getPatchSouthWest = function(pxcor, pycor) {
if (pycor === this.minPycor) {
if (pxcor === this.minPxcor) {
return this._getPatchAt(this.maxPxcor, this.maxPycor);
} else {
return this._getPatchAt(pxcor - 1, this.maxPycor);
}
} else if (pxcor === this.minPxcor) {
return this._getPatchAt(this.maxPxcor, pycor - 1);
} else {
return this._getPatchAt(pxcor - 1, pycor - 1);
}
};
Torus.prototype._getPatchSouthEast = function(pxcor, pycor) {
if (pycor === this.minPycor) {
if (pxcor === this.maxPxcor) {
return this._getPatchAt(this.minPxcor, this.maxPycor);
} else {
return this._getPatchAt(pxcor + 1, this.maxPycor);
}
} else if (pxcor === this.maxPxcor) {
return this._getPatchAt(this.minPxcor, pycor - 1);
} else {
return this._getPatchAt(pxcor + 1, pycor - 1);
}
};
Torus.prototype._getPatchNorthEast = function(pxcor, pycor) {
if (pycor === this.maxPycor) {
if (pxcor === this.maxPxcor) {
return this._getPatchAt(this.minPxcor, this.minPycor);
} else {
return this._getPatchAt(pxcor + 1, this.minPycor);
}
} else if (pxcor === this.maxPxcor) {
return this._getPatchAt(this.minPxcor, pycor + 1);
} else {
return this._getPatchAt(pxcor + 1, pycor + 1);
}
};
Torus.prototype._shortestX = function(x1, x2) {
return this._shortestXWrapped(x1, x2);
};
Torus.prototype._shortestY = function(y1, y2) {
return this._shortestYWrapped(y1, y2);
};
return Torus;
})(Topology);
}).call(this);
},{"./topology":"67eG/c","lodash":"4HJaAd"}],"qudk3y":[function(require,module,exports){
(function() {
var Topology, VertCylinder,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
Topology = require('./topology');
module.exports = VertCylinder = (function(_super) {
__extends(VertCylinder, _super);
function VertCylinder() {
return VertCylinder.__super__.constructor.apply(this, arguments);
}
VertCylinder.prototype._wrapInX = true;
VertCylinder.prototype._wrapInY = false;
VertCylinder.prototype.wrapX = function(pos) {
return this._wrapXLeniently(pos);
};
VertCylinder.prototype.wrapY = function(pos) {
return this._wrapYCautiously(pos);
};
VertCylinder.prototype._getPatchNorth = function(pxcor, pycor) {
return (pycor !== this.maxPycor) && this._getPatchAt(pxcor, pycor + 1);
};
VertCylinder.prototype._getPatchSouth = function(pxcor, pycor) {
return (pycor !== this.minPycor) && this._getPatchAt(pxcor, pycor - 1);
};
VertCylinder.prototype._getPatchEast = function(pxcor, pycor) {
if (pxcor === this.maxPxcor) {
return this._getPatchAt(this.minPxcor, pycor);
} else {
return this._getPatchAt(pxcor + 1, pycor);
}
};
VertCylinder.prototype._getPatchWest = function(pxcor, pycor) {
if (pxcor === this.minPxcor) {
return this._getPatchAt(this.maxPxcor, pycor);
} else {
return this._getPatchAt(pxcor - 1, pycor);
}
};
VertCylinder.prototype._getPatchNorthWest = function(pxcor, pycor) {
if (pycor === this.maxPycor) {
return false;
} else if (pxcor === this.minPxcor) {
return this._getPatchAt(this.maxPxcor, pycor + 1);
} else {
return this._getPatchAt(pxcor - 1, pycor + 1);
}
};
VertCylinder.prototype._getPatchSouthWest = function(pxcor, pycor) {
if (pycor === this.minPycor) {
return false;
} else if (pxcor === this.minPxcor) {
return this._getPatchAt(this.maxPxcor, pycor - 1);
} else {
return this._getPatchAt(pxcor - 1, pycor - 1);
}
};
VertCylinder.prototype._getPatchSouthEast = function(pxcor, pycor) {
if (pycor === this.minPycor) {
return false;
} else if (pxcor === this.maxPxcor) {
return this._getPatchAt(this.minPxcor, pycor - 1);
} else {
return this._getPatchAt(pxcor + 1, pycor - 1);
}
};
VertCylinder.prototype._getPatchNorthEast = function(pxcor, pycor) {
if (pycor === this.maxPycor) {
return false;
} else if (pxcor === this.maxPxcor) {
return this._getPatchAt(this.minPxcor, pycor + 1);
} else {
return this._getPatchAt(pxcor + 1, pycor + 1);
}
};
VertCylinder.prototype._refineScratchPads = function(yy, xx, scratch, scratch2, coefficient) {
var diffuseVal, x, y, _i, _j, _ref, _ref1;
for (y = _i = yy, _ref = yy * 2; yy <= _ref ? _i < _ref : _i > _ref; y = yy <= _ref ? ++_i : --_i) {
for (x = _j = xx, _ref1 = xx * 2; xx <= _ref1 ? _j < _ref1 : _j > _ref1; x = xx <= _ref1 ? ++_j : --_j) {
diffuseVal = (scratch[x - xx][y - yy] / 8) * coefficient;
if ((yy < y && y < (yy * 2) - 1)) {
scratch2[x - xx][y - yy] += scratch[x - xx][y - yy] - (8 * diffuseVal);
scratch2[(x - 1) % xx][(y - 1) % yy] += diffuseVal;
scratch2[(x - 1) % xx][y % yy] += diffuseVal;
scratch2[(x - 1) % xx][(y + 1) % yy] += diffuseVal;
scratch2[x % xx][(y + 1) % yy] += diffuseVal;
scratch2[x % xx][(y - 1) % yy] += diffuseVal;
scratch2[(x + 1) % xx][(y - 1) % yy] += diffuseVal;
scratch2[(x + 1) % xx][y % yy] += diffuseVal;
scratch2[(x + 1) % xx][(y + 1) % yy] += diffuseVal;
} else if (y === yy) {
scratch2[x - xx][y - yy] += scratch[x - xx][y - yy] - (5 * diffuseVal);
scratch2[(x - 1) % xx][y % yy] += diffuseVal;
scratch2[(x - 1) % xx][(y + 1) % yy] += diffuseVal;
scratch2[x % xx][(y + 1) % yy] += diffuseVal;
scratch2[(x + 1) % xx][y % yy] += diffuseVal;
scratch2[(x + 1) % xx][(y + 1) % yy] += diffuseVal;
} else {
scratch2[x - xx][y - yy] += scratch[x - xx][y - yy] - (5 * diffuseVal);
scratch2[(x - 1) % xx][y % yy] += diffuseVal;
scratch2[(x - 1) % xx][(y - 1) % yy] += diffuseVal;
scratch2[x % xx][(y - 1) % yy] += diffuseVal;
scratch2[(x + 1) % xx][y % yy] += diffuseVal;
scratch2[(x + 1) % xx][(y - 1) % yy] += diffuseVal;
}
}
}
};
VertCylinder.prototype._shortestX = function(x1, x2) {
return this._shortestXWrapped(x1, x2);
};
VertCylinder.prototype._shortestY = function(y1, y2) {
return this._shortestNotWrapped(y1, y2);
};
return VertCylinder;
})(Topology);
}).call(this);
},{"./topology":"67eG/c"}],"engine/core/topology/vertcylinder":[function(require,module,exports){
module.exports=require('qudk3y');
},{}],"engine/core/turtle":[function(require,module,exports){
module.exports=require('d1H0D2');
},{}],"d1H0D2":[function(require,module,exports){
(function() {
var AbstractAgentSet, Comparator, Exception, Nobody, PenManager, Trig, Turtle, TurtleSet, VariableManager, _,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
_ = require('lodash');
AbstractAgentSet = require('./abstractagentset');
Nobody = require('./nobody');
TurtleSet = require('./turtleset');
PenManager = require('./structure/penmanager');
VariableManager = require('./structure/variablemanager');
Comparator = require('tortoise/util/comparator');
Exception = require('tortoise/util/exception');
Trig = require('tortoise/util/trig');
module.exports = Turtle = (function() {
Turtle.prototype._breed = void 0;
Turtle.prototype._links = void 0;
Turtle.prototype._shape = void 0;
Turtle.prototype._updateVarsByName = void 0;
Turtle.prototype._varManager = void 0;
function Turtle(world, id, genUpdate, _registerDeath, _createTurtle, _removeTurtle, _color, _heading, xcor, ycor, breed, _label, _labelcolor, _hidden, _size, penManager) {
var varNames;
this.world = world;
this.id = id;
this._registerDeath = _registerDeath;
this._createTurtle = _createTurtle;
this._removeTurtle = _removeTurtle;
this._color = _color != null ? _color : 0;
this._heading = _heading != null ? _heading : 0;
this.xcor = xcor != null ? xcor : 0;
this.ycor = ycor != null ? ycor : 0;
if (breed == null) {
breed = this.world.breedManager.turtles();
}
this._label = _label != null ? _label : "";
this._labelcolor = _labelcolor != null ? _labelcolor : 9.9;
this._hidden = _hidden != null ? _hidden : false;
this._size = _size != null ? _size : 1.0;
this.penManager = penManager != null ? penManager : new PenManager(genUpdate(this));
this.addLink = __bind(this.addLink, this);
this._updateVarsByName = genUpdate(this);
varNames = this.world.turtlesOwnNames.concat(breed.varNames);
this._varManager = this._genVarManager(varNames, world.turtleManager.turtlesOfBreed);
this._links = [];
this._setBreed(breed);
this.getPatchHere().trackTurtle(this);
}
Turtle.prototype.getBreedName = function() {
return this._breed.name;
};
Turtle.prototype._setXcor = function(newX, tiedCaller) {
var dx, oldX, originPatch, turtles;
if (tiedCaller == null) {
tiedCaller = void 0;
}
originPatch = this.getPatchHere();
oldX = this.xcor;
this.xcor = this.world.topology.wrapX(newX);
this._updateVarsByName("xcor");
if (originPatch !== this.getPatchHere()) {
originPatch.untrackTurtle(this);
this.getPatchHere().trackTurtle(this);
}
this._refreshLinks();
turtles = this._tiedTurtles();
dx = this.xcor - oldX;
turtles.fixeds.concat(turtles.others).forEach((function(_this) {
return function(turtle) {
if (turtle !== tiedCaller) {
turtle._setXcor(turtle.xcor + dx, _this);
}
};
})(this));
};
Turtle.prototype._setYcor = function(newY, tiedCaller) {
var dy, oldY, originPatch, turtles;
if (tiedCaller == null) {
tiedCaller = void 0;
}
originPatch = this.getPatchHere();
oldY = this.ycor;
this.ycor = this.world.topology.wrapY(newY);
this._updateVarsByName("ycor");
if (originPatch !== this.getPatchHere()) {
originPatch.untrackTurtle(this);
this.getPatchHere().trackTurtle(this);
}
this._refreshLinks();
turtles = this._tiedTurtles();
dy = this.ycor - oldY;
turtles.fixeds.concat(turtles.others).forEach((function(_this) {
return function(turtle) {
if (turtle !== tiedCaller) {
turtle._setYcor(turtle.ycor + dy, _this);
}
};
})(this));
};
Turtle.prototype.addLink = function(link) {
this._links.push(link);
};
Turtle.prototype.canMove = function(distance) {
return this.patchAhead(distance) !== Nobody;
};
Turtle.prototype.distance = function(agent) {
return this.world.topology.distance(this.xcor, this.ycor, agent);
};
Turtle.prototype.distanceXY = function(x, y) {
return this.world.topology.distanceXY(this.xcor, this.ycor, x, y);
};
Turtle.prototype.getCoords = function() {
return [this.xcor, this.ycor];
};
Turtle.prototype.towards = function(agent) {
var x, y, _ref;
_ref = agent.getCoords(), x = _ref[0], y = _ref[1];
return this.towardsXY(x, y);
};
Turtle.prototype.towardsXY = function(x, y) {
return this.world.topology.towards(this.xcor, this.ycor, x, y);
};
Turtle.prototype.faceXY = function(x, y) {
if (x !== this.xcor || y !== this.ycor) {
this._setHeading(this.world.topology.towards(this.xcor, this.ycor, x, y));
}
};
Turtle.prototype.face = function(agent) {
var x, y, _ref;
_ref = agent.getCoords(), x = _ref[0], y = _ref[1];
this.faceXY(x, y);
};
Turtle.prototype.inRadius = function(agents, radius) {
return this.world.topology.inRadius(this.xcor, this.ycor, agents, radius);
};
Turtle.prototype.patchAt = function(dx, dy) {
var error, x, y;
try {
x = this.world.topology.wrapX(this.xcor + dx);
y = this.world.topology.wrapY(this.ycor + dy);
return this.world.getPatchAt(x, y);
} catch (_error) {
error = _error;
if (error instanceof Exception.TopologyInterrupt) {
return Nobody;
} else {
throw error;
}
}
};
Turtle.prototype.turtlesAt = function(dx, dy) {
return this.getPatchHere().turtlesAt(dx, dy);
};
Turtle.prototype.connectedLinks = function(isDirected, isSource, breedName) {
var breedNameMatches, filterFunc;
if (breedName == null) {
breedName = "LINKS";
}
breedNameMatches = this._linkBreedMatches(breedName);
filterFunc = isDirected ? (function(_this) {
return function(link) {
return (link.isDirected && link.end1 === _this && isSource) || (link.isDirected && link.end2 === _this && !isSource);
};
})(this) : (function(_this) {
return function(link) {
return (!link.isDirected && link.end1 === _this) || (!link.isDirected && link.end2 === _this);
};
})(this);
return this.world.links().filter((function(_this) {
return function(x) {
return breedNameMatches(x) && filterFunc(x);
};
})(this));
};
Turtle.prototype.linkNeighbors = function(isDirected, isSource, breedName) {
var breedNameMatches, reductionFunc, turtles;
breedNameMatches = this._linkBreedMatches(breedName);
reductionFunc = isDirected ? (function(_this) {
return function(acc, link) {
if (breedNameMatches(link)) {
if (link.isDirected && link.end1 === _this && isSource) {
acc.push(link.end2);
} else if (link.isDirected && link.end2 === _this && !isSource) {
acc.push(link.end1);
}
}
return acc;
};
})(this) : (function(_this) {
return function(acc, link) {
if (breedNameMatches(link)) {
if (!link.isDirected && link.end1 === _this) {
acc.push(link.end2);
} else if (!link.isDirected && link.end2 === _this) {
acc.push(link.end1);
}
}
return acc;
};
})(this);
turtles = world.links().toArray().reduce(reductionFunc, []);
return new TurtleSet(turtles);
};
Turtle.prototype.isLinkNeighbor = function(isDirected, isSource, breedName, otherTurtle) {
return this.linkNeighbors(isDirected, isSource, breedName).contains(otherTurtle);
};
Turtle.prototype.findLinkViaNeighbor = function(isDirected, isSource, breedName, otherTurtle) {
var breedNameMatches, findFunc, _ref;
breedNameMatches = this._linkBreedMatches(breedName);
findFunc = (function() {
if (isDirected) {
return (function(_this) {
return function(link) {
var isDirectedFromMe, isDirectedToMe;
isDirectedFromMe = link.isDirected && link.end1 === _this && link.end2 === otherTurtle && isSource;
isDirectedToMe = link.isDirected && link.end1 === otherTurtle && link.end2 === _this && !isSource;
return breedNameMatches(link) && (isDirectedFromMe || isDirectedToMe);
};
})(this);
} else if (!isDirected && !this.world.breedManager.links().isDirected()) {
return (function(_this) {
return function(link) {
var isFromMe, isToMe;
isFromMe = !link.isDirected && link.end1 === _this && link.end2 === otherTurtle;
isToMe = !link.isDirected && link.end2 === _this && link.end1 === otherTurtle;
return breedNameMatches(link) && (isFromMe || isToMe);
};
})(this);
} else {
throw new Error("LINKS is a directed breed.");
}
}).call(this);
return (_ref = this.world.links().find(findFunc)) != null ? _ref : Nobody;
};
Turtle.prototype.otherEnd = function() {
if (this === this.world.selfManager.myself().end1) {
return this.world.selfManager.myself().end2;
} else {
return this.world.selfManager.myself().end1;
}
};
Turtle.prototype.patchRightAndAhead = function(angle, distance) {
var error, heading, newX, newY;
heading = this._normalizeHeading(this._heading + angle);
try {
newX = this.world.topology.wrapX(this.xcor + distance * Trig.sin(heading));
newY = this.world.topology.wrapY(this.ycor + distance * Trig.cos(heading));
return this.world.getPatchAt(newX, newY);
} catch (_error) {
error = _error;
if (error instanceof Exception.TopologyInterrupt) {
return Nobody;
} else {
throw error;
}
}
};
Turtle.prototype.patchLeftAndAhead = function(angle, distance) {
return this.patchRightAndAhead(-angle, distance);
};
Turtle.prototype.patchAhead = function(distance) {
return this.patchRightAndAhead(0, distance);
};
Turtle.prototype.ask = function(f) {
this.world.selfManager.askAgent(f)(this);
if (this.world.selfManager.self().id === -1) {
throw new Exception.DeathInterrupt;
}
};
Turtle.prototype.projectionBy = function(f) {
if (!this._isDead()) {
return this.world.selfManager.askAgent(f)(this);
} else {
throw new Error("That " + this._breed.singular + " is dead.");
}
};
Turtle.prototype.fd = function(distance) {
var increment, remaining;
increment = distance > 0 ? 1 : -1;
remaining = distance;
if (distance > 0) {
while (remaining >= increment && this.jumpIfAble(increment)) {
remaining -= increment;
}
} else if (distance < 0) {
while (remaining <= increment && this.jumpIfAble(increment)) {
remaining -= increment;
}
}
this.jumpIfAble(remaining);
};
Turtle.prototype.jumpIfAble = function(distance) {
var canMove;
canMove = this.canMove(distance);
if (canMove) {
this._jump(distance);
}
return canMove;
};
Turtle.prototype._jump = function(distance) {
this._setXcor(this.xcor + distance * this.dx());
this._setYcor(this.ycor + distance * this.dy());
};
Turtle.prototype.dx = function() {
return Trig.sin(this._heading);
};
Turtle.prototype.dy = function() {
return Trig.cos(this._heading);
};
Turtle.prototype.right = function(angle, tiedCaller) {
var newHeading;
if (tiedCaller == null) {
tiedCaller = void 0;
}
newHeading = this._heading + angle;
this._setHeading(this._normalizeHeading(newHeading), tiedCaller);
};
Turtle.prototype.setXY = function(x, y, tiedCaller) {
var error, origXcor, origYcor;
if (tiedCaller == null) {
tiedCaller = void 0;
}
origXcor = this.xcor;
origYcor = this.ycor;
try {
this._setXcor(x, tiedCaller);
this._setYcor(y, tiedCaller);
} catch (_error) {
error = _error;
this._setXcor(origXcor, tiedCaller);
this._setYcor(origYcor, tiedCaller);
if (error instanceof Exception.TopologyInterrupt) {
throw new Exception.TopologyInterrupt("The point [ " + x + " , " + y + " ] is outside of the boundaries of the world and wrapping is not permitted in one or both directions.");
} else {
throw error;
}
}
};
Turtle.prototype.hideTurtle = function(shouldHide) {
this._setIsHidden(shouldHide);
};
Turtle.prototype.isBreed = function(breedName) {
return this._breed.name.toUpperCase() === breedName.toUpperCase();
};
Turtle.prototype.die = function() {
this._breed.remove(this);
if (this.id !== -1) {
this._removeTurtle(this.id);
this._seppuku();
this.world.links().forEach((function(_this) {
return function(link) {
var error;
if (link.end1.id === _this.id || link.end2.id === _this.id) {
try {
link.die();
} catch (_error) {
error = _error;
if (!(error instanceof Exception.DeathInterrupt)) {
throw error;
}
}
}
};
})(this));
this.id = -1;
this.getPatchHere().untrackTurtle(this);
this.world.observer.unfocus(this);
}
throw new Exception.DeathInterrupt("Call only from inside an askAgent block");
};
Turtle.prototype.getVariable = function(varName) {
return this._varManager[varName];
};
Turtle.prototype.setVariable = function(varName, value) {
this._varManager[varName] = value;
};
Turtle.prototype.getPatchHere = function() {
return this.world.getPatchAt(this.xcor, this.ycor);
};
Turtle.prototype.getPatchVariable = function(varName) {
return this.getPatchHere().getVariable(varName);
};
Turtle.prototype.setPatchVariable = function(varName, value) {
this.getPatchHere().setVariable(varName, value);
};
Turtle.prototype.getNeighbors = function() {
return this.getPatchHere().getNeighbors();
};
Turtle.prototype.getNeighbors4 = function() {
return this.getPatchHere().getNeighbors4();
};
Turtle.prototype.turtlesHere = function() {
return this.getPatchHere().turtlesHere();
};
Turtle.prototype.breedHere = function(breedName) {
return this.getPatchHere().breedHere(breedName);
};
Turtle.prototype.hatch = function(n, breedName) {
var breed, isNameValid, newTurtles;
isNameValid = (breedName != null) && !_(breedName).isEmpty();
breed = isNameValid ? this.world.breedManager.get(breedName) : this._breed;
newTurtles = _(0).range(n).map((function(_this) {
return function() {
return _this._makeTurtleCopy(breed);
};
})(this)).value();
return new TurtleSet(newTurtles, breed);
};
Turtle.prototype._makeTurtleCopy = function(breed) {
var turtle;
turtle = this._createTurtle(this._color, this._heading, this.xcor, this.ycor, breed, this._label, this._labelcolor, this._hidden, this._size, this.penManager.clone());
_(this.world.turtlesOwnNames).forEach((function(_this) {
return function(varName) {
turtle.setVariable(varName, _this.getVariable(varName));
};
})(this));
return turtle;
};
Turtle.prototype.moveTo = function(agent) {
var x, y, _ref;
_ref = agent.getCoords(), x = _ref[0], y = _ref[1];
this.setXY(x, y);
};
Turtle.prototype.followMe = function() {
this.world.observer.follow(this);
};
Turtle.prototype.rideMe = function() {
this.world.observer.ride(this);
};
Turtle.prototype.watchMe = function() {
this.world.observer.watch(this);
};
Turtle.prototype.removeLink = function(link) {
this._links.splice(this._links.indexOf(link));
};
Turtle.prototype.compare = function(x) {
if (x instanceof Turtle) {
return Comparator.numericCompare(this.id, x.id);
} else {
return Comparator.NOT_EQUALS;
}
};
Turtle.prototype.toString = function() {
if (!this._isDead()) {
return "(" + this._breed.singular + " " + this.id + ")";
} else {
return "nobody";
}
};
Turtle.prototype._isDead = function() {
return this.id === -1;
};
Turtle.prototype._linkBreedMatches = function(breedName) {
return function(link) {
return breedName === "LINKS" || breedName === link.getBreedName();
};
};
Turtle.prototype._normalizeHeading = function(heading) {
if ((0 <= heading && heading < 360)) {
return heading;
} else {
return ((heading % 360) + 360) % 360;
}
};
Turtle.prototype._refreshLinks = function() {
var linkTypes;
if (!_(this._links).isEmpty()) {
linkTypes = [[true, true], [true, false], [false, false]];
_(linkTypes).map((function(_this) {
return function(_arg) {
var isDirected, isSource;
isDirected = _arg[0], isSource = _arg[1];
return _this.connectedLinks(isDirected, isSource).toArray();
};
})(this)).flatten().forEach(function(link) {
link.updateEndRelatedVars();
});
}
};
Turtle.prototype._seppuku = function() {
this._registerDeath(this.id);
};
Turtle.prototype._tiedTurtles = function() {
var f, filterFunc, fixeds, links, others, _ref;
filterFunc = (function(_this) {
return function(link) {
return link.tiemode !== "none" && ((link.end1 === _this) || (link.end2 === _this && !link.isDirected));
};
})(this);
links = this.world.links().filter(filterFunc).toArray();
f = (function(_this) {
return function(_arg, link) {
var fixeds, others, turtle;
fixeds = _arg[0], others = _arg[1];
turtle = link.end1 === _this ? link.end2 : link.end1;
if (link.tiemode === "fixed") {
return [fixeds.concat([turtle]), others];
} else {
return [fixeds, others.concat([turtle])];
}
};
})(this);
_ref = _(links).foldl(f, [[], []]), fixeds = _ref[0], others = _ref[1];
return {
fixeds: fixeds,
others: others
};
};
Turtle.prototype._genVarManager = function(extraVarNames, getTurtlesByBreedName) {
var varBundles;
varBundles = [
{
name: 'breed',
get: ((function(_this) {
return function() {
return getTurtlesByBreedName(_this._breed.name);
};
})(this)),
set: ((function(_this) {
return function(x) {
return _this._setBreed(x);
};
})(this))
}, {
name: 'color',
get: ((function(_this) {
return function() {
return _this._color;
};
})(this)),
set: ((function(_this) {
return function(x) {
return _this._setColor(x);
};
})(this))
}, {
name: 'heading',
get: ((function(_this) {
return function() {
return _this._heading;
};
})(this)),
set: ((function(_this) {
return function(x) {
return _this._setHeading(x);
};
})(this))
}, {
name: 'hidden?',
get: ((function(_this) {
return function() {
return _this._hidden;
};
})(this)),
set: ((function(_this) {
return function(x) {
return _this._setIsHidden(x);
};
})(this))
}, {
name: 'label',
get: ((function(_this) {
return function() {
return _this._label;
};
})(this)),
set: ((function(_this) {
return function(x) {
return _this._setLabel(x);
};
})(this))
}, {
name: 'label-color',
get: ((function(_this) {
return function() {
return _this._labelcolor;
};
})(this)),
set: ((function(_this) {
return function(x) {
return _this._setLabelColor(x);
};
})(this))
}, {
name: 'pen-mode',
get: ((function(_this) {
return function() {
return _this.penManager.getMode().toString();
};
})(this)),
set: ((function(_this) {
return function(x) {
return _this.penManager.setPenMode(x);
};
})(this))
}, {
name: 'pen-size',
get: ((function(_this) {
return function() {
return _this.penManager.getSize();
};
})(this)),
set: ((function(_this) {
return function(x) {
return _this.penManager.setSize(x);
};
})(this))
}, {
name: 'shape',
get: ((function(_this) {
return function() {
return _this._shape;
};
})(this)),
set: ((function(_this) {
return function(x) {
return _this._setShape(x);
};
})(this))
}, {
name: 'size',
get: ((function(_this) {
return function() {
return _this._size;
};
})(this)),
set: ((function(_this) {
return function(x) {
return _this._setSize(x);
};
})(this))
}, {
name: 'who',
get: ((function(_this) {
return function() {
return _this.id;
};
})(this)),
set: (function() {})
}, {
name: 'xcor',
get: ((function(_this) {
return function() {
return _this.xcor;
};
})(this)),
set: ((function(_this) {
return function(x) {
return _this._setXcor(x);
};
})(this))
}, {
name: 'ycor',
get: ((function(_this) {
return function() {
return _this.ycor;
};
})(this)),
set: ((function(_this) {
return function(x) {
return _this._setYcor(x);
};
})(this))
}
];
return new VariableManager(extraVarNames, varBundles);
};
Turtle.prototype._genVarUpdate = function(varName) {
this._updateVarsByName(varName);
};
/*
"Jason, this is craziness!", you say. "Not quite," I say. It _is_ kind of lame, but changing turtle members
needs to be controlled, so that all changes cause updates to be triggered. And since the `VariableManager` needs
to know how to set all of the variables, we may as well declare the code for that in a place where it can be
easily reused. --JAB (6/2/14)
*/
Turtle.prototype._setBreed = function(breed) {
var freshNames, newNames, obsoletedNames, oldNames, trueBreed;
trueBreed = (function() {
if (_(breed).isString()) {
return this.world.breedManager.get(breed);
} else if (breed instanceof AbstractAgentSet) {
if (breed.getBreedName != null) {
return this.world.breedManager.get(breed.getBreedName());
} else {
throw new Error("You can't set BREED to a non-breed agentset.");
}
} else {
return breed;
}
}).call(this);
if (this._breed !== trueBreed) {
trueBreed.add(this);
newNames = trueBreed.varNames;
oldNames = this._breed != null ? (this._breed.remove(this), this._breed.varNames) : [];
obsoletedNames = _(oldNames).difference(newNames).value();
freshNames = _(newNames).difference(oldNames).value();
this._varManager.refineBy(obsoletedNames)(freshNames);
}
this._breed = trueBreed;
this._genVarUpdate("breed");
this._setShape(trueBreed.getShape());
if (trueBreed !== this.world.breedManager.turtles()) {
this.world.breedManager.turtles().add(this);
}
};
Turtle.prototype._setColor = function(color) {
this._color = ColorModel.wrapColor(color);
this._genVarUpdate("color");
};
Turtle.prototype._setHeading = function(heading, tiedCaller) {
var dh, oldHeading, turtles, x, y, _ref;
if (tiedCaller == null) {
tiedCaller = void 0;
}
oldHeading = this._heading;
this._heading = this._normalizeHeading(heading);
this._genVarUpdate("heading");
dh = this._heading - oldHeading;
_ref = this.getCoords(), x = _ref[0], y = _ref[1];
turtles = this._tiedTurtles();
turtles.fixeds.forEach((function(_this) {
return function(turtle) {
if (turtle !== tiedCaller) {
turtle.right(dh, _this);
}
};
})(this));
turtles.fixeds.concat(turtles.others).forEach((function(_this) {
return function(turtle) {
var newX, newY, r, theta, tx, ty, _ref1;
if (turtle !== tiedCaller) {
r = _this.distance(turtle);
_ref1 = turtle.getCoords(), tx = _ref1[0], ty = _ref1[1];
theta = StrictMath.toDegrees(StrictMath.atan2(ty - y, x - tx)) - 90 + dh;
newX = x + r * Trig.sin(theta);
newY = y + r * Trig.cos(theta);
turtle.setXY(newX, newY, _this);
}
};
})(this));
};
Turtle.prototype._setIsHidden = function(isHidden) {
this._hidden = isHidden;
this._genVarUpdate("hidden?");
};
Turtle.prototype._setLabel = function(label) {
this._label = label;
this._genVarUpdate("label");
};
Turtle.prototype._setLabelColor = function(color) {
this._labelcolor = ColorModel.wrapColor(color);
this._genVarUpdate("label-color");
};
Turtle.prototype._setShape = function(shape) {
this._shape = shape.toLowerCase();
this._genVarUpdate("shape");
};
Turtle.prototype._setSize = function(size) {
this._size = size;
this._genVarUpdate("size");
};
return Turtle;
})();
}).call(this);
},{"./abstractagentset":"H2TUw+","./nobody":"xMfcne","./structure/penmanager":"KmqHcj","./structure/variablemanager":"OHTrEx","./turtleset":"4S23fo","lodash":"4HJaAd","tortoise/util/comparator":11,"tortoise/util/exception":12,"tortoise/util/trig":18}],"4S23fo":[function(require,module,exports){
(function() {
var AbstractAgentSet, DeadSkippingIterator, TurtleSet,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
AbstractAgentSet = require('./abstractagentset');
DeadSkippingIterator = require('./structure/deadskippingiterator');
module.exports = TurtleSet = (function(_super) {
__extends(TurtleSet, _super);
function TurtleSet(_agents, _breedName, _specialName) {
this._agents = _agents;
this._breedName = _breedName != null ? _breedName : "TURTLES";
this._specialName = _specialName;
TurtleSet.__super__.constructor.call(this, this._agents);
}
TurtleSet.prototype.getBreedName = function() {
return this._breedName;
};
TurtleSet.prototype.iterator = function() {
return new DeadSkippingIterator(this._agents);
};
TurtleSet.prototype.toString = function() {
var _ref;
return (_ref = this._specialName) != null ? _ref : "(agentset, " + (this.size()) + " " + (this.getBreedName().toLowerCase()) + ")";
};
TurtleSet.prototype._generateFrom = function(newAgentArr, agents) {
return new TurtleSet(newAgentArr, agents.getBreedName());
};
return TurtleSet;
})(AbstractAgentSet);
}).call(this);
},{"./abstractagentset":"H2TUw+","./structure/deadskippingiterator":"6ZdcXg"}],"engine/core/turtleset":[function(require,module,exports){
module.exports=require('4S23fo');
},{}],"8ahyeg":[function(require,module,exports){
(function() {
var Exception, LinkManager, Nobody, Observer, Patch, PatchSet, StrictMath, Ticker, TurtleManager, World, topologyFactory,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
Nobody = require('./nobody');
Observer = require('./observer');
Patch = require('./patch');
PatchSet = require('./patchset');
topologyFactory = require('./topology/factory');
LinkManager = require('./world/linkmanager');
Ticker = require('./world/ticker');
TurtleManager = require('./world/turtlemanager');
StrictMath = require('tortoise/shim/strictmath');
Exception = require('tortoise/util/exception');
module.exports = World = (function() {
World.prototype.id = 0;
World.prototype.linkManager = void 0;
World.prototype.observer = void 0;
World.prototype.ticker = void 0;
World.prototype.topology = void 0;
World.prototype.turtleManager = void 0;
World.prototype._patches = void 0;
World.prototype._patchesAllBlack = void 0;
World.prototype._patchesWithLabels = void 0;
function World(selfManager, _updater, breedManager, globalNames, interfaceGlobalNames, turtlesOwnNames, linksOwnNames, patchesOwnNames, minPxcor, maxPxcor, minPycor, maxPycor, _patchSize, wrappingAllowedInX, wrappingAllowedInY, turtleShapeList, linkShapeList) {
this.selfManager = selfManager;
this._updater = _updater;
this.breedManager = breedManager;
this.turtlesOwnNames = turtlesOwnNames;
this.linksOwnNames = linksOwnNames;
this.patchesOwnNames = patchesOwnNames;
this._declarePatchesNotAllBlack = __bind(this._declarePatchesNotAllBlack, this);
this._setUnbreededLinksUndirected = __bind(this._setUnbreededLinksUndirected, this);
this._setUnbreededLinksDirected = __bind(this._setUnbreededLinksDirected, this);
this._decrementPatchLabelCount = __bind(this._decrementPatchLabelCount, this);
this._incrementPatchLabelCount = __bind(this._incrementPatchLabelCount, this);
this.getPatchAt = __bind(this.getPatchAt, this);
this.patches = __bind(this.patches, this);
this._updater.collectUpdates();
this._updater.registerWorldState({
worldWidth: maxPxcor - minPxcor + 1,
worldHeight: maxPycor - minPycor + 1,
minPxcor: minPxcor,
minPycor: minPycor,
maxPxcor: maxPxcor,
maxPycor: maxPycor,
linkBreeds: "XXX IMPLEMENT ME",
linkShapeList: linkShapeList,
patchSize: _patchSize,
patchesAllBlack: this._patchesAllBlack,
patchesWithLabels: this._patchesWithLabels,
ticks: -1,
turtleBreeds: "XXX IMPLEMENT ME",
turtleShapeList: turtleShapeList,
unbreededLinksAreDirected: false,
wrappingAllowedInX: wrappingAllowedInX,
wrappingAllowedInY: wrappingAllowedInY
});
this.linkManager = new LinkManager(this, breedManager, _updater, this._setUnbreededLinksDirected, this._setUnbreededLinksUndirected);
this.observer = new Observer(this._updater.updated, globalNames, interfaceGlobalNames);
this.ticker = new Ticker(this._updater.updated(this));
this.topology = null;
this.turtleManager = new TurtleManager(this, breedManager, _updater);
this._patches = [];
this._patchesAllBlack = true;
this._patchesWithLabels = 0;
this.resize(minPxcor, maxPxcor, minPycor, maxPycor, wrappingAllowedInX, wrappingAllowedInY);
}
World.prototype.createPatches = function() {
var id, nested, patch, x, y, _i, _len, _ref, _ref1;
nested = (function() {
var _i, _ref, _ref1, _results;
_results = [];
for (y = _i = _ref = this.topology.maxPycor, _ref1 = this.topology.minPycor; _ref <= _ref1 ? _i <= _ref1 : _i >= _ref1; y = _ref <= _ref1 ? ++_i : --_i) {
_results.push((function() {
var _j, _ref2, _ref3, _results1;
_results1 = [];
for (x = _j = _ref2 = this.topology.minPxcor, _ref3 = this.topology.maxPxcor; _ref2 <= _ref3 ? _j <= _ref3 : _j >= _ref3; x = _ref2 <= _ref3 ? ++_j : --_j) {
id = (this.topology.width * (this.topology.maxPycor - y)) + x - this.topology.minPxcor;
_results1.push(new Patch(id, x, y, this, this._updater.updated, this._declarePatchesNotAllBlack, this._decrementPatchLabelCount, this._incrementPatchLabelCount));
}
return _results1;
}).call(this));
}
return _results;
}).call(this);
this._patches = (_ref = []).concat.apply(_ref, nested);
_ref1 = this._patches;
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
patch = _ref1[_i];
this._updater.updated(patch)("pxcor", "pycor", "pcolor", "plabel", "plabel-color");
}
};
World.prototype.links = function() {
return this.linkManager.links();
};
World.prototype.turtles = function() {
return this.turtleManager.turtles();
};
World.prototype.patches = function() {
return new PatchSet(this._patches, "patches");
};
World.prototype.resize = function(minPxcor, maxPxcor, minPycor, maxPycor, wrapsInX, wrapsInY) {
if (wrapsInX == null) {
wrapsInX = this.topology._wrapInX;
}
if (wrapsInY == null) {
wrapsInY = this.topology._wrapInY;
}
if (!((minPxcor <= 0 && 0 <= maxPxcor) && (minPycor <= 0 && 0 <= maxPycor))) {
throw new Error("You must include the point (0, 0) in the world.");
}
this.turtleManager._clearTurtlesSuspended();
this.changeTopology(wrapsInX, wrapsInY, minPxcor, maxPxcor, minPycor, maxPycor);
this.createPatches();
this._declarePatchesAllBlack();
this._resetPatchLabelCount();
this._updater.updated(this)("width", "height", "minPxcor", "minPycor", "maxPxcor", "maxPycor");
};
World.prototype.changeTopology = function(wrapsInX, wrapsInY, minX, maxX, minY, maxY) {
if (minX == null) {
minX = this.topology.minPxcor;
}
if (maxX == null) {
maxX = this.topology.maxPxcor;
}
if (minY == null) {
minY = this.topology.minPycor;
}
if (maxY == null) {
maxY = this.topology.maxPycor;
}
this.topology = topologyFactory(wrapsInX, wrapsInY, minX, maxX, minY, maxY, this.patches, this.getPatchAt);
};
World.prototype.getPatchAt = function(x, y) {
var error, index, trueX, trueY;
try {
trueX = this.topology.wrapX(x);
trueY = this.topology.wrapY(y);
index = (this.topology.maxPycor - StrictMath.round(trueY)) * this.topology.width + (StrictMath.round(trueX) - this.topology.minPxcor);
return this._patches[index];
} catch (_error) {
error = _error;
if (error instanceof Exception.TopologyInterrupt) {
return Nobody;
} else {
throw error;
}
}
};
World.prototype.clearAll = function() {
this.observer.clearCodeGlobals();
this.observer.resetPerspective();
this.turtleManager.clearTurtles();
this.createPatches();
this.linkManager._resetIDs();
this._declarePatchesAllBlack();
this._resetPatchLabelCount();
this.ticker.clear();
};
World.prototype.clearPatches = function() {
this.patches().forEach(function(patch) {
patch.reset();
});
this._declarePatchesAllBlack();
this._resetPatchLabelCount();
};
World.prototype.getNeighbors = function(pxcor, pycor) {
return new PatchSet(this.topology.getNeighbors(pxcor, pycor));
};
World.prototype.getNeighbors4 = function(pxcor, pycor) {
return new PatchSet(this.topology.getNeighbors4(pxcor, pycor));
};
World.prototype._incrementPatchLabelCount = function() {
this._setPatchLabelCount(function(count) {
return count + 1;
});
};
World.prototype._decrementPatchLabelCount = function() {
this._setPatchLabelCount(function(count) {
return count - 1;
});
};
World.prototype._resetPatchLabelCount = function() {
this._setPatchLabelCount(function() {
return 0;
});
};
World.prototype._setPatchLabelCount = function(updateCountFunc) {
this._patchesWithLabels = updateCountFunc(this._patchesWithLabels);
this._updater.updated(this)("patchesWithLabels");
};
World.prototype._setUnbreededLinksDirected = function() {
this.breedManager.setUnbreededLinksDirected();
this._updater.updated(this)("unbreededLinksAreDirected");
};
World.prototype._setUnbreededLinksUndirected = function() {
this.breedManager.setUnbreededLinksUndirected();
this._updater.updated(this)("unbreededLinksAreDirected");
};
World.prototype._declarePatchesAllBlack = function() {
this._patchesAllBlack = true;
this._updater.updated(this)("patchesAllBlack");
};
World.prototype._declarePatchesNotAllBlack = function() {
this._patchesAllBlack = false;
this._updater.updated(this)("patchesAllBlack");
};
return World;
})();
}).call(this);
},{"./nobody":"xMfcne","./observer":"2IE8Rg","./patch":"t5DuqE","./patchset":"yG3HYq","./topology/factory":"tkIP+/","./world/linkmanager":"3oC7No","./world/ticker":"7rhyJn","./world/turtlemanager":"9OrcFc","tortoise/shim/strictmath":8,"tortoise/util/exception":12}],"engine/core/world":[function(require,module,exports){
module.exports=require('8ahyeg');
},{}],"engine/core/world/idmanager":[function(require,module,exports){
module.exports=require('MQpYgZ');
},{}],"MQpYgZ":[function(require,module,exports){
(function() {
var IDManager;
module.exports = IDManager = (function() {
IDManager.prototype._count = void 0;
function IDManager() {
this.reset();
}
IDManager.prototype.reset = function() {
this._count = 0;
};
IDManager.prototype.next = function() {
return this._count++;
};
IDManager.prototype.suspendDuring = function(f) {
var oldCount;
oldCount = this._count;
f();
this._count = oldCount;
};
return IDManager;
})();
}).call(this);
},{}],"3oC7No":[function(require,module,exports){
(function() {
var Builtins, IDManager, Link, LinkManager, LinkSet, Nobody, SortedLinks, stableSort, _,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
_ = require('lodash');
Link = require('../link');
LinkSet = require('../linkset');
Nobody = require('../nobody');
Builtins = require('../structure/builtins');
IDManager = require('./idmanager');
SortedLinks = require('./sortedlinks');
stableSort = require('tortoise/util/stablesort');
module.exports = LinkManager = (function() {
LinkManager.prototype._links = void 0;
LinkManager.prototype._linksFrom = void 0;
LinkManager.prototype._idManager = void 0;
LinkManager.prototype._linksTo = void 0;
function LinkManager(_world, _breedManager, _updater, _notifyIsDirected, _notifyIsUndirected) {
this._world = _world;
this._breedManager = _breedManager;
this._updater = _updater;
this._notifyIsDirected = _notifyIsDirected;
this._notifyIsUndirected = _notifyIsUndirected;
this._removeLink = __bind(this._removeLink, this);
this.linksOfBreed = __bind(this.linksOfBreed, this);
this._links = new SortedLinks;
this._linksFrom = {};
this._idManager = new IDManager;
this._linksTo = {};
}
LinkManager.prototype.createDirectedLink = function(from, to, breedName) {
if (breedName.toUpperCase() === "LINKS") {
this._notifyIsDirected();
}
return this._createLink(true, from, to, breedName);
};
LinkManager.prototype.createDirectedLinks = function(source, others, breedName) {
if (breedName.toUpperCase() === "LINKS") {
this._notifyIsDirected();
}
return this._createLinksBy((function(_this) {
return function(turtle) {
return _this._createLink(true, source, turtle, breedName);
};
})(this))(others);
};
LinkManager.prototype.createReverseDirectedLinks = function(source, others, breedName) {
if (breedName.toUpperCase() === "LINKS") {
this._notifyIsDirected();
}
return this._createLinksBy((function(_this) {
return function(turtle) {
return _this._createLink(true, turtle, source, breedName);
};
})(this))(others);
};
LinkManager.prototype.createUndirectedLink = function(source, other, breedName) {
return this._createLink(false, source, other, breedName);
};
LinkManager.prototype.createUndirectedLinks = function(source, others, breedName) {
return this._createLinksBy((function(_this) {
return function(turtle) {
return _this._createLink(false, source, turtle, breedName);
};
})(this))(others);
};
LinkManager.prototype.getLink = function(fromId, toId, breedName) {
var findFunc, isDirected, _ref;
if (breedName == null) {
breedName = "LINKS";
}
isDirected = this._breedManager.get(breedName).isDirected();
findFunc = function(link) {
return link.getBreedName().toLowerCase() === breedName.toLowerCase() && (link.end1.id === fromId && link.end2.id === toId) || (!isDirected && link.end1.id === toId && link.end2.id === fromId);
};
return (_ref = this._links.find(findFunc)) != null ? _ref : Nobody;
};
LinkManager.prototype.links = function() {
var thunk;
thunk = ((function(_this) {
return function() {
return _this._links.toArray();
};
})(this));
return new LinkSet(thunk, "LINKS", "links");
};
LinkManager.prototype.linksOfBreed = function(breedName) {
var thunk;
thunk = ((function(_this) {
return function() {
return stableSort(_this._breedManager.get(breedName).members)(function(x, y) {
return x.compare(y).toInt;
});
};
})(this));
return new LinkSet(thunk, breedName, breedName);
};
LinkManager.prototype._removeLink = function(link) {
var l, remove;
l = this._links.find(function(l) {
return l.id === link.id;
});
this._links = this._links.remove(l);
if (this._links.isEmpty()) {
this._notifyIsUndirected();
}
remove = function(set, id1, id2) {
if (set != null) {
return set[id1] = _(set[id1]).without(id2).value();
}
};
remove(this._linksFrom[link.getBreedName()], link.end1.id, link.end2.id);
if (!link.isDirected) {
remove(this._linksTo[link.getBreedName()], link.end2.id, link.end1.id);
}
};
LinkManager.prototype._resetIDs = function() {
return this._idManager.reset();
};
LinkManager.prototype._createLink = function(isDirected, from, to, breedName) {
var breed, end1, end2, link, _ref;
_ref = from.id < to.id || isDirected ? [from, to] : [to, from], end1 = _ref[0], end2 = _ref[1];
if (!this._linkExists(end1.id, end2.id, isDirected, breedName)) {
breed = this._breedManager.get(breedName);
link = new Link(this._idManager.next(), isDirected, end1, end2, this._world, this._updater.updated, this._updater.registerDeadLink, this._removeLink, this.linksOfBreed, breed);
this._updater.updated(link).apply(null, Builtins.linkBuiltins);
this._updater.updated(link).apply(null, Builtins.linkExtras);
this._links.insert(link);
this._insertIntoSets(end1.id, end2.id, isDirected, breedName);
return link;
} else {
return Nobody;
}
};
LinkManager.prototype._createLinksBy = function(mkLink) {
return function(turtles) {
var isLink, links;
isLink = function(other) {
return other !== Nobody;
};
links = turtles.toArray().map(mkLink).filter(isLink);
return new LinkSet(links);
};
};
LinkManager.prototype._insertIntoSets = function(fromID, toID, isDirected, breedName) {
var insertIntoSet;
insertIntoSet = function(set, id1, id2) {
var neighbors;
if (set[breedName] == null) {
set[breedName] = {};
}
neighbors = set[breedName][id1];
if (neighbors != null) {
return neighbors.push(id2);
} else {
return set[breedName][id1] = [id2];
}
};
insertIntoSet(this._linksFrom, fromID, toID);
if (!isDirected) {
insertIntoSet(this._linksTo, toID, fromID);
}
};
LinkManager.prototype._linkExists = function(id1, id2, isDirected, breedName) {
var _ref, _ref1;
return _((_ref = this._linksFrom[breedName]) != null ? _ref[id1] : void 0).contains(id2) || (!isDirected && _((_ref1 = this._linksTo[breedName]) != null ? _ref1[id1] : void 0).contains(id2));
};
return LinkManager;
})();
}).call(this);
},{"../link":"r3RBLf","../linkset":"I7p8+g","../nobody":"xMfcne","../structure/builtins":"B6cYv5","./idmanager":"MQpYgZ","./sortedlinks":"8zgRob","lodash":"4HJaAd","tortoise/util/stablesort":16}],"engine/core/world/linkmanager":[function(require,module,exports){
module.exports=require('3oC7No');
},{}],"engine/core/world/sortedlinks":[function(require,module,exports){
module.exports=require('8zgRob');
},{}],"8zgRob":[function(require,module,exports){
(function() {
var Mori, SortedLinks, linkCompare;
linkCompare = require('../structure/linkcompare');
Mori = require('mori');
module.exports = SortedLinks = (function() {
SortedLinks._links = void 0;
function SortedLinks() {
this._links = Mori.sorted_set_by(linkCompare);
}
SortedLinks.prototype.insert = function(link) {
this._links = Mori.conj(this._links, link);
return this;
};
SortedLinks.prototype.remove = function(link) {
this._links = Mori.disj(this._links, link);
return this;
};
SortedLinks.prototype.find = function(pred) {
return Mori.first(Mori.filter(pred, this._links));
};
SortedLinks.prototype.isEmpty = function() {
return Mori.is_empty(this._links);
};
SortedLinks.prototype.toArray = function() {
return Mori.clj_to_js(this._links);
};
return SortedLinks;
})();
}).call(this);
},{"../structure/linkcompare":"2uDRqE","mori":"ekOHxz"}],"7rhyJn":[function(require,module,exports){
(function() {
var Exception, Ticker;
Exception = require('tortoise/util/exception');
module.exports = Ticker = (function() {
Ticker.prototype._count = void 0;
function Ticker(_updateFunc) {
this._updateFunc = _updateFunc;
this._count = -1;
}
Ticker.prototype.reset = function() {
this._updateTicks(function() {
return 0;
});
};
Ticker.prototype.clear = function() {
this._updateTicks(function() {
return -1;
});
};
Ticker.prototype.tick = function() {
if (this._count === -1) {
throw new Error("The tick counter has not been started yet. Use RESET-TICKS.");
} else {
this._updateTicks(function(counter) {
return counter + 1;
});
}
};
Ticker.prototype.tickAdvance = function(n) {
if (this._count === -1) {
throw new Error("The tick counter has not been started yet. Use RESET-TICKS.");
} else if (n < 0) {
throw new Error("Cannot advance the tick counter by a negative amount.");
} else {
this._updateTicks(function(counter) {
return counter + n;
});
}
};
Ticker.prototype.tickCount = function() {
if (this._count === -1) {
throw new Error("The tick counter has not been started yet. Use RESET-TICKS.");
}
return this._count;
};
Ticker.prototype._updateTicks = function(updateCountFunc) {
this._count = updateCountFunc(this._count);
this._updateFunc("ticks");
};
return Ticker;
})();
}).call(this);
},{"tortoise/util/exception":12}],"engine/core/world/ticker":[function(require,module,exports){
module.exports=require('7rhyJn');
},{}],"9OrcFc":[function(require,module,exports){
(function() {
var Builtins, ColorModel, Exception, IDManager, Nobody, Random, Turtle, TurtleManager, TurtleSet, _,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
_ = require('lodash');
Nobody = require('../nobody');
Turtle = require('../turtle');
TurtleSet = require('../turtleset');
Builtins = require('../structure/builtins');
IDManager = require('./idmanager');
Random = require('tortoise/shim/random');
ColorModel = require('tortoise/util/colormodel');
Exception = require('tortoise/util/exception');
module.exports = TurtleManager = (function() {
TurtleManager.prototype._idManager = void 0;
TurtleManager.prototype._turtles = void 0;
TurtleManager.prototype._turtlesById = void 0;
function TurtleManager(_world, _breedManager, _updater) {
this._world = _world;
this._breedManager = _breedManager;
this._updater = _updater;
this._removeTurtle = __bind(this._removeTurtle, this);
this._createTurtle = __bind(this._createTurtle, this);
this.turtlesOfBreed = __bind(this.turtlesOfBreed, this);
this._idManager = new IDManager;
this._turtles = [];
this._turtlesById = {};
}
TurtleManager.prototype.clearTurtles = function() {
this.turtles().forEach(function(turtle) {
var error;
try {
turtle.die();
} catch (_error) {
error = _error;
if (!(error instanceof Exception.DeathInterrupt)) {
throw error;
}
}
});
this._idManager.reset();
};
TurtleManager.prototype.createOrderedTurtles = function(n, breedName) {
var turtles;
turtles = _(0).range(n).map((function(_this) {
return function(num) {
var color, heading;
color = ColorModel.nthColor(num);
heading = (360 * num) / n;
return _this._createTurtle(color, heading, 0, 0, _this._breedManager.get(breedName));
};
})(this)).value();
return new TurtleSet(turtles, breedName);
};
TurtleManager.prototype.createTurtles = function(n, breedName, xcor, ycor) {
var turtles;
if (xcor == null) {
xcor = 0;
}
if (ycor == null) {
ycor = 0;
}
turtles = _(0).range(n).map((function(_this) {
return function() {
var color, heading;
color = ColorModel.randomColor();
heading = Random.nextInt(360);
return _this._createTurtle(color, heading, xcor, ycor, _this._breedManager.get(breedName));
};
})(this)).value();
return new TurtleSet(turtles, breedName);
};
TurtleManager.prototype.getTurtle = function(id) {
return this._turtlesById[id] || Nobody;
};
TurtleManager.prototype.getTurtleOfBreed = function(breedName, id) {
var turtle;
turtle = this.getTurtle(id);
if (turtle.getBreedName().toUpperCase() === breedName.toUpperCase()) {
return turtle;
} else {
return Nobody;
}
};
TurtleManager.prototype.turtles = function() {
return new TurtleSet(this._turtles, "TURTLES", "turtles");
};
TurtleManager.prototype.turtlesOfBreed = function(breedName) {
var breed;
breed = this._breedManager.get(breedName);
return new TurtleSet(breed.members, breedName, breedName);
};
TurtleManager.prototype._clearTurtlesSuspended = function() {
this._idManager.suspendDuring((function(_this) {
return function() {
return _this.clearTurtles();
};
})(this));
};
TurtleManager.prototype._createTurtle = function(color, heading, xcor, ycor, breed, label, lcolor, isHidden, size, penManager) {
var id, turtle;
id = this._idManager.next();
turtle = new Turtle(this._world, id, this._updater.updated, this._updater.registerDeadTurtle, this._createTurtle, this._removeTurtle, color, heading, xcor, ycor, breed, label, lcolor, isHidden, size, penManager);
this._updater.updated(turtle).apply(null, Builtins.turtleBuiltins);
this._turtles.push(turtle);
this._turtlesById[id] = turtle;
return turtle;
};
TurtleManager.prototype._removeTurtle = function(id) {
var turtle;
turtle = this._turtlesById[id];
this._turtles.splice(this._turtles.indexOf(turtle), 1);
delete this._turtlesById[id];
};
return TurtleManager;
})();
}).call(this);
},{"../nobody":"xMfcne","../structure/builtins":"B6cYv5","../turtle":"d1H0D2","../turtleset":"4S23fo","./idmanager":"MQpYgZ","lodash":"4HJaAd","tortoise/shim/random":7,"tortoise/util/colormodel":10,"tortoise/util/exception":12}],"engine/core/world/turtlemanager":[function(require,module,exports){
module.exports=require('9OrcFc');
},{}],"OB2y0z":[function(require,module,exports){
(function() {
var Dump, Tasks, _;
_ = require('lodash');
Tasks = require('./prim/tasks');
Dump = function(x) {
var itemStr;
if (_(x).isArray()) {
itemStr = _(x).map(Dump).value().join(" ");
return "[" + itemStr + "]";
} else if (Tasks.isReporterTask(x)) {
return "(reporter task)";
} else if (Tasks.isCommandTask(x)) {
return "(command task)";
} else {
return String(x);
}
};
module.exports = Dump;
}).call(this);
},{"./prim/tasks":"RGwRBX","lodash":"4HJaAd"}],"engine/dump":[function(require,module,exports){
module.exports=require('OB2y0z');
},{}],"LrlmrN":[function(require,module,exports){
(function() {
var AbstractAgentSet, Hasher, Link, Nobody, Turtle, Type, _;
_ = require('lodash');
AbstractAgentSet = require('./core/abstractagentset');
Link = require('./core/link');
Nobody = require('./core/nobody');
Turtle = require('./core/turtle');
Type = require('tortoise/util/typechecker');
Hasher = function(x) {
var f;
if (x instanceof Turtle || x instanceof Link) {
return x.id;
} else if (x === Nobody) {
return -1;
} else if (Type(x).isArray()) {
f = function(acc, x) {
return 31 * acc + (x != null ? Hasher(x) : 0);
};
return _(x).foldl(f, 1);
} else if (x instanceof AbstractAgentSet) {
return Hasher(x.toArray());
} else {
return x.toString();
}
};
module.exports = Hasher;
}).call(this);
},{"./core/abstractagentset":"H2TUw+","./core/link":"r3RBLf","./core/nobody":"xMfcne","./core/turtle":"d1H0D2","lodash":"4HJaAd","tortoise/util/typechecker":19}],"engine/hasher":[function(require,module,exports){
module.exports=require('LrlmrN');
},{}],"cVEtBN":[function(require,module,exports){
(function() {
var LayoutManager, Random, StrictMath, Trig, _;
_ = require('lodash');
Random = require('tortoise/shim/random');
StrictMath = require('tortoise/shim/strictmath');
Trig = require('tortoise/util/trig');
module.exports = LayoutManager = (function() {
function LayoutManager(_world) {
this._world = _world;
}
LayoutManager.prototype.layoutSpring = function(nodeSet, linkSet, spr, len, rep) {
var agt, ax, ay, degCounts, nodeCount, tMap, _ref;
if (!nodeSet.isEmpty()) {
_ref = this._initialize(nodeSet), ax = _ref[0], ay = _ref[1], tMap = _ref[2], agt = _ref[3];
nodeCount = nodeSet.size();
degCounts = this._calcDegreeCounts(linkSet, tMap, nodeCount);
this._updateXYArraysForNeighbors(ax, ay, linkSet, tMap, degCounts, spr, len);
this._updateXYArraysForAll(ax, ay, agt, degCounts, nodeCount, rep);
this._moveTurtles(ax, ay, agt, nodeCount);
}
};
LayoutManager.prototype._initialize = function(nodeSet) {
var agt, ax, ay, tMap, turtles;
ax = [];
ay = [];
tMap = [];
agt = [];
turtles = nodeSet.shuffled().toArray();
_(0).range(turtles.length).forEach(function(i) {
var turtle;
turtle = turtles[i];
agt[i] = turtle;
tMap[turtle.id] = i;
ax[i] = 0.0;
ay[i] = 0.0;
});
return [ax, ay, tMap, agt];
};
LayoutManager.prototype._calcDegreeCounts = function(links, idToIndexMap, nodeCount) {
var baseCounts;
baseCounts = _(0).range(nodeCount).map(function() {
return 0;
}).value();
links.forEach(function(link) {
var f, t1, t2;
t1 = link.end1;
t2 = link.end2;
f = function(turtle) {
var index;
index = idToIndexMap[turtle.id];
if (index != null) {
return baseCounts[index]++;
}
};
f(t1);
f(t2);
});
return baseCounts;
};
LayoutManager.prototype._updateXYArraysForNeighbors = function(ax, ay, links, idToIndexMap, degCounts, spr, len) {
var indexAndCountOf;
indexAndCountOf = function(turtle) {
var index;
index = idToIndexMap[turtle.id];
if (index != null) {
return [index, degCounts[index]];
} else {
return [-1, 0];
}
};
links.forEach(function(link) {
var degCount1, degCount2, dist, div, dx, dy, f, newDX, newDY, t1, t1Index, t2, t2Index, _ref, _ref1, _ref2;
t1 = link.end1;
t2 = link.end2;
_ref = indexAndCountOf(t1), t1Index = _ref[0], degCount1 = _ref[1];
_ref1 = indexAndCountOf(t2), t2Index = _ref1[0], degCount2 = _ref1[1];
dist = t1.distance(t2);
div = Math.max((degCount1 + degCount2) / 2.0, 1.0);
_ref2 = dist === 0 ? [(spr * len) / div, 0] : (f = spr * (dist - len) / div, newDX = f * (t2.xcor - t1.xcor) / dist, newDY = f * (t2.ycor - t1.ycor) / dist, [newDX, newDY]), dx = _ref2[0], dy = _ref2[1];
if (t1Index !== -1) {
ax[t1Index] += dx;
ay[t1Index] += dy;
}
if (t2Index !== -1) {
ax[t2Index] -= dx;
ay[t2Index] -= dy;
}
});
};
LayoutManager.prototype._updateXYArraysForAll = function(ax, ay, agents, degCounts, nodeCount, rep) {
var ang, dist, div, dx, dy, f, i, j, newDX, newDY, t1, t2, _i, _j, _ref, _ref1;
for (i = _i = 0; 0 <= nodeCount ? _i < nodeCount : _i > nodeCount; i = 0 <= nodeCount ? ++_i : --_i) {
t1 = agents[i];
for (j = _j = _ref = i + 1; _ref <= nodeCount ? _j < nodeCount : _j > nodeCount; j = _ref <= nodeCount ? ++_j : --_j) {
t2 = agents[j];
div = Math.max((degCounts[i] + degCounts[j]) / 2.0, 1.0);
_ref1 = t2.xcor === t1.xcor && t2.ycor === t1.ycor ? (ang = 360 * Random.nextDouble(), newDX = -(rep / div * Trig.sin(StrictMath.toRadians(ang))), newDY = -(rep / div * Trig.cos(StrictMath.toRadians(ang))), [newDX, newDY]) : (dist = t1.distance(t2), f = rep / (dist * dist) / div, newDX = -(f * (t2.xcor - t1.xcor) / dist), newDY = -(f * (t2.ycor - t1.ycor) / dist), [newDX, newDY]), dx = _ref1[0], dy = _ref1[1];
ax[i] += dx;
ay[i] += dy;
ax[j] -= dx;
ay[j] -= dy;
}
}
};
LayoutManager.prototype._moveTurtles = function(ax, ay, agt, nodeCount) {
var bounded, calculateLimit, calculateXCor, calculateYCor, height, limit, maxX, maxY, minX, minY, perturbment, width;
maxX = this._world.topology.maxPxcor;
minX = this._world.topology.minPxcor;
maxY = this._world.topology.maxPycor;
minY = this._world.topology.minPycor;
height = this._world.topology.height;
width = this._world.topology.width;
if (nodeCount > 1) {
perturbment = (width + height) / 1.0e10;
ax[0] += Random.nextDouble() * perturbment - perturbment / 2.0;
ay[0] += Random.nextDouble() * perturbment - perturbment / 2.0;
}
limit = (width + height) / 50.0;
bounded = function(min, max) {
return function(x) {
if (x < min) {
return min;
} else if (x > max) {
return max;
} else {
return x;
}
};
};
calculateLimit = bounded(-limit, limit);
calculateXCor = bounded(minX, maxX);
calculateYCor = bounded(minY, maxY);
_(0).range(nodeCount).forEach(function(i) {
var newX, newY, turtle;
turtle = agt[i];
newX = calculateXCor(turtle.xcor + calculateLimit(ax[i]));
newY = calculateYCor(turtle.ycor + calculateLimit(ay[i]));
turtle.setXY(newX, newY);
});
};
return LayoutManager;
})();
}).call(this);
},{"lodash":"4HJaAd","tortoise/shim/random":7,"tortoise/shim/strictmath":8,"tortoise/util/trig":18}],"engine/prim/layoutmanager":[function(require,module,exports){
module.exports=require('cVEtBN');
},{}],"rScFap":[function(require,module,exports){
(function() {
var LinkPrims;
module.exports = LinkPrims = (function() {
LinkPrims._linkManager = void 0;
LinkPrims._self = void 0;
function LinkPrims(_world) {
this._world = _world;
this._linkManager = this._world.linkManager;
this._self = this._world.selfManager.self;
}
LinkPrims.prototype.createLinkFrom = function(otherTurtle, breedName) {
return this._linkManager.createDirectedLink(otherTurtle, this._self(), breedName);
};
LinkPrims.prototype.createLinksFrom = function(otherTurtles, breedName) {
return this._linkManager.createReverseDirectedLinks(this._self(), otherTurtles.shuffled(), breedName);
};
LinkPrims.prototype.createLinkTo = function(otherTurtle, breedName) {
return this._linkManager.createDirectedLink(this._self(), otherTurtle, breedName);
};
LinkPrims.prototype.createLinksTo = function(otherTurtles, breedName) {
return this._linkManager.createDirectedLinks(this._self(), otherTurtles.shuffled(), breedName);
};
LinkPrims.prototype.createLinkWith = function(otherTurtle, breedName) {
return this._linkManager.createUndirectedLink(this._self(), otherTurtle, breedName);
};
LinkPrims.prototype.createLinksWith = function(otherTurtles, breedName) {
return this._linkManager.createUndirectedLinks(this._self(), otherTurtles.shuffled(), breedName);
};
LinkPrims.prototype.connectedLinks = function(isDirected, isSource, breedName) {
return this._self().connectedLinks(isDirected, isSource, breedName);
};
LinkPrims.prototype.linkNeighbors = function(isDirected, isSource, breedName) {
return this._self().linkNeighbors(isDirected, isSource, breedName);
};
LinkPrims.prototype.isLinkNeighbor = function(isDirected, isSource, breedName) {
return (function(_this) {
return function(otherTurtle) {
return _this._self().isLinkNeighbor(isDirected, isSource, breedName, otherTurtle);
};
})(this);
};
LinkPrims.prototype.findLinkViaNeighbor = function(isDirected, isSource, breedName) {
return (function(_this) {
return function(otherTurtle) {
return _this._self().findLinkViaNeighbor(isDirected, isSource, breedName, otherTurtle);
};
})(this);
};
return LinkPrims;
})();
}).call(this);
},{}],"engine/prim/linkprims":[function(require,module,exports){
module.exports=require('rScFap');
},{}],"vH+78D":[function(require,module,exports){
(function() {
var AbstractAgentSet, Comparator, Exception, Link, ListPrims, Nobody, Patch, StrictMath, Turtle, Type, stableSort, _,
__slice = [].slice;
_ = require('lodash');
AbstractAgentSet = require('../core/abstractagentset');
Link = require('../core/link');
Nobody = require('../core/nobody');
Patch = require('../core/patch');
Turtle = require('../core/turtle');
StrictMath = require('tortoise/shim/strictmath');
Comparator = require('tortoise/util/comparator');
Exception = require('tortoise/util/exception');
stableSort = require('tortoise/util/stablesort');
Type = require('tortoise/util/typechecker');
module.exports = ListPrims = (function() {
function ListPrims(_hasher, _equality) {
this._hasher = _hasher;
this._equality = _equality;
}
ListPrims.prototype.butFirst = function(xs) {
return xs.slice(1);
};
ListPrims.prototype.butLast = function(xs) {
return xs.slice(0, xs.length - 1);
};
ListPrims.prototype.empty = function(xs) {
return xs.length === 0;
};
ListPrims.prototype.first = function(xs) {
return xs[0];
};
ListPrims.prototype.fput = function(x, xs) {
return [x].concat(xs);
};
ListPrims.prototype.item = function(n, xs) {
return xs[n];
};
ListPrims.prototype.last = function(xs) {
return xs[xs.length - 1];
};
ListPrims.prototype.length = function(xs) {
return xs.length;
};
ListPrims.prototype.list = function() {
var xs;
xs = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
return xs;
};
ListPrims.prototype.lput = function(x, xs) {
var result;
result = xs.slice(0);
result.push(x);
return result;
};
ListPrims.prototype.max = function(xs) {
return Math.max.apply(Math, xs);
};
ListPrims.prototype.mean = function(xs) {
return this.sum(xs) / xs.length;
};
ListPrims.prototype.member = function(x, xs) {
if (Type(xs).isArray()) {
return _(xs).some((function(_this) {
return function(y) {
return _this._equality(x, y);
};
})(this));
} else if (Type(x).isString()) {
return xs.indexOf(x) !== -1;
} else {
return xs.exists(function(a) {
return x === a;
});
}
};
ListPrims.prototype.min = function(xs) {
return Math.min.apply(Math, xs);
};
ListPrims.prototype.nOf = function(n, agentsOrList) {
var items, newItems;
if (agentsOrList instanceof AbstractAgentSet) {
items = agentsOrList.iterator().toArray();
newItems = this._nOfArray(n, items);
return agentsOrList.copyWithNewAgents(newItems);
} else {
throw new Error("n-of not implemented on lists yet");
}
};
ListPrims.prototype.oneOf = function(agentsOrList) {
var arr;
arr = agentsOrList instanceof AbstractAgentSet ? agentsOrList.iterator().toArray() : agentsOrList;
if (arr.length === 0) {
return Nobody;
} else {
return arr[Random.nextInt(arr.length)];
}
};
ListPrims.prototype.position = function(x, xs) {
var index;
index = Type(xs).isArray() ? _(xs).findIndex((function(_this) {
return function(y) {
return _this._equality(x, y);
};
})(this)) : xs.indexOf(x);
if (index !== -1) {
return index;
} else {
return false;
}
};
ListPrims.prototype.removeDuplicates = function(xs) {
var f, out, _ref;
if (xs.length < 2) {
return xs;
} else {
f = (function(_this) {
return function(_arg, x) {
var accArr, accSet, hash, values;
accArr = _arg[0], accSet = _arg[1];
hash = _this._hasher(x);
values = accSet[hash];
if (values != null) {
if (!_(values).some(function(y) {
return _this._equality(x, y);
})) {
accArr.push(x);
values.push(x);
}
} else {
accArr.push(x);
accSet[hash] = [x];
}
return [accArr, accSet];
};
})(this);
_ref = xs.reduce(f, [[], {}]), out = _ref[0], _ref[1];
return out;
}
};
ListPrims.prototype.reverse = function(xs) {
if (Type(xs).isArray()) {
return xs.slice(0).reverse();
} else if (typeof xs === "string") {
return xs.split("").reverse().join("");
} else {
throw new Error("can only reverse lists and strings");
}
};
ListPrims.prototype.remove = function(x, xs) {
if (Type(xs).isArray()) {
return _(xs).filter((function(_this) {
return function(y) {
return !_this._equality(x, y);
};
})(this)).value();
} else {
return xs.replace(new RegExp(x, "g"), "");
}
};
ListPrims.prototype.removeItem = function(n, xs) {
var post, pre, temp;
if (Type(xs).isArray()) {
temp = xs.slice(0);
temp.splice(n, 1);
return temp;
} else {
pre = xs.slice(0, n);
post = xs.slice(n + 1);
return pre + post;
}
};
ListPrims.prototype.replaceItem = function(n, xs, x) {
var post, pre, temp;
if (Type(xs).isArray()) {
temp = xs.slice(0);
temp.splice(n, 1, x);
return temp;
} else {
pre = xs.slice(0, n);
post = xs.slice(n + 1);
return pre + x + post;
}
};
ListPrims.prototype.sentence = function() {
var f, xs;
xs = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
f = function(acc, x) {
if (Type(x).isArray()) {
return acc.concat(x);
} else {
acc.push(x);
return acc;
}
};
return _(xs).foldl(f, []);
};
ListPrims.prototype.sort = function(xs) {
var agentClasses, filtered, forAll;
if (Type(xs).isArray()) {
filtered = _.filter(xs, function(x) {
return x !== Nobody;
});
forAll = function(f) {
return _.all(filtered, f);
};
agentClasses = [Turtle, Patch, Link];
if (_(filtered).isEmpty()) {
return filtered;
} else if (forAll(function(x) {
return Type(x).isNumber();
})) {
return filtered.sort(function(x, y) {
return Comparator.numericCompare(x, y).toInt;
});
} else if (forAll(function(x) {
return Type(x).isString();
})) {
return filtered.sort();
} else if (_(agentClasses).some(function(agentClass) {
return forAll(function(x) {
return x instanceof agentClass;
});
})) {
return stableSort(filtered)(function(x, y) {
return x.compare(y).toInt;
});
} else {
throw new Error("We don't know how to sort your kind here!");
}
} else if (xs instanceof AbstractAgentSet) {
return xs.sort();
} else {
throw new Error("can only sort lists and agentsets");
}
};
ListPrims.prototype.sublist = function(xs, n1, n2) {
return xs.slice(n1, n2);
};
ListPrims.prototype.substring = function(xs, n1, n2) {
return xs.substr(n1, n2 - n1);
};
ListPrims.prototype.sum = function(xs) {
return xs.reduce((function(a, b) {
return a + b;
}), 0);
};
ListPrims.prototype.variance = function(xs) {
var count, mean, numbers, squareOfDifference, sum;
numbers = _(xs).filter(function(x) {
return Type(x).isNumber();
});
count = numbers.size();
if (count < 2) {
throw new Error("Can't find the variance of a list without at least two numbers");
}
sum = numbers.foldl((function(acc, x) {
return acc + x;
}), 0);
mean = sum / count;
squareOfDifference = numbers.foldl((function(acc, x) {
return acc + StrictMath.pow(x - mean, 2);
}), 0);
return squareOfDifference / (count - 1);
};
ListPrims.prototype._nOfArray = function(n, items) {
var i, index1, index2, j, newIndex1, newIndex2, result, _ref;
switch (n) {
case 0:
return [];
case 1:
return [items[Random.nextInt(items.length)]];
case 2:
index1 = Random.nextInt(items.length);
index2 = Random.nextInt(items.length - 1);
_ref = index2 >= index1 ? [index1, index2 + 1] : [index2, index1], newIndex1 = _ref[0], newIndex2 = _ref[1];
return [items[newIndex1], items[newIndex2]];
default:
i = 0;
j = 0;
result = [];
while (j < n) {
if (Random.nextInt(items.length - i) < n - j) {
result.push(items[i]);
j += 1;
}
i += 1;
}
return result;
}
};
return ListPrims;
})();
}).call(this);
},{"../core/abstractagentset":"H2TUw+","../core/link":"r3RBLf","../core/nobody":"xMfcne","../core/patch":"t5DuqE","../core/turtle":"d1H0D2","lodash":"4HJaAd","tortoise/shim/strictmath":8,"tortoise/util/comparator":11,"tortoise/util/exception":12,"tortoise/util/stablesort":16,"tortoise/util/typechecker":19}],"engine/prim/listprims":[function(require,module,exports){
module.exports=require('vH+78D');
},{}],"engine/prim/prims":[function(require,module,exports){
module.exports=require('F1Ty61');
},{}],"F1Ty61":[function(require,module,exports){
(function() {
var AbstractAgentSet, Comparator, Exception, Link, LinkSet, Nobody, Patch, PatchSet, Prims, Printer, Random, Timer, Turtle, TurtleSet, Type, _,
__slice = [].slice,
__modulo = function(a, b) { return (a % b + +b) % b; };
_ = require('lodash');
AbstractAgentSet = require('../core/abstractagentset');
Link = require('../core/link');
LinkSet = require('../core/linkset');
Nobody = require('../core/nobody');
Patch = require('../core/patch');
PatchSet = require('../core/patchset');
Turtle = require('../core/turtle');
TurtleSet = require('../core/turtleset');
Printer = require('tortoise/shim/printer');
Random = require('tortoise/shim/random');
Comparator = require('tortoise/util/comparator');
Exception = require('tortoise/util/exception');
Timer = require('tortoise/util/timer');
Type = require('tortoise/util/typechecker');
module.exports = Prims = (function() {
Prims.prototype._everyMap = void 0;
function Prims(_dumper, _hasher) {
this._dumper = _dumper;
this._hasher = _hasher;
this._everyMap = {};
}
Prims.prototype.boom = function() {
throw new Error("boom!");
};
Prims.prototype.breedOn = function(breedName, x) {
var patches, turtles;
patches = (function() {
if (x instanceof Patch) {
return [x];
} else if (x instanceof Turtle) {
return [x.getPatchHere()];
} else if (x instanceof PatchSet) {
return x.toArray();
} else if (x instanceof TurtleSet) {
return _(x.iterator().toArray()).map(function(t) {
return t.getPatchHere();
}).value();
} else {
throw new Error("`breed-on` unsupported for class '" + (typeof x) + "'");
}
})();
turtles = _(patches).map(function(p) {
return p.turtles;
}).flatten().filter(function(t) {
return t.getBreedName() === breedName;
}).value();
return new TurtleSet(turtles, breedName);
};
Prims.prototype.equality = function(a, b) {
var subsumes;
if ((a != null) && (b != null)) {
return (a === b) || (Type(a).isArray() && Type(b).isArray() ? a.length === b.length && a.every((function(_this) {
return function(elem, i) {
return _this.equality(elem, b[i]);
};
})(this)) : a instanceof AbstractAgentSet && b instanceof AbstractAgentSet ? (subsumes = (function(_this) {
return function(xs, ys) {
var index, x, _i, _len;
for (index = _i = 0, _len = xs.length; _i < _len; index = ++_i) {
x = xs[index];
if (!_this.equality(ys[index], x)) {
return false;
}
}
return true;
};
})(this), a.size() === b.size() && Object.getPrototypeOf(a) === Object.getPrototypeOf(b) && subsumes(a.sort(), b.sort())) : (a instanceof AbstractAgentSet && (a.getBreedName != null) && a.getBreedName() === b.name) || (b instanceof AbstractAgentSet && (b.getBreedName != null) && b.getBreedName() === a.name) || (a === Nobody && b.id === -1) || (b === Nobody && a.id === -1) || ((a instanceof Turtle || a instanceof Link) && a.compare(b) === Comparator.EQUALS));
} else {
throw new Error("Checking equality on undefined is an invalid condition");
}
};
/*
This implementation is closer than our original implementation, but still wrong. `every`'s dictionary entry claims:
"Runs the given commands only if it's been more than number seconds since the last time this agent ran them in this context."
But a more-accurate description of this implementation would be:
"Runs the given commands only if it's been more than number seconds since the last time they were run in this context."
Basically, there's no agent-checking yet. --JAB (9/12/14)
*/
Prims.prototype.every = function(time, fn, fid) {
var existingEntry;
existingEntry = this._everyMap[fid];
if ((existingEntry == null) || existingEntry.elapsed() >= time) {
this._everyMap[fid] = new Timer();
fn();
}
};
Prims.prototype.gt = function(a, b) {
if ((Type(a).isString() && Type(b).isString()) || (Type(a).isNumber() && Type(b).isNumber())) {
return a > b;
} else if (typeof a === typeof b && (a.compare != null) && (b.compare != null)) {
return a.compare(b) === Comparator.GREATER_THAN;
} else {
throw new Error("Invalid operands to `gt`");
}
};
Prims.prototype.gte = function(a, b) {
return this.gt(a, b) || this.equality(a, b);
};
Prims.prototype.isBreed = function(breedName, x) {
if ((x.isBreed != null) && x.id !== -1) {
return x.isBreed(breedName);
} else {
return false;
}
};
Prims.prototype.linkSet = function() {
var inputs;
inputs = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
return this._createAgentSet(inputs, Link, LinkSet);
};
Prims.prototype.lt = function(a, b) {
if ((Type(a).isString() && Type(b).isString()) || (Type(a).isNumber() && Type(b).isNumber())) {
return a < b;
} else if (typeof a === typeof b && (a.compare != null) && (b.compare != null)) {
return a.compare(b) === Comparator.LESS_THAN;
} else {
throw new Error("Invalid operands to `lt`");
}
};
Prims.prototype.lte = function(a, b) {
return this.lt(a, b) || this.equality(a, b);
};
Prims.prototype.mod = function(a, b) {
return __modulo(a, b);
};
Prims.prototype.outputPrint = function(x) {
Printer(this._dumper(x));
};
Prims.prototype.patchSet = function() {
var inputs;
inputs = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
return this._createAgentSet(inputs, Patch, PatchSet);
};
Prims.prototype.precision = function(n, places) {
var multiplier, result;
multiplier = Math.pow(10, places);
result = Math.floor(n * multiplier + .5) / multiplier;
if (places > 0) {
return result;
} else {
return Math.round(result);
}
};
Prims.prototype.random = function(n) {
var truncated;
truncated = n >= 0 ? Math.ceil(n) : Math.floor(n);
if (truncated === 0) {
return 0;
} else if (truncated > 0) {
return Random.nextLong(truncated);
} else {
return -Random.nextLong(-truncated);
}
};
Prims.prototype.randomFloat = function(n) {
return n * Random.nextDouble();
};
Prims.prototype.repeat = function(n, fn) {
var _i;
for (_i = 0; 0 <= n ? _i < n : _i > n; 0 <= n ? _i++ : _i--) {
fn();
}
};
Prims.prototype.subtractHeadings = function(h1, h2) {
var diff;
diff = (h1 % 360) - (h2 % 360);
if ((-180 < diff && diff <= 180)) {
return diff;
} else if (diff > 0) {
return diff - 360;
} else {
return diff + 360;
}
};
Prims.prototype.toInt = function(n) {
return n | 0;
};
Prims.prototype.turtleSet = function() {
var inputs;
inputs = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
return this._createAgentSet(inputs, Turtle, TurtleSet);
};
Prims.prototype.turtlesOn = function(agentsOrAgent) {
var turtles;
if (agentsOrAgent instanceof AbstractAgentSet) {
turtles = _(agentsOrAgent.iterator().toArray()).map(function(agent) {
return agent.turtlesHere().toArray();
}).flatten().value();
return new TurtleSet(turtles);
} else {
return agentsOrAgent.turtlesHere();
}
};
Prims.prototype._createAgentSet = function(inputs, tClass, outClass) {
var addT, buildFromAgentSet, buildItems, flattened, hashIt, hashSet, head, result;
flattened = _(inputs).flatten().value();
if (_(flattened).isEmpty()) {
return new outClass([]);
} else if (flattened.length === 1) {
head = flattened[0];
if (head instanceof outClass) {
return head;
} else if (head instanceof tClass) {
return new outClass([head]);
} else {
return new outClass([]);
}
} else {
result = [];
hashSet = {};
hashIt = this._hasher;
addT = function(p) {
var hash;
hash = hashIt(p);
if (!hashSet.hasOwnProperty(hash)) {
result.push(p);
hashSet[hash] = true;
}
};
buildFromAgentSet = function(agentSet) {
return agentSet.forEach(addT);
};
buildItems = (function(_this) {
return function(inputs) {
var input, _i, _len, _results;
_results = [];
for (_i = 0, _len = inputs.length; _i < _len; _i++) {
input = inputs[_i];
if (Type(input).isArray()) {
_results.push(buildItems(input));
} else if (input instanceof tClass) {
_results.push(addT(input));
} else if (input !== Nobody) {
_results.push(buildFromAgentSet(input));
} else {
_results.push(void 0);
}
}
return _results;
};
})(this);
buildItems(flattened);
return new outClass(result);
}
};
return Prims;
})();
}).call(this);
},{"../core/abstractagentset":"H2TUw+","../core/link":"r3RBLf","../core/linkset":"I7p8+g","../core/nobody":"xMfcne","../core/patch":"t5DuqE","../core/patchset":"yG3HYq","../core/turtle":"d1H0D2","../core/turtleset":"4S23fo","lodash":"4HJaAd","tortoise/shim/printer":6,"tortoise/shim/random":7,"tortoise/util/comparator":11,"tortoise/util/exception":12,"tortoise/util/timer":17,"tortoise/util/typechecker":19}],"engine/prim/selfprims":[function(require,module,exports){
module.exports=require('PUrfyc');
},{}],"PUrfyc":[function(require,module,exports){
(function() {
var SelfPrims;
module.exports = SelfPrims = (function() {
function SelfPrims(_getSelf) {
this._getSelf = _getSelf;
}
SelfPrims.prototype.fd = function(n) {
this._getSelf().fd(n);
};
SelfPrims.prototype.bk = function(n) {
this._getSelf().fd(-n);
};
SelfPrims.prototype.jump = function(n) {
return this._getSelf().jumpIfAble(n);
};
SelfPrims.prototype.right = function(n) {
this._getSelf().right(n);
};
SelfPrims.prototype.left = function(n) {
this._getSelf().right(-n);
};
SelfPrims.prototype.setXY = function(x, y) {
this._getSelf().setXY(x, y);
};
SelfPrims.prototype.getNeighbors = function() {
return this._getSelf().getNeighbors();
};
SelfPrims.prototype.getNeighbors4 = function() {
return this._getSelf().getNeighbors4();
};
SelfPrims.prototype.sprout = function(n, breedName) {
return this._getSelf().sprout(n, breedName);
};
SelfPrims.prototype.hatch = function(n, breedName) {
return this._getSelf().hatch(n, breedName);
};
SelfPrims.prototype.die = function() {
this._getSelf().die();
};
SelfPrims.prototype.other = function(agentSet) {
var self;
self = this._getSelf();
return agentSet.filter((function(_this) {
return function(agent) {
return agent !== self;
};
})(this));
};
SelfPrims.prototype.getVariable = function(varName) {
return this._getSelf().getVariable(varName);
};
SelfPrims.prototype.setVariable = function(varName, value) {
this._getSelf().setVariable(varName, value);
};
SelfPrims.prototype.getPatchVariable = function(varName) {
return this._getSelf().getPatchVariable(varName);
};
SelfPrims.prototype.setPatchVariable = function(varName, value) {
this._getSelf().setPatchVariable(varName, value);
};
return SelfPrims;
})();
}).call(this);
},{}],"RGwRBX":[function(require,module,exports){
(function() {
var Exception, Type, _,
__slice = [].slice;
_ = require('lodash');
Exception = require('tortoise/util/exception');
Type = require('tortoise/util/typechecker');
module.exports = {
commandTask: function(fn) {
fn.isReporter = false;
return fn;
},
reporterTask: function(fn) {
fn.isReporter = true;
return fn;
},
isReporterTask: function(x) {
return Type(x).isFunction() && x.isReporter;
},
isCommandTask: function(x) {
return Type(x).isFunction() && !x.isReporter;
},
map: function() {
var fn, lists;
fn = arguments[0], lists = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
return this._processLists(fn, lists, "map");
},
nValues: function(n, fn) {
return _(0).range(n).map(fn).value();
},
forEach: function() {
var fn, lists;
fn = arguments[0], lists = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
this._processLists(fn, lists, "foreach");
},
_processLists: function(fn, lists, primName) {
var head, numLists;
numLists = lists.length;
head = lists[0];
if (numLists === 1) {
return head.map(fn);
} else if (_(lists).all(function(l) {
return l.length === head.length;
})) {
return _.zip.apply(_, lists).map(function(tuple) {
return fn.apply(null, tuple);
});
} else {
throw new Error("All the list arguments to " + (primName.toUpperCase()) + " must be the same length.");
}
}
};
}).call(this);
},{"lodash":"4HJaAd","tortoise/util/exception":12,"tortoise/util/typechecker":19}],"engine/prim/tasks":[function(require,module,exports){
module.exports=require('RGwRBX');
},{}],"zSkDPr":[function(require,module,exports){
(function() {
var Exception, Link, Observer, Patch, Turtle, Update, Updater, World, ignored,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
__slice = [].slice;
Link = require('./core/link');
Observer = require('./core/observer');
Patch = require('./core/patch');
Turtle = require('./core/turtle');
World = require('./core/world');
Exception = require('tortoise/util/exception');
ignored = ["", ""];
Update = (function() {
function Update(turtles, patches, links, observer, world) {
this.turtles = turtles != null ? turtles : {};
this.patches = patches != null ? patches : {};
this.links = links != null ? links : {};
this.observer = observer != null ? observer : {};
this.world = world != null ? world : {};
}
return Update;
})();
module.exports = Updater = (function() {
Updater.prototype._updates = void 0;
function Updater() {
this.updated = __bind(this.updated, this);
this.registerDeadTurtle = __bind(this.registerDeadTurtle, this);
this.registerDeadLink = __bind(this.registerDeadLink, this);
this._flushUpdates();
}
Updater.prototype.collectUpdates = function() {
var temp;
temp = this._updates;
this._flushUpdates();
return temp;
};
Updater.prototype.registerDeadLink = function(id) {
this._update("links", id, {
WHO: -1
});
};
Updater.prototype.registerDeadTurtle = function(id) {
this._update("turtles", id, {
WHO: -1
});
};
Updater.prototype.registerWorldState = function(state, id) {
if (id == null) {
id = 0;
}
this._update("world", id, state);
};
Updater.prototype.updated = function(obj) {
return (function(_this) {
return function() {
var entry, entryUpdate, mapping, objMap, update, v, value, varName, vars, _i, _len, _ref;
vars = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
update = _this._updates[0];
_ref = (function() {
if (obj instanceof Turtle) {
return [update.turtles, this._turtleMap(obj)];
} else if (obj instanceof Patch) {
return [update.patches, this._patchMap(obj)];
} else if (obj instanceof Link) {
return [update.links, this._linkMap(obj)];
} else if (obj instanceof World) {
return [update.world, this._worldMap(obj)];
} else if (obj instanceof Observer) {
return [update.observer, this._observerMap(obj)];
} else {
throw new Error("Unrecognized update type");
}
}).call(_this), entry = _ref[0], objMap = _ref[1];
entryUpdate = entry[obj.id] || {};
if (entryUpdate['WHO'] < 0) {
delete entryUpdate['WHO'];
}
for (_i = 0, _len = vars.length; _i < _len; _i++) {
v = vars[_i];
mapping = objMap[v];
if (mapping != null) {
if (mapping !== ignored) {
varName = mapping[0], value = mapping[1];
entryUpdate[varName] = value;
entry[obj.id] = entryUpdate;
}
} else {
throw new Error("Unknown " + obj.constructor.name + " variable for update: " + v);
}
}
};
})(this);
};
Updater.prototype._turtleMap = function(turtle) {
return {
breed: ["BREED", turtle.getBreedName()],
color: ["COLOR", turtle._color],
heading: ["HEADING", turtle._heading],
id: ["WHO", turtle.id],
'label-color': ["LABEL-COLOR", turtle._labelcolor],
'hidden?': ["HIDDEN?", turtle._hidden],
label: ["LABEL", turtle._label.toString()],
'pen-size': ["PEN-SIZE", turtle.penManager.getSize()],
'pen-mode': ["PEN-MODE", turtle.penManager.getMode().toString()],
shape: ["SHAPE", turtle._shape],
size: ["SIZE", turtle._size],
xcor: ["XCOR", turtle.xcor],
ycor: ["YCOR", turtle.ycor]
};
};
Updater.prototype._patchMap = function(patch) {
return {
id: ["WHO", patch.id],
pcolor: ["PCOLOR", patch._pcolor],
plabel: ["PLABEL", patch._plabel.toString()],
'plabel-color': ["PLABEL-COLOR", patch._plabelcolor],
pxcor: ["PXCOR", patch.pxcor],
pycor: ["PYCOR", patch.pycor]
};
};
Updater.prototype._linkMap = function(link) {
return {
breed: ["BREED", link.getBreedName()],
color: ["COLOR", link._color],
end1: ["END1", link.end1.id],
end2: ["END2", link.end2.id],
heading: ["HEADING", link.getHeading()],
'hidden?': ["HIDDEN?", link._isHidden],
id: ["ID", link.id],
label: ["LABEL", link._label.toString()],
'label-color': ["LABEL-COLOR", link._labelcolor],
midpointx: ["MIDPOINTX", link.getMidpointX()],
midpointy: ["MIDPOINTY", link.getMidpointY()],
shape: ["SHAPE", link._shape],
size: ["SIZE", link.getSize()],
thickness: ["THICKNESS", link._thickness],
'tie-mode': ["TIE-MODE", link.tiemode],
lcolor: ignored,
llabel: ignored,
llabelcolor: ignored,
lhidden: ignored,
lbreed: ignored,
lshape: ignored
};
};
Updater.prototype._worldMap = function(world) {
return {
height: ["worldHeight", world.topology.height],
id: ["WHO", world.id],
patchesAllBlack: ["patchesAllBlack", world._patchesAllBlack],
patchesWithLabels: ["patchesWithLabels", world._patchesWithLabels],
maxPxcor: ["MAXPXCOR", world.topology.maxPxcor],
maxPycor: ["MAXPYCOR", world.topology.maxPycor],
minPxcor: ["MINPXCOR", world.topology.minPxcor],
minPycor: ["MINPYCOR", world.topology.minPycor],
ticks: ["ticks", world.ticker._count],
unbreededLinksAreDirected: ["unbreededLinksAreDirected", world.breedManager.links().isDirected()],
width: ["worldWidth", world.topology.width]
};
};
Updater.prototype._observerMap = function(observer) {
return {
id: ["WHO", observer.id],
perspective: ["perspective", observer._perspective.toInt],
targetAgent: ["targetAgent", observer._getTargetAgentUpdate()]
};
};
Updater.prototype._update = function(agentType, id, newAgent) {
this._updates[0][agentType][id] = newAgent;
};
Updater.prototype._flushUpdates = function() {
this._updates = [new Update()];
};
return Updater;
})();
}).call(this);
},{"./core/link":"r3RBLf","./core/observer":"2IE8Rg","./core/patch":"t5DuqE","./core/turtle":"d1H0D2","./core/world":"8ahyeg","tortoise/util/exception":12}],"engine/updater":[function(require,module,exports){
module.exports=require('zSkDPr');
},{}],"engine/workspace":[function(require,module,exports){
module.exports=require('ySLy9z');
},{}],"ySLy9z":[function(require,module,exports){
(function() {
var BreedManager, Dump, Hasher, LayoutManager, LinkPrims, ListPrims, Prims, SelfManager, SelfPrims, Timer, Updater, World,
__slice = [].slice;
Dump = require('./dump');
Hasher = require('./hasher');
Updater = require('./updater');
BreedManager = require('./core/breedmanager');
World = require('./core/world');
SelfManager = require('./core/structure/selfmanager');
LayoutManager = require('./prim/layoutmanager');
LinkPrims = require('./prim/linkprims');
ListPrims = require('./prim/listprims');
Prims = require('./prim/prims');
SelfPrims = require('./prim/selfprims');
Timer = require('tortoise/util/timer');
module.exports = function(breedObjs) {
return function() {
var breedManager, layoutManager, linkPrims, listPrims, prims, selfManager, selfPrims, timer, updater, world, worldArgs;
worldArgs = arguments;
selfManager = new SelfManager;
breedManager = new BreedManager(breedObjs);
prims = new Prims(Dump, Hasher);
selfPrims = new SelfPrims(selfManager.self);
timer = new Timer;
updater = new Updater;
world = (function(func, args, ctor) {
ctor.prototype = func.prototype;
var child = new ctor, result = func.apply(child, args);
return Object(result) === result ? result : child;
})(World, [selfManager, updater, breedManager].concat(__slice.call(worldArgs)), function(){});
layoutManager = new LayoutManager(world);
linkPrims = new LinkPrims(world);
listPrims = new ListPrims(Hasher, prims.equality.bind(prims));
return {
selfManager: selfManager,
breedManager: breedManager,
layoutManager: layoutManager,
linkPrims: linkPrims,
listPrims: listPrims,
prims: prims,
selfPrims: selfPrims,
timer: timer,
updater: updater,
world: world
};
};
};
}).call(this);
},{"./core/breedmanager":"GRdTwj","./core/structure/selfmanager":"UzkpAA","./core/world":"8ahyeg","./dump":"OB2y0z","./hasher":"LrlmrN","./prim/layoutmanager":"cVEtBN","./prim/linkprims":"rScFap","./prim/listprims":"vH+78D","./prim/prims":"F1Ty61","./prim/selfprims":"PUrfyc","./updater":"zSkDPr","tortoise/util/timer":17}],"nashorn/denuller":[function(require,module,exports){
module.exports=require('ifYDNE');
},{}],"ifYDNE":[function(require,module,exports){
/*
used to work around Nashorn bug where JSON.parse on objects with
integer keys sometimes invents nonexistent entries with null values;
see http://bugs.java.com/bugdatabase/view_bug.do?bug_id=8038119 --ST
The bug has been marked as fixed in Java 8u20, but that's the most recent
Java 8 version at the moment, so let's give it a little time to disseminate
before throwing `Denuller` out. --JAB (9/8/14)
*/
(function() {
var denull, _;
_ = require('lodash');
denull = function(x) {
var transformFunc;
if (_(x).isArray()) {
return _(x).map(denull).value();
} else if (_(x).isObject()) {
transformFunc = function(acc, value, key) {
if ((value != null) || isNaN(key)) {
acc[key] = denull(value);
}
return acc;
};
return _(x).transform(transformFunc, {}).value();
} else {
return x;
}
};
module.exports = denull;
}).call(this);
},{"lodash":"4HJaAd"}],"shim/cloner":[function(require,module,exports){
module.exports=require('q8hHLd');
},{}],"q8hHLd":[function(require,module,exports){
module.exports=require(5)
},{"lodash":"4HJaAd"}],"shim/printer":[function(require,module,exports){
module.exports=require('7dPD1G');
},{}],"7dPD1G":[function(require,module,exports){
module.exports=require(6)
},{}],"shim/random":[function(require,module,exports){
module.exports=require('n6XlHe');
},{}],"n6XlHe":[function(require,module,exports){
module.exports=require(7)
},{}],"T4eYmM":[function(require,module,exports){
module.exports=require(8)
},{"./cloner":"q8hHLd"}],"shim/strictmath":[function(require,module,exports){
module.exports=require('T4eYmM');
},{}],"util/abstractmethoderror":[function(require,module,exports){
module.exports=require('csOWU+');
},{}],"csOWU+":[function(require,module,exports){
module.exports=require(9)
},{}],"util/call":[function(require,module,exports){
module.exports=require('FYTAuy');
},{}],"FYTAuy":[function(require,module,exports){
(function() {
var Exception,
__slice = [].slice;
Exception = require('./exception');
module.exports = function() {
var args, e, fn;
fn = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
try {
return fn.apply(null, args);
} catch (_error) {
e = _error;
if (!(e instanceof Exception.StopInterrupt)) {
throw e;
}
}
};
}).call(this);
},{"./exception":"vNR0Gj"}],"util/colormodel":[function(require,module,exports){
module.exports=require('M/5ebg');
},{}],"M/5ebg":[function(require,module,exports){
module.exports=require(10)
},{"../shim/random":"n6XlHe","lodash":"4HJaAd"}],"util/comparator":[function(require,module,exports){
module.exports=require('kooBVS');
},{}],"kooBVS":[function(require,module,exports){
module.exports=require(11)
},{}],"util/exception":[function(require,module,exports){
module.exports=require('vNR0Gj');
},{}],"vNR0Gj":[function(require,module,exports){
module.exports=require(12)
},{}],"util/iterator":[function(require,module,exports){
module.exports=require('jdvs0w');
},{}],"jdvs0w":[function(require,module,exports){
module.exports=require(13)
},{}],"util/notimplemented":[function(require,module,exports){
module.exports=require('mdoUix');
},{}],"mdoUix":[function(require,module,exports){
(function() {
module.exports = function(name, defaultValue) {
if (defaultValue == null) {
defaultValue = {};
}
if ((typeof console !== "undefined" && console !== null) && (console.warn != null)) {
console.warn("The `" + name + "` primitive has not yet been implemented.");
}
return function() {
return defaultValue;
};
};
}).call(this);
},{}],"OJjBWI":[function(require,module,exports){
module.exports=require(14)
},{"./iterator":"jdvs0w","lodash":"4HJaAd"}],"util/seq":[function(require,module,exports){
module.exports=require('OJjBWI');
},{}],"util/shufflerator":[function(require,module,exports){
module.exports=require('7zIjul');
},{}],"7zIjul":[function(require,module,exports){
module.exports=require(15)
},{"../shim/random":"n6XlHe","./iterator":"jdvs0w"}],"util/stablesort":[function(require,module,exports){
module.exports=require('iXiUJK');
},{}],"iXiUJK":[function(require,module,exports){
module.exports=require(16)
},{"lodash":"4HJaAd"}],"util/timer":[function(require,module,exports){
module.exports=require('GGkWHy');
},{}],"GGkWHy":[function(require,module,exports){
module.exports=require(17)
},{}],"util/trig":[function(require,module,exports){
module.exports=require('AZ3OQ7');
},{}],"AZ3OQ7":[function(require,module,exports){
module.exports=require(18)
},{"../shim/strictmath":"T4eYmM","./exception":"vNR0Gj"}],"NS7iDt":[function(require,module,exports){
module.exports=require(19)
},{}],"util/typechecker":[function(require,module,exports){
module.exports=require('NS7iDt');
},{}]},{},["9MEHHl"]);;
(function() {
window.AgentModel = (function() {
var mergeObjectInto;
function AgentModel() {
this.turtles = {};
this.patches = {};
this.links = {};
this.observer = {};
this.world = {};
}
AgentModel.prototype.update = function(modelUpdate) {
var index, linkId, linkUpdates, patch, patchId, patchUpdates, turtleId, turtleUpdates, worldUpdate, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2, _ref3;
turtleUpdates = modelUpdate.turtles;
if (turtleUpdates) {
_ref = Object.keys(turtleUpdates);
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
turtleId = _ref[_i];
if (isFinite(turtleId)) {
this.updateTurtle(turtleId, turtleUpdates[turtleId]);
}
}
}
linkUpdates = modelUpdate.links;
if (linkUpdates) {
_ref1 = Object.keys(linkUpdates);
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
linkId = _ref1[_j];
this.updateLink(linkId, linkUpdates[linkId]);
}
}
if ((modelUpdate.world != null) && (modelUpdate.world[0] != null)) {
worldUpdate = modelUpdate.world[0];
mergeObjectInto(modelUpdate.world[0], this.world);
if ((worldUpdate.minPxcor != null) && (worldUpdate.maxPxcor != null) && (worldUpdate.minPycor != null) && (worldUpdate.maxPycor != null)) {
_ref2 = this.patches;
for (index in _ref2) {
patch = _ref2[index];
if (patch.pxcor < worldUpdate.minPxcor || patch.pxcor > worldUpdate.maxPxcor || patch.pycor < worldUpdate.minPycor || patch.pycor > worldUpdate.maxPycor) {
delete this.patches[index];
}
}
}
}
patchUpdates = modelUpdate.patches;
if (patchUpdates) {
_ref3 = Object.keys(patchUpdates);
for (_k = 0, _len2 = _ref3.length; _k < _len2; _k++) {
patchId = _ref3[_k];
this.updatePatch(patchId, patchUpdates[patchId]);
}
}
if ((modelUpdate.observer != null) && (modelUpdate.observer[0] != null)) {
mergeObjectInto(modelUpdate.observer[0], this.observer);
}
};
AgentModel.prototype.updateTurtle = function(turtleId, varUpdates) {
var t;
if (varUpdates === null || varUpdates['WHO'] === -1) {
return delete this.turtles[turtleId];
} else {
t = this.turtles[turtleId];
if (t == null) {
t = this.turtles[turtleId] = {
heading: 360 * Math.random(),
xcor: 0,
ycor: 0,
shape: 'default',
color: 'hsl(' + (360 * Math.random()) + ',100%,50%)'
};
}
return mergeObjectInto(varUpdates, t);
}
};
AgentModel.prototype.updateLink = function(linkId, varUpdates) {
var l;
if (varUpdates === null || varUpdates['WHO'] === -1) {
return delete this.links[linkId];
} else {
l = this.links[linkId];
if (l == null) {
l = this.links[linkId] = {
shape: 'default',
color: 5
};
}
return mergeObjectInto(varUpdates, l);
}
};
AgentModel.prototype.updatePatch = function(patchId, varUpdates) {
var p;
p = this.patches[patchId];
if (p == null) {
p = this.patches[patchId] = {};
}
return mergeObjectInto(varUpdates, p);
};
mergeObjectInto = function(updatedObject, targetObject) {
var value, variable;
for (variable in updatedObject) {
value = updatedObject[variable];
targetObject[variable.toLowerCase()] = value;
}
};
return AgentModel;
})();
}).call(this);
//# sourceMappingURL=agentmodel.js.map
;
(function() {
var b, baseIndex, cachedNetlogoColors, color, colorArrayToCSS, colorTimesTen, g, i, netlogoBaseColors, netlogoColorNamesIndices, r, step, _i, _len, _ref;
window.netlogoColorToCSS = function(netlogoColor) {
var a, array, b, g, r, _ref;
_ref = array = netlogoColorToRGB(netlogoColor), r = _ref[0], g = _ref[1], b = _ref[2];
a = array.length > 3 ? array[3] : 255;
if (a < 255) {
return "rgba(" + r + ", " + g + ", " + b + ", " + (a / 255) + ")";
} else {
return "rgb(" + r + ", " + g + ", " + b + ")";
}
};
window.netlogoColorToRGB = function(netlogoColor) {
switch (typeof netlogoColor) {
case "number":
return cachedNetlogoColors[Math.floor(netlogoColor * 10)];
case "object":
return netlogoColor.map(Math.round);
case "string":
return netlogoBaseColors[netlogoColorNamesIndices[netlogoColor]];
default:
return console.error("Unrecognized color: " + netlogoColor);
}
};
netlogoColorNamesIndices = {};
_ref = ['gray', 'red', 'orange', 'brown', 'yellow', 'green', 'lime', 'turqoise', 'cyan', 'sky', 'blue', 'violet', 'magenta', 'pink', 'black', 'white'];
for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
color = _ref[i];
netlogoColorNamesIndices[color] = i;
}
netlogoBaseColors = [[140, 140, 140], [215, 48, 39], [241, 105, 19], [156, 109, 70], [237, 237, 47], [87, 176, 58], [42, 209, 57], [27, 158, 119], [82, 196, 196], [43, 140, 190], [50, 92, 168], [123, 78, 163], [166, 25, 105], [224, 126, 149], [0, 0, 0], [255, 255, 255]];
cachedNetlogoColors = (function() {
var _j, _ref1, _results;
_results = [];
for (colorTimesTen = _j = 0; _j <= 1400; colorTimesTen = ++_j) {
baseIndex = Math.floor(colorTimesTen / 100);
_ref1 = netlogoBaseColors[baseIndex], r = _ref1[0], g = _ref1[1], b = _ref1[2];
step = (colorTimesTen % 100 - 50) / 50.48 + 0.012;
if (step < 0) {
r += Math.floor(r * step);
g += Math.floor(g * step);
b += Math.floor(b * step);
} else {
r += Math.floor((0xFF - r) * step);
g += Math.floor((0xFF - g) * step);
b += Math.floor((0xFF - b) * step);
}
_results.push([r, g, b]);
}
return _results;
})();
colorArrayToCSS = function(array) {
var a, _ref1;
_ref1 = array.map(Math.round), r = _ref1[0], g = _ref1[1], b = _ref1[2];
a = array.length > 3 ? array[3] : 255;
if (a < 255) {
return "rgba(" + r + ", " + g + ", " + b + ", " + (a / 255) + ")";
} else {
return "rgb(" + r + ", " + g + ", " + b + ")";
}
};
}).call(this);
//# sourceMappingURL=colors.js.map
;
(function() {
var drawPath, setColoring,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
window.ShapeDrawer = (function() {
function ShapeDrawer(shapes) {
this.shapes = shapes;
}
ShapeDrawer.prototype.drawShape = function(ctx, turtleColor, shapeName) {
ctx.translate(.5, -.5);
ctx.scale(-1 / 300, 1 / 300);
this.drawRawShape(ctx, turtleColor, shapeName);
};
ShapeDrawer.prototype.drawRawShape = function(ctx, turtleColor, shapeName) {
var elem, shape, _i, _len, _ref;
shape = this.shapes[shapeName] || defaultShape;
_ref = shape.elements;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
elem = _ref[_i];
draw[elem.type](ctx, turtleColor, elem);
}
};
return ShapeDrawer;
})();
window.CachingShapeDrawer = (function(_super) {
__extends(CachingShapeDrawer, _super);
function CachingShapeDrawer(shapes) {
CachingShapeDrawer.__super__.constructor.call(this, shapes);
this.shapeCache = {};
}
CachingShapeDrawer.prototype.drawShape = function(ctx, turtleColor, shapeName) {
var shapeCanvas, shapeCtx, shapeKey;
shapeName = shapeName.toLowerCase();
shapeKey = this.shapeKey(shapeName, turtleColor);
shapeCanvas = this.shapeCache[shapeKey];
if (shapeCanvas == null) {
shapeCanvas = document.createElement('canvas');
shapeCanvas.width = shapeCanvas.height = 300;
shapeCtx = shapeCanvas.getContext('2d');
this.drawRawShape(shapeCtx, turtleColor, shapeName);
this.shapeCache[shapeKey] = shapeCanvas;
}
ctx.translate(.5, -.5);
ctx.scale(-1 / 300, 1 / 300);
ctx.drawImage(shapeCanvas, 0, 0);
};
CachingShapeDrawer.prototype.shapeKey = function(shapeName, turtleColor) {
return [shapeName, netlogoColorToCSS(turtleColor)];
};
return CachingShapeDrawer;
})(ShapeDrawer);
setColoring = function(ctx, turtleColor, element) {
turtleColor = netlogoColorToCSS(turtleColor);
if (element.filled) {
if (element.marked) {
ctx.fillStyle = turtleColor;
} else {
ctx.fillStyle = element.color;
}
} else {
if (element.marked) {
ctx.strokeStyle = turtleColor;
} else {
ctx.strokeStyle = element.color;
}
}
};
drawPath = function(ctx, turtleColor, element) {
setColoring(ctx, turtleColor, element);
if (element.filled) {
ctx.fill();
} else {
ctx.stroke();
}
};
window.draw = {
circle: function(ctx, turtleColor, circle) {
var r;
r = circle.diam / 2;
ctx.beginPath();
ctx.arc(circle.x + r, circle.y + r, r, 0, 2 * Math.PI, false);
ctx.closePath();
drawPath(ctx, turtleColor, circle);
},
polygon: function(ctx, turtleColor, polygon) {
var i, x, xcors, y, ycors, _i, _len, _ref;
xcors = polygon.xcors;
ycors = polygon.ycors;
ctx.beginPath();
ctx.moveTo(xcors[0], ycors[0]);
_ref = xcors.slice(1);
for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
x = _ref[i];
y = ycors[i + 1];
ctx.lineTo(x, y);
}
ctx.closePath();
drawPath(ctx, turtleColor, polygon);
},
rectangle: function(ctx, turtleColor, rectangle) {
var h, w, x, y;
x = rectangle.xmin;
y = rectangle.ymin;
w = rectangle.xmax - x;
h = rectangle.ymax - y;
setColoring(ctx, turtleColor, rectangle);
if (rectangle.filled) {
ctx.fillRect(x, y, w, h);
} else {
ctx.strokeRect(x, y, w, h);
}
},
line: function(ctx, turtleColor, line) {
var h, w, x, y;
x = line.x1;
y = line.y1;
w = line.x2 - line.x1;
h = line.y2 - line.y1;
setColoring(ctx, turtleColor, line);
ctx.lineWidth = 15;
ctx.beginPath();
ctx.moveTo(line.x1, line.y1);
ctx.lineTo(line.x2, line.y2);
ctx.stroke();
ctx.lineWidth = .1;
}
};
window.defaultShape = {
rotate: true,
elements: [
{
type: 'polygon',
color: 'grey',
filled: 'true',
marked: 'true',
xcors: [150, 40, 150, 260],
ycors: [5, 250, 205, 250]
}
]
};
}).call(this);
//# sourceMappingURL=drawshape.js.map
;
defaultShapes = {
"default": {
"rotate": true,
"elements": [
{
"xcors": [
150,
40,
150,
260
],
"ycors": [
5,
250,
205,
250
],
"type": "polygon",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
}
]
},
"airplane": {
"rotate": true,
"elements": [
{
"xcors": [
150,
135,
120,
120,
15,
15,
120,
135,
105,
120,
150,
180,
210,
165,
180,
285,
285,
180,
180,
165
],
"ycors": [
0,
15,
60,
105,
165,
195,
180,
240,
270,
285,
270,
285,
270,
240,
180,
195,
165,
105,
60,
15
],
"type": "polygon",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
}
]
},
"arrow": {
"rotate": true,
"elements": [
{
"xcors": [
150,
0,
105,
105,
195,
195,
300
],
"ycors": [
0,
150,
150,
293,
293,
150,
150
],
"type": "polygon",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
}
]
},
"box": {
"rotate": false,
"elements": [
{
"xcors": [
150,
285,
285,
150
],
"ycors": [
285,
225,
75,
135
],
"type": "polygon",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"xcors": [
150,
15,
150,
285
],
"ycors": [
135,
75,
15,
75
],
"type": "polygon",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"xcors": [
15,
15,
150,
150
],
"ycors": [
75,
225,
285,
135
],
"type": "polygon",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"x1": 150,
"y1": 285,
"x2": 150,
"y2": 135,
"type": "line",
"color": "rgba(0, 0, 0, 1.0)",
"filled": false,
"marked": false
},
{
"x1": 150,
"y1": 135,
"x2": 15,
"y2": 75,
"type": "line",
"color": "rgba(0, 0, 0, 1.0)",
"filled": false,
"marked": false
},
{
"x1": 150,
"y1": 135,
"x2": 285,
"y2": 75,
"type": "line",
"color": "rgba(0, 0, 0, 1.0)",
"filled": false,
"marked": false
}
]
},
"bug": {
"rotate": true,
"elements": [
{
"x": 96,
"y": 182,
"diam": 108,
"type": "circle",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"x": 110,
"y": 127,
"diam": 80,
"type": "circle",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"x": 110,
"y": 75,
"diam": 80,
"type": "circle",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"x1": 150,
"y1": 100,
"x2": 80,
"y2": 30,
"type": "line",
"color": "rgba(141, 141, 141, 1.0)",
"filled": false,
"marked": true
},
{
"x1": 150,
"y1": 100,
"x2": 220,
"y2": 30,
"type": "line",
"color": "rgba(141, 141, 141, 1.0)",
"filled": false,
"marked": true
}
]
},
"butterfly": {
"rotate": true,
"elements": [
{
"xcors": [
150,
209,
225,
225,
195,
165,
150
],
"ycors": [
165,
199,
225,
255,
270,
255,
240
],
"type": "polygon",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"xcors": [
150,
89,
75,
75,
105,
135,
150
],
"ycors": [
165,
198,
225,
255,
270,
255,
240
],
"type": "polygon",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"xcors": [
139,
100,
55,
25,
10,
10,
25,
40,
85,
139
],
"ycors": [
148,
105,
90,
90,
105,
135,
180,
195,
194,
163
],
"type": "polygon",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"xcors": [
162,
200,
245,
275,
290,
290,
275,
260,
215,
162
],
"ycors": [
150,
105,
90,
90,
105,
135,
180,
195,
195,
165
],
"type": "polygon",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"xcors": [
150,
135,
120,
135,
150,
165,
180,
165
],
"ycors": [
255,
225,
150,
120,
105,
120,
150,
225
],
"type": "polygon",
"color": "rgba(0, 0, 0, 1.0)",
"filled": true,
"marked": false
},
{
"x": 135,
"y": 90,
"diam": 30,
"type": "circle",
"color": "rgba(0, 0, 0, 1.0)",
"filled": true,
"marked": false
},
{
"x1": 150,
"y1": 105,
"x2": 195,
"y2": 60,
"type": "line",
"color": "rgba(0, 0, 0, 1.0)",
"filled": false,
"marked": false
},
{
"x1": 150,
"y1": 105,
"x2": 105,
"y2": 60,
"type": "line",
"color": "rgba(0, 0, 0, 1.0)",
"filled": false,
"marked": false
}
]
},
"car": {
"rotate": false,
"elements": [
{
"xcors": [
300,
279,
261,
240,
226,
213,
203,
185,
159,
135,
75,
0,
0,
0,
300,
300
],
"ycors": [
180,
164,
144,
135,
132,
106,
84,
63,
50,
50,
60,
150,
165,
225,
225,
180
],
"type": "polygon",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"x": 180,
"y": 180,
"diam": 90,
"type": "circle",
"color": "rgba(0, 0, 0, 1.0)",
"filled": true,
"marked": false
},
{
"x": 30,
"y": 180,
"diam": 90,
"type": "circle",
"color": "rgba(0, 0, 0, 1.0)",
"filled": true,
"marked": false
},
{
"xcors": [
162,
132,
134,
209,
194,
189,
180
],
"ycors": [
80,
78,
135,
135,
105,
96,
89
],
"type": "polygon",
"color": "rgba(0, 0, 0, 1.0)",
"filled": true,
"marked": false
},
{
"x": 47,
"y": 195,
"diam": 58,
"type": "circle",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"x": 195,
"y": 195,
"diam": 58,
"type": "circle",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
}
]
},
"circle": {
"rotate": false,
"elements": [
{
"x": 0,
"y": 0,
"diam": 300,
"type": "circle",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
}
]
},
"circle 2": {
"rotate": false,
"elements": [
{
"x": 0,
"y": 0,
"diam": 300,
"type": "circle",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"x": 30,
"y": 30,
"diam": 240,
"type": "circle",
"color": "rgba(0, 0, 0, 1.0)",
"filled": true,
"marked": false
}
]
},
"cloud": {
"rotate": false,
"elements": [
{
"x": 13,
"y": 118,
"diam": 94,
"type": "circle",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"x": 86,
"y": 101,
"diam": 127,
"type": "circle",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"x": 51,
"y": 51,
"diam": 108,
"type": "circle",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"x": 118,
"y": 43,
"diam": 95,
"type": "circle",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"x": 158,
"y": 68,
"diam": 134,
"type": "circle",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
}
]
},
"co2-molecule": {
"rotate": true,
"elements": [
{
"x": 183,
"y": 63,
"diam": 84,
"type": "circle",
"color": "rgba(255, 255, 255, 1.0)",
"filled": true,
"marked": false
},
{
"x": 183,
"y": 63,
"diam": 84,
"type": "circle",
"color": "rgba(0, 0, 0, 1.0)",
"filled": false,
"marked": false
},
{
"x": 75,
"y": 75,
"diam": 150,
"type": "circle",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"x": 75,
"y": 75,
"diam": 150,
"type": "circle",
"color": "rgba(0, 0, 0, 1.0)",
"filled": false,
"marked": false
},
{
"x": 33,
"y": 63,
"diam": 84,
"type": "circle",
"color": "rgba(255, 255, 255, 1.0)",
"filled": true,
"marked": false
},
{
"x": 33,
"y": 63,
"diam": 84,
"type": "circle",
"color": "rgba(0, 0, 0, 1.0)",
"filled": false,
"marked": false
}
]
},
"cow": {
"rotate": false,
"elements": [
{
"xcors": [
200,
197,
179,
177,
166,
140,
93,
78,
72,
49,
48,
37,
25,
25,
45,
103,
179,
198,
252,
272,
293,
285,
255,
242,
224
],
"ycors": [
193,
249,
249,
196,
187,
189,
191,
179,
211,
209,
181,
149,
120,
89,
72,
84,
75,
76,
64,
81,
103,
121,
121,
118,
167
],
"type": "polygon",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"xcors": [
73,
86,
62,
48
],
"ycors": [
210,
251,
249,
208
],
"type": "polygon",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"xcors": [
25,
16,
9,
23,
25,
39
],
"ycors": [
114,
195,
204,
213,
200,
123
],
"type": "polygon",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
}
]
},
"cylinder": {
"rotate": false,
"elements": [
{
"x": 0,
"y": 0,
"diam": 300,
"type": "circle",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
}
]
},
"dot": {
"rotate": false,
"elements": [
{
"x": 90,
"y": 90,
"diam": 120,
"type": "circle",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
}
]
},
"face happy": {
"rotate": false,
"elements": [
{
"x": 8,
"y": 8,
"diam": 285,
"type": "circle",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"x": 60,
"y": 75,
"diam": 60,
"type": "circle",
"color": "rgba(0, 0, 0, 1.0)",
"filled": true,
"marked": false
},
{
"x": 180,
"y": 75,
"diam": 60,
"type": "circle",
"color": "rgba(0, 0, 0, 1.0)",
"filled": true,
"marked": false
},
{
"xcors": [
150,
90,
62,
47,
67,
90,
109,
150,
192,
210,
227,
251,
236,
212
],
"ycors": [
255,
239,
213,
191,
179,
203,
218,
225,
218,
203,
181,
194,
217,
240
],
"type": "polygon",
"color": "rgba(0, 0, 0, 1.0)",
"filled": true,
"marked": false
}
]
},
"face neutral": {
"rotate": false,
"elements": [
{
"x": 8,
"y": 7,
"diam": 285,
"type": "circle",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"x": 60,
"y": 75,
"diam": 60,
"type": "circle",
"color": "rgba(0, 0, 0, 1.0)",
"filled": true,
"marked": false
},
{
"x": 180,
"y": 75,
"diam": 60,
"type": "circle",
"color": "rgba(0, 0, 0, 1.0)",
"filled": true,
"marked": false
},
{
"xmin": 60,
"ymin": 195,
"xmax": 240,
"ymax": 225,
"type": "rectangle",
"color": "rgba(0, 0, 0, 1.0)",
"filled": true,
"marked": false
}
]
},
"face sad": {
"rotate": false,
"elements": [
{
"x": 8,
"y": 8,
"diam": 285,
"type": "circle",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"x": 60,
"y": 75,
"diam": 60,
"type": "circle",
"color": "rgba(0, 0, 0, 1.0)",
"filled": true,
"marked": false
},
{
"x": 180,
"y": 75,
"diam": 60,
"type": "circle",
"color": "rgba(0, 0, 0, 1.0)",
"filled": true,
"marked": false
},
{
"xcors": [
150,
90,
62,
47,
67,
90,
109,
150,
192,
210,
227,
251,
236,
212
],
"ycors": [
168,
184,
210,
232,
244,
220,
205,
198,
205,
220,
242,
229,
206,
183
],
"type": "polygon",
"color": "rgba(0, 0, 0, 1.0)",
"filled": true,
"marked": false
}
]
},
"fish": {
"rotate": false,
"elements": [
{
"xcors": [
44,
21,
15,
0,
15,
0,
13,
20,
45
],
"ycors": [
131,
87,
86,
120,
150,
180,
214,
212,
166
],
"type": "polygon",
"color": "rgba(255, 255, 255, 1.0)",
"filled": true,
"marked": false
},
{
"xcors": [
135,
119,
95,
76,
46,
60
],
"ycors": [
195,
235,
218,
210,
204,
165
],
"type": "polygon",
"color": "rgba(255, 255, 255, 1.0)",
"filled": true,
"marked": false
},
{
"xcors": [
75,
83,
71,
86,
166,
135
],
"ycors": [
45,
77,
103,
114,
78,
60
],
"type": "polygon",
"color": "rgba(255, 255, 255, 1.0)",
"filled": true,
"marked": false
},
{
"xcors": [
30,
151,
226,
280,
292,
292,
287,
270,
195,
151,
30
],
"ycors": [
136,
77,
81,
119,
146,
160,
170,
195,
210,
212,
166
],
"type": "polygon",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"x": 215,
"y": 106,
"diam": 30,
"type": "circle",
"color": "rgba(0, 0, 0, 1.0)",
"filled": true,
"marked": false
}
]
},
"flag": {
"rotate": false,
"elements": [
{
"xmin": 60,
"ymin": 15,
"xmax": 75,
"ymax": 300,
"type": "rectangle",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"xcors": [
90,
270,
90
],
"ycors": [
150,
90,
30
],
"type": "polygon",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"x1": 75,
"y1": 135,
"x2": 90,
"y2": 135,
"type": "line",
"color": "rgba(141, 141, 141, 1.0)",
"filled": false,
"marked": true
},
{
"x1": 75,
"y1": 45,
"x2": 90,
"y2": 45,
"type": "line",
"color": "rgba(141, 141, 141, 1.0)",
"filled": false,
"marked": true
}
]
},
"flower": {
"rotate": false,
"elements": [
{
"xcors": [
135,
165,
180,
180,
150,
165,
195,
195,
165
],
"ycors": [
120,
165,
210,
240,
300,
300,
240,
195,
135
],
"type": "polygon",
"color": "rgba(89, 176, 60, 1.0)",
"filled": true,
"marked": false
},
{
"x": 85,
"y": 132,
"diam": 38,
"type": "circle",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"x": 130,
"y": 147,
"diam": 38,
"type": "circle",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"x": 192,
"y": 85,
"diam": 38,
"type": "circle",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"x": 85,
"y": 40,
"diam": 38,
"type": "circle",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"x": 177,
"y": 40,
"diam": 38,
"type": "circle",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"x": 177,
"y": 132,
"diam": 38,
"type": "circle",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"x": 70,
"y": 85,
"diam": 38,
"type": "circle",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"x": 130,
"y": 25,
"diam": 38,
"type": "circle",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"x": 96,
"y": 51,
"diam": 108,
"type": "circle",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"x": 113,
"y": 68,
"diam": 74,
"type": "circle",
"color": "rgba(0, 0, 0, 1.0)",
"filled": true,
"marked": false
},
{
"xcors": [
189,
219,
249,
279,
234
],
"ycors": [
233,
188,
173,
188,
218
],
"type": "polygon",
"color": "rgba(89, 176, 60, 1.0)",
"filled": true,
"marked": false
},
{
"xcors": [
180,
150,
105,
75,
135
],
"ycors": [
255,
210,
210,
240,
240
],
"type": "polygon",
"color": "rgba(89, 176, 60, 1.0)",
"filled": true,
"marked": false
}
]
},
"house": {
"rotate": false,
"elements": [
{
"xmin": 45,
"ymin": 120,
"xmax": 255,
"ymax": 285,
"type": "rectangle",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"xmin": 120,
"ymin": 210,
"xmax": 180,
"ymax": 285,
"type": "rectangle",
"color": "rgba(0, 0, 0, 1.0)",
"filled": true,
"marked": false
},
{
"xcors": [
15,
150,
285
],
"ycors": [
120,
15,
120
],
"type": "polygon",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"x1": 30,
"y1": 120,
"x2": 270,
"y2": 120,
"type": "line",
"color": "rgba(0, 0, 0, 1.0)",
"filled": false,
"marked": false
}
]
},
"leaf": {
"rotate": false,
"elements": [
{
"xcors": [
150,
135,
120,
60,
30,
60,
60,
15,
30,
15,
40,
45,
60,
90,
105,
120,
105,
120,
135,
150,
165,
180,
195,
180,
195,
210,
240,
255,
263,
285,
270,
285,
240,
240,
270,
240,
180,
165
],
"ycors": [
210,
195,
210,
210,
195,
180,
165,
135,
120,
105,
104,
90,
90,
105,
120,
120,
60,
60,
30,
15,
30,
60,
60,
120,
120,
105,
90,
90,
104,
105,
120,
135,
165,
180,
195,
210,
210,
195
],
"type": "polygon",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"xcors": [
135,
135,
120,
105,
105,
135,
165,
165
],
"ycors": [
195,
240,
255,
255,
285,
285,
240,
195
],
"type": "polygon",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
}
]
},
"line": {
"rotate": true,
"elements": [
{
"x1": 150,
"y1": 0,
"x2": 150,
"y2": 300,
"type": "line",
"color": "rgba(141, 141, 141, 1.0)",
"filled": false,
"marked": true
}
]
},
"line half": {
"rotate": true,
"elements": [
{
"x1": 150,
"y1": 0,
"x2": 150,
"y2": 150,
"type": "line",
"color": "rgba(141, 141, 141, 1.0)",
"filled": false,
"marked": true
}
]
},
"molecule water": {
"rotate": true,
"elements": [
{
"x": 183,
"y": 63,
"diam": 84,
"type": "circle",
"color": "rgba(255, 255, 255, 1.0)",
"filled": true,
"marked": false
},
{
"x": 183,
"y": 63,
"diam": 84,
"type": "circle",
"color": "rgba(0, 0, 0, 1.0)",
"filled": false,
"marked": false
},
{
"x": 75,
"y": 75,
"diam": 150,
"type": "circle",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"x": 75,
"y": 75,
"diam": 150,
"type": "circle",
"color": "rgba(0, 0, 0, 1.0)",
"filled": false,
"marked": false
},
{
"x": 33,
"y": 63,
"diam": 84,
"type": "circle",
"color": "rgba(255, 255, 255, 1.0)",
"filled": true,
"marked": false
},
{
"x": 33,
"y": 63,
"diam": 84,
"type": "circle",
"color": "rgba(0, 0, 0, 1.0)",
"filled": false,
"marked": false
}
]
},
"pentagon": {
"rotate": false,
"elements": [
{
"xcors": [
150,
15,
60,
240,
285
],
"ycors": [
15,
120,
285,
285,
120
],
"type": "polygon",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
}
]
},
"person": {
"rotate": false,
"elements": [
{
"x": 110,
"y": 5,
"diam": 80,
"type": "circle",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"xcors": [
105,
120,
90,
105,
135,
150,
165,
195,
210,
180,
195
],
"ycors": [
90,
195,
285,
300,
300,
225,
300,
300,
285,
195,
90
],
"type": "polygon",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"xmin": 127,
"ymin": 79,
"xmax": 172,
"ymax": 94,
"type": "rectangle",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"xcors": [
195,
240,
225,
165
],
"ycors": [
90,
150,
180,
105
],
"type": "polygon",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"xcors": [
105,
60,
75,
135
],
"ycors": [
90,
150,
180,
105
],
"type": "polygon",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
}
]
},
"plant": {
"rotate": false,
"elements": [
{
"xmin": 135,
"ymin": 90,
"xmax": 165,
"ymax": 300,
"type": "rectangle",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"xcors": [
135,
90,
45,
75,
135
],
"ycors": [
255,
210,
195,
255,
285
],
"type": "polygon",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"xcors": [
165,
210,
255,
225,
165
],
"ycors": [
255,
210,
195,
255,
285
],
"type": "polygon",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"xcors": [
135,
90,
45,
75,
135
],
"ycors": [
180,
135,
120,
180,
210
],
"type": "polygon",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"xcors": [
165,
165,
225,
255,
210
],
"ycors": [
180,
210,
180,
120,
135
],
"type": "polygon",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"xcors": [
135,
90,
45,
75,
135
],
"ycors": [
105,
60,
45,
105,
135
],
"type": "polygon",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"xcors": [
165,
165,
225,
255,
210
],
"ycors": [
105,
135,
105,
45,
60
],
"type": "polygon",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"xcors": [
135,
120,
150,
180,
165
],
"ycors": [
90,
45,
15,
45,
90
],
"type": "polygon",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
}
]
},
"ray": {
"rotate": true,
"elements": [
{
"x1": 150,
"y1": 0,
"x2": 150,
"y2": 315,
"type": "line",
"color": "rgba(141, 141, 141, 1.0)",
"filled": false,
"marked": true
},
{
"x1": 120,
"y1": 255,
"x2": 150,
"y2": 225,
"type": "line",
"color": "rgba(141, 141, 141, 1.0)",
"filled": false,
"marked": true
},
{
"x1": 150,
"y1": 225,
"x2": 180,
"y2": 255,
"type": "line",
"color": "rgba(141, 141, 141, 1.0)",
"filled": false,
"marked": true
},
{
"x1": 120,
"y1": 165,
"x2": 150,
"y2": 135,
"type": "line",
"color": "rgba(141, 141, 141, 1.0)",
"filled": false,
"marked": true
},
{
"x1": 120,
"y1": 75,
"x2": 150,
"y2": 45,
"type": "line",
"color": "rgba(141, 141, 141, 1.0)",
"filled": false,
"marked": true
},
{
"x1": 150,
"y1": 135,
"x2": 180,
"y2": 165,
"type": "line",
"color": "rgba(141, 141, 141, 1.0)",
"filled": false,
"marked": true
},
{
"x1": 150,
"y1": 45,
"x2": 180,
"y2": 75,
"type": "line",
"color": "rgba(141, 141, 141, 1.0)",
"filled": false,
"marked": true
}
]
},
"sheep": {
"rotate": false,
"elements": [
{
"x": 203,
"y": 65,
"diam": 88,
"type": "circle",
"color": "rgba(255, 255, 255, 1.0)",
"filled": true,
"marked": true
},
{
"x": 70,
"y": 65,
"diam": 162,
"type": "circle",
"color": "rgba(255, 255, 255, 1.0)",
"filled": true,
"marked": true
},
{
"x": 150,
"y": 105,
"diam": 120,
"type": "circle",
"color": "rgba(255, 255, 255, 1.0)",
"filled": true,
"marked": true
},
{
"xcors": [
218,
240,
255,
278
],
"ycors": [
120,
165,
165,
120
],
"type": "polygon",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": false
},
{
"x": 214,
"y": 72,
"diam": 67,
"type": "circle",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": false
},
{
"xmin": 164,
"ymin": 223,
"xmax": 179,
"ymax": 298,
"type": "rectangle",
"color": "rgba(255, 255, 255, 1.0)",
"filled": true,
"marked": true
},
{
"xcors": [
45,
30,
30,
15,
45
],
"ycors": [
285,
285,
240,
195,
210
],
"type": "polygon",
"color": "rgba(255, 255, 255, 1.0)",
"filled": true,
"marked": true
},
{
"x": 3,
"y": 83,
"diam": 150,
"type": "circle",
"color": "rgba(255, 255, 255, 1.0)",
"filled": true,
"marked": true
},
{
"xmin": 65,
"ymin": 221,
"xmax": 80,
"ymax": 296,
"type": "rectangle",
"color": "rgba(255, 255, 255, 1.0)",
"filled": true,
"marked": true
},
{
"xcors": [
195,
210,
210,
240,
195
],
"ycors": [
285,
285,
240,
210,
210
],
"type": "polygon",
"color": "rgba(255, 255, 255, 1.0)",
"filled": true,
"marked": true
},
{
"xcors": [
276,
285,
302,
294
],
"ycors": [
85,
105,
99,
83
],
"type": "polygon",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": false
},
{
"xcors": [
219,
210,
193,
201
],
"ycors": [
85,
105,
99,
83
],
"type": "polygon",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": false
}
]
},
"square": {
"rotate": false,
"elements": [
{
"xmin": 30,
"ymin": 30,
"xmax": 270,
"ymax": 270,
"type": "rectangle",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
}
]
},
"square 2": {
"rotate": false,
"elements": [
{
"xmin": 30,
"ymin": 30,
"xmax": 270,
"ymax": 270,
"type": "rectangle",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"xmin": 60,
"ymin": 60,
"xmax": 240,
"ymax": 240,
"type": "rectangle",
"color": "rgba(0, 0, 0, 1.0)",
"filled": true,
"marked": false
}
]
},
"star": {
"rotate": false,
"elements": [
{
"xcors": [
151,
185,
298,
207,
242,
151,
59,
94,
3,
116
],
"ycors": [
1,
108,
108,
175,
282,
216,
282,
175,
108,
108
],
"type": "polygon",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
}
]
},
"target": {
"rotate": false,
"elements": [
{
"x": 0,
"y": 0,
"diam": 300,
"type": "circle",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"x": 30,
"y": 30,
"diam": 240,
"type": "circle",
"color": "rgba(0, 0, 0, 1.0)",
"filled": true,
"marked": false
},
{
"x": 60,
"y": 60,
"diam": 180,
"type": "circle",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"x": 90,
"y": 90,
"diam": 120,
"type": "circle",
"color": "rgba(0, 0, 0, 1.0)",
"filled": true,
"marked": false
},
{
"x": 120,
"y": 120,
"diam": 60,
"type": "circle",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
}
]
},
"tree": {
"rotate": false,
"elements": [
{
"x": 118,
"y": 3,
"diam": 94,
"type": "circle",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"xmin": 120,
"ymin": 195,
"xmax": 180,
"ymax": 300,
"type": "rectangle",
"color": "rgba(157, 110, 72, 1.0)",
"filled": true,
"marked": false
},
{
"x": 65,
"y": 21,
"diam": 108,
"type": "circle",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"x": 116,
"y": 41,
"diam": 127,
"type": "circle",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"x": 45,
"y": 90,
"diam": 120,
"type": "circle",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"x": 104,
"y": 74,
"diam": 152,
"type": "circle",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
}
]
},
"triangle": {
"rotate": false,
"elements": [
{
"xcors": [
150,
15,
285
],
"ycors": [
30,
255,
255
],
"type": "polygon",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
}
]
},
"triangle 2": {
"rotate": false,
"elements": [
{
"xcors": [
150,
15,
285
],
"ycors": [
30,
255,
255
],
"type": "polygon",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"xcors": [
151,
225,
75
],
"ycors": [
99,
223,
224
],
"type": "polygon",
"color": "rgba(0, 0, 0, 1.0)",
"filled": true,
"marked": false
}
]
},
"truck": {
"rotate": false,
"elements": [
{
"xmin": 4,
"ymin": 45,
"xmax": 195,
"ymax": 187,
"type": "rectangle",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"xcors": [
296,
296,
259,
244,
208,
207
],
"ycors": [
193,
150,
134,
104,
104,
194
],
"type": "polygon",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"xmin": 195,
"ymin": 60,
"xmax": 195,
"ymax": 105,
"type": "rectangle",
"color": "rgba(255, 255, 255, 1.0)",
"filled": true,
"marked": false
},
{
"xcors": [
238,
252,
219,
218
],
"ycors": [
112,
141,
141,
112
],
"type": "polygon",
"color": "rgba(0, 0, 0, 1.0)",
"filled": true,
"marked": false
},
{
"x": 234,
"y": 174,
"diam": 42,
"type": "circle",
"color": "rgba(0, 0, 0, 1.0)",
"filled": true,
"marked": false
},
{
"xmin": 181,
"ymin": 185,
"xmax": 214,
"ymax": 194,
"type": "rectangle",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"x": 144,
"y": 174,
"diam": 42,
"type": "circle",
"color": "rgba(0, 0, 0, 1.0)",
"filled": true,
"marked": false
},
{
"x": 24,
"y": 174,
"diam": 42,
"type": "circle",
"color": "rgba(0, 0, 0, 1.0)",
"filled": true,
"marked": false
},
{
"x": 24,
"y": 174,
"diam": 42,
"type": "circle",
"color": "rgba(141, 141, 141, 1.0)",
"filled": false,
"marked": true
},
{
"x": 144,
"y": 174,
"diam": 42,
"type": "circle",
"color": "rgba(141, 141, 141, 1.0)",
"filled": false,
"marked": true
},
{
"x": 234,
"y": 174,
"diam": 42,
"type": "circle",
"color": "rgba(141, 141, 141, 1.0)",
"filled": false,
"marked": true
}
]
},
"turtle": {
"rotate": true,
"elements": [
{
"xcors": [
215,
240,
246,
228,
215,
193
],
"ycors": [
204,
233,
254,
266,
252,
210
],
"type": "polygon",
"color": "rgba(89, 176, 60, 1.0)",
"filled": true,
"marked": false
},
{
"xcors": [
195,
225,
245,
260,
269,
261,
240,
225,
210
],
"ycors": [
90,
75,
75,
89,
108,
124,
105,
105,
105
],
"type": "polygon",
"color": "rgba(89, 176, 60, 1.0)",
"filled": true,
"marked": false
},
{
"xcors": [
105,
75,
55,
40,
31,
39,
60,
75,
90
],
"ycors": [
90,
75,
75,
89,
108,
124,
105,
105,
105
],
"type": "polygon",
"color": "rgba(89, 176, 60, 1.0)",
"filled": true,
"marked": false
},
{
"xcors": [
132,
134,
107,
108,
150,
192,
192,
169,
172
],
"ycors": [
85,
64,
51,
17,
2,
18,
52,
65,
87
],
"type": "polygon",
"color": "rgba(89, 176, 60, 1.0)",
"filled": true,
"marked": false
},
{
"xcors": [
85,
60,
54,
72,
85,
107
],
"ycors": [
204,
233,
254,
266,
252,
210
],
"type": "polygon",
"color": "rgba(89, 176, 60, 1.0)",
"filled": true,
"marked": false
},
{
"xcors": [
119,
179,
209,
224,
220,
175,
128,
81,
74,
88
],
"ycors": [
75,
75,
101,
135,
225,
261,
261,
224,
135,
99
],
"type": "polygon",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
}
]
},
"wheel": {
"rotate": false,
"elements": [
{
"x": 3,
"y": 3,
"diam": 294,
"type": "circle",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"x": 30,
"y": 30,
"diam": 240,
"type": "circle",
"color": "rgba(0, 0, 0, 1.0)",
"filled": true,
"marked": false
},
{
"x1": 150,
"y1": 285,
"x2": 150,
"y2": 15,
"type": "line",
"color": "rgba(141, 141, 141, 1.0)",
"filled": false,
"marked": true
},
{
"x1": 15,
"y1": 150,
"x2": 285,
"y2": 150,
"type": "line",
"color": "rgba(141, 141, 141, 1.0)",
"filled": false,
"marked": true
},
{
"x": 120,
"y": 120,
"diam": 60,
"type": "circle",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"x1": 216,
"y1": 40,
"x2": 79,
"y2": 269,
"type": "line",
"color": "rgba(141, 141, 141, 1.0)",
"filled": false,
"marked": true
},
{
"x1": 40,
"y1": 84,
"x2": 269,
"y2": 221,
"type": "line",
"color": "rgba(141, 141, 141, 1.0)",
"filled": false,
"marked": true
},
{
"x1": 40,
"y1": 216,
"x2": 269,
"y2": 79,
"type": "line",
"color": "rgba(141, 141, 141, 1.0)",
"filled": false,
"marked": true
},
{
"x1": 84,
"y1": 40,
"x2": 221,
"y2": 269,
"type": "line",
"color": "rgba(141, 141, 141, 1.0)",
"filled": false,
"marked": true
}
]
},
"wolf": {
"rotate": false,
"elements": [
{
"xcors": [
253,
245,
245
],
"ycors": [
133,
131,
133
],
"type": "polygon",
"color": "rgba(0, 0, 0, 1.0)",
"filled": true,
"marked": false
},
{
"xcors": [
2,
13,
30,
38,
38,
20,
20,
27,
38,
40,
31,
31,
60,
68,
75,
66,
65,
82,
84,
100,
103,
77,
79,
100,
98,
119,
143,
160,
166,
172,
173,
167,
160,
154,
169,
178,
186,
198,
200,
217,
219,
207,
195,
192,
210,
227,
242,
259,
284,
277,
293,
299,
297,
273,
270
],
"ycors": [
194,
197,
191,
193,
205,
226,
257,
265,
266,
260,
253,
230,
206,
198,
209,
228,
243,
261,
268,
267,
261,
239,
231,
207,
196,
201,
202,
195,
210,
213,
238,
251,
248,
265,
264,
247,
240,
260,
271,
271,
262,
258,
230,
198,
184,
164,
144,
145,
151,
141,
140,
134,
127,
119,
105
],
"type": "polygon",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"xcors": [
-1,
14,
36,
40,
53,
82,
134,
159,
188,
227,
236,
238,
268,
269,
281,
269,
269
],
"ycors": [
195,
180,
166,
153,
140,
131,
133,
126,
115,
108,
102,
98,
86,
92,
87,
103,
113
],
"type": "polygon",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
}
]
},
"x": {
"rotate": false,
"elements": [
{
"xcors": [
270,
225,
30,
75
],
"ycors": [
75,
30,
225,
270
],
"type": "polygon",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
},
{
"xcors": [
30,
75,
270,
225
],
"ycors": [
75,
30,
225,
270
],
"type": "polygon",
"color": "rgba(141, 141, 141, 1.0)",
"filled": true,
"marked": true
}
]
}
}
;
(function() {
var PatchView, SpotlightView, TurtleView, View,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
if (window.AgentModel == null) {
console.error('view.js requires agentmodel.js!');
}
window.AgentStreamController = (function() {
function AgentStreamController(container) {
this.container = container;
this.layers = this.container.querySelector('.view-layers');
if (this.layers != null) {
this.spotlightView = new SpotlightView(this.layers.querySelector('.spotlight-view'));
this.turtleView = new TurtleView(this.layers.querySelector('.turtle-view'));
this.patchView = new PatchView(this.layers.querySelector('.patch-view'));
} else {
this.spotlightView = new SpotlightView();
this.turtleView = new TurtleView();
this.patchView = new PatchView();
this.layers = document.createElement('div');
this.layers.style.width = '100%';
this.layers.style.position = 'relative';
this.layers.classList.add('view-layers');
this.container.appendChild(this.layers);
this.spotlightView.canvas.style.position = 'absolute';
this.spotlightView.canvas.style.top = '0px';
this.spotlightView.canvas.style.left = '0px';
this.spotlightView.canvas.style['z-index'] = 2;
this.spotlightView.canvas.classList.add('spotlight-view');
this.turtleView.canvas.style.position = 'absolute';
this.turtleView.canvas.style.top = '0px';
this.turtleView.canvas.style.left = '0px';
this.turtleView.canvas.style['z-index'] = 1;
this.turtleView.canvas.classList.add('turtle-view');
this.patchView.canvas.style['z-index'] = 0;
this.patchView.canvas.classList.add('patch-view');
this.layers.appendChild(this.spotlightView.canvas);
this.layers.appendChild(this.patchView.canvas);
this.layers.appendChild(this.turtleView.canvas);
}
this.mouseDown = false;
this.mouseInside = false;
this.mouseXcor = 0;
this.mouseYcor = 0;
this.initMouseTracking();
this.model = new AgentModel();
this.model.world.turtleshapelist = defaultShapes;
this.repaint();
}
AgentStreamController.prototype.initMouseTracking = function() {
this.turtleView.canvas.addEventListener('mousedown', (function(_this) {
return function(e) {
return _this.mouseDown = true;
};
})(this));
document.addEventListener('mouseup', (function(_this) {
return function(e) {
return _this.mouseDown = false;
};
})(this));
this.turtleView.canvas.addEventListener('mouseenter', (function(_this) {
return function(e) {
return _this.mouseInside = true;
};
})(this));
this.turtleView.canvas.addEventListener('mouseleave', (function(_this) {
return function(e) {
return _this.mouseInside = false;
};
})(this));
return this.turtleView.canvas.addEventListener('mousemove', (function(_this) {
return function(e) {
_this.mouseXcor = _this.turtleView.xPixToPcor(e.pageX - _this.layers.offsetLeft);
return _this.mouseYcor = _this.turtleView.yPixToPcor(e.pageY - _this.layers.offsetTop);
};
})(this));
};
AgentStreamController.prototype.repaint = function() {
this.spotlightView.repaint(this.model);
this.turtleView.repaint(this.model);
return this.patchView.repaint(this.model);
};
AgentStreamController.prototype.update = function(modelUpdate) {
return this.model.update(modelUpdate);
};
return AgentStreamController;
})();
View = (function() {
function View(canvas) {
this.canvas = canvas;
this.quality = 1;
if (this.canvas == null) {
this.canvas = document.createElement('canvas');
this.canvas["class"] = 'netlogo-canvas';
this.canvas.width = 500;
this.canvas.height = 500;
this.canvas.style.width = "100%";
}
this.ctx = this.canvas.getContext('2d');
}
View.prototype.matchesWorld = function(world) {
return ((this.maxpxcor != null) && (this.minpxcor != null) && (this.maxpycor != null) && (this.minpycor != null) && (this.patchsize != null)) && ((world.maxpxcor == null) || world.maxpxcor === this.maxpxcor) && ((world.minpxcor == null) || world.minpxcor === this.minpxcor) && ((world.maxpycor == null) || world.maxpycor === this.maxpycor) && ((world.minpycor == null) || world.minpycor === this.minpycor) && ((world.patchsize == null) || world.patchsize === this.patchsize);
};
View.prototype.transformToWorld = function(world) {
this.maxpxcor = world.maxpxcor != null ? world.maxpxcor : 25;
this.minpxcor = world.minpxcor != null ? world.minpxcor : -25;
this.maxpycor = world.maxpycor != null ? world.maxpycor : 25;
this.minpycor = world.minpycor != null ? world.minpycor : -25;
this.patchsize = world.patchsize != null ? world.patchsize : 9;
this.onePixel = 1 / this.patchsize;
this.patchWidth = this.maxpxcor - this.minpxcor + 1;
this.patchHeight = this.maxpycor - this.minpycor + 1;
this.canvas.width = this.patchWidth * this.patchsize * this.quality;
this.canvas.height = this.patchHeight * this.patchsize * this.quality;
this.ctx.setTransform(this.canvas.width / this.patchWidth, 0, 0, -this.canvas.height / this.patchHeight, -(this.minpxcor - .5) * this.canvas.width / this.patchWidth, (this.maxpycor + .5) * this.canvas.height / this.patchHeight);
return this.ctx.font = '10pt "Lucida Grande", sans-serif';
};
View.prototype.xPixToPcor = function(x) {
return this.minpxcor - .5 + this.patchWidth * x / this.canvas.offsetWidth;
};
View.prototype.yPixToPcor = function(y) {
return this.maxpycor + .5 - this.patchHeight * y / this.canvas.offsetHeight;
};
View.prototype.drawLabel = function(label, color, x, y) {
label = label != null ? label.toString() : '';
if (label.length > 0) {
this.ctx.save();
this.ctx.translate(x, y);
this.ctx.scale(1 / this.patchsize, -1 / this.patchsize);
this.ctx.textAlign = 'end';
this.ctx.fillStyle = netlogoColorToCSS(color);
this.ctx.fillText(label, 0, 0);
return this.ctx.restore();
}
};
View.prototype.turtleType = 1;
View.prototype.patchType = 2;
View.prototype.linkType = 3;
View.prototype.watch = function(model) {
var id, links, observer, patches, turtles, type, _ref;
observer = model.observer, turtles = model.turtles, links = model.links, patches = model.patches;
if (observer.perspective > 0 && observer.targetagent && observer.targetagent[1] >= 0) {
_ref = observer.targetagent, type = _ref[0], id = _ref[1];
switch (type) {
case this.turtleType:
return model.turtles[id];
case this.patchType:
return model.patches[id];
case this.linkType:
return model.links[id];
}
} else {
return null;
}
};
View.prototype.follow = function(model) {
if (model.observer.perspective === 2) {
return watch(model);
} else {
return null;
}
};
return View;
})();
SpotlightView = (function(_super) {
__extends(SpotlightView, _super);
function SpotlightView() {
return SpotlightView.__super__.constructor.apply(this, arguments);
}
SpotlightView.prototype.dimmed = "rgba(0, 0, 50, " + (100 / 255) + ")";
SpotlightView.prototype.spotlightInnerBorder = "rgba(200, 255, 255, " + (100 / 255) + ")";
SpotlightView.prototype.spotlightOuterBorder = "rgba(200, 255, 255, " + (50 / 255) + ")";
SpotlightView.prototype.clear = 'white';
SpotlightView.prototype.outer = function() {
return 10 / this.patchsize;
};
SpotlightView.prototype.middle = function() {
return 8 / this.patchsize;
};
SpotlightView.prototype.inner = function() {
return 4 / this.patchsize;
};
SpotlightView.prototype.drawCircle = function(x, y, diam, color) {
this.ctx.fillStyle = color;
this.ctx.beginPath();
this.ctx.arc(x, y, diam / 2, 0, 2 * Math.PI);
return this.ctx.fill();
};
SpotlightView.prototype.drawSpotlight = function(x, y, size) {
this.ctx.lineWidth = this.onePixel;
this.ctx.globalCompositeOperation = 'source-over';
this.ctx.fillStyle = this.dimmed;
this.ctx.fillRect(this.minpxcor - 0.5, this.minpycor - 0.5, this.patchWidth, this.patchHeight);
this.ctx.globalCompositeOperation = 'destination-out';
this.drawCircle(x, y, size + this.outer(), this.clear);
this.ctx.globalCompositeOperation = 'source-over';
this.drawCircle(x, y, size + this.outer(), this.dimmed);
this.drawCircle(x, y, size + this.middle(), this.spotlightOuterBorder);
this.drawCircle(x, y, size + this.inner(), this.spotlightInnerBorder);
this.ctx.globalCompositeOperation = 'destination-out';
return this.drawCircle(x, y, size, this.clear);
};
SpotlightView.prototype.adjustSize = function(size) {
return Math.max(size, this.patchWidth / 16, this.patchHeight / 16);
};
SpotlightView.prototype.dimensions = function(agent) {
if (agent.xcor != null) {
return [agent.xcor, agent.ycor, 2 * agent.size];
} else if (agent.pxcor != null) {
return [agent.pxcor, agent.pycor, 2];
} else {
return [agent.midpointx, agent.midpointy, agent.size];
}
};
SpotlightView.prototype.repaint = function(model) {
var size, watched, xcor, ycor, _ref;
this.transformToWorld(model.world);
watched = this.watch(model);
if (watched != null) {
_ref = this.dimensions(watched), xcor = _ref[0], ycor = _ref[1], size = _ref[2];
return this.drawSpotlight(xcor, ycor, this.adjustSize(size));
}
};
return SpotlightView;
})(View);
TurtleView = (function(_super) {
__extends(TurtleView, _super);
function TurtleView(canvas) {
TurtleView.__super__.constructor.call(this, canvas);
this.drawer = new CachingShapeDrawer({});
this.quality = 3;
}
TurtleView.prototype.drawTurtle = function(turtle, canWrapX, canWrapY) {
var size, xcor, ycor;
if (!turtle['hidden?']) {
xcor = turtle.xcor || 0;
ycor = turtle.ycor || 0;
size = turtle.size || 1;
this.drawTurtleAt(turtle, xcor, ycor);
if (canWrapX) {
if (xcor - size < this.minpxcor) {
this.drawTurtleAt(turtle, xcor + this.patchWidth, ycor);
}
if (xcor + size > this.maxpxcor) {
this.drawTurtleAt(turtle, xcor - this.patchWidth, ycor);
}
}
if (canWrapY) {
if (ycor - size < this.minpycor) {
this.drawTurtleAt(turtle, xcor, ycor + this.patchHeight);
}
if (ycor + size > this.maxpycor) {
return this.drawTurtleAt(turtle, xcor, ycor - this.patchHeight);
}
}
}
};
TurtleView.prototype.drawTurtleAt = function(turtle, xcor, ycor) {
var angle, heading, scale, shape, shapeName;
heading = turtle.heading || 0;
scale = turtle.size || 1;
angle = (180 - heading) / 360 * 2 * Math.PI;
shapeName = turtle.shape;
shape = this.drawer.shapes[shapeName] || defaultShape;
this.ctx.save();
this.ctx.translate(xcor, ycor);
if (shape.rotate) {
this.ctx.rotate(angle);
} else {
this.ctx.rotate(Math.PI);
}
this.ctx.scale(scale, scale);
this.drawer.drawShape(this.ctx, turtle.color, shapeName);
this.ctx.restore();
return this.drawLabel(turtle.label, turtle['label-color'], xcor + turtle.size / 2, ycor - turtle.size / 2);
};
TurtleView.prototype.drawLine = function(x1, y1, x2, y2) {
this.ctx.moveTo(x1, y1);
return this.ctx.lineTo(x2, y2);
};
TurtleView.prototype.drawLink = function(link, turtles, canWrapX, canWrapY) {
var end1, end2, wrapX, wrapY, x1, x2, y1, y2;
if (!link['hidden?']) {
end1 = turtles[link.end1];
end2 = turtles[link.end2];
x1 = end1.xcor;
y1 = end1.ycor;
x2 = end2.xcor;
y2 = end2.ycor;
wrapX = canWrapX && (x1 - (x2 - this.patchWidth) < Math.abs(x1 - x2)) || (x2 - (x1 - this.patchWidth)) < Math.abs(x1 - x2);
wrapY = canWrapY && (y1 - (y2 - this.patchHeight) < Math.abs(y1 - y2)) || (y2 - (y1 - this.patchHeight) < Math.abs(y1 - y2));
this.ctx.strokeStyle = netlogoColorToCSS(link.color);
this.ctx.lineWidth = link.thickness > this.onePixel ? link.thickness : this.onePixel;
this.ctx.beginPath();
if (wrapX && wrapY) {
if (x1 < x2) {
if (y1 < y2) {
this.drawLine(x1, y1, x2 - this.patchWidth, y2 - this.patchHeight);
this.drawLine(x1 + this.patchWidth, y1, x2, y2 - this.patchHeight);
this.drawLine(x1 + this.patchWidth, y1 + this.patchHeight, x2, y2);
this.drawLine(x1, y1 + this.patchHeight, x2 - this.patchWidth, y2);
} else {
this.drawLine(x1, y1, x2 - this.patchWidth, y2 + this.patchHeight);
this.drawLine(x1 + this.patchWidth, y1, x2, y2 + this.patchHeight);
this.drawLine(x1 + this.patchWidth, y1 - this.patchHeight, x2, y2);
this.drawLine(x1, y1 - this.patchHeight, x2 - this.patchWidth, y2);
}
} else {
if (y1 < y2) {
this.drawLine(x1, y1, x2 + this.patchWidth, y2 - this.patchHeight);
this.drawLine(x1 - this.patchWidth, y1, x2, y2 - this.patchHeight);
this.drawLine(x1 - this.patchWidth, y1 + this.patchHeight, x2, y2);
this.drawLine(x1, y1 + this.patchHeight, x2 + this.patchWidth, y2);
} else {
this.drawLine(x1, y1, x2 + this.patchWidth, y2 + this.patchHeight);
this.drawLine(x1 - this.patchWidth, y1, x2, y2 + this.patchHeight);
this.drawLine(x1 - this.patchWidth, y1 - this.patchHeight, x2, y2);
this.drawLine(x1, y1 - this.patchHeight, x2 + this.patchWidth, y2);
}
}
} else if (wrapX) {
if (x1 < x2) {
this.drawLine(x1, y1, x2 - this.patchWidth, y2);
this.drawLine(x1 + this.patchWidth, y1, x2, y2);
} else {
this.drawLine(x1, y1, x2 + this.patchWidth, y2);
this.drawLine(x1 - this.patchWidth, y1, x2, y2);
}
} else if (wrapY) {
if (y1 < y2) {
this.drawLine(x1, y1, x2, y2 - this.patchHeight);
this.drawLine(x1, y1 + this.patchHeight, x2, y2);
} else {
this.drawLine(x1, y1 - this.patchHeight, x2, y2);
this.drawLine(x1, y1, x2, y2 + this.patchHeight);
}
} else {
this.drawLine(x1, y1, x2, y2);
}
}
return this.ctx.stroke();
};
TurtleView.prototype.repaint = function(model) {
var id, link, links, turtle, turtles, world;
world = model.world;
turtles = model.turtles;
links = model.links;
this.transformToWorld(world);
if (world.turtleshapelist !== this.drawer.shapes && typeof world.turtleshapelist === "object") {
this.drawer = new CachingShapeDrawer(world.turtleshapelist);
}
for (id in links) {
link = links[id];
this.drawLink(link, turtles, world.wrappingallowedinx, world.wrappingallowediny);
}
this.ctx.lineWidth = this.onePixel;
for (id in turtles) {
turtle = turtles[id];
this.drawTurtle(turtle, world.wrappingallowedinx, world.wrappingallowediny);
}
};
return TurtleView;
})(View);
PatchView = (function(_super) {
__extends(PatchView, _super);
function PatchView(canvas) {
PatchView.__super__.constructor.call(this, canvas);
this.scratchCanvas = document.createElement('canvas');
this.scratchCtx = this.scratchCanvas.getContext('2d');
this.quality = 2;
}
PatchView.prototype.transformToWorld = function(world) {
PatchView.__super__.transformToWorld.call(this, world);
this.scratchCanvas.width = this.patchWidth;
this.scratchCanvas.height = this.patchHeight;
this.ctx.imageSmoothingEnabled = false;
this.ctx.webkitImageSmoothingEnabled = false;
this.ctx.mozImageSmoothingEnabled = false;
this.ctx.oImageSmoothingEnabled = false;
this.ctx.fillStyle = 'black';
return this.ctx.fillRect(this.minpxcor - .5, this.minpycor - .5, this.patchWidth, this.patchHeight);
};
PatchView.prototype.colorPatches = function(patches) {
var b, g, i, ignore, imageData, patch, r, trans, _ref, _results;
imageData = this.ctx.createImageData(this.patchWidth, this.patchHeight);
for (ignore in patches) {
patch = patches[ignore];
_ref = netlogoColorToRGB(patch.pcolor), r = _ref[0], g = _ref[1], b = _ref[2];
i = ((this.maxpycor - patch.pycor) * this.patchWidth + (patch.pxcor - this.minpxcor)) * 4;
imageData.data[i + 0] = r;
imageData.data[i + 1] = g;
imageData.data[i + 2] = b;
imageData.data[i + 3] = 255;
}
this.scratchCtx.putImageData(imageData, 0, 0);
trans = this.minpycor + this.maxpycor;
this.ctx.translate(0, trans);
this.ctx.scale(1, -1);
this.ctx.drawImage(this.scratchCanvas, this.minpxcor - .5, this.minpycor - .5, this.patchWidth, this.patchHeight);
this.ctx.scale(1, -1);
this.ctx.translate(0, -trans);
_results = [];
for (ignore in patches) {
patch = patches[ignore];
_results.push(this.drawLabel(patch.plabel, patch['plabel-color'], patch.pxcor + .5, patch.pycor - .5));
}
return _results;
};
PatchView.prototype.repaint = function(model) {
var patches, world;
world = model.world;
patches = model.patches;
if (!this.matchesWorld(world)) {
this.transformToWorld(world);
}
return this.colorPatches(patches);
};
return PatchView;
})(View);
}).call(this);
//# sourceMappingURL=view.js.map
;
(function() {
window.Widgets = {
widgets: [],
widgetUpdateFuncs: [],
sliderUpdateFuncs: [],
addTo: function(session) {
var widget, _i, _len, _ref, _results;
_ref = this.widgets;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
widget = _ref[_i];
_results.push(widget(session));
}
return _results;
},
runUpdateFuncs: function() {
var func, _i, _j, _len, _len1, _ref, _ref1, _results;
_ref = this.widgetUpdateFuncs;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
func = _ref[_i];
func();
}
_ref1 = this.sliderUpdateFuncs;
_results = [];
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
func = _ref1[_j];
_results.push(func());
}
return _results;
},
setDimensions: function(e, left, top, right, bottom) {
e.style.width = right - left;
e.style.height = bottom - top;
e.style.top = top;
return e.style.left = left;
},
addButton: function(display, left, top, right, bottom, code, forever) {
var escapedDisplay;
escapedDisplay = display.replace("'", "\\'");
return this.widgets.push((function(_this) {
return function(session) {
var button, running;
button = session.container.querySelector("button[netlogo-display='" + escapedDisplay + "']");
if (button == null) {
button = document.createElement('button');
button.setAttribute('netlogo-display', display);
button.style.position = "absolute";
button.style.fontSize = "8pt";
_this.setDimensions(button, left, top, right, bottom);
session.container.appendChild(button);
}
button.innerHTML = display + (forever ? " (Off)" : "");
if (forever) {
running = false;
button.addEventListener("click", (function() {
running = !running;
return button.innerHTML = display + (running ? " (On)" : " (Off)");
}));
return _this.widgetUpdateFuncs.push((function() {
if (running) {
return code();
}
}));
} else {
return button.addEventListener("click", code);
}
};
})(this));
},
addSlider: function(display, left, top, right, bottom, setter, min, max, def, step) {
var escapedDisplay;
escapedDisplay = display.replace("'", "\\'");
return this.widgets.push((function(_this) {
return function(session) {
var input, inputs, label, numberInput, rangeInput, slider, update, width, _i, _len, _results;
inputs = session.container.querySelectorAll(("input[type=range][netlogo-display='" + escapedDisplay + "'], ") + ("input[type=number][netlogo-display='" + escapedDisplay + "']"));
if (inputs.length === 0) {
slider = document.createElement('div');
slider.style.position = "absolute";
slider.style.fontSize = "8pt";
_this.setDimensions(slider, left, top, right, bottom);
width = Math.max(min.toString().length, max.toString().length) + 2;
numberInput = document.createElement('input');
numberInput.type = "number";
numberInput.setAttribute('netlogo-display', display);
numberInput.style.cssFloat = "right";
numberInput.style.fontSize = "8pt";
numberInput.style.width = width + "em";
numberInput.style.padding = "0px";
numberInput.style.marginTop = "-3px";
numberInput.style.borderWidth = "1px";
numberInput.style.textAlign = "right";
rangeInput = document.createElement('input');
rangeInput.setAttribute('netlogo-display', display);
rangeInput.type = "range";
rangeInput.style.width = "97%";
rangeInput.style.padding = "0px";
label = document.createElement('label');
label.innerHTML = display;
slider.appendChild(rangeInput);
label.appendChild(numberInput);
slider.appendChild(label);
session.container.appendChild(slider);
inputs = [rangeInput, numberInput];
}
update = function(e) {
var input, value, _i, _len;
value = parseInt(e.target.value);
if (!isNaN(value)) {
for (_i = 0, _len = inputs.length; _i < _len; _i++) {
input = inputs[_i];
input.value = value;
}
return setter(value);
}
};
_results = [];
for (_i = 0, _len = inputs.length; _i < _len; _i++) {
input = inputs[_i];
if (typeof max === 'function') {
_this.sliderUpdateFuncs.push((function() {
return input.max = max();
}));
}
input.max = max;
if (typeof min === 'function') {
_this.sliderUpdateFuncs.push((function() {
return input.min = min();
}));
}
input.min = min;
if (typeof step === 'function') {
_this.sliderUpdateFuncs.push((function() {
return input.step = step();
}));
}
input.step = step;
input.value = def;
_results.push(input.addEventListener("input", update));
}
return _results;
};
})(this));
},
addSwitch: function(display, left, top, right, bottom, setter) {
var escapedDisplay;
escapedDisplay = display.replace("'", "\\'");
return this.widgets.push((function(_this) {
return function(session) {
var input, label, swtch;
input = session.container.querySelector("input[type='checkbox'][netlogo-display='" + escapedDisplay + "']");
if (input == null) {
swtch = document.createElement('div');
swtch.style.position = "absolute";
swtch.style.fontSize = "8pt";
_this.setDimensions(swtch, left, top, right, bottom);
input = document.createElement('input');
input.setAttribute('netlogo-display', display);
input.type = "checkbox";
input.style.cssFloat = "left";
label = document.createElement('label');
label.innerHTML = display;
swtch.appendChild(input);
swtch.appendChild(label);
session.container.appendChild(swtch);
}
return input.onchange = function() {
return setter(input.checked);
};
};
})(this));
},
addChooser: function(display, left, top, right, bottom, defaultValue, choices, setter) {
var escapedDisplay;
escapedDisplay = display.replace("'", "\\'");
return this.widgets.push((function(_this) {
return function(session) {
var choice, choiceElem, chooser, label, select, _i, _len;
chooser = session.container.querySelector("div[netlogo-display='" + escapedDisplay + "']");
if (typeof input === "undefined" || input === null) {
chooser = document.createElement('div');
chooser.style.position = 'absolute';
chooser.style.fontSize = '8pt';
_this.setDimensions(chooser, left, top, right, bottom);
label = document.createElement('label');
label.innerHTML = display;
select = document.createElement('select');
for (_i = 0, _len = choices.length; _i < _len; _i++) {
choice = choices[_i];
choiceElem = document.createElement('option');
choiceElem.value = choice;
choiceElem.innerHTML = choice;
select.appendChild(choiceElem);
}
select.value = defaultValue;
chooser.appendChild(label);
chooser.appendChild(document.createElement('br'));
chooser.appendChild(select);
session.container.appendChild(chooser);
}
select = chooser.querySelector('select');
return select.addEventListener('change', function() {
return setter(select.value);
});
};
})(this));
},
addMonitor: function(display, left, top, right, bottom, code) {
var escapedDisplay;
escapedDisplay = display.replace("'", "\\'");
return this.widgets.push((function(_this) {
return function(session) {
var heading, monitor, value;
value = session.container.querySelector("div[netlogo-display='" + escapedDisplay + "']");
if (value == null) {
monitor = document.createElement('div');
monitor.style.position = "absolute";
monitor.style.fontSize = "8pt";
monitor.style.backgroundColor = "#CCCCCC";
_this.setDimensions(monitor, left, top, right, bottom);
heading = document.createElement('label');
heading.style.margin = 4;
heading.innerHTML = display;
heading.style.position = "relative";
value = document.createElement('div');
value.setAttribute('netlogo-display', display);
value.style.backgroundColor = "white";
value.style.position = "relative";
value.style.margin = 4;
value.style.padding = 2;
monitor.appendChild(heading);
monitor.appendChild(value);
session.container.appendChild(monitor);
}
value.innerHTML = "0";
return _this.widgetUpdateFuncs.push(function() {
var e, result;
try {
result = code();
} catch (_error) {
e = _error;
if (e instanceof NetLogoException) {
result = "N/A";
} else {
throw e;
}
}
return value.innerHTML = result;
});
};
})(this));
},
addTextBox: function(display, left, top, right, bottom) {
var escapedDisplay;
escapedDisplay = display.replace("'", "\\'");
return this.widgets.push((function(_this) {
return function(session) {
var textBox;
textBox = session.container.querySelector("div[netlogo-display='" + escapedDisplay + "']");
if (textBox == null) {
textBox = document.createElement('div');
textBox.setAttribute('netlogo-display', display);
textBox.style.position = "absolute";
textBox.style.fontSize = "8pt";
textBox.style.border = "2px solid black";
textBox.style.textAlign = "center";
_this.setDimensions(textBox, left + 2, top + 2, right - 2, bottom - 2);
textBox.innerHTML = display;
return session.container.appendChild(textBox);
}
};
})(this));
},
addOutput: function(display, left, top, right, bottom) {},
addView: function(left, top, right, bottom) {
return this.widgets.push((function(_this) {
return function(session) {
return _this.setDimensions(session.controller.layers, left, top, right, bottom);
};
})(this));
},
addPlot: function(display, left, top, right, bottom, ymin, ymax, xmin, xmax) {
return this.widgets.push((function(_this) {
return function(session) {
var plot;
if (session.plot) {
plot = document.createElement('div');
plot.style.position = "absolute";
plot.style.border = "1px solid black";
_this.setDimensions(plot, left, top, right, bottom);
session.container.appendChild(plot);
return session.plot.boot(display, ymin, ymax, xmin, xmax, plot);
}
};
})(this));
}
};
}).call(this);
//# sourceMappingURL=widgets.js.map
;
(function() {
window.GoogleGraph = {
xpoint: 0,
display: "Temperature",
drawPlot: function() {
this.chart = new google.visualization.LineChart(this.graphcontainer);
this.resetData();
return setInterval(this.gplot.bind(this), 100);
},
resetData: function() {
this.data = new google.visualization.DataTable();
this.data.addColumn('number', 'Tick');
this.data.addColumn('number', this.display);
this.data.setColumnProperty(0, 'type', 'number');
this.data.setColumnProperty(1, 'type', 'number');
return this.chart.draw(this.data);
},
gplot: function() {
var opts;
opts = {
backgroundColor: '#fcfdfd',
chartArea: {
width: "80%"
},
enableInteractivity: false,
legend: {
position: 'top',
textStyle: {
color: 'blue',
fontSize: 12
},
alignment: 'center'
},
vAxis: {
minValue: this.xmin,
maxValue: this.xmax
},
hAxis: {
minValue: this.ymin,
maxValue: this.ymax
}
};
return this.chart.draw(this.data, opts);
},
boot: function(display, ymin, ymax, xmin, xmax, graphcontainer) {
this.display = display;
this.graphcontainer = graphcontainer;
this.ymin = ymin;
this.ymax = ymax;
this.xmin = xmin;
this.xmax = xmax;
google.load('visualization', '1', {
packages: ['corechart']
});
return google.setOnLoadCallback(this.drawPlot.bind(this));
},
plot: function(y) {
this.data.addRow([this.xpoint, y]);
return this.xpoint++;
},
reset: function() {
if (this.data) {
this.data.removeRows(0, this.data.getNumberOfRows());
}
return this.xpoint = 0;
}
};
}).call(this);
//# sourceMappingURL=googlegraph.js.map
;
(function() {
var Connection;
window.connect = function(socketURL) {
return new Connection(new WebSocket(socketURL));
};
Connection = (function() {
function Connection(socket) {
this.socket = socket;
this.listeners = {
'all': []
};
this.outbox = [];
this.socket.onmessage = (function(_this) {
return function(event) {
return _this.dispatch(JSON.parse(event.data));
};
})(this);
this.socket.onopen = (function(_this) {
return function() {
var msg, _i, _len, _ref, _results;
_ref = _this.outbox;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
msg = _ref[_i];
_results.push(_this.send(msg));
}
return _results;
};
})(this);
}
Connection.prototype.send = function(message) {
if (this.socket.readyState === this.socket.OPEN) {
return this.socket.send(JSON.stringify(message));
} else {
return this.outbox.push(message);
}
};
Connection.prototype.dispatch = function(msg) {
var listener, _i, _j, _len, _len1, _ref, _ref1, _results;
_ref = this.listeners['all'];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
listener = _ref[_i];
listener(msg);
}
if (this.listeners[msg.kind] == null) {
this.listeners[msg.kind] = [];
}
_ref1 = this.listeners[msg.kind];
_results = [];
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
listener = _ref1[_j];
_results.push(listener(msg));
}
return _results;
};
Connection.prototype.on = function(kind, listener) {
if (this.listeners[kind] == null) {
this.listeners[kind] = [];
}
return this.listeners[kind].push(listener);
};
return Connection;
})();
}).call(this);
//# sourceMappingURL=connection.js.map
;
(function() {
window.SessionLite = (function() {
SessionLite.controller = void 0;
function SessionLite(container) {
this.container = container;
this.controller = new AgentStreamController(container);
}
SessionLite.prototype.update = function(modelUpdate) {
var update, _i, _len;
if (modelUpdate instanceof Array) {
for (_i = 0, _len = modelUpdate.length; _i < _len; _i++) {
update = modelUpdate[_i];
this.controller.update(update);
}
} else {
this.controller.update(modelUpdate);
}
return this.controller.repaint();
};
return SessionLite;
})();
}).call(this);
//# sourceMappingURL=session-lite.js.map
;
var workspace = tortoise_require('engine/workspace')([{ name: 'SHEEP', singular: 'a-sheep', varNames: [] }, { name: 'WOLVES', singular: 'wolf', varNames: [] }])(['initial-number-sheep', 'sheep-gain-from-food', 'sheep-reproduce', 'initial-number-wolves', 'wolf-gain-from-food', 'wolf-reproduce', 'grass?', 'grass-regrowth-time', 'show-energy?', 'grass'], ['initial-number-sheep', 'sheep-gain-from-food', 'sheep-reproduce', 'initial-number-wolves', 'wolf-gain-from-food', 'wolf-reproduce', 'grass?', 'grass-regrowth-time', 'show-energy?'], ['energy'], [], ['countdown'], -25, 25, -25, 25, 9.0, true, true, {"default":{"rotate":true,"elements":[{"xcors":[150,40,150,260],"ycors":[5,250,205,250],"type":"polygon","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true}]},"airplane":{"rotate":true,"elements":[{"xcors":[150,135,120,120,15,15,120,135,105,120,150,180,210,165,180,285,285,180,180,165],"ycors":[0,15,60,105,165,195,180,240,270,285,270,285,270,240,180,195,165,105,60,15],"type":"polygon","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true}]},"arrow":{"rotate":true,"elements":[{"xcors":[150,0,105,105,195,195,300],"ycors":[0,150,150,293,293,150,150],"type":"polygon","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true}]},"box":{"rotate":false,"elements":[{"xcors":[150,285,285,150],"ycors":[285,225,75,135],"type":"polygon","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"xcors":[150,15,150,285],"ycors":[135,75,15,75],"type":"polygon","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"xcors":[15,15,150,150],"ycors":[75,225,285,135],"type":"polygon","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"x1":150,"y1":285,"x2":150,"y2":135,"type":"line","color":"rgba(0, 0, 0, 1.0)","filled":false,"marked":false},{"x1":150,"y1":135,"x2":15,"y2":75,"type":"line","color":"rgba(0, 0, 0, 1.0)","filled":false,"marked":false},{"x1":150,"y1":135,"x2":285,"y2":75,"type":"line","color":"rgba(0, 0, 0, 1.0)","filled":false,"marked":false}]},"bug":{"rotate":true,"elements":[{"x":96,"y":182,"diam":108,"type":"circle","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"x":110,"y":127,"diam":80,"type":"circle","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"x":110,"y":75,"diam":80,"type":"circle","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"x1":150,"y1":100,"x2":80,"y2":30,"type":"line","color":"rgba(141, 141, 141, 1.0)","filled":false,"marked":true},{"x1":150,"y1":100,"x2":220,"y2":30,"type":"line","color":"rgba(141, 141, 141, 1.0)","filled":false,"marked":true}]},"butterfly":{"rotate":true,"elements":[{"xcors":[150,209,225,225,195,165,150],"ycors":[165,199,225,255,270,255,240],"type":"polygon","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"xcors":[150,89,75,75,105,135,150],"ycors":[165,198,225,255,270,255,240],"type":"polygon","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"xcors":[139,100,55,25,10,10,25,40,85,139],"ycors":[148,105,90,90,105,135,180,195,194,163],"type":"polygon","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"xcors":[162,200,245,275,290,290,275,260,215,162],"ycors":[150,105,90,90,105,135,180,195,195,165],"type":"polygon","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"xcors":[150,135,120,135,150,165,180,165],"ycors":[255,225,150,120,105,120,150,225],"type":"polygon","color":"rgba(0, 0, 0, 1.0)","filled":true,"marked":false},{"x":135,"y":90,"diam":30,"type":"circle","color":"rgba(0, 0, 0, 1.0)","filled":true,"marked":false},{"x1":150,"y1":105,"x2":195,"y2":60,"type":"line","color":"rgba(0, 0, 0, 1.0)","filled":false,"marked":false},{"x1":150,"y1":105,"x2":105,"y2":60,"type":"line","color":"rgba(0, 0, 0, 1.0)","filled":false,"marked":false}]},"car":{"rotate":false,"elements":[{"xcors":[300,279,261,240,226,213,203,185,159,135,75,0,0,0,300,300],"ycors":[180,164,144,135,132,106,84,63,50,50,60,150,165,225,225,180],"type":"polygon","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"x":180,"y":180,"diam":90,"type":"circle","color":"rgba(0, 0, 0, 1.0)","filled":true,"marked":false},{"x":30,"y":180,"diam":90,"type":"circle","color":"rgba(0, 0, 0, 1.0)","filled":true,"marked":false},{"xcors":[162,132,134,209,194,189,180],"ycors":[80,78,135,135,105,96,89],"type":"polygon","color":"rgba(0, 0, 0, 1.0)","filled":true,"marked":false},{"x":47,"y":195,"diam":58,"type":"circle","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"x":195,"y":195,"diam":58,"type":"circle","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true}]},"circle":{"rotate":false,"elements":[{"x":0,"y":0,"diam":300,"type":"circle","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true}]},"circle 2":{"rotate":false,"elements":[{"x":0,"y":0,"diam":300,"type":"circle","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"x":30,"y":30,"diam":240,"type":"circle","color":"rgba(0, 0, 0, 1.0)","filled":true,"marked":false}]},"cow":{"rotate":false,"elements":[{"xcors":[200,197,179,177,166,140,93,78,72,49,48,37,25,25,45,103,179,198,252,272,293,285,255,242,224],"ycors":[193,249,249,196,187,189,191,179,211,209,181,149,120,89,72,84,75,76,64,81,103,121,121,118,167],"type":"polygon","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"xcors":[73,86,62,48],"ycors":[210,251,249,208],"type":"polygon","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"xcors":[25,16,9,23,25,39],"ycors":[114,195,204,213,200,123],"type":"polygon","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true}]},"cylinder":{"rotate":false,"elements":[{"x":0,"y":0,"diam":300,"type":"circle","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true}]},"dot":{"rotate":false,"elements":[{"x":90,"y":90,"diam":120,"type":"circle","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true}]},"face happy":{"rotate":false,"elements":[{"x":8,"y":8,"diam":285,"type":"circle","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"x":60,"y":75,"diam":60,"type":"circle","color":"rgba(0, 0, 0, 1.0)","filled":true,"marked":false},{"x":180,"y":75,"diam":60,"type":"circle","color":"rgba(0, 0, 0, 1.0)","filled":true,"marked":false},{"xcors":[150,90,62,47,67,90,109,150,192,210,227,251,236,212],"ycors":[255,239,213,191,179,203,218,225,218,203,181,194,217,240],"type":"polygon","color":"rgba(0, 0, 0, 1.0)","filled":true,"marked":false}]},"face neutral":{"rotate":false,"elements":[{"x":8,"y":7,"diam":285,"type":"circle","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"x":60,"y":75,"diam":60,"type":"circle","color":"rgba(0, 0, 0, 1.0)","filled":true,"marked":false},{"x":180,"y":75,"diam":60,"type":"circle","color":"rgba(0, 0, 0, 1.0)","filled":true,"marked":false},{"xmin":60,"ymin":195,"xmax":240,"ymax":225,"type":"rectangle","color":"rgba(0, 0, 0, 1.0)","filled":true,"marked":false}]},"face sad":{"rotate":false,"elements":[{"x":8,"y":8,"diam":285,"type":"circle","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"x":60,"y":75,"diam":60,"type":"circle","color":"rgba(0, 0, 0, 1.0)","filled":true,"marked":false},{"x":180,"y":75,"diam":60,"type":"circle","color":"rgba(0, 0, 0, 1.0)","filled":true,"marked":false},{"xcors":[150,90,62,47,67,90,109,150,192,210,227,251,236,212],"ycors":[168,184,210,232,244,220,205,198,205,220,242,229,206,183],"type":"polygon","color":"rgba(0, 0, 0, 1.0)","filled":true,"marked":false}]},"fish":{"rotate":false,"elements":[{"xcors":[44,21,15,0,15,0,13,20,45],"ycors":[131,87,86,120,150,180,214,212,166],"type":"polygon","color":"rgba(255, 255, 255, 1.0)","filled":true,"marked":false},{"xcors":[135,119,95,76,46,60],"ycors":[195,235,218,210,204,165],"type":"polygon","color":"rgba(255, 255, 255, 1.0)","filled":true,"marked":false},{"xcors":[75,83,71,86,166,135],"ycors":[45,77,103,114,78,60],"type":"polygon","color":"rgba(255, 255, 255, 1.0)","filled":true,"marked":false},{"xcors":[30,151,226,280,292,292,287,270,195,151,30],"ycors":[136,77,81,119,146,160,170,195,210,212,166],"type":"polygon","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"x":215,"y":106,"diam":30,"type":"circle","color":"rgba(0, 0, 0, 1.0)","filled":true,"marked":false}]},"flag":{"rotate":false,"elements":[{"xmin":60,"ymin":15,"xmax":75,"ymax":300,"type":"rectangle","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"xcors":[90,270,90],"ycors":[150,90,30],"type":"polygon","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"x1":75,"y1":135,"x2":90,"y2":135,"type":"line","color":"rgba(141, 141, 141, 1.0)","filled":false,"marked":true},{"x1":75,"y1":45,"x2":90,"y2":45,"type":"line","color":"rgba(141, 141, 141, 1.0)","filled":false,"marked":true}]},"flower":{"rotate":false,"elements":[{"xcors":[135,165,180,180,150,165,195,195,165],"ycors":[120,165,210,240,300,300,240,195,135],"type":"polygon","color":"rgba(89, 176, 60, 1.0)","filled":true,"marked":false},{"x":85,"y":132,"diam":38,"type":"circle","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"x":130,"y":147,"diam":38,"type":"circle","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"x":192,"y":85,"diam":38,"type":"circle","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"x":85,"y":40,"diam":38,"type":"circle","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"x":177,"y":40,"diam":38,"type":"circle","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"x":177,"y":132,"diam":38,"type":"circle","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"x":70,"y":85,"diam":38,"type":"circle","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"x":130,"y":25,"diam":38,"type":"circle","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"x":96,"y":51,"diam":108,"type":"circle","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"x":113,"y":68,"diam":74,"type":"circle","color":"rgba(0, 0, 0, 1.0)","filled":true,"marked":false},{"xcors":[189,219,249,279,234],"ycors":[233,188,173,188,218],"type":"polygon","color":"rgba(89, 176, 60, 1.0)","filled":true,"marked":false},{"xcors":[180,150,105,75,135],"ycors":[255,210,210,240,240],"type":"polygon","color":"rgba(89, 176, 60, 1.0)","filled":true,"marked":false}]},"house":{"rotate":false,"elements":[{"xmin":45,"ymin":120,"xmax":255,"ymax":285,"type":"rectangle","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"xmin":120,"ymin":210,"xmax":180,"ymax":285,"type":"rectangle","color":"rgba(0, 0, 0, 1.0)","filled":true,"marked":false},{"xcors":[15,150,285],"ycors":[120,15,120],"type":"polygon","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"x1":30,"y1":120,"x2":270,"y2":120,"type":"line","color":"rgba(0, 0, 0, 1.0)","filled":false,"marked":false}]},"leaf":{"rotate":false,"elements":[{"xcors":[150,135,120,60,30,60,60,15,30,15,40,45,60,90,105,120,105,120,135,150,165,180,195,180,195,210,240,255,263,285,270,285,240,240,270,240,180,165],"ycors":[210,195,210,210,195,180,165,135,120,105,104,90,90,105,120,120,60,60,30,15,30,60,60,120,120,105,90,90,104,105,120,135,165,180,195,210,210,195],"type":"polygon","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"xcors":[135,135,120,105,105,135,165,165],"ycors":[195,240,255,255,285,285,240,195],"type":"polygon","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true}]},"line":{"rotate":true,"elements":[{"x1":150,"y1":0,"x2":150,"y2":300,"type":"line","color":"rgba(141, 141, 141, 1.0)","filled":false,"marked":true}]},"line half":{"rotate":true,"elements":[{"x1":150,"y1":0,"x2":150,"y2":150,"type":"line","color":"rgba(141, 141, 141, 1.0)","filled":false,"marked":true}]},"pentagon":{"rotate":false,"elements":[{"xcors":[150,15,60,240,285],"ycors":[15,120,285,285,120],"type":"polygon","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true}]},"person":{"rotate":false,"elements":[{"x":110,"y":5,"diam":80,"type":"circle","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"xcors":[105,120,90,105,135,150,165,195,210,180,195],"ycors":[90,195,285,300,300,225,300,300,285,195,90],"type":"polygon","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"xmin":127,"ymin":79,"xmax":172,"ymax":94,"type":"rectangle","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"xcors":[195,240,225,165],"ycors":[90,150,180,105],"type":"polygon","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"xcors":[105,60,75,135],"ycors":[90,150,180,105],"type":"polygon","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true}]},"plant":{"rotate":false,"elements":[{"xmin":135,"ymin":90,"xmax":165,"ymax":300,"type":"rectangle","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"xcors":[135,90,45,75,135],"ycors":[255,210,195,255,285],"type":"polygon","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"xcors":[165,210,255,225,165],"ycors":[255,210,195,255,285],"type":"polygon","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"xcors":[135,90,45,75,135],"ycors":[180,135,120,180,210],"type":"polygon","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"xcors":[165,165,225,255,210],"ycors":[180,210,180,120,135],"type":"polygon","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"xcors":[135,90,45,75,135],"ycors":[105,60,45,105,135],"type":"polygon","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"xcors":[165,165,225,255,210],"ycors":[105,135,105,45,60],"type":"polygon","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"xcors":[135,120,150,180,165],"ycors":[90,45,15,45,90],"type":"polygon","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true}]},"sheep":{"rotate":false,"elements":[{"x":203,"y":65,"diam":88,"type":"circle","color":"rgba(255, 255, 255, 1.0)","filled":true,"marked":true},{"x":70,"y":65,"diam":162,"type":"circle","color":"rgba(255, 255, 255, 1.0)","filled":true,"marked":true},{"x":150,"y":105,"diam":120,"type":"circle","color":"rgba(255, 255, 255, 1.0)","filled":true,"marked":true},{"xcors":[218,240,255,278],"ycors":[120,165,165,120],"type":"polygon","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":false},{"x":214,"y":72,"diam":67,"type":"circle","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":false},{"xmin":164,"ymin":223,"xmax":179,"ymax":298,"type":"rectangle","color":"rgba(255, 255, 255, 1.0)","filled":true,"marked":true},{"xcors":[45,30,30,15,45],"ycors":[285,285,240,195,210],"type":"polygon","color":"rgba(255, 255, 255, 1.0)","filled":true,"marked":true},{"x":3,"y":83,"diam":150,"type":"circle","color":"rgba(255, 255, 255, 1.0)","filled":true,"marked":true},{"xmin":65,"ymin":221,"xmax":80,"ymax":296,"type":"rectangle","color":"rgba(255, 255, 255, 1.0)","filled":true,"marked":true},{"xcors":[195,210,210,240,195],"ycors":[285,285,240,210,210],"type":"polygon","color":"rgba(255, 255, 255, 1.0)","filled":true,"marked":true},{"xcors":[276,285,302,294],"ycors":[85,105,99,83],"type":"polygon","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":false},{"xcors":[219,210,193,201],"ycors":[85,105,99,83],"type":"polygon","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":false}]},"square":{"rotate":false,"elements":[{"xmin":30,"ymin":30,"xmax":270,"ymax":270,"type":"rectangle","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true}]},"square 2":{"rotate":false,"elements":[{"xmin":30,"ymin":30,"xmax":270,"ymax":270,"type":"rectangle","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"xmin":60,"ymin":60,"xmax":240,"ymax":240,"type":"rectangle","color":"rgba(0, 0, 0, 1.0)","filled":true,"marked":false}]},"star":{"rotate":false,"elements":[{"xcors":[151,185,298,207,242,151,59,94,3,116],"ycors":[1,108,108,175,282,216,282,175,108,108],"type":"polygon","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true}]},"target":{"rotate":false,"elements":[{"x":0,"y":0,"diam":300,"type":"circle","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"x":30,"y":30,"diam":240,"type":"circle","color":"rgba(0, 0, 0, 1.0)","filled":true,"marked":false},{"x":60,"y":60,"diam":180,"type":"circle","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"x":90,"y":90,"diam":120,"type":"circle","color":"rgba(0, 0, 0, 1.0)","filled":true,"marked":false},{"x":120,"y":120,"diam":60,"type":"circle","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true}]},"tree":{"rotate":false,"elements":[{"x":118,"y":3,"diam":94,"type":"circle","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"xmin":120,"ymin":195,"xmax":180,"ymax":300,"type":"rectangle","color":"rgba(157, 110, 72, 1.0)","filled":true,"marked":false},{"x":65,"y":21,"diam":108,"type":"circle","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"x":116,"y":41,"diam":127,"type":"circle","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"x":45,"y":90,"diam":120,"type":"circle","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"x":104,"y":74,"diam":152,"type":"circle","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true}]},"triangle":{"rotate":false,"elements":[{"xcors":[150,15,285],"ycors":[30,255,255],"type":"polygon","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true}]},"triangle 2":{"rotate":false,"elements":[{"xcors":[150,15,285],"ycors":[30,255,255],"type":"polygon","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"xcors":[151,225,75],"ycors":[99,223,224],"type":"polygon","color":"rgba(0, 0, 0, 1.0)","filled":true,"marked":false}]},"truck":{"rotate":false,"elements":[{"xmin":4,"ymin":45,"xmax":195,"ymax":187,"type":"rectangle","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"xcors":[296,296,259,244,208,207],"ycors":[193,150,134,104,104,194],"type":"polygon","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"xmin":195,"ymin":60,"xmax":195,"ymax":105,"type":"rectangle","color":"rgba(255, 255, 255, 1.0)","filled":true,"marked":false},{"xcors":[238,252,219,218],"ycors":[112,141,141,112],"type":"polygon","color":"rgba(0, 0, 0, 1.0)","filled":true,"marked":false},{"x":234,"y":174,"diam":42,"type":"circle","color":"rgba(0, 0, 0, 1.0)","filled":true,"marked":false},{"xmin":181,"ymin":185,"xmax":214,"ymax":194,"type":"rectangle","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"x":144,"y":174,"diam":42,"type":"circle","color":"rgba(0, 0, 0, 1.0)","filled":true,"marked":false},{"x":24,"y":174,"diam":42,"type":"circle","color":"rgba(0, 0, 0, 1.0)","filled":true,"marked":false},{"x":24,"y":174,"diam":42,"type":"circle","color":"rgba(141, 141, 141, 1.0)","filled":false,"marked":true},{"x":144,"y":174,"diam":42,"type":"circle","color":"rgba(141, 141, 141, 1.0)","filled":false,"marked":true},{"x":234,"y":174,"diam":42,"type":"circle","color":"rgba(141, 141, 141, 1.0)","filled":false,"marked":true}]},"turtle":{"rotate":true,"elements":[{"xcors":[215,240,246,228,215,193],"ycors":[204,233,254,266,252,210],"type":"polygon","color":"rgba(89, 176, 60, 1.0)","filled":true,"marked":false},{"xcors":[195,225,245,260,269,261,240,225,210],"ycors":[90,75,75,89,108,124,105,105,105],"type":"polygon","color":"rgba(89, 176, 60, 1.0)","filled":true,"marked":false},{"xcors":[105,75,55,40,31,39,60,75,90],"ycors":[90,75,75,89,108,124,105,105,105],"type":"polygon","color":"rgba(89, 176, 60, 1.0)","filled":true,"marked":false},{"xcors":[132,134,107,108,150,192,192,169,172],"ycors":[85,64,51,17,2,18,52,65,87],"type":"polygon","color":"rgba(89, 176, 60, 1.0)","filled":true,"marked":false},{"xcors":[85,60,54,72,85,107],"ycors":[204,233,254,266,252,210],"type":"polygon","color":"rgba(89, 176, 60, 1.0)","filled":true,"marked":false},{"xcors":[119,179,209,224,220,175,128,81,74,88],"ycors":[75,75,101,135,225,261,261,224,135,99],"type":"polygon","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true}]},"wheel":{"rotate":false,"elements":[{"x":3,"y":3,"diam":294,"type":"circle","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"x":30,"y":30,"diam":240,"type":"circle","color":"rgba(0, 0, 0, 1.0)","filled":true,"marked":false},{"x1":150,"y1":285,"x2":150,"y2":15,"type":"line","color":"rgba(141, 141, 141, 1.0)","filled":false,"marked":true},{"x1":15,"y1":150,"x2":285,"y2":150,"type":"line","color":"rgba(141, 141, 141, 1.0)","filled":false,"marked":true},{"x":120,"y":120,"diam":60,"type":"circle","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"x1":216,"y1":40,"x2":79,"y2":269,"type":"line","color":"rgba(141, 141, 141, 1.0)","filled":false,"marked":true},{"x1":40,"y1":84,"x2":269,"y2":221,"type":"line","color":"rgba(141, 141, 141, 1.0)","filled":false,"marked":true},{"x1":40,"y1":216,"x2":269,"y2":79,"type":"line","color":"rgba(141, 141, 141, 1.0)","filled":false,"marked":true},{"x1":84,"y1":40,"x2":221,"y2":269,"type":"line","color":"rgba(141, 141, 141, 1.0)","filled":false,"marked":true}]},"wolf":{"rotate":false,"elements":[{"xcors":[253,245,245],"ycors":[133,131,133],"type":"polygon","color":"rgba(0, 0, 0, 1.0)","filled":true,"marked":false},{"xcors":[2,13,30,38,38,20,20,27,38,40,31,31,60,68,75,66,65,82,84,100,103,77,79,100,98,119,143,160,166,172,173,167,160,154,169,178,186,198,200,217,219,207,195,192,210,227,242,259,284,277,293,299,297,273,270],"ycors":[194,197,191,193,205,226,257,265,266,260,253,230,206,198,209,228,243,261,268,267,261,239,231,207,196,201,202,195,210,213,238,251,248,265,264,247,240,260,271,271,262,258,230,198,184,164,144,145,151,141,140,134,127,119,105],"type":"polygon","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"xcors":[-1,14,36,40,53,82,134,159,188,227,236,238,268,269,281,269,269],"ycors":[195,180,166,153,140,131,133,126,115,108,102,98,86,92,87,103,113],"type":"polygon","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true}]},"x":{"rotate":false,"elements":[{"xcors":[270,225,30,75],"ycors":[75,30,225,270],"type":"polygon","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true},{"xcors":[30,75,270,225],"ycors":[75,30,225,270],"type":"polygon","color":"rgba(141, 141, 141, 1.0)","filled":true,"marked":true}]}}, {"default":{}});
var BreedManager = workspace.breedManager;
var LayoutManager = workspace.layoutManager;
var LinkPrims = workspace.linkPrims;
var ListPrims = workspace.listPrims;
var Prims = workspace.prims;
var SelfPrims = workspace.selfPrims;
var SelfManager = workspace.selfManager;
var Updater = workspace.updater;
var world = workspace.world;
var Call = tortoise_require('util/call');
var ColorModel = tortoise_require('util/colormodel');
var Exception = tortoise_require('util/exception');
var Trig = tortoise_require('util/trig');
var Type = tortoise_require('util/typechecker');
var notImplemented = tortoise_require('util/notimplemented');
var Dump = tortoise_require('engine/dump');
var Link = tortoise_require('engine/core/link');
var LinkSet = tortoise_require('engine/core/linkset');
var Nobody = tortoise_require('engine/core/nobody');
var PatchSet = tortoise_require('engine/core/patchset');
var Turtle = tortoise_require('engine/core/turtle');
var TurtleSet = tortoise_require('engine/core/turtleset');
var Tasks = tortoise_require('engine/prim/tasks');
var AgentModel = tortoise_require('agentmodel');
var Denuller = tortoise_require('nashorn/denuller');
var Random = tortoise_require('shim/random');
var StrictMath = tortoise_require('shim/strictmath');
function setup() {
world.clearAll();
world.patches().ask(function() {
SelfPrims.setPatchVariable('pcolor', 55);
}, true);
if (world.observer.getGlobal('grass?')) {
world.patches().ask(function() {
SelfPrims.setPatchVariable('pcolor', ListPrims.oneOf([55, 35]));
if (Prims.equality(SelfPrims.getPatchVariable('pcolor'), 55)) {
SelfPrims.setPatchVariable('countdown', world.observer.getGlobal('grass-regrowth-time'));
}
else {
SelfPrims.setPatchVariable('countdown', Prims.random(world.observer.getGlobal('grass-regrowth-time')));
}
}, true);
}
BreedManager.setDefaultShape(world.turtleManager.turtlesOfBreed("SHEEP").getBreedName(), "sheep")
world.turtleManager.createTurtles(world.observer.getGlobal('initial-number-sheep'), 'SHEEP').ask(function() {
SelfPrims.setVariable('color', 9.9);
SelfPrims.setVariable('size', 1.5);
SelfPrims.setVariable('label-color', (105 - 2));
SelfPrims.setVariable('energy', Prims.random((2 * world.observer.getGlobal('sheep-gain-from-food'))));
SelfPrims.setXY(world.topology.randomXcor(), world.topology.randomYcor());
}, true);
BreedManager.setDefaultShape(world.turtleManager.turtlesOfBreed("WOLVES").getBreedName(), "wolf")
world.turtleManager.createTurtles(world.observer.getGlobal('initial-number-wolves'), 'WOLVES').ask(function() {
SelfPrims.setVariable('color', 0);
SelfPrims.setVariable('size', 2);
SelfPrims.setVariable('energy', Prims.random((2 * world.observer.getGlobal('wolf-gain-from-food'))));
SelfPrims.setXY(world.topology.randomXcor(), world.topology.randomYcor());
}, true);
Call(displayLabels);
world.observer.setGlobal('grass', world.patches().agentFilter(function() {
return Prims.equality(SelfPrims.getPatchVariable('pcolor'), 55);
}).size());
world.ticker.reset();
}
function go() {
if (!world.turtles().nonEmpty()) {
throw new Exception.StopInterrupt;
}
world.turtleManager.turtlesOfBreed("SHEEP").ask(function() {
Call(move);
if (world.observer.getGlobal('grass?')) {
SelfPrims.setVariable('energy', (SelfPrims.getVariable('energy') - 1));
Call(eatGrass);
}
Call(death);
Call(reproduceSheep);
}, true);
world.turtleManager.turtlesOfBreed("WOLVES").ask(function() {
Call(move);
SelfPrims.setVariable('energy', (SelfPrims.getVariable('energy') - 1));
Call(catchSheep);
Call(death);
Call(reproduceWolves);
}, true);
if (world.observer.getGlobal('grass?')) {
world.patches().ask(function() {
Call(growGrass);
}, true);
}
world.observer.setGlobal('grass', world.patches().agentFilter(function() {
return Prims.equality(SelfPrims.getPatchVariable('pcolor'), 55);
}).size());
world.ticker.tick();
Call(displayLabels);
}
function move() {
SelfPrims.right(Prims.random(50));
SelfPrims.left(Prims.random(50));
SelfPrims.fd(1);
}
function eatGrass() {
if (Prims.equality(SelfPrims.getPatchVariable('pcolor'), 55)) {
SelfPrims.setPatchVariable('pcolor', 35);
SelfPrims.setVariable('energy', (SelfPrims.getVariable('energy') + world.observer.getGlobal('sheep-gain-from-food')));
}
}
function reproduceSheep() {
if (Prims.lt(Prims.randomFloat(100), world.observer.getGlobal('sheep-reproduce'))) {
SelfPrims.setVariable('energy', (SelfPrims.getVariable('energy') / 2));
SelfPrims.hatch(1, '').ask(function() {
SelfPrims.right(Prims.randomFloat(360));
SelfPrims.fd(1);
}, true);
}
}
function reproduceWolves() {
if (Prims.lt(Prims.randomFloat(100), world.observer.getGlobal('wolf-reproduce'))) {
SelfPrims.setVariable('energy', (SelfPrims.getVariable('energy') / 2));
SelfPrims.hatch(1, '').ask(function() {
SelfPrims.right(Prims.randomFloat(360));
SelfPrims.fd(1);
}, true);
}
}
function catchSheep() {
var prey = ListPrims.oneOf(SelfManager.self().breedHere("SHEEP"));
if (!Prims.equality(prey, Nobody)) {
prey.ask(function() {
SelfPrims.die();
}, true);
SelfPrims.setVariable('energy', (SelfPrims.getVariable('energy') + world.observer.getGlobal('wolf-gain-from-food')));
}
}
function death() {
if (Prims.lt(SelfPrims.getVariable('energy'), 0)) {
SelfPrims.die();
}
}
function growGrass() {
if (Prims.equality(SelfPrims.getPatchVariable('pcolor'), 35)) {
if (Prims.lte(SelfPrims.getPatchVariable('countdown'), 0)) {
SelfPrims.setPatchVariable('pcolor', 55);
SelfPrims.setPatchVariable('countdown', world.observer.getGlobal('grass-regrowth-time'));
}
else {
SelfPrims.setPatchVariable('countdown', (SelfPrims.getPatchVariable('countdown') - 1));
}
}
}
function displayLabels() {
world.turtles().ask(function() {
SelfPrims.setVariable('label', "");
}, true);
if (world.observer.getGlobal('show-energy?')) {
world.turtleManager.turtlesOfBreed("WOLVES").ask(function() {
SelfPrims.setVariable('label', StrictMath.round(SelfPrims.getVariable('energy')));
}, true);
if (world.observer.getGlobal('grass?')) {
world.turtleManager.turtlesOfBreed("SHEEP").ask(function() {
SelfPrims.setVariable('label', StrictMath.round(SelfPrims.getVariable('energy')));
}, true);
}
}
}
world.observer.setGlobal('initial-number-sheep', 100);
world.observer.setGlobal('sheep-gain-from-food', 4);
world.observer.setGlobal('sheep-reproduce', 4);
world.observer.setGlobal('initial-number-wolves', 50);
world.observer.setGlobal('wolf-gain-from-food', 20);
world.observer.setGlobal('wolf-reproduce', 5);
world.observer.setGlobal('grass?', true);
world.observer.setGlobal('grass-regrowth-time', 30);
world.observer.setGlobal('show-energy?', false);Widgets.addView(350, 10, 819, 500)
Widgets.addSlider("initial-number-sheep", 3, 150, 177, 183, function(newVal) { world.observer.setGlobal('initial-number-sheep', newVal); }, 0, 250, 100.0, 1)
Widgets.addSlider("sheep-gain-from-food", 3, 187, 177, 220, function(newVal) { world.observer.setGlobal('sheep-gain-from-food', newVal); }, 0.0, 50.0, 4.0, 1.0)
Widgets.addSlider("sheep-reproduce", 3, 222, 177, 255, function(newVal) { world.observer.setGlobal('sheep-reproduce', newVal); }, 1.0, 20.0, 4.0, 1.0)
Widgets.addSlider("initial-number-wolves", 181, 150, 346, 183, function(newVal) { world.observer.setGlobal('initial-number-wolves', newVal); }, 0, 250, 50.0, 1)
Widgets.addSlider("wolf-gain-from-food", 181, 186, 346, 219, function(newVal) { world.observer.setGlobal('wolf-gain-from-food', newVal); }, 0.0, 100.0, 20.0, 1.0)
Widgets.addSlider("wolf-reproduce", 181, 222, 346, 255, function(newVal) { world.observer.setGlobal('wolf-reproduce', newVal); }, 0.0, 20.0, 5.0, 1.0)
Widgets.addSwitch("grass?", 5, 87, 99, 120, function(newVal) { world.observer.setGlobal('grass?', newVal); })
Widgets.addSlider("grass-regrowth-time", 106, 88, 318, 121, function(newVal) { world.observer.setGlobal('grass-regrowth-time', newVal); }, 0, 100, 30.0, 1)
Widgets.addButton("setup", 8, 28, 77, 61, function() { Call(setup); }, false)
Widgets.addButton("go", 90, 28, 157, 61, function() { Call(go); }, true)
Widgets.addPlot("populations", 12, 312, 328, 509, 0.0, 100.0, 0.0, 100.0 )
Widgets.addMonitor("sheep", 50, 265, 121, 310, function() { return Prims.precision(world.turtleManager.turtlesOfBreed("SHEEP").size(), 3) })
Widgets.addMonitor("wolves", 125, 265, 207, 310, function() { return Prims.precision(world.turtleManager.turtlesOfBreed("WOLVES").size(), 3) })
Widgets.addMonitor("grass / 4", 211, 265, 287, 310, function() { return Prims.precision((world.observer.getGlobal('grass') / 4), 0) })
Widgets.addTextBox("Sheep settings", 8, 130, 148, 149)
Widgets.addTextBox("Wolf settings", 186, 130, 299, 148)
Widgets.addTextBox("Grass settings", 9, 68, 161, 86)
Widgets.addSwitch("show-energy?", 167, 28, 303, 61, function(newVal) { world.observer.setGlobal('show-energy?', newVal); })
<!-- If it has child nodes, it has already been parsed from Markdown. --JAB (8/28/14) -->
<!-- Grabbing `nodeValue` allows us to basically unescape the HTML --JAB (8/28/14) -->
var infoElem = document.getElementById('netlogo-info');
if (!infoElem.childNodes[0].hasChildNodes())
infoElem.innerHTML = markdown.toHTML(infoElem.childNodes[0].nodeValue.trim());
var session = new SessionLite(document.getElementsByClassName('view-container')[0]);
var runner = -1;
var tickCounter = document.getElementById('tick-counter');
var lastUpdate = 0;
var speedSlider = document.getElementById('speed-slider');
window.addEventListener('load', initPage);
if(useGoogleGraph) {
session.graph = GoogleGraph;
Grapher.graph = GoogleGraph;
}
Widgets.addTo(session);
function initPage() {
speedSlider.value = 0.5;
tickCounter.textContent = '0';
initCodeVisibility();
initInfoVisibility();
}
// NetLogo code visibility stuff below
const VISIBILITY_CSS = 'display';
const HIDDEN_CSS = 'none';
const SHOW_STR = 'Show ';
const HIDE_STR = 'Hide ';
const CODE_LABEL = 'NetLogo Code';
const INFO_LABEL = 'Model Info';
var codeSpan = document.getElementById('netlogo-code');
var infoSpan = document.getElementById('netlogo-info');
var toggleCodeButton = document.getElementById('toggle-code-button');
var toggleInfoButton = document.getElementById('toggle-info-button');
function initVisibility(textElem, button, label) {
textElem.style[VISIBILITY_CSS] = HIDDEN_CSS;
button.value = SHOW_STR + label;
}
function toggleVisibility(span, button, label) {
var style = window.getComputedStyle(span);
var isVisible = style.getPropertyValue(VISIBILITY_CSS) !== HIDDEN_CSS;
if (isVisible) {
span.style[VISIBILITY_CSS] = HIDDEN_CSS;
button.value = SHOW_STR + label;
}
else {
span.style[VISIBILITY_CSS] = 'block';
button.value = HIDE_STR + label;
}
}
var initCodeVisibility = initVisibility. bind(this, codeSpan, toggleCodeButton, CODE_LABEL);
var toggleCodeVisibility = toggleVisibility.bind(this, codeSpan, toggleCodeButton, CODE_LABEL);
var initInfoVisibility = initVisibility. bind(this, infoSpan, toggleInfoButton, INFO_LABEL);
var toggleInfoVisibility = toggleVisibility.bind(this, infoSpan, toggleInfoButton, INFO_LABEL);
session.update(Updater.collectUpdates());
function updateTickCounter() {
try {
tickCounter.textContent = typeof world.ticker.tickCount() === 'number' ? world.ticker.tickCount() : '';
} catch(err) {
}
}
function goForever() {
var speed = Math.exp(speedSlider.value * 8);
var delta = Math.min(new Date().getTime() - lastUpdate, 30);
var numUpdates = Math.floor(speed * delta / 1000 + 1);
for (var i=0; i < numUpdates; i++) {
Widgets.runUpdateFuncs()
}
updateTickCounter();
session.update(Updater.collectUpdates());
lastUpdate = new Date().getTime();
runner = setTimeout(goForever, 1000 / speed);
}
goForever()
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment